project QadFinancials > class BDInvoice > method AdditionalUpdatesAllQDInvoiceMovement

Description

This submethod of AdditionalUpdatesAll handles all actions on the creation of QDinvoiceMovemnt records that will be used by the balance-daemon to keep the debtor-balances up-to-date.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.AdditionalUpdatesAll


program code (program8/bdinvoice.p)

    
    /* ============================================================ */
    /* Create a QDinvoicemovement record for every Dinvoicemovement */
    /* => will be handled by daemon, to update creditor balance     */
    /* ============================================================ */
        
    /* ============================================================ */
    /* No new movements => no actions needed                        */
    /* ============================================================ */
    if not can-find (first tDInvoiceMovement where
                           tDInvoiceMovement.tc_Status = "N":U)
    then Return.
    
    /* ========================== */
    /* Set default return-status  */
    /* ========================== */
    assign oiReturnStatus = -98.
    
    /* ======================================================================================= */
    /* General note: BJournalEntry is already started and opened by the caller-method          */
    /* ======================================================================================= */
    if can-find (first tDInvoiceMovement where 
                       tDInvoiceMovement.tc_Status <> "":U) and 
       (viBJournalEntryDIID                  = 0 or 
        viBJournalEntryDIID                  = ? or
        valid-handle(vhBJournalEntryDIInst) <> true)
    then do :
        assign vcMessage      = trim(#T-13'Internal error: unexpected situation-no communication to the postings available':255(17891)T-13#) + chr(10) +
                                trim(substitute(#T-14'Instance ID = &1.':255(17892)T-14#,string(viBJournalEntryDIID)))                                  + chr(10) +
                                trim(substitute(#T-15'Valid handle = &1.':255(17893)T-15#,string(valid-handle(vhBJournalEntryDIInst) = TRUE)))          + chr(10) +
                                trim(substitute(#T-16'Handle value = &1.':255(17894)T-16#,string(vhBJournalEntryDIInst)))
               oiReturnStatus = -3.
        <M-12 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QADFIN-4528':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        Return.
    end. /* if */
    
    /* =============== */
    /* Initialisations */
    /* =============== */
    empty temp-table tQDInvoiceMovementToCreate.
    assign viDCInvoiceMovementToCreateSeq   = 0.
    
    /* ============================ */
    /* Go through all new movements */
    /* ============================ */
    for each tDInvoice where 
             tDInvoice.tc_Status <> "D":U,
        each tDInvoiceMovement where
             tDInvoiceMovement.tc_ParentRowid = tDInvoice.tc_Rowid and
             tDInvoiceMovement.tc_Status      = "N":U :
        
        /* ==================================================================== */
        /* Get the amounts out of the JE: check for the link to the postingline */
        /* ==================================================================== */
        find first tPostingPostingLineInfoDIJE where
                   tPostingPostingLineInfoDIJE.tiPostingLine_ID = tDInvoiceMovement.PostingLine_ID
                   no-error.
        if not available tPostingPostingLineInfoDIJE
        then do:
            assign vcMessage      = trim(#T-20'Internal error: unexpected situation - no posting line information available':255(999890251)T-20#) + chr(10) +
                                    trim(substitute(#T-21'Posting Line ID = &1.':255(999890249)T-21#,string(tDInvoiceMovement.PostingLine_ID)))
                   oiReturnStatus = -3.
            <M-19 run SetMessage (input  vcMessage (icMessage), 
                         input  '':U (icArguments), 
                         input  '':U (icFieldName), 
                         input  '':U (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  '':U (icRowid), 
                         input  'QadFin-8984':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            next.
        end. /* if not available tPostingPostingLineInfoDIJE */
        
        /* =========================================================================== */
        /* Get the amounts out of the DB when we cannot get them out of the JE-instance */
        /* =========================================================================== */
        if tPostingPostingLineInfoDIJE.tdPostingLineDebitLC  = 0 and 
           tPostingPostingLineInfoDIJE.tdPostingLineCreditLC = 0
        then do:
            /* if it is not in instance, look in db */
            <Q-5 run PostingByPostingLineId (all) (Read) (NoCache)
               (input tDInvoice.Company_ID, (CompanyId)
                input tDInvoiceMovement.PostingLine_ID, (PostingLineId)
                output dataset tqPostingByPostingLineId) in BPosting >
            find tqPostingByPostingLineId where 
                 tqPostingByPostingLineId.tiCompany_ID     = tDInvoice.Company_ID and 
                 tqPostingByPostingLineId.tiPostingLine_ID = tDInvoiceMovement.PostingLine_ID
                 no-lock no-error.
            if available tqPostingByPostingLineId
            then assign tPostingPostingLineInfoDIJE.tdPostingLineDebitTC  = tqPostingByPostingLineId.tdPostingLineDebitTC
                        tPostingPostingLineInfoDIJE.tdPostingLineDebitLC  = tqPostingByPostingLineId.tdPostingLineDebitLC
                        tPostingPostingLineInfoDIJE.tdPostingLineDebitCC  = tqPostingByPostingLineId.tdPostingLineDebitCC
                        tPostingPostingLineInfoDIJE.tdPostingLineCreditTC = tqPostingByPostingLineId.tdPostingLineCreditTC
                        tPostingPostingLineInfoDIJE.tdPostingLineCreditLC = tqPostingByPostingLineId.tdPostingLineCreditLC
                        tPostingPostingLineInfoDIJE.tdPostingLineCreditCC = tqPostingByPostingLineId.tdPostingLineCreditLC
                        tPostingPostingLineInfoDIJE.tiGL_ID               = tqPostingByPostingLineId.tiGL_ID
                        tPostingPostingLineInfoDIJE.tiDivision_ID         = tqPostingByPostingLineId.tiDivision_ID
                        tPostingPostingLineInfoDIJE.tiProject_ID          = tqPostingByPostingLineId.tiProject_ID
                        tPostingPostingLineInfoDIJE.tiJournal_ID          = tqPostingByPostingLineId.tiJournal_ID
                        tPostingPostingLineInfoDIJE.tiCostCentre_ID       = tqPostingByPostingLineId.tiCostCentre_ID.
        end. /* if tPostingPostingLineInfoDIJE.tdPostingLineDebitLC = 0 and */
        
        /* =============================== */
        /* Create the temp-table records   */
        /* =============================== */
        create tQDInvoiceMovementToCreate.
        assign viDCInvoiceMovementToCreateSeq                           = viDCInvoiceMovementToCreateSeq + 1
               tQDInvoiceMovementToCreate.tc_Rowid                      = string(viDCInvoiceMovementToCreateSeq)
               tQDInvoiceMovementToCreate.DInvoiceMovementDebitLC       = tPostingPostingLineInfoDIJE.tdPostingLineDebitLC
               tQDInvoiceMovementToCreate.DInvoiceMovementCreditLC      = tPostingPostingLineInfoDIJE.tdPostingLineCreditLC
               tQDInvoiceMovementToCreate.DInvoiceMovementDebitTC       = tPostingPostingLineInfoDIJE.tdPostingLineDebitTC
               tQDInvoiceMovementToCreate.DInvoiceMovementCreditTC      = tPostingPostingLineInfoDIJE.tdPostingLineCreditTC
               tQDInvoiceMovementToCreate.DInvoiceMovementDebitCC       = tPostingPostingLineInfoDIJE.tdPostingLineDebitCC
               tQDInvoiceMovementToCreate.DInvoiceMovementCreditCC      = tPostingPostingLineInfoDIJE.tdPostingLineCreditCC
               tQDInvoiceMovementToCreate.DInvoiceMovementVatDebLC      = if tDInvoice.tc_Status = "N":U then tDInvoice.DInvoiceVatDebitLC else 0
               tQDInvoiceMovementToCreate.DInvoiceMovementVatCredLC     = if tDInvoice.tc_Status = "N":U then tDInvoice.DInvoiceVatCreditLC else 0
               tQDInvoiceMovementToCreate.DInvoiceMovementVatDebTC      = if tDInvoice.tc_Status = "N":U then tDInvoice.DInvoiceVatDebitTC else 0
               tQDInvoiceMovementToCreate.DInvoiceMovementVatCredTC     = if tDInvoice.tc_Status = "N":U then tDInvoice.DInvoiceVatCreditTC else 0
               tQDInvoiceMovementToCreate.DInvoiceMovementVatDebCC      = if tDInvoice.tc_Status = "N":U then tDInvoice.DInvoiceVatDebitCC else 0
               tQDInvoiceMovementToCreate.DInvoiceMovementVatCredCC     = if tDInvoice.tc_Status = "N":U then tDInvoice.DInvoiceVatCreditCC else 0
               tQDInvoiceMovementToCreate.DInvoiceMovementIsInvoice     = if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then true else false
               tQDInvoiceMovementToCreate.DInvoiceMovementIsCreditN     = if tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} or tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} then true else false
               tQDInvoiceMovementToCreate.DInvoiceMovementType          = tDInvoiceMovement.DInvoiceMovementType
               tQDInvoiceMovementToCreate.DInvoiceMovementInfo          = trim(string(tDInvoice.DInvoicePostingYear)) + '/':U + trim(string(tDInvoice.DInvoicePostingPeriod)) + '/':U + trim(tDInvoice.tcJournalCode) + '/':U + trim(string(tDInvoice.DInvoiceVoucher))
               tQDInvoiceMovementToCreate.MovementYearPeriod            = tDInvoiceMovement.DInvoiceMovementYearPeriod
               tQDInvoiceMovementToCreate.Company_ID                    = tDInvoice.Company_ID /* viCompanyId would also be okay as the company of the invoice is always the current company when making the DInvoiceMovements */
               tQDInvoiceMovementToCreate.Currency_ID                   = tDInvoice.DInvoiceCurrency_ID
               tQDInvoiceMovementToCreate.Debtor_ID                     = tDInvoice.Debtor_ID
               tQDInvoiceMovementToCreate.Period_ID                     = tDInvoiceMovement.Period_ID
               tQDInvoiceMovementToCreate.GL_ID                         = tPostingPostingLineInfoDIJE.tiGL_ID
               tQDInvoiceMovementToCreate.Division_ID                   = tPostingPostingLineInfoDIJE.tiDivision_ID
               tQDInvoiceMovementToCreate.Project_ID                    = tPostingPostingLineInfoDIJE.tiProject_ID
               tQDInvoiceMovementToCreate.CostCentre_ID                 = tPostingPostingLineInfoDIJE.tiCostCentre_ID
               tQDInvoiceMovementToCreate.Journal_ID                    = tPostingPostingLineInfoDIJE.tiJournal_ID
               tQDInvoiceMovementToCreate.ttValidityDate                = tDInvoice.DInvoiceTaxPointDate
               tQDInvoiceMovementToCreate.tdExchangeRate                = tDInvoice.DInvoiceExchangeRate
               tQDInvoiceMovementToCreate.tdExchangeRateScale           = tDInvoice.DInvoiceRateScale.
        
    end. /* for each tDInvoice where tDInvoice.tc_Status <> "D":U, each tDInvoiceMovement where */
    
    /* ====================================================================================================================== */
    /* IMPORTANT NOTE:                                                                                                        */
    /* We will not go through the normal approach with Starting&Opening the external instance and then call a method in there */
    /* as that decreases the performance too much.  In stead, we stop here as we have the required tQDInvoiceMovementToCreate */
    /* records and we will save them in BPosting:POSTSAVE using dynamic buffers as that will be much faster                   */
    /* The program-code in here to call is kep in comments although it should never be executed anymore but we want to keep   */
    /* it like this so the 'Show Usage' still shows at least the correct calling class.                                       */ 
    /* SO: Please do note uncomment or remove this commented out program-code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                  */
    /* ====================================================================================================================== */
    /* COMMENTED-OUT - See comments Above
        /* Call a method in BQCInvoiceMov that will create these records  */
        if can-find(first tQDInvoiceMovementToCreate)
        then do:
            if viBQDInvoiceMovementID = 0 or viBQDInvoiceMovementID = ?
            then do:
                <I-7 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "True"
                &CLASS              = "BQDInvoiceMovement"}>
            end. /* if viBQDInvoiceMovementID = 0 or viBQDInvoiceMovementID = ? */
            else do:
                <I-8 {bFcOpenInstance
                &CLASS           = "BQDInvoiceMovement"}>
            end.
            <M-9 run ApiCreateQDInvoiceMovement (input  tQDInvoiceMovementToCreate (tAPIQDInvoiceMovement), 
                                         input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                                         output viExternalReturnStatus (oiReturnStatus)) in BQDInvoiceMovement>
            <I-10 {bFcCloseInstance
                &CLASS           = "BQDInvoiceMovement"}>
            if viExternalReturnStatus <> 0 
            then assign oiReturnStatus = viExternalReturnStatus.
            if viExternalReturnStatus < 0
            then Return.
        end. /* if can-find */
    COMMENTED-OUT - See comments Above
    */
        
    /* ========================== */
    /* Set return-status = OK     */
    /* ========================== */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.