project QadFinancials > class BDInvoice > method UpdateDeductionForBouncedDDoc


Parameters


iiDDocumentIDinputinteger
icDDocStatusinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDDocument.AdditionalUpdatesDeductions


program code (program1/bdinvoice.p)

/* ====================================================================================== *
 * Method       :   Update Deduction Detail for Bounced Payment                           *
 * Description  :      
1. For the deduction detail lines with status "Pending" or "Approved for Credit", the status of the deduction detail should be 'Credited' after bouncing.
2. For the deduction detail lines with status "Approved Write-Off", "Auto Write-off", "Credited" or "Rejected", the status of the deduction detail should be 'Rejected' after bouncing.
3. After bouncing the payment, the result of the bouncing should be appended in the field 'Approve/Reject Comment'.
 The result should be displayed as 'Bounced-***', *** is the original deduction detail status before bouncing.    
 * -------------------------------------------------------------------------------------- *
 * Parameters   :       iiDDocumentID as Integer                                          *
 * ====================================================================================== */
 
assign oiReturnStatus = -98
       viLocalReturn  = 0
       vcDInvoiceIdList = '':U.

MAIN_BLOCK:
do on error undo, return:
    /* Default output parameters */
    /*Reject? continue*/
    /*assign vhFcComponent = ?. */
    <Q-64 run GetPostingInfoByDocumentID (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input iiDDocumentID, (DDocumentID)
        output dataset tqGetPostingInfoByDocumentID) in BDDocument>
           
    for first tqGetPostingInfoByDocumentID:
        vcDeductionPostingKey = string(tqGetPostingInfoByDocumentID.tiPostingYear) + '/':U + tqGetPostingInfoByDocumentID.tcJournalCode + '/':U + string(tiPostingVoucher, "999999999":U).
        
        <Q-10 run GetDeductionByDDocumentID (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input iiDDocumentID, (DDocumentID)
            output dataset tqGetDeductionByDDocumentID) in BDDocument>
        
        for each tqGetDeductionByDDocumentID:
                    
            <Q-82 run GetPostingTextByDInvoiceID (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input tqGetDeductionByDDocumentID.tiDInvoice_ID, (DInvoiceID)
                output dataset tqGetPostingTextByDInvoiceID) in BDInvoice>

             if can-find(first tqGetPostingTextByDInvoiceID where tqGetPostingTextByDInvoiceID.tcPostingText begins vcDeductionPostingKey) then
                assign vcDInvoiceIdList = vcDInvoiceIdList + string(tqGetDeductionByDDocumentID.tiDInvoice_Id) + chr(4).
        end. /*for first tqGetPostingInfoByDocumentID*/
    end. /*for first tqGetPostingInfoByDocumentID*/ 
    /*
    <Q-19 run GetDeductionByDDocumentID (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input iiDDocumentID, (DDocumentID)
        output dataset tqGetDeductionByDDocumentID) in BDDocument>
    /*Loop the DInvoice_ID*/
    for each tqGetDeductionByDDocumentID:
        assign vcDInvoiceIdList = vcDInvoiceIdList + string(tqGetDeductionByDDocumentID.tiDInvoice_Id) + chr(4).
    end.
    */
    if vcDInvoiceIdList = '':U then 
    do:
        assign oiReturnStatus = 0.
        return.
    end.
    assign vcDInvoiceIdList = substring(vcDInvoiceIdList, 1, length(vcDInvoiceIdList,'CHARACTER') - 1 , 'CHARACTER').
    /* load the original dinvoicededuction data */
    <M-65 run DataLoad
        (input  ? (icRowids), 
        input  vcDInvoiceIdList (icPkeys), 
        input  ? (icObjectIds), 
        input  ? (icFreeform), 
        input  ? (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice> 

    for each tDInvoiceDeduction:
      
        find first tqGetDeductionByDDocumentID where tqGetDeductionByDDocumentID.tiDInvoice_Id = tDInvoiceDeduction.DInvoice_ID no-error.

        if available(tqGetDeductionByDDocumentID) and (icDDocStatus = {&DOCUMENTSTATUS-BOUNCED} or icDDocStatus = {&DOCUMENTSTATUS-INIT}) then
        do:
            assign tDInvoiceDeduction.tc_status = "C":U.

            vcOldDeductionStatus = '':U.

            vcOldDeductionStatus = <M-60 GetDeductionStatusTranslation
                                      (input  tDInvoiceDeduction.DInvoiceDeductionStatus (icStatus), 
                                       output oiReturnStatus (oiReturnStatus)) in BDInvoice>.

            if icDDocStatus = {&DOCUMENTSTATUS-BOUNCED} then
                tDInvoiceDeduction.DInvoiceDeductionApRejCom = trim({&DOCUMENTSTATUS-BOUNCED-TR}) + "--" +  trim(vcOldDeductionStatus).
            else
                tDInvoiceDeduction.DInvoiceDeductionApRejCom = trim({&DOCUMENTSTATUS-INIT-TR}) + "--" + trim(vcOldDeductionStatus).
    
            if tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT} 
                or tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-PENDING} then
            do:
                tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-CREDITED}.
            end. 
            else if tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-APPROVEWRITEOFF} 
                or tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-CREDITED}  
                or  tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-REJECTED} 
                or  tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-WRITE-OFF} then
            do:
                tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-REJECTED}.
            end.  
        end. 
  
    end.

    <M-13 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>

    if viFcReturnSuper <> 0 then 
        assign viLocalReturn = viFcReturnSuper.

    if viFcReturnSuper <  0 then 
        leave MAIN_BLOCK.

    <M-35 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>

    if viFcReturnSuper <> 0 then 
        assign viLocalReturn = viFcReturnSuper.

    if viFcReturnSuper <  0 then 
        leave MAIN_BLOCK.

end. /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturn.