project QadFinancials > class TConCheck > method TechnicalValidation09DDocument

Description

Submethod of TechnicalValidation for checking DDocument


Parameters


iiCompanyIDinputinteger
itFromDateinputdate
itToDateinputdate
oiErrorNumbersoutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TConCheck.TechnicalValidation


program code (program1/tconcheck.p)

/**********************************************************************************/
/* CheckARPayments                                                                */
/**********************************************************************************/
PUT STREAM sTechOut unformatted " " skip. 
PUT STREAM sTechOut unformatted vcPrefix2 + "Start Validation of AR payments (ALL)" skip.

assign vcValidStatus  = 'INITIAL,ACCEPTED,PORTFOLIO,INCASSO,DISCONT,BOUNCED,PAID,PAIDCON,VOID'.
assign vcValidType    = 'DRAFT,TRANSFER,CHEQUE,PROMISSORYNOTE,SUMMARYSTATEMENT,DIRECTDEBIT,CREDITCARD'.
assign vcValidSubType = 'AUT,MAN'.

for each DDocument fields (DDocument.Company_ID DDocument.DDocument_ID) where DDocumentCreationDate >= itFromDate and DDocumentCreationDate <= itToDate
    no-lock break by DDocument.Company_ID :
   if first-of (DDocument.Company_ID) and not can-find (Company of DDocument) 
   then do:
       PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";DDocument found with no valid company" skip.
       assign oiErrorNumbers = oiErrorNumbers + 1.
   end.
end.

/* Go through each Company */
for each company no-lock :

    /* ==================================================================================== */
    /* Do some checking on DDocument                                                        */
    /* ==================================================================================== */
    for each DDocument OF company  
        where DDocument.DDocumentCreationDate >= itFromDate and
              DDocument.DDocumentCreationDate <= itToDate no-lock :

        if(not can-do(vcValidStatus,DDocument.DDocumentStatus)) 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";Invalid document status '" + DDocument.DDocumentStatus + "'." skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        if(not can-do(vcValidType,DDocument.DDocumentType)) 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";Invalid document type '" + DDocument.DDocumentType + "'." skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        if(not can-do(vcValidSubType,DDocument.DDocumentSubType)) 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";Invalid document sub-type '" + DDocument.DDocumentSubType + "'." skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        assign vdAllocatedTC = 0
               vdDiscountTC  = 0.

        /* Note that DDocumentInvoiceXref accounts for staged payments */
        for each DDocumentInvoiceXref no-lock where 
                 DDocumentInvoiceXref.DDocument_id=DDocument.DDocument_id:

            assign vdAllocatedStageTC = 0
                   vdDiscountStageTC = 0.

            for each DDocInvoiceXrefStage no-lock where 
                     DDocInvoiceXrefStage.DDocumentInvoiceXref_id=DDocumentInvoiceXref.DDocumentInvoiceXref_id:

                assign vdAllocatedStageTC = vdAllocatedStageTC + DDocInvoiceXrefStage.DDocInvoiceXrefStageAlloTC
                       vdDiscountStageTC  = vdDiscountStageTC + DDocInvoiceXrefStage.DDocInvoiceXrefStageDiscTC.
            end.
          
            assign vdAllocatedTC = vdAllocatedTC + DDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
                   vdDiscountTC  = vdDiscountTC  + DDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC.

            if (vdAllocatedStageTC <> 0 and 
                abs(vdAllocatedStageTC) - abs(vdDiscountStageTC) <> abs(DDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC) - abs(DDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC)) 
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DDocumentInvoiceXref;" + string (DDocument.DDocument_ID) + "," + string(DDocumentInvoiceXref.DDocumentInvoiceXref_id) + ";Unbalanced staged payment: " + string(abs(vdAllocatedStageTC) - abs(vdDiscountStageTC)) + ":" + string(abs(DDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC) - abs(DDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC)) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.

        end. /* for each DDocumentInvoiceXref */

        if(vdAllocatedStageTC <> 0 and abs(vdAllocatedTC) - abs(vdDiscountTC) <> abs(vdAllocatedStageTC) - abs(vdDiscountStageTC)) 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";Unbalanced staged payment: " + string(abs(vdAllocatedTC) - abs(vdDiscountTC)) + ":" + string(abs(vdAllocatedStageTC) - abs(vdDiscountStageTC)) skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.
        
        if(not can-do("VOID,BOUNCED,INITIAL",DDocument.DDocumentStatus) and abs(vdAllocatedTC) - abs(vdDiscountTC) <> abs(DDocument.DDocumentOriginalDebitTC + DDocument.DDocumentOriginalCreditTC)) 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";Unbalanced payment: " + string(abs(vdAllocatedTC) - abs(vdDiscountTC)) + ":" +  string(vdAllocatedStageTC - vdDiscountStageTC) + ":" + string(vdAllocatedStageTC - vdDiscountStageTC) + ":" + string(DDocument.DDocumentOriginalCreditTC) + ":" + string(DDocument.DDocumentOriginalDebitTC) + ":" + DDocument.DDocumentStatus + ":"+ DDocument.DDocumentType skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        if(DDocument.DCollection_ID <> ? and DDocument.DCollection_ID <> 0) then do:
            find DCollection of DDocument no-lock no-error.
            if not available DCollection 
            then do:
                 PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";No CCollection found." skip.
                 assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
        end.

        find Debtor of DDocument no-lock no-error.
        if not available Debtor 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";No Debtor found." skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        find Currency of DDocument no-lock no-error.
        if not available Currency
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";No Currency found." skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        find GL of DDocument no-lock no-error.
        if not available GL 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";No GL found." skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.

        if(DDocument.DDocumentSubType = "AUT" ) then do:
            find DPaySel of DDocument no-lock no-error.
            if not available DPaySel 
            then do:
                 PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";No DPaySel found." skip.
                 assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
        end.

        if(DDocument.CreationUsr_ID <> ? and DDocument.CreationUsr_ID <> 0) then do:
            find Usr where Usr.Usr_ID = DDocument.CreationUsr_ID no-lock no-error.
            if not available Usr 
            then do:
                 PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";No Usr found." skip.
                 assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
        end.

        find BankNumber of DDocument no-lock no-error.
        if not available BankNumber 
        then do:
             PUT STREAM sTechOut unformatted vcPrefix + "DDocument;" + string (DDocument.DDocument_ID) + ";No BankNumber found." skip.
             assign oiErrorNumbers = oiErrorNumbers + 1.
        end.
    end . /* for each DDocument */
end. /* for each company */

PUT STREAM sTechOut unformatted vcPrefix2 + "END Validation of AR payments" skip.