/**************************************************************************
* Function: I5642018_CheckMediaObject
*
* Notes:
ATI#597
API JDEGTAllocFetch no longer appears to work at all. Will completely re-write this for 9.0
Logic:
- Check to See if there are any attachments of any type
- If there is only one attachment and it is a empty/blank text attachments, then delete it.
- If there is an empty/blank text attachment, but there are other non-text attachments DONT delete
anything.
*
* Returns:
*
* Parameters:
**************************************************************************/
static ID I5642018_CheckMediaObject(LPBHVRCOM lpBhvrCom, LPVOID lpVoid, HUSER hUser, LPD5642018_CACHE_PCA lpCachePCA)
{
/************************************************************************
* Variable declarations
************************************************************************/
ID idReturn = ER_SUCCESS;
JDEDB_RESULT jdedbResult = JDEDB_FAILED;
DSGT5642PCAA dsMOKey = {0};
LPMODATA pMOData = (LPMODATA)NULL;
long i, nTotalRec=0;
BOOL bTextAttachmentsFound = FALSE;
/************************************************************************
* Main Processing
************************************************************************/
/* check to see if any attachments exist */
jdeStrncpy(dsMOKey.szCompanyKeyOrderNo, lpCachePCA->szCompanyKeyOrderNo, DIM(dsMOKey.szCompanyKeyOrderNo)-1);
MathCopy(&dsMOKey.mnDocumentOrderInvoiceE, &lpCachePCA->mnDocumentOrderInvoiceE );
jdeStrncpy(dsMOKey.szOrderType, lpCachePCA->szOrderType, DIM(dsMOKey.szOrderType)-1);
MathCopy(&dsMOKey.mnIdentifierShortItem, &lpCachePCA->mnIdentifierShortItem );
jdeStrncpy(dsMOKey.szReasonCode, lpCachePCA->szReasonCode, DIM(dsMOKey.szReasonCode)-1);
jdedbResult = jdeGTGet_AllMOType(B5642018_MEDIA_OBJECT_DS, (void *)&dsMOKey, &pMOData, &nTotalRec);
if(jdedbResult != JDEDB_PASSED || !pMOData || nTotalRec <= 0)
goto FunctionCleanUp;
/* check for a blank text attachments */
for(i = 0; i < nTotalRec; i++)
{
LPMODATA pMODataTmp=(pMOData + i), pMODataText=(LPMODATA)NULL;
long j, nTotalRecText=0;
if(pMODataTmp->nMOType != OBJ_RTFTEXT)
continue;
/* if we find at least one non-blank text attachment, no need to go any further */
jdedbResult = jdeGTGet_GenericText(
B5642018_MEDIA_OBJECT_DS, (void *)&dsMOKey, pMODataTmp->nSeq, &pMODataText, &nTotalRecText);
if(jdedbResult != JDEDB_PASSED || !pMODataText)
{
if(pMODataText)
jdeGTFreeMOData(pMODataText, nTotalRecText);
goto FunctionCleanUp;
}
for(j = 0; j < nTotalRecText; j++)
{
if( !IsStringBlank((pMODataText+j)->pData) )
{
jdeGTFreeMOData(pMODataText, nTotalRecText);
goto FunctionCleanUp;
}
}
jdeGTFreeMOData(pMODataText, nTotalRecText);
bTextAttachmentsFound = TRUE;
}
/* if this point is reached it means that any text attachments found were blank, delete all text attachments */
if(bTextAttachmentsFound)
{
jdeGTDelete_AllText(B5642018_MEDIA_OBJECT_DS, (void *)&dsMOKey);
}
/************************************************************************
* Function Clean Up
************************************************************************/
FunctionCleanUp:
if(pMOData)
jdeGTFreeMOData(pMOData, nTotalRec);
return idReturn;
}