project QadFinancials > class BCInvoice > method UpdateCInvoiceBank

Description

Update the banknumber of the supplier invoice when the own banknumber of the Supplier payment changed


Parameters


tUpdateCInvoiceBankNumberinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCDocument.AdditionalUpdatesCInvoice


program code (program5/bcinvoice.p)

assign oiReturnStatus = -98.

for each tUpdateCInvoiceBankNumber:
    if not can-find (first tCInvoice where
                           tCInvoice.CInvoice_ID = tUpdateCInvoiceBankNumber.tiCInvoiceId)
    then assign vcListCInvoiceIds =  if vcListCInvoiceIds = "":U
                                     then string(tUpdateCInvoiceBankNumber.tiCInvoiceId)
                                     else
                                     if lookup(string(tUpdateCInvoiceBankNumber.tiCInvoiceId), vcListCInvoiceIds, chr(4)) = 0
                                     then vcListCInvoiceIds + chr(4) + string (tUpdateCInvoiceBankNumber.tiCInvoiceId)
                                     else vcListCInvoiceIds.
end.

if vcListCInvoiceIds <> "":U
then do:
    <M-2 run DataLoad
       (input  '':U (icRowids), 
        input  vcListCinvoiceIds (icPkeys), 
        input  '':U (icObjectIds), 
        input  '':U (icFreeform), 
        input  true (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    if viFcReturnSuper <> 0
    then do:
        assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then do :
            assign vcMessage      = trim(substitute(#T-4'Data could not be loaded: unable to load the list of supplier invoices (&1).':100(1107)T-4#, replace(vcListCInvoiceIds, chr(4), ",":U))).
            <M-3 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  1 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-8871':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>    
            return.
        end. /* if oiReturnStatus < 0 */
    end. /* if viFcReturnSuper <> 0 */
end. /* if vcListCInvoiceIds <> "":U */

for each tUpdateCInvoiceBankNumber:
    find first tCInvoice where
               tCInvoice.CInvoice_ID = tUpdateCInvoiceBankNumber.tiCInvoiceId
               no-error.
    if not available tCInvoice
    then do:
        assign vcMessage = trim(#T-16'The invoice was not found. The system cannot update it.':100(65684)t-16#).
        <M-5 run SetMessage
          (input  vcMessage (icMessage), 
           input  '':U (icArguments), 
           input  '':U (icFieldName), 
           input  '':U (icFieldValue), 
           input  'E':U (icType), 
           input  1 (iiSeverity), 
           input  '':U (icRowid), 
           input  'QadFin-8872':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BCInvoice>    
        Next.
    end. /* if not available tDInvoice */
               
    
       
    if can-find (first tCInvoiceBank where
               tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
               tCInvoiceBank.tc_Status    <> "D":U and
               tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiOldBankNumberId)
    then do:
   
        find first tCInvoiceBank where
                   tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
                   tCInvoiceBank.tc_Status    <> "D":U and
                   tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId
                   no-lock no-error.
        /*Same bankNumber found, consolidate to the new banknumber and delete the old one */
        if available tCInvoiceBank
        then do:
            assign tCInvoiceBank.CInvoiceBankToPayTC = tCInvoiceBank.CInvoiceBankToPayTC + tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC
                   tCInvoiceBank.tlValidatePayment   = false.
            if tCInvoiceBank.tc_Status = "":U
            then assign tCInvoiceBank.tc_Status = "C":U.
            find first tCInvoiceBank where
                       tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
                       tCInvoiceBank.tc_Status    <> "D":U and
                       tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiOldBankNumberId
                       no-lock no-error.
            if available tCInvoiceBank
            then do:
                if tCInvoiceBank.tc_Status = "N":U
                then delete tCInvoice.
                else assign tCInvoiceBank.tc_Status = "D":U.
            end.
        end.
        else do:
            find first tCInvoiceBank where
                       tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
                       tCInvoiceBank.tc_Status    <> "D":U and
                       tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiOldBankNumberId
                       no-lock no-error.
            assign tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId.
            assign tCInvoiceBank.tc_Status = if tCInvoiceBank.tc_Status = "":U then "C":U else tCInvoiceBank.tc_Status.
            

            /* delete the Payment attributes if Payformat changed */
            if tUpdateCInvoiceBankNumber.tlPayFormatChanged
            then do:
                for each tCInvoiceBankPayCode where 
                         tCInvoiceBankPayCode.tc_ParentRowid = tCInvoiceBank.tc_Rowid and
                         tCInvoiceBankPayCode.tc_Status      <> "D":U:
                    
                        if tCInvoiceBankPayCode.tc_Status = "N":U
                        then delete tCInvoiceBankPayCode. 
                        else assign tCInvoiceBankPayCode.tc_Status = "D":U.
                end.
            end.  
        end.
    end.
end.
 
if oiReturnStatus = -98
then assign oiReturnStatus = 0.