project QadFinancials > class BAPMatching > method AdditionalUpdatesAllCreatePLCirec

Description

AdditionalUpdatesAllCreateCirec; submethod of AdditionalUpdatesAll that is located in the same segment and that takes care of the creation of a cirec-posting-line and the creation of a record in the associated temp-table.


Parameters


icAPMatchingPostingRowidIDinputcharacterAPMatchingPostingRowidID
icCirecGLCodeinputcharacter
icCirecDivisionCodeinputcharacterCirecDivisionCode
icPostingTextinputcharacterPostingText
idSumPosVarUsageTCPosVarRateTCinputdecimalSumPosVarUsageTCPosVarRateTC: this field will be used to raise the HoldAmount of the invoice and should thus be in the currency of the invoice
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAll


program code (program6/bapmatching.p)

/* ======================== */
    /* Set default ReturnStatus */
    /* ======================== */
    assign oiReturnStatus = -98.
        
    /* ============================================================================ */
    /* First check whether everything is availablable what is supposed to be avail  */
    /* ============================================================================ */
    if not available tAPMatching  
    then do :
        assign oiReturnStatus  = -3
               vcMsgAPMatching = trim(substitute(#T-3'Internal error: information is missing.':255(49818)T-3#)) + chr(10) + 
                                 trim(substitute(#T-4'Available matching header: &1.':234(49819)T-4#,available (tAPMatching))) .
        <M-2 run SetMessage (input  vcMsgAPMatching (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QadFin-5415':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Return.
    end. /* if not avail */

    /* ==================================================================================== */
    /* Create the CIREC posting line in submethod using BJournalEntry.AddStandardPosting()  */
    /* and hold the ID of this posting-line inf tAPMatching.CirecPostingLine_ID             */
    /* Amount is posted to the Credit when positive, to the Debit (* -1) when negative      */
    /* ==================================================================================== */
    assign vdDebitTC  = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if tAPMatching.APMatchingTotalAmountTC < 0 then tAPMatching.APMatchingTotalAmountTC * -1 else 0
                        else if tAPMatching.APMatchingTotalAmountTC > 0 then tAPMatching.APMatchingTotalAmountTC * -1 else 0
           vdDebitLC  = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if tAPMatching.APMatchingTotalAmountLC < 0 then tAPMatching.APMatchingTotalAmountLC * -1 else 0
                        else if tAPMatching.APMatchingTotalAmountLC > 0 then tAPMatching.APMatchingTotalAmountLC * -1 else 0
           vdCreditTC = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if tAPMatching.APMatchingTotalAmountTC > 0 then tAPMatching.APMatchingTotalAmountTC else 0
                        else if tAPMatching.APMatchingTotalAmountTC < 0 then tAPMatching.APMatchingTotalAmountTC else 0
           vdCreditLC = if tAPMatching.tcCInvoiceType = {&INVOICETYPE-INVOICE} or
                           tAPMatching.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE}
                        then if tAPMatching.APMatchingTotalAmountLC > 0 then tAPMatching.APMatchingTotalAmountLC else 0
                        else if tAPMatching.APMatchingTotalAmountLC < 0 then tAPMatching.APMatchingTotalAmountLC else 0.
    /* Assign CC-amounts */
    if viCompanyCCID = tAPMatching.Currency_ID
    then assign vdDebitCC  = vdDebitTC
                vdCreditCC = vdCreditTC. 
    else if vlDomainIsStatutory = false
         then assign vdDebitCC  = vdDebitLC
                     vdCreditCC = vdCreditLC.    
         else if vdCreditLC <> 0
              then assign vdCreditCC = <M-9 RoundAmount
                                          (input  vdCreditTC * tAPMatching.tdCInvoiceCCRate * tAPMatching.tdCInvoiceCCScale (idUnroundedAmount), 
                                           input  viCompanyCCId (iiCurrencyID), 
                                           input  ? (icCurrencyCode)) in BAPMatching>.
              else if vdDebitLC  <> 0 
                   then assign vdDebitCC  = <M-10 RoundAmount
                                               (input  vdDebitTC * tAPMatching.tdCInvoiceCCRate * tAPMatching.tdCInvoiceCCScale (idUnroundedAmount), 
                                                input  viCompanyCCId (iiCurrencyID), 
                                                input  ? (icCurrencyCode)) in BAPMatching>.
    /* create the posting line */
    empty temp-table tDefaultSafsAPM.
    <M-1 run AddStandardPosting
       (input  icAPMatchingPostingRowidID (icPostingtcRowid), 
        input  icCirecGLCode (icGLCode), 
        input  icCirecDivisionCode (icDivisionCode), 
        input  '':U (icCostCentreCode), 
        input  '':U (icCostCentreText), 
        input  '':U (icProjectCode), 
        input  '':U (icProjectText), 
        input  tAPMatching.tcBusinessRelationICCode (icIntercoBusinessRelationCode), 
        input  tAPMatching.tcCurrencyCode (icCurrencyCode), 
        input  vdDebitTC (idDebitTC), 
        input  vdDebitLC (idDebitLC), 
        input  vdDebitCC (idDebitCC), 
        input  0 (idDebitPC), 
        input  vdCreditTC (idCreditTC), 
        input  vdCreditLC (idCreditLC), 
        input  vdCreditCC (idCreditCC), 
        input  0 (idCreditPC), 
        input  0 (idQty), 
        input  icPostingText (icLineText), 
        input  '':U (icSafText), 
        input  tDefaultSafsAPM (tDefaultSafs), 
        input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
        input  tAPMatching.tdCInvoiceExchangeRate (idExchangeRate), 
        input  tAPMatching.tdCinvoiceRateScale (idExchangeRateScale), 
        output tAPMatching.CirecPostingLine_ID (oiPostingLineId), 
        input  0 (iiSafStructureId), 
        input  '':U (icSafStructureCode), 
        input  '':U (icAllocationKey), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    If viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then Return.
    
    /* I19 requirement for Brazil ============================================================== */
    /* Update posting line to control account to contain legal document number filled in         */
    /* ========================================================================================= */
    if vcLegalDocNbr <> ?
    then do:
        <M-45 run SetPostingLineLegalDocNumber
           (input  ? (icPostingLineTcRowID), 
            input  tAPMatching.CirecPostingLine_ID (iiPostingLineID), 
            input  vcLegalDocNbr (icLegalDocumentNumber), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and oiReturnStatus = 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then return.
    end. /* if vlDomainIsFiscalConfirm and */

    
    /* ==================================================================================== */
    /* Gather some information for updating the creditor invoices                           */
    /* Create a tCInvoiceForAPMatching record and assign all fields properly                */
    /* Raise a warning in case the HoldAmount on the invoice will be set                    */
    /* ==================================================================================== */
    create tExtAllocateCInvoiceAPM.
    assign tExtAllocateCInvoiceAPM.tiCICompanyId                = tAPMatching.Company_ID
           tExtAllocateCInvoiceAPM.tiCInvoiceId                 = tAPMatching.CInvoice_ID
           tExtAllocateCInvoiceAPM.tlCInvoiceIsLogisticMatching = true
           tExtAllocateCInvoiceAPM.tiCInvoiceVoucher            = tAPMatching.tiCInvoiceVoucher
           tExtAllocateCInvoiceAPM.tiCirecPostingLineId         = tAPMatching.CirecPostingLine_ID
           tExtAllocateCInvoiceAPM.tcJournalCode                = tAPMatching.tcCInvoiceJournalCode
           tExtAllocateCInvoiceAPM.tiPeriodYear                 = tAPMatching.tiCInvoicePostingYear
           tExtAllocateCInvoiceAPM.ttPostingDate                = tAPMatching.APMatchingDate  
           tExtAllocateCInvoiceAPM.tiPostingId                  = tAPMatching.Posting_ID
           tExtAllocateCInvoiceAPM.tcReasonCode                 = tAPMatching.tcReasonCode
           tExtAllocateCInvoiceAPM.tiReasonId                   = tAPMatching.Reason_ID
           tExtAllocateCInvoiceAPM.tdCInvoiceHoldAmountTC       = idSumPosVarUsageTCPosVarRateTC.
    if tExtAllocateCInvoiceAPM.tdCInvoiceHoldAmountTC <> 0 and 
       tExtAllocateCInvoiceAPM.tdCInvoiceHoldAmountTC <> ?
    then do :
        assign oiReturnStatus  = +1
               vcMsgAPMatching = trim(substitute(#T-12'Warning: the hold amount of the invoice (&1/&2/&3) will be updated due to the positive variance.':255(733751132)T-12#,string(tAPMatching.tiCInvoicePostingYear),tAPMatching.tcCInvoiceJournalCode,string(tAPMatching.tiCInvoiceVoucher))) + chr(10) + 
                                 trim(substitute(#T-13'Hold amount: &1.':255(69502)T-13#,string(tExtAllocateCInvoiceAPM.tdCInvoiceHoldAmountTC))) .
        <M-11 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'W':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8125':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    end. /* if tExtAllocateCInvoiceAPM.tdCInvoiceHoldAmountTC <> 0 and */
    
    /* ======================== */
    /* Set ReturnStatus = OK    */
    /* ======================== */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.