project QadFinancials > class BPosting > method AddControlPosting

Description

add a posting line on a control GL account to current posting


Parameters


icPostingtcRowidinputcharactertposting.tc_Rowid
icGLCodeinputcharacter(control) gl account
icDivisionCodeinputcharacterSub-Account
icIntercoBusinessRelationCodeinputcharacterinterco
icCurrencyCodeinputcharactercurrency
idDebitTCinputdecimalDebitTC
idDebitLCinputdecimalDebitLC
idDebitCCinputdecimalDebitCC
idCreditTCinputdecimalCreditTC
idCreditLCinputdecimalCreditLC
idCreditCCinputdecimalCreditCC
icTextinputcharacterText
iiMasterIdinputintegerID of the master object
f.e. for posting on debtor control accounts this is debtor_id
iiTransactionIdinputintegerID of the transaction object
f.e. for posting on debtor control accounts this is debtorinvoice_id or payment_id
idExchangeRateinputdecimal
idExchangeRateScaleinputdecimal
idPostingLineCCRateinputdecimal
idPostingLineCCScaleinputdecimal
icAllocationKeyinputcharacter
icCostCentreCodeinputcharacter
icProjectCodeinputcharacter
tDefaultSafsinputtemp-tableDefault Safs
All callers should define a temp-table like BPosting:tDefaultSAFs and empty the temp-table right before they call AddControlPosting
All caller that are supplier-related should create a record in the temp-table like BPosting:tDefaultSAFs with SafConceptCode={&SAFCONCEPT-SUPPLIERTYPE} and SafCode=<supplier-type>. This should be done after the empty temp-table and before the call to AddControlPosting.
itExchangeRateDateinputdate
oiPostingLineIdoutputintegerPostingLineId
ilLinkedCrCyDaemonReqExistsinputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCDocument.AdditionalUpdatesPostingBankCharge
method BCDocument.AdditionalUpdatesPostingBankChargeCtrl
method BCDocument.AdditionalUpdatesPostingDocCtrl2
method BCInvoice.CreateCInvoiceMovements
method BCInvoice.CreateCIPostingControl
method BDDocument.AdditionalUpdatesPostingDocCtrl2
method BDInvoice.AdditionalUpdatesAllCreateDA
method BDInvoice.AdditionalUpdatesAllCreateDALinkedDI
method BDInvoice.CreateDInvoiceMovements
method BDInvoice.CreateDIPosting


program code (program1/bposting.p)

/* ====================================== */
/* Exception handling and param resetting */
/* ====================================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0
       idExchangeRate      = round(idExchangeRate, 10)
       idExchangeRateScale = round(idExchangeRateScale, 10).
       
/* =============== */
/* Start the block */
/* =============== */
ADDSTANDARDPOSTINGBLOCK : DO :
    
    /* ======================= */
    /* Get the correct posting */
    /* ======================= */
    find tPosting where
         tPosting.tc_Rowid = icPostingtcRowid no-error.
    if not available tPosting
    then do:
        assign vcMessage           = trim(substitute(#T-3'Internal error: posting record not found for row ID &1.':150(3199)T-3#, icPostingtcRowid))
               viLocalReturnStatus = -3.
        <M-2 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-868':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave ADDSTANDARDPOSTINGBLOCK.
    end. /* if not available tPosting */
    if itExchangeRateDate = ? then assign itExchangeRateDate = tPosting.PostingDate.
    
    /* ====================================================================== */
    /* Call submethod that creates the posting-line                           */
    /* After this call: tqGLForPostingLineCreation and tPostingLine are avail */
    /* ====================================================================== */
    <M-5 run AddPostingSub
       (input  icGLCode (icGLCode), 
        input  icDivisionCode (icDivisionCode), 
        input  icCurrencyCode (icCurrencyCode), 
        input  icIntercoBusinessRelationCode (icBusinessRelationIntercoCode), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Leave ADDSTANDARDPOSTINGBLOCK.
    if not available tqGLForPostingLineCreation or 
       not available tPostingLine
    then do :
        assign vcMessage           = trim(substitute(#T-29'Internal error. The system cannot find the posting record details for row ID '&1'.':255(69655)T-29#, icPostingtcRowid)) + chr(10) + 
                                     trim(substitute(#T-30'Available &1: &2':255(69656)T-30#,"tPostingLine":U,(if available tPostingLine then trim(#T-31'Yes':4(16037)T-31#) else trim(#T-32'No':5(69659)T-32#)) ))  + chr(10) + 
                                     trim(substitute(#T-33'Available &1: &2':255(69656)T-33#,"tqGLForPostingLineCreation":U,(if available tqGLForPostingLineCreation then trim(#T-34'Yes':4(16037)T-34#) else trim(#T-35'No':5(69661)T-35#)) ))
               viLocalReturnStatus = -3.
        <M-28 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-9628':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave ADDSTANDARDPOSTINGBLOCK.
    end. /*  if not available tqGLForPostingLineCreation or  */
     
    /* ==================================================== */
    /* Retrieve / Set the Analysis on the GL. This is not   */
    /* allowed for YearClosings as they only go to GL-level */
    /* ==================================================== */
    if tPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING}
    then do:
        /* ========================= Set the CostCentre and its optional SAFs === */      
        if tqGLForPostingLineCreation.tlGLIsCostCentreAccount
        then do:        
            if icCostCentreCode = "":U or 
               icCostCentreCode = ?
            then do:
                if tPosting.PostingParentText <> {&POSTINGPARENTTEXT-APMATCHING} and /* Skip this defaulting in case it concerns an APMatchign-posting */
                   tqGLForPostingLineCreation.tiCostCentreProfile_ID <> 0 and 
                   tqGLForPostingLineCreation.tiCostCentreProfile_ID <> ?    
                then do:
                    <Q-19 run GetCostCentreFromProfile (all) (Read) (Cache)
                       (input tPosting.Company_ID, (CompanyId)
                        input tqGLForPostingLineCreation.tiCostCentreProfile_ID, (CostCentreProfileId)
                        output dataset tqCostCentreFromProfile) in BProfile>
                    find first tqCostCentreFromProfile no-error.
                    if available tqCostCentreFromProfile
                    then do:
                        assign tPostingLine.CostCentre_ID           = tqCostCentreFromProfile.tiCostCentre_ID
                               tPostingLine.tcCostCentreCode        = tqCostCentreFromProfile.tcCostCentreCode
                               tPostingLine.tcCostCentreDescription = tqCostCentreFromProfile.tcCostCentreDescription.
                        <M-20 run AddDefaultSaf
                           (input  {&POSTINGSAFPARENTTYPE-COSTCENTRE} (icType), 
                            input  tPostingLine.CostCentre_ID (iiObjectId), 
                            input  ? (iiSafStructureId), 
                            input  ? (icSafStructureCode), 
                            input  tPostingLine.GL_ID (iiGLId), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                        if viFcReturnSuper <> 0
                        then assign viLocalReturnStatus = viFcReturnSuper.
                        if viFcReturnSuper < 0 
                        then Leave ADDSTANDARDPOSTINGBLOCK.
                    end. /* if available tqCostCentreFromProfile */
                end. /* if (tqGLForPostingLineCreation.tiCostCentreProfile_ID <> 0 and */
            end. /* if icCostCentreCode = "":U or  */
            else do:
                <Q-21 run CostCentrePrim (all) (Read) (Cache)
                   (input tPosting.Company_ID, (CompanyId)
                    input 0, (CostCentreID)
                    input icCostCentreCode, (CostCentreCode)
                    output dataset tqCostCentrePrim) in BCostCentre>
                find first tqCostCentrePrim no-error.
                if available tqCostCentrePrim
                then do:
                    assign tPostingLine.CostCentre_ID           = tqCostCentrePrim.tiCostCentre_ID
                           tPostingLine.tcCostCentreCode        = tqCostCentrePrim.tcCostCentreCode
                           tPostingLine.tcCostCentreDescription = tqCostCentrePrim.tcCostCentreDescription.
                    <M-22 run AddDefaultSaf
                       (input  {&POSTINGSAFPARENTTYPE-COSTCENTRE} (icType), 
                        input  tPostingLine.CostCentre_ID (iiObjectId), 
                        input  ? (iiSafStructureId), 
                        input  ? (icSafStructureCode), 
                        input  tPostingLine.GL_ID (iiGLId), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    if viFcReturnSuper <> 0
                    then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0 
                    then Leave ADDSTANDARDPOSTINGBLOCK.
                end. /* if available tqCostCentrePrim */
            end. /* Not if icCostCentreCode = "":U or  */
        end. /* if tqGLForPostingLineCreation.tlGLIsCostCentreAccount */
        /* ========================= Set the Project and its optional SAFs === */
        if tqGLForPostingLineCreation.tcGLAnalysisLimitation   = {&GLANALYSISLIMITATION-EXCLEACHOTHER} and
           tPostingLine.tcCostCentreCode                      <> "":U
        then assign tPostingLine.tcProjectCode        = "":U
                    tPostingLine.tcProjectDescription = "":U
                    tPostingLine.Project_ID           = 0.        
        else if tqGLForPostingLineCreation.tlGLIsProjectAccount
        then do:
            if icProjectCode = "":U
            or icProjectCode = ?
            then do:
                if tPosting.PostingParentText <> {&POSTINGPARENTTEXT-APMATCHING} and /* Skip this defaulting in case it concerns an APMatchign-posting */
                   tqGLForPostingLineCreation.tiProjectProfile_ID <> 0 and 
                   tqGLForPostingLineCreation.tiProjectProfile_ID <> ? 
                then do:
                    <Q-23 run GetProjectFromProfile (all) (Read) (Cache)
                       (input tPosting.Company_ID, (CompanyId)
                        input tqGLForPostingLineCreation.tiProjectProfile_ID, (ProjectProfileID)
                        output dataset tqProjectFromProfile) in BProfile>
                    find first tqProjectFromProfile no-error.
                    if available tqProjectFromProfile 
                    then do:
                        assign tPostingLine.Project_ID             = tqProjectFromProfile.tiProject_ID
                               tPostingLine.tcProjectCode          = tqProjectFromProfile.tcProjectCode
                               tPostingLine.tcProjectDescription   = tqProjectFromProfile.tcProjectDescription.
                        <M-24 run AddDefaultSaf
                           (input  {&POSTINGSAFPARENTTYPE-PROJECT} (icType), 
                            input  tPostingLine.Project_ID (iiObjectId), 
                            input  ? (iiSafStructureId), 
                            input  ? (icSafStructureCode), 
                            input  tPostingLine.GL_ID (iiGLId), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                        if viFcReturnSuper <> 0
                        then assign viLocalReturnStatus = viFcReturnSuper.
                        if viFcReturnSuper < 0 
                        then Leave ADDSTANDARDPOSTINGBLOCK.
                    end. /* if available tqProjectFromProfile */
                end. /* if (tqGLForPostingLineCreation.tiProjectProfile_ID <> 0 and  */
            end. /* if icProjectCode = "":U or */
            else do:
                <Q-25 run ProjectByCode (all) (Read) (Cache)
                   (input tPosting.Company_ID, (CompanyId)
                    input icProjectCode, (ProjectCode)
                    output dataset tqProjectByCode) in BProject>
                find first tqProjectByCode no-error.
                if available tqProjectByCode
                then do:
                    assign tPostingLine.Project_ID             = tqProjectByCode.tiProject_ID
                           tPostingLine.tcProjectCode          = tqProjectByCode.tcProjectCode
                           tPostingLine.tcProjectDescription   = tqProjectByCode.tcProjectDescription.
                    <M-26 run AddDefaultSaf
                       (input  {&POSTINGSAFPARENTTYPE-PROJECT} (icType), 
                        input  tPostingLine.Project_ID (iiObjectId), 
                        input  ? (iiSafStructureId), 
                        input  ? (icSafStructureCode), 
                        input  tPostingLine.GL_ID (iiGLId), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    if viFcReturnSuper <> 0
                    then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0 
                    then Leave ADDSTANDARDPOSTINGBLOCK.
                end. /* if available tqProjectByCode */
            end. /* Not if icProjectCode = "":U or */ 
        end. /* if tqGLForPostingLineCreation.tlGLIsProjectAccount */
        /* ========================= Set the Saf-information === */
        if tqGLForPostingLineCreation.tlGLIsSafAccount = true
        then do:
            <M-27 run AddDefaultSaf
               (input  {&POSTINGSAFPARENTTYPE-GL} (icType), 
                input  tPostingLine.GL_ID (iiObjectId), 
                input  ? (iiSafStructureId), 
                input  ? (icSafStructureCode), 
                input  tPostingLine.GL_ID (iiGLId), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            if viFcReturnSuper <> 0
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 
            then Leave ADDSTANDARDPOSTINGBLOCK.
        end. /* if tqGLForPostingLineCreation.tlGLIsSafAccount */
    end. /* end of if tPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING} */
     
    /* ========= */
    /* Assign LC */
    /* ========= */
    if idDebitLC  = ? or idCreditLC = ? 
    then do:
        if idExchangeRate      = ? or
           idExchangeRate      = 0 or 
           idExchangeRateScale = ? or
           idExchangeRateScale = 0
        then do:
            if tPostingLine.Currency_ID = viCompanyLCId
            then assign idDebitLC           = idDebitTC
                        idCreditLC          = idCreditTC
                        idExchangeRate      = 1
                        idExchangeRateScale = 1.
            else do:                
                <M-12 run GetExchangeRate
                   (input  tPosting.Company_ID (iiCompanyID), 
                    input  tPostingLine.Currency_ID (iiFromCurrencyID), 
                    input  ? (icFromCurrencyCode), 
                    input  viCompanyLCId (iiToCurrencyID), 
                    input  ? (icToCurrencyCode), 
                    input  ? (iiExchangeRateTypeID), 
                    input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                    input  itExchangeRateDate (itValidityDate), 
                    output vdRate (odExchangeRate), 
                    output vdRateScale (odExchangeScaleFactor), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>
                if viFcReturnSuper <> 0
                then assign viLocalReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 
                then Leave ADDSTANDARDPOSTINGBLOCK.
                if idDebitLC = ?
                then assign idExchangeRate      = vdRate
                            idExchangeRateScale = vdRateScale
                            idDebitLC           = <M-13 RoundAmount
                                                     (input  idDebitTC * vdRate * vdRatescale (idUnroundedAmount), 
                                                      input  viCompanyLCId (iiCurrencyID), 
                                                      input  vcCompanyLC (icCurrencyCode)) in business>.
                if idCreditLC = ?
                then assign idExchangeRate      = vdRate
                            idExchangeRateScale = vdRateScale
                            idCreditLC          = <M-14 RoundAmount
                                                     (input  idCreditTC * vdRate * vdRateScale (idUnroundedAmount), 
                                                      input  viCompanyLCId (iiCurrencyID), 
                                                      input  vcCompanyLC (icCurrencyCode)) in business>.
            end. /* if tPostingLine.Currency_ID = viCompanyLCId */
        end. /*  if idExchangeRate      = ? or */
        else assign idDebitLC  = <M-15 RoundAmount
                                    (input  idDebitTC  * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                     input  viCompanyLCId (iiCurrencyID), 
                                     input  vcCompanyLC (icCurrencyCode)) in BPosting>
                    idCreditLC = <M-16 RoundAmount
                                    (input  idCreditTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount), 
                                     input  viCompanyLCId (iiCurrencyID), 
                                     input  vcCompanyLC (icCurrencyCode)) in BPosting>.
    end. /* if idDebitLC  = ? or idCreditLC = ? */
    else if idExchangeRate = ? or idExchangeRateScale = ?
         then if idDebitTC - idCreditTC = 0
              then assign idExchangeRate      = 0
                          idExchangeRateScale = 0.
              else assign idExchangeRate      = absolute(round((idDebitLC - idCreditLC) / (idDebitTC - idCreditTC), 10))
                          idExchangeRateScale = 1.     
    /* ========= */
    /* Assign CC */
    /* ========= */
    if idDebitCC  = ? or
       idCreditCC = ?
    then do:
        if idPostingLineCCRate = ? or idPostingLineCCScale = ?
        then do:  
            if viCompanyCCId = tPostingLine.Currency_ID
            then assign idDebitCC            = idDebitTC
                        idCreditCC           = idCreditTC
                        idPostingLineCCRate  = 1
                        idPostingLineCCScale = 1.
            else if vlDomainIsStatutory = false
                 then assign idDebitCC            = idDebitLC
                             idCreditCC           = idCreditLC
                             idPostingLineCCRate  = idExchangeRate
                             idPostingLineCCScale = idExchangeRateScale.
                 else do:
                    assign vhFcComponent = ?.   
                    <M-1 run GetExchangeRate
                        (input  tPosting.Company_ID (iiCompanyID), 
                         input  tPostingLine.Currency_ID (iiFromCurrencyID), 
                         input  ? (icFromCurrencyCode), 
                         input  viCompanyCCID (iiToCurrencyID), 
                         input  ? (icToCurrencyCode), 
                         input  ? (iiExchangeRateTypeID), 
                         input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                         input  itExchangeRateDate (itValidityDate), 
                         output idPostingLineCCRate (odExchangeRate), 
                         output idPostingLineCCScale (odExchangeScaleFactor), 
                         output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    if viFcReturnSuper <> 0
                    then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0 
                    then Leave ADDSTANDARDPOSTINGBLOCK.
                    if idDebitCC = ?
                    then assign idDebitCC = <M-7 RoundAmount
                                                (input  idDebitTC * idPostingLineCCRate * idPostingLineCCScale (idUnroundedAmount), 
                                                 input  viCompanyCCId (iiCurrencyID), 
                                                 input  '':U (icCurrencyCode)) in business>.
                    if idCreditCC = ?
                    then assign idCreditCC = <M-8 RoundAmount
                                                (input  idCreditTC * idPostingLineCCRate * idPostingLineCCScale (idUnroundedAmount), 
                                                 input  viCompanyCCId (iiCurrencyID), 
                                                 input  '':U (icCurrencyCode)) in business>.
                 end. /* Not if viCompanyCCId = viCompanyLCId */
        end. /* if idPostingLineCCRate = ? or idPostingLineCCScale = ? */
        else if vlDomainIsStatutory = false
             then assign idDebitCC            = idDebitLC
                         idCreditCC           = idCreditLC
                         idPostingLineCCRate  = idExchangeRate
                         idPostingLineCCScale = idExchangeRateScale.
             else assign idDebitCC  = <M-17 RoundAmount
                                         (input  idDebitTC * idPostingLineCCRate * idPostingLineCCScale (idUnroundedAmount), 
                                          input  viCompanyCCId (iiCurrencyID), 
                                          input  '':U (icCurrencyCode)) in business>
                         idCreditCC = <M-18 RoundAmount
                                         (input  idCreditTC * idPostingLineCCRate * idPostingLineCCScale (idUnroundedAmount), 
                                          input  viCompanyCCId (iiCurrencyID), 
                                          input  '':U (icCurrencyCode)) in business>.
    end. /* Assign CC */
    else if idPostingLineCCRate = ? or idPostingLineCCScale = ?
         then if idDebitTC - idCreditTC = 0
              then assign idPostingLineCCRate  = 0
                          idPostingLineCCScale = 0.
              else assign idPostingLineCCRate  = absolute(round((idDebitCC - idCreditCC) / (idDebitTC - idCreditTC), 10))
                          idPostingLineCCScale = 1.

    /* ============================= */
    /* Assign the PostingLine fields */
    /* ============================= */
    assign tPostingLine.PostingLineText           = icText
           tPostingLine.PostingLineDebitTC        = idDebitTC
           tPostingLine.PostingLineDebitLC        = idDebitLC
           tPostingLine.PostingLineDebitCC        = idDebitCC
           tPostingLine.PostingLineCreditTC       = idCreditTC
           tPostingLine.PostingLineCreditLC       = idCreditLC
           tPostingLine.PostingLineCreditCC       = idCreditCC
           tPostingLine.PostingLineMaster_ID      = iiMasterId
           tPostingLine.PostingLineTransaction_ID = iiTransactionId
           tPostingLine.PostingLineExchangeRate   = idExchangeRate
           tPostingLine.PostingLineRateScale      = idExchangeRateScale
           tPostingLine.PostingLineCCRate         = idPostingLineCCRate 
           tPostingLine.PostingLineCCScale        = idPostingLineCCScale
           tPostingLine.tcAllocationKey           = icAllocationKey
           tPostingLine.tcAllocationType          = if icAllocationKey = "":U or
                                                       icAllocationKey = ?
                                                    then "":U
                                                    else "N":U
           tPostingLine.tlLinkedCrCyDaemonReqExists = ilLinkedCrCyDaemonReqExists
           oiPostingLineId                        = tPostingLine.PostingLine_ID.

END. /* ADDSTANDARDPOSTINGBLOCK */

/* ================== */
/* Exception handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.