project QadFinancials > class BPosting > method UpdateInvoiceNumbers

Description

When domain is using consecutive invoice numbering, then a temporary number was used to create the posting. All occurences of this number will be changed with the correct permanent number at moment of presave of the invoice.


Parameters


tUpdateInvoiceNumbersPostinginputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.PreSave
method BDInvoice.PreSave


program code (program6/bposting.p)

/* Error handling */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.

UPDATEBLOCK:
do:
    for each tUpdateInvoiceNumbersPosting:
        find tPosting where
             tPosting.tc_Status     <> 'D':U                                      and
             tPosting.Company_ID     = tUpdateInvoiceNumbersPosting.tiCompany_ID  and
             tPosting.PostingYear    = tUpdateInvoiceNumbersPosting.tiPeriodYear  and
             tPosting.tcJournalCode  = tUpdateInvoiceNumbersPosting.tcJournalCode and
             tPosting.PostingVoucher = tUpdateInvoiceNumbersPosting.tiTempVoucher
             no-error.
        if not available tPosting 
        then do:
            assign vcMessage           = trim(#T-98'Could not find the posting record to assign with the permanent invoice number.':255(404979025)T-98#) + chr(10) + 
                                         trim(substitute(#T-41'Company ID: &1, Posting Year: &2, Daybook Code: &3, Voucher: &4.':255(729867255)T-41#, 
                                                         trim(string(tUpdateInvoiceNumbersPosting.tiCompany_ID)), 
                                                         trim(string(tUpdateInvoiceNumbersPosting.tiPeriodYear)), 
                                                         trim(tUpdateInvoiceNumbersPosting.tcJournalCode), 
                                                         trim(string(tUpdateInvoiceNumbersPosting.tiTempVoucher)) ))
                   viLocalReturnStatus = -3.
            <M-75 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'S':U (icType), 
                input  2 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-122974':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            leave UPDATEBLOCK.
        end. /* if not available tPosting  */
    
        assign tPosting.PostingVoucher             = tUpdateInvoiceNumbersPosting.tiNewVoucher
               tPosting.PostingInvoiceReferenceTxt = replace(tPosting.PostingInvoiceReferenceTxt, string(tUpdateInvoiceNumbersPosting.tiTempVoucher), string(tUpdateInvoiceNumbersPosting.tiNewVoucher))
               tPosting.PostingOriginDocument      = replace(tPosting.PostingOriginDocument, string(tUpdateInvoiceNumbersPosting.tiTempVoucher), string(tUpdateInvoiceNumbersPosting.tiNewVoucher))
               viPostingID                         = tPosting.Posting_ID
               vcPostingInvoiceReferenceTxt        = tPosting.PostingInvoiceReferenceTxt
               no-error.
    end. /* for each tUpdateInvoiceNumbersPosting: */
    
    for each tPosting where 
             tPosting.tc_Status  <> "D":U and
             tPosting.tc_Status  <> "C":U and
             tPosting.Posting_ID <> viPostingID :
      assign tPosting.PostingInvoiceReferenceTxt = vcPostingInvoiceReferenceTxt.
    end.    

    /* ========================== */
    /* Update fields in BQPosting */
    /* ========================== */
    if viBQPostingPostingID <> 0 and viBQPostingPostingID <> ?
    then do:
        <I-42 {bFcOpenInstance
             &CLASS           = "Transaction"}>

        <M-29 run GetInstanceDetails
           (input  'BQPosting':U (icComponentShortName), 
            input  viCompanyId (iiCompanyIdOfInstance), 
            output viDummy (oiInstanceId), 
            output vhBQPostingPostingInst (ohInstanceHandle), 
            output viMethodReturnStatus (oiReturnStatus)) in Transaction>

        <I-1 {bFcCloseInstance
             &CLASS           = "Transaction"}>
             
        if viMethodReturnStatus <> 0 and oiReturnStatus >= 0
        then assign oiReturnStatus = viMethodReturnStatus.
        if viMethodReturnStatus < 0
        then return.

        if valid-handle(vhBQPostingPostingInst)
        then do:
            <M-88 run UpdatePostingNumbers
               (input  tUpdateInvoiceNumbersPosting (tUpdateInvoiceNumbersQPosting), 
                output viFcReturnSuper (oiReturnStatus)) in BQPosting>        
            if viFcReturnSuper <> 0 and oiReturnStatus >= 0
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
        end. /* if valid-handle(vhBQPostingPostingInst) */
    end. /* if viBQPostingPostingID <> 0 and viBQPostingPostingID <> ? */
end. /* UPDATEBLOCK */

/* Error handling */
assign oiReturnStatus = viLocalReturnStatus.