project QadFinancials > class BAPMatching > method AdditionalUpdatesAllLinesPLAddPostingLine

Description

This method creates normal or cross company posting-lines


Parameters


icAPMatchingPostingRowIdinputcharacter
icGLCodeinputcharacter
icDivisionCodeinputcharacter
icCostCentreCodeinputcharacter
icProjectCodeinputcharacter
icOpAllocCodeinputcharacterOperational Allocation Code. If this parameter is passed several posting lines will be created based on the number of detail lines linked to the operational allocation code. The GL Code that is passed will not be used.
idDebitTCinputdecimal
idDebitLCinputdecimal
idDebitCCinputdecimal
idCreditTCinputdecimal
idCreditLCinputdecimal
idCreditCCinputdecimal
icPostingTextinputcharacter
idTCLCExchangeRateinputdecimal
idTCLCExchangeScaleinputdecimal
idTCCCExchangeRateinputdecimal
idTCCCExchangeScaleinputdecimal
tDefaultSafsAPMinputtemp-table
oiPostingLineIdoutputinteger
ilisCallForVarianceOrTaxinputlogicalThis parameter is true when calling method for Variance account or Tax Account
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllLinesPLExpenseAcruals
method BAPMatching.AdditionalUpdatesAllLinesPLReceiptPvod
method BAPMatching.AdditionalUpdatesAllLinesPLVarExchRate
method BAPMatching.AdditionalUpdatesAllLinesPLVarRate
method BAPMatching.AdditionalUpdatesAllLinesPLVarUsageSub2
method BAPMatching.AdditionalUpdatesAllTaxNewOne
method BAPMatching.AdditionalUpdatesAllTaxNewTwo
method BAPMatching.AdditionalUpdatesAllTaxOldOne


program code (program6/bapmatching.p)

assign oiReturnStatus = -98.

/* =========================================================== */
/* This method expects valid records in following tables       */
/* =========================================================== */
if not available tAPMatching   or 
   not available tAPMatchingLn or 
   (not available tqDomainForInterCompany and 
    tAPMatching.Company_ID <> tAPMatchingLn.APMatchingLnPvodCompID)
then do :
    assign oiReturnStatus = -3
           vcMessageText  = trim(substitute(#T-7'Internal error: information that should have been available is not available.':255(999890799)T-7#)) + chr(10) + 
                            trim(substitute(#T-8'Available matching header: &1.':234(49819)T-8#,available (tAPMatching))) + chr(10) + 
                            trim(substitute(#T-9'Available matching details: &1.':234(49820)T-9#,available (tAPMatchingLn))).
    if tAPMatching.Company_ID <> tAPMatchingLn.APMatchingLnPvodCompID
    then assign vcMessageText = vcMessageText + chr(10) + trim(substitute(#T-13'Available cross-company information from the domain: &1.':234(63364)T-13#,available (tqDomainForInterCompany))).
    <M-12 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-5999':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    return.
end. /* if not avail */     
    
/* ================================================================== */
/* Split across multiple GLs when Operational Allocation Code is used */
/* ================================================================== */
if icOpAllocCode <> ? and
   icOpAllocCode <> "":U
then do:
    <M-57 run AdditionalUpdatesAllLinesPLAddPostingLineOpAllocCode
       (input  icAPMatchingPostingRowId (icAPMatchingPostingRowId), 
        input  icGLCode (icGLCode), 
        input  icDivisionCode (icDivisionCode), 
        input  icCostCentreCode (icCostCentreCode), 
        input  icProjectCode (icProjectCode), 
        input  icOpAllocCode (icOpAllocCode), 
        input  idDebitTC (idDebitTC), 
        input  idDebitLC (idDebitLC), 
        input  idDebitCC (idDebitCC), 
        input  idCreditTC (idCreditTC), 
        input  idCreditLC (idCreditLC), 
        input  idCreditCC (idCreditCC), 
        input  icPostingText (icPostingText), 
        input  idTCLCExchangeRate (idTCLCExchangeRate), 
        input  idTCLCExchangeScale (idTCLCExchangeScale), 
        input  idTCCCExchangeRate (idTCCCExchangeRate), 
        input  idTCCCExchangeScale (idTCCCExchangeScale), 
        input  tDefaultSafsAPM (tDefaultSafsAPM), 
        output oiPostingLineId (oiPostingLineId), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return.
end. /* if icOpAllocCode <> ? and */
else do:
    /* ============================================== */
    /* Get the Intercompany code of the PO's Supplier */
    /* ============================================== */
    if ilisCallForVarianceOrTax = false
    then do:
        assign vcBusinessRelationInterCoCode = "":U.

        <Q-89 run PurchaseOrderForCreditorBR (all) (Read) (Cache)
           (input tAPMatchingLn.APMatchingLnPvodOrder, (PurchaseOrder)
            input if tAPMatchingLn.APMatchingLnPvodSupplier = '':U then ? else tAPMatchingLn.APMatchingLnPvodSupplier, (CreditorCode)
            input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
            input tAPMatchingLn.PvoDomain, (PvoDomain)
            output dataset tqPurchaseOrderForCreditorBR) in BMfgPO>

        find first tqPurchaseOrderForCreditorBR where
                   tqPurchaseOrderForCreditorBR.tcpo_domain = tAPMatchingLn.PvoDomain             and
                   tqPurchaseOrderForCreditorBR.tcpo_nbr    = tAPMatchingLn.APMatchingLnPvodOrder
                   no-error.

        if available tqPurchaseOrderForCreditorBR
        then assign vcBusinessRelationInterCoCode = tqPurchaseOrderForCreditorBR.tcBusinessRelationICCode.

    end. /* if ilisCallForVarianceOrTax = false */

    /* ===================================================================== */
    /* Created posting-line resizeds in the same company as matching posting */
    /* ===================================================================== */
    if tAPMatching.Company_ID = tAPMatchingLn.APMatchingLnPvodCompID
    then do:
        <M-1 run AddStandardPosting
           (input  icAPMatchingPostingRowId (icPostingtcRowid), 
            input  icGLCode (icGLCode), 
            input  icDivisionCode (icDivisionCode), 
            input  icCostCentreCode (icCostCentreCode), 
            input  '':U (icCostCentreText), 
            input  icProjectCode (icProjectCode), 
            input  '':U (icProjectText), 
            input  if ilisCallForVarianceOrTax = false then vcBusinessRelationInterCoCode else tAPMatching.tcBusinessRelationICCode (icIntercoBusinessRelationCode), 
            input  tAPMatching.tcCurrencyCode (icCurrencyCode), 
            input  idDebitTC (idDebitTC), 
            input  idDebitLC (idDebitLC), 
            input  idDebitCC (idDebitCC), 
            input  0 (idDebitPC), 
            input  idCreditTC (idCreditTC), 
            input  idCreditLC (idCreditLC), 
            input  idCreditCC (idCreditCC), 
            input  0 (idCreditPC), 
            input  0 (idQty), 
            input  icPostingText (icLineText), 
            input  '':U (icSafText), 
            input  tDefaultSafsAPM (tDefaultSafs), 
            input  0 (icExchangeRateType), 
            input  idTCLCExchangeRate (idExchangeRate), 
            input  idTCLCExchangeScale (idExchangeRateScale), 
            input  idTCCCExchangeRate (idPostingLineCCRate), 
            input  idTCCCExchangeScale (idPostingLineCCScale), 
            output oiPostingLineId (oiPostingLineId), 
            input  0 (iiSafStructureId), 
            input  '':U (icSafStructureCode), 
            input  '':U (icAllocationKey), 
            input  false (ilLinkedCrCyDaemonReqExists), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>       

        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then return.
        
        /* I19 requirement for Brazil =============================================================== */
        /* If the AP matching is for the Legal document, all posting lines needs to contain reference */
        /* to this legal document                                                                     */
        /* ========================================================================================== */
        if vcLegalDocNbr <> ?
        then do:
            <M-43 run SetPostingLineLegalDocNumber
               (input  ? (icPostingLineTcRowID), 
                input  oiPostingLineId (iiPostingLineID), 
                input  vcLegalDocNbr (icLegalDocumentNumber), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper <> 0 and oiReturnStatus >= 0 then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper <  0 then return.            
        end. /* if vcLegalDocNbr <> ? */

    end. /* if tAPMatching.Company_ID = tAPMatchingLn.APMatchingLnPvodCompID */
        
    /* =========================================================== */
    /* Create                                                      */
    /* 1. Posting line in current company which will be cross com- */
    /*    pany posting line pointing to another company            */
    /* 2. Create new request for cross company posting daemon for  */
    /*    creation of posting in second company                    */
    /* =========================================================== */
    else do :    
        /* Find the Interco-Code (ICCode) of the company of the PVOD */
        assign vcBusinessRelationInterCoCode = "":U.

        <Q-59 run CompanyBusinessRelation (all) (Read) (NoCache)
           (input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
            output dataset tqCompanyBusinessRelation) in BCompany>

        find first tqCompanyBusinessRelation where 
                   tqCompanyBusinessRelation.tiCompany_ID = tAPMatchingLn.APMatchingLnPvodCompID 
                   no-error.

        if available tqCompanyBusinessRelation
        then assign vcBusinessRelationInterCoCode = tqCompanyBusinessRelation.tcBusinessRelationICCode
                    vcTargetCompanyCode           = tqCompanyBusinessRelation.tcCompanyCode.
            
        /* Create posting-line on the cross-cy account */
        <M-2 run AddStandardPosting
           (input  icAPMatchingPostingRowId (icPostingtcRowid), 
            input  tqDomainForInterCompany.tcIntercoAPGLCode (icGLCode), 
            input  '':U (icDivisionCode), 
            input  '':U (icCostCentreCode), 
            input  '':U (icCostCentreText), 
            input  '':U (icProjectCode), 
            input  '':U (icProjectText), 
            input  vcBusinessRelationInterCoCode (icIntercoBusinessRelationCode), 
            input  tAPMatching.tcCurrencyCode (icCurrencyCode), 
            input  idDebitTC (idDebitTC), 
            input  idDebitLC (idDebitLC), 
            input  idDebitCC (idDebitCC), 
            input  0 (idDebitPC), 
            input  idCreditTC (idCreditTC), 
            input  idCreditLC (idCreditLC), 
            input  idCreditCC (idCreditCC), 
            input  0 (idCreditPC), 
            input  0 (idQty), 
            input  icPostingText (icLineText), 
            input  '':U (icSafText), 
            input  tDefaultSafsAPM (tDefaultSafs), 
            input  0 (icExchangeRateType), 
            input  idTCLCExchangeRate (idExchangeRate), 
            input  idTCLCExchangeScale (idExchangeRateScale), 
            input  idTCCCExchangeRate (idPostingLineCCRate), 
            input  idTCCCExchangeScale (idPostingLineCCScale), 
            output oiPostingLineId (oiPostingLineId), 
            input  0 (iiSafStructureId), 
            input  '':U (icSafStructureCode), 
            input  '':U (icAllocationKey), 
            input  true (ilLinkedCrCyDaemonReqExists), 
            input  ? (itExchangeRateDate), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>  

        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then return.
        
        /* I19 requirement for Brazil =============================================================== */
        /* If the AP matching is for the Legal document, all posting lines needs to contain reference */
        /* to this legal document                                                                     */
        /* ========================================================================================== */
        if vcLegalDocNbr <> ?
        then do:
            <M-48 run SetPostingLineLegalDocNumber
               (input  ? (icPostingLineTcRowID), 
                input  oiPostingLineId (iiPostingLineID), 
                input  vcLegalDocNbr (icLegalDocumentNumber), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper <> 0 and oiReturnStatus >= 0 then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper <  0 then return.            
        end. /* if vcLegalDocNbr <> ? */
        
        /* Gather the ID of the GL and the other analytical details   */
        assign viCrossCompanyGLId = ?.
        if icGLCode <> ? and
           icGLCode <> '':U
        then do:
            <Q-3 run GLPrim (all) (Read) (NoCache)
               (input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
                input icGLCode, (GLCode)
                input ?, (GLId)
                output dataset tqGLPrim) in BGL >
            find first tqGLPrim no-error.
            if available tqGLPrim
            then assign viCrossCompanyGLId = tqGLPrim.tiGL_ID.
        end. /* if icGLCode <> ? and */

        assign viCrossCompanyDivisionId = ?.
        if icDivisionCode <> ? and
           icDivisionCode <> '':U
        then do:
            <Q-4 run DivisionPrim (all) (Read) (NoCache)
               (input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
                input ?, (DivisionID)
                input icDivisionCode, (DivisionCode)
                output dataset tqDivisionPrim) in BDivision >
            find first tqDivisionPrim no-error.
            if available tqDivisionPrim
            then assign viCrossCompanyDivisionId = tqDivisionPrim.tiDivision_ID.
        end. /* if icDivisionCode <> ? and */

        assign viCrossCompanyProjectId = ?.
        if icProjectCode <> ? and
           icProjectCode <> '':U
        then do:
            <Q-5 run ProjectPrim (all) (Read) (NoCache)
               (input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
                input ?, (ProjectID)
                input icProjectCode, (ProjectCode)
                output dataset tqProjectPrim) in BProject >
            find first tqProjectPrim no-error .              
            if available tqProjectPrim
            then assign viCrossCompanyProjectId = tqProjectPrim.tiProject_ID.
        end. /* if icProjectCode */

        assign viCrossCompanyCostCentreId = ?.
        if icCostCentreCode <> ? and
           icCostCentreCode <> '':U
        then do:
            <Q-6 run CostCentrePrim (all) (Read) (NoCache)
               (input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
                input ?, (CostCentreID)
                input icCostCentreCode, (CostCentreCode)
                output dataset tqCostCentrePrim) in BCostCentre >
            find first tqCostCentrePrim no-error.            
            if available tqCostCentrePrim
            then assign viCrossCompanyCostCentreId = tqCostCentrePrim.tiCostCentre_ID.
        end. /* if icCostCentreCode <> ? or */
        
        /* create temp-table record holding the cross company daemon request to create posting in second company */
        /* Note that field QCrossCyPostingInfo is not just assigned to icPostingText as we want to see the company-code (and the voucher) as well in the cross-cy-daemon-request */
        Create tExtQCrossCyPostingAPM.
        Assign tExtQCrossCyPostingAPM.QCrossCyPosting_ID           = 0
               tExtQCrossCyPostingAPM.CrossCompanyGLIsCredit       = (if idCreditLC <> 0 and idCreditLC <> ? 
                                                                      then false 
                                                                      else true)
               tExtQCrossCyPostingAPM.QCrossCyPostingAmountTC      = (if idCreditTC <> 0 and idCreditTC <> ? 
                                                                      then idCreditTC 
                                                                      else idDebitTC)
               tExtQCrossCyPostingAPM.QCrossCyPostingAmountLC      = (if idCreditLC <> 0 and idCreditLC <> ? 
                                                                      then idCreditLC 
                                                                      else idDebitLC)
               tExtQCrossCyPostingAPM.QCrossCyPostingAmountCC      = (if idCreditCC <> 0 and idCreditCC <> ? 
                                                                      then idCreditCC 
                                                                      else idDebitCC)
               tExtQCrossCyPostingAPM.QCrossCyPostingQTY           = 0
               tExtQCrossCyPostingAPM.QCrossCyPostingCreateDate    = Today
               tExtQCrossCyPostingAPM.QCrossCyPostingCreateTime    = Time
               tExtQCrossCyPostingAPM.CInvoice_ID                  = 0
               tExtQCrossCyPostingAPM.Company_ID                   = tAPMatchingLn.APMatchingLnPvodCompID
               tExtQCrossCyPostingAPM.CrossCompanyGL_ID            = tqDomainForInterCompany.tiIntercoAPGL_ID
               tExtQCrossCyPostingAPM.Currency_ID                  = tAPMatching.Currency_ID
               tExtQCrossCyPostingAPM.DInvoice_ID                  = 0
               tExtQCrossCyPostingAPM.OriginatorCompany_ID         = tAPMatching.Company_ID
               tExtQCrossCyPostingAPM.OriginatorPosting_ID         = tAPMatching.Posting_ID
               tExtQCrossCyPostingAPM.OriginatorJournal_ID         = tAPMatching.Journal_ID
               tExtQCrossCyPostingAPM.OriginatorPostingLine_ID     = oiPostingLineId
               tExtQCrossCyPostingAPM.QCrossCyPostingInfo          = trim(#T-41'AP Matching':20(49266)T-41#) + ": ":U + trim(vcTargetCompanyCode) + "/":U + string(tAPMatching.tiPeriodYear, "9999":U) + "/":U + string(tAPMatching.tiPeriodPeriod, "99":U) + "/":U + tAPMatching.tcJournalCode + "/":U + string(tAPMatching.tiPostingVoucher)
               tExtQCrossCyPostingAPM.APMatchingGL_ID              = viCrossCompanyGLId
               tExtQCrossCyPostingAPM.APMatchingDivision_ID        = viCrossCompanyDivisionId
               tExtQCrossCyPostingAPM.APMatchingProject_ID         = viCrossCompanyProjectId
               tExtQCrossCyPostingAPM.APMatchingCostCentre_ID      = viCrossCompanyCostCentreId
               tExtQCrossCyPostingAPM.tc_Rowid                     = string(- oiPostingLineId). 
    end. /* else do: of if tAPMatching.Company_ID = tAPMatchingLn.APMatchingLnPvodCompID */
end. /* else do: */

/* return */
if oiReturnStatus = -98 
then assign oiReturnStatus = 0.