project QadFinancials > class BDInvoice > method ApiUpdateCInvoiceWithNewBank

Description

This method is called to update the bank linked to a Customer Invoice before the Payment selection is created.

It is a business practice in Brazil only to decide which bank will issue the "Boleto Bancario" and send to the
customer after the customer invoice creation.

Bank Number ID or a combination of Own Bank Number, Entity Code, Gl Code and Debtor Code can used to identify the bank details to change to Invoice ID or a combination of Posting Year, Journal Code, Voucher Number and Company Id can be used the invoice in the supplied dataset

oiReturnStatus
-1 - Invalid Bank Number ID

output parameter ErrorCode per invoice update
0 - Invoice Update Success
-2 - Invalid Own Bank Number
-3 - Error retrieving Bank Details
-4 - Bank Details not setup for customer
-5 - Invoice can not be on a Customer Payment Selection Payment
-6 - Bank not found for Invoice
-7 - Invoice must be open to change bank details
-8 - Invoice not found


Parameters


tApiUpdateDInvoiceWithNewBankinput-outputtemp-table
iiBankNumber_IDinputinteger
icOwnBankNumberinputcharacter
icPayFormatTypeCodeinputcharacter
icGlAccountCodeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.TestApiUpdateCInvoiceWithNewBank


program code (program3/bdinvoice.p)

/* ===================================*/
/* This method is called to update the bank linked to a Customer Invoice before the Payment selection is created. */
/* It is a business practice in Brazil only to decide which bank will issue the "Boleto Bancario" and send to the */
/* customer after the customer invoice creation. */

/* Bank Number ID or a combination of Own Bank Number, Entity Code, Gl Code and Debtor Code can used to identify the bank details to change to */

/* Invoice ID or a combination of Posting Year, Journal Code, Voucher Number and Company Id can be used the invoice in the supplied dataset */

/* oiReturnStatus */
/* -1 - Invalid Bank Number ID */
  
/* output parameter ErrorCode per invoice update                        */
/*  0 - Invoice Update Success                                          */
/* -2 - Invalid Own Bank Number                                         */
/* -3 - Error retrieving Bank Details                                   */
/* -4 - Bank Details not setup for customer                             */
/* -5 - Invoice can not be on a Customer Payment Selection Payment      */
/* -6 - Bank not found for Invoice                                      */
/* -7 - Invoice must be open to change bank details                     */
/* -8 - Invoice not found                                               */

/* ==================================================*/

<M-19 run ClearData  (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>

if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
    then return.

assign     
    oiReturnStatus = 0.   
   
if iiBankNumber_ID = ? and (icOwnBankNumber = "" or icOwnBankNumber = ?) 
then do:
   
    assign oiReturnStatus = -2    
           vcMessage = #T-81'Invalid Bank Details supplied to API':255(518197461)T-81#.
    
     <M-84 run SetMessage
        (input  vcMessage (icMessage), 
         input  '':U (icArguments), 
         input  '':U (icFieldName), 
         input  '':U (icFieldValue), 
         input  'E':U (icType), 
         input  2 (iiSeverity), 
         input  '':U (icRowid), 
         input  'qadfin-154453':U (icFcMsgNumber), 
         input  '':U (icFcExplanation), 
         input  '':U (icFcIdentification), 
         input  '':U (icFcContext), 
         output viFcReturnSuper (oiReturnStatus)) in BDInvoice>             

end.
else do:

    /* Load data from the database into the class temp-tables of the business class */      
    <M-10 run LoadCInvoiceForNewBankAPI
       (input  tApiUpdateDInvoiceWithNewBank (tApiUpdateDInvoiceWithNewBank), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice> 
      
    if oiReturnStatus < 0
        then return.      
          
    /* Loop over the invoices and update the bank details */  
    for each tApiUpdateDInvoiceWithNewBank:
    
        assign 
            tApiUpdateDInvoiceWithNewBank.tiErrorCode = -9.          
        
        
        find first tDInvoice where tDInvoice.DInvoice_ID = tApiUpdateDInvoiceWithNewBank.tiDInvoice_ID no-lock no-error.
                                      
        if available tDInvoice
        then do:     
                               
            assign vcInvoiceDetails = trim(string(tDInvoice.DInvoicePostingYear)) + '/':U + 
                                      trim(tDInvoice.tcJournalCode) + '/':U + 
                                      trim(string(tDInvoice.DInvoiceVoucher)).
                 
            /* Verify that invoice is open */           
            if tDInvoice.DInvoiceIsOpen
            then do:                                               
                find first tDInvoiceBank where tDInvoiceBank.DInvoice_ID = tDInvoice.DInvoice_ID no-lock no-error.
                
                if available tDInvoiceBank
                then do:  
                    
                    /* Make sure the invoice isnt on a payment selection */  
                <Q-31 run DPaySelLineByParentObjectID (all) (Read) (NoCache)
                       (input tDInvoice.Dinvoice_ID, (ParentObjectID)
                        input {&PAYMENTSELECTIONTYPE-INVOICE}, (ObjectType)
                        input tDInvoice.Company_ID, (CompanyId)
                        input ?, (LineStatus)
                        output dataset tqDPaySelLineByParentObjectID) in BDPaymentSelection>
                                                   
                    if Not can-find (first tqDPaySelLineByParentObjectID 
                                            where tqDPaySelLineByParentObjectID.tiDPaySelLineParentObject_ID = tDInvoice.Dinvoice_ID 
                                            and tqDPaySelLineByParentObjectID.tcDPaySelLineObjectType = {&PAYMENTSELECTIONTYPE-INVOICE})                                                                                              
                    then do:  
                        /* Verify that the own bank number is valid for the customer/debtor */       
                        <Q-71 run DebtorBankNumberPayFormat (all) (Read) (NoCache)
                           (input tDInvoice.Company_ID, (CompanyId)
                            input tDInvoiceBank.BankNumber_ID, (BankNumberID)
                            output dataset tqDebtorBankNumberPayFormat) in BBankNumber>                                 
                            
                        if can-find (first tqDebtorBankNumberPayFormat 
                                                    where tqDebtorBankNumberPayFormat.tiDebtor_ID = tDInvoice.Debtor_ID )     
                        then do:                                                                                                          
                            if iiBankNumber_ID = ? or iiBankNumber_ID = 0 
                            then do: 
                                                                       
                                find first tqDebtorBankNumberPayFormat where 
                                           tqDebtorBankNumberPayFormat.tiDebtor_ID         = tDInvoice.Debtor_ID and 
                                           tqDebtorBankNumberPayFormat.tcOwnBankNumber     = icOwnBankNumber     and
                                           tqDebtorBankNumberPayFormat.tcOwnGLCode         = icGlAccountCode     and
                                           tqDebtorBankNumberPayFormat.tcPayFormatTypeCode = icPayFormatTypeCode no-error.
                                                                          
                                assign  iiBankNumber_ID = ?
                                        viBankNumber_ID = iiBankNumber_ID.
                                           
                                if available tqDebtorBankNumberPayFormat 
                                then do:                              
                                    assign viBankNumber_ID = tqDebtorBankNumberPayFormat.tiBankNumber_ID.
                                end.                                                                                   
                            end.
                            else do:                                                                                                    
                                assign viBankNumber_ID = iiBankNumber_ID.
                            end.                                
                            
                            if viBankNumber_ID <> ? 
                            then do:                                                                                                                                                    
                                /* Replace the old Bank number with new id*/                            
                                assign 
                                    tDInvoiceBank.tc_Status       = 'C':U
                                    tDInvoiceBank.tcOwnBankNumber = icOwnBankNumber
                                    tDInvoiceBank.BankNumber_ID   = viBankNumber_ID.
                                                                                                           
                                <M-72 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                                
                                if viFcReturnSuper <> 0
                                then do:                                        
                                        assign 
                                            tApiUpdateDInvoiceWithNewBank.tiErrorCode = -2
                                            tApiUpdateDInvoiceWithNewBank.tcErrorMessage = substitute(#T-6'Error updating Invoice (&1) with new Own Bank number':255(820278672)T-6#,vcInvoiceDetails).
                                end.
                                 
                                 /* Do the update for the invoice  */                           
                                <M-48 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                                 
                                if viFcReturnSuper <> 0 
                                then do:    
                                        assign 
                                            tApiUpdateDInvoiceWithNewBank.tiErrorCode = viFcReturnSuper
                                            tApiUpdateDInvoiceWithNewBank.tcErrorMessage = substitute(#T-34'Error updating bank details on customer invoice &1':255(76257788)T-34#,vcInvoiceDetails).
                                end.
                                else do:                               
                                        assign 
                                            tApiUpdateDInvoiceWithNewBank.tiErrorCode = 0
                                            tApiUpdateDInvoiceWithNewBank.tcErrorMessage = "".
                                end.   
                            end. /* if viBankNumber_ID <> ? */
                            else do:
                                assign 
                                    tApiUpdateDInvoiceWithNewBank.tiErrorCode = -3
                                    tApiUpdateDInvoiceWithNewBank.tcErrorMessage = substitute(#T-80'Error retrieving Bank Details for Invoice &1':255(459036611)T-80#,vcInvoiceDetails).
                            end.                               
                        end. /* can-find (first tqDebtorBankNumberPayFormat  */                
                        else do:                                                                
                            assign 
                                tApiUpdateDInvoiceWithNewBank.tiErrorCode = -4                                
                                tApiUpdateDInvoiceWithNewBank.tcErrorMessage = substitute(#T-49'Bank Details not setup for customer invoice &1':255(323454589)T-49#,vcInvoiceDetails).
                        end.        
                    end. /* if Not can-find (first tqDPaySelLineByParentObjectID */
                    else do:                             
                        assign 
                            tApiUpdateDInvoiceWithNewBank.tiErrorCode = -5
                            tApiUpdateDInvoiceWithNewBank.tcErrorMessage = substitute(#T-91'Invoice (&1) must not be on a Customer Payment Selection Payment':255(781495385)T-91#,vcInvoiceDetails).
                    end.                                                       
                end. /* if available tDInvoiceBank */                                                                                              
                else do:
                    assign 
                        tApiUpdateDInvoiceWithNewBank.tiErrorCode = -6
                        tApiUpdateDInvoiceWithNewBank.tcErrorMessage = substitute(#T-13'Bank Details not found for Invoice (&1)':255(785650567)T-13#,vcInvoiceDetails).
                end.                      
            end.
            else do: /* Invoice not found */              
                assign 
                    tApiUpdateDInvoiceWithNewBank.tiErrorCode = -7
                    tApiUpdateDInvoiceWithNewBank.tcErrorMessage = substitute(#T-7'Invoice (&1) must be open to change bank details':255(14444222)T-7#,vcInvoiceDetails).                
            end.                                          
        end. /* if available tDInvoice */
        else do: /* Invoice not found */              
            assign 
                tApiUpdateDInvoiceWithNewBank.tiErrorCode = -8
                tApiUpdateDInvoiceWithNewBank.tcErrorMessage = #T-38'Invoice not found.':255(413950799)T-38#.                
        end.    
    end. /* for each */   
               
    /* Set meessage if <> 0 */        
    if tApiUpdateDInvoiceWithNewBank.tiErrorCode <> 0 
    then do:            
        <M-96 run SetMessage
           (input  tApiUpdateDInvoiceWithNewBank.tcErrorMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  2 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-218596':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    end.            
end. /* Else do*/
 

<M-65 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>

if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
    then return.