project QadFinancials > class BJournalEntry > method UpdatePostingLine

Description

This method updates some details of posting line


Parameters


icPostingLineRowIdinputcharacter
iiPostingLineIdinputinteger
icNewGLCodeinputcharacter
iiNewGLIdinputinteger
ilIsUpdateGLAccountinputlogical
icNewDivisionCodeinputcharacter
ilIsUpdateDivisioninputlogical
icNewCostCentreCodeinputcharacter
ilIsUpdateCostCentreinputlogical
icNewProjectCodeinputcharacter
ilIsUpdateProjectinputlogical
idDebitTCinputdecimal
idDebitCCinputdecimal
idDebitLCinputdecimal
idCreditTCinputdecimal
idCreditCCinputdecimal
idCreditLCinputdecimal
ilIsUpdateAmountinputlogical
icBusinessRelationIntercoCodeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.CreateMFPosting
method BCInvoice.ReplaceCInvoicePosting
method BCInvoice.ReverseCInvoicePosting


program code (program6/bjournalentry.p)

/* =================================================================================================== */
/* Method      : UpdatePostingLine                                                                     */
/* Desc        : This method updates existing posting line about new details                           */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  PostingLineRowId     Row id of posting line to be updated                             */
/*          (I)  PostingLineId        ID of posting line                                               */
/*          (I)  NewGLCode            Code of new G/L account                                          */
/*          (I)  NewGLId              ID of new G/L account                                            */
/*          (I)  IsUpdateGLAccount    Update posting line with new GL account                          */
/*          (I)  NewDivisionCode      Code of new division                                             */
/*          (I)  IsUpdateDivision     Update posting line with new Division                            */
/*          (I)  NewCostCentreCode    Code of new cost centre                                          */
/*          (I)  IsUpdateCostCentre   Update posting line with cost centre                             */
/*          (I)  NewProjectCode       Code of new project                                              */
/*          (I)  IsUpdateProject      Update posting line with project                                 */
/*          (I)  DebitTC              New Debit TC amount                                              */
/*          (I)  DebitCC              New Debit CC amount                                              */
/*          (I)  DebitLC              New Debit LC amount                                              */
/*          (I)  CreditTC             New Credit TC amount                                             */
/*          (I)  CreditCC             New Credit CC amount                                             */
/*          (I)  CreditLC             New Credit LC amount                                             */
/*          (I)  IsUpdateAmount       Update posting line with new amount                              */
/* =================================================================================================== */

assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.

/* =================================================================================================== */
/* Normalize input parameters                                                                          */
/* =================================================================================================== */
if icPostingLineRowId = "":U then assign icPostingLineRowId = ?.
if iiPostingLineId    = 0    then assign iiPostingLineId    = ?.
if icNewGLCode        = "":U then assign icNewGLCode        = ?.
if iiNewGLId          = 0    then assign iiNewGLId          = ?.
if icNewDivisionCode  = "":U then assign icNewDivisionCode  = ?.
if icNewProjectCode   = "":U then assign icNewProjectCode   = ?. 

/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if icPostingLineRowId = ? and
   iiPostingLineId    = ?
then do:
    assign vcContext = substitute("icPostingLineRowId=&1|iiPostingLineId", icPostingLineRowId, iiPostingLineId)
           vcContext = replace(vcContext, "|":U, chr(2)).
    <M-1 run SetMessage
       (input  #T-1'You have not entered all the mandatory values.':255(63250)t-1# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-8163':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    assign oiReturnStatus = -1.
    return.
end.

MAIN_BLOCK: DO:
    
    find tPostingLine where
         (if icPostingLineRowId <> ? then tPostingLine.tc_Rowid = icPostingLineRowId else true) and
         (if iiPostingLineId    <> ? then tPostingLine.PostingLine_ID = iiPostingLineId else true)
         no-error.
    if not available tPostingLine
    then do:
        assign vcContext = substitute("icPostingLineRowId=&1|iiPostingLineId", icPostingLineRowId, iiPostingLineId)
               vcContext = replace(vcContext, "|":U, chr(2)).
        <M-2 run SetMessage
           (input  #T-46'There is a missing posting line record':253(196400925)T-46# (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'S':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-8164':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  vcContext (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end. /* if not available tPostingLine */
    find tPosting where
         tPosting.tc_Rowid = tPostingLine.tc_ParentRowid
         no-error.
    if not available tPosting
    then do:
        assign vcContext = substitute("PostingLineParentRowId=&1", tPostingLine.tc_ParentRowid)
               vcContext = replace(vcContext, "|":U, chr(2)).        
        <M-94 run SetMessage
           (input  #T-61'There is a missing posting record':254(88000160)T-61# (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'S':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-676500':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  vcContext (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end. /* if not available tPosting */
    
    
    /* =================================================================================================== */
    /* Get some details about GL account if needed                                                         */
    /* =================================================================================================== */
    if ilIsUpdateGLAccount or
       ilIsUpdateCostCentre or
       ilIsUpdateDivision or
       ilIsUpdateProject
    then do:
        if icNewGLCode = ? and iiNewGLId = ?
        then assign icNewGLCode = tPostingLine.tcGLCode
                    iiNewGLId   = tPostingLine.GL_ID.
        
        <Q-89 run GLForPostingLineCreation (all) (Read) (NoCache)
           (input viCompanyId, (CompanyID)
            input icNewGLCode, (GLCode)
            input iiNewGLId, (GLId)
            output dataset tqGLForPostingLineCreation) in BGL >
        find first tqGLForPostingLineCreation no-error.
        if not available tqGLForPostingLineCreation
        then do:
            assign vcContext = "icNewGLCode=&1|iiNewGLId=&2":U
                   vcContext = substitute(vcContext, icNewGLCode, iiNewGLId)
                   vcContext = replace(vcContext, "|":U, chr(2)).
            <M-66 run SetMessage
               (input  #T-43'The system cannot read the GL account definition.':255(69193)T-43# (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'S':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-117524':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  vcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            assign viLocalReturnStatus = -1.
            leave MAIN_BLOCK.        
        end.
    end.
    
    
    /* =================================================================================================== */
    /* Change G/L account                                                                                  */
    /* =================================================================================================== */
    if ilIsUpdateGLAccount
    then assign tPostingLine.GL_ID                  = tqGLForPostingLineCreation.tiGL_ID
               tPostingLine.tcGLCode               = tqGLForPostingLineCreation.tcGLCode
               tPostingLine.tcGLTypeCode           = tqGLForPostingLineCreation.tcGLTypeCode
               tPostingLine.tlGLIsAutomaticAccount = tqGLForPostingLineCreation.tlGLIsAutomaticAccount
               tPostingLine.tcGLDescription        = tqGLForPostingLineCreation.tcGLDescription
               tPostingLine.tlGLIsDebitAccount     = tqGLForPostingLineCreation.tlGLIsDebitAccount.
              
    if tqGLForPostingLineCreation.tlGLIsIntercoAccount
    then do:
        if tqGLForPostingLineCreation.tlGLIsFixedInterco
        or icBusinessRelationIntercoCode = ""
        or icBusinessRelationIntercoCode = ?
        then do:
            if tqGLForPostingLineCreation.tiBusinessRelation_ID <> 0 and 
               tqGLForPostingLineCreation.tiBusinessRelation_ID <> ?
            then do:
                <Q-30 run BusinessRelationByIDCodeIC (all) (Read) (Cache)
                   (input tqGLForPostingLineCreation.tiBusinessRelation_ID, (BusinessRelationID)
                    input ?, (BusinessRelationCode)
                    input ?, (BusinessRelationIntercoCode)
                    input true, (BusinessRelationIsActive)
                    output dataset tqBusinessRelationByIDCodeIC) in BBusinessRelation>

                find first tqBusinessRelationByIDCodeIC where
                           tqBusinessRelationByIDCodeIC.tiBusinessRelation_ID = tqGLForPostingLineCreation.tiBusinessRelation_ID
                           no-error.
                if available tqBusinessRelationByIDCodeIC
                then assign tPostingLine.IntercoBusinessRelation_ID    = tqBusinessRelationByIDCodeIC.tiBusinessRelation_ID
                            tPostingLine.tcIntercoBusinessRelationCode = tqBusinessRelationByIDCodeIC.tcBusinessRelationICCode.                        
            end.
        end.
        else do:
             <Q-74 run BusinessRelationByIDCodeIC (all) (Read) (Cache)
                (input ?, (BusinessRelationID)
                 input ?, (BusinessRelationCode)
                 input icBusinessRelationIntercoCode, (BusinessRelationIntercoCode)
                 input true, (BusinessRelationIsActive)
                 output dataset tqBusinessRelationByIDCodeIC) in BBusinessRelation>

            find first tqBusinessRelationByIDCodeIC where
                           tqBusinessRelationByIDCodeIC.tcBusinessRelationICCode = Icbusinessrelationintercocode
                       no-error.
            if available tqBusinessRelationByIDCodeIC 
            then assign tPostingLine.IntercoBusinessRelation_ID    = tqBusinessRelationByIDCodeIC.tiBusinessRelation_ID
                        tPostingLine.tcIntercoBusinessRelationCode = tqBusinessRelationByIDCodeIC.tcBusinessRelationICCode.
        end.
    end. 

    /* =================================================================================================== */
    /* Change Division                                                                                     */
    /* =================================================================================================== */
    if ilIsUpdateDivision
    then do:
        /* Division */
        if tqGLForPostingLineCreation.tlGLIsDivisionAccount
        then do:
            /* Take division from existing posting line if it's there */
            if icNewDivisionCode = ? 
            then assign icNewDivisionCode = tPostingLine.tcDivisionCode.
             
            /* Take default division from G/L account */
            if icNewDivisionCode = ?
            then do:
                if tqGLForPostingLineCreation.tiDivisionProfile_ID <> 0 and 
                   tqGLForPostingLineCreation.tiDivisionProfile_ID <> ?
                then do:
                    <Q-10 run GetDivisionFromProfile (all) (Read) (NoCache)
                       (input tPostingLine.Company_ID, (CompanyId)
                        input tqGLForPostingLineCreation.tiDivisionProfile_ID, (DivisionProfileId)
                        output dataset tqDivisionFromProfile) in BProfile >
                    find first tqDivisionFromProfile no-error.
                    if available tqDivisionFromProfile
                    then assign tPostingLine.Division_ID    = tqDivisionFromProfile.tiDivision_ID
                                tPostingLine.tcDivisionCode = tqDivisionFromProfile.tcDivisionCode.
                end.
            end.
            else do:
                <Q-11 run DivisionPrim (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    input ?, (DivisionID)
                    input icNewDivisionCode, (DivisionCode)
                    output dataset tqDivisionPrim) in BDivision >
                find first tqDivisionPrim no-error.
                if available tqDivisionPrim
                then assign tPostingLine.Division_ID    = tqDivisionPrim.tiDivision_ID
                            tPostingLine.tcDivisionCode = tqDivisionPrim.tcDivisionCode.
            end.
        end.
    end. /* if ilIsUpdateDivision  */    
        
    /* =================================================================================================== */
    /* Change Cost Centre                                                                                  */
    /* =================================================================================================== */
    if ilIsUpdateCostCentre
    then do:
        if tqGLForPostingLineCreation.tlGLIsCostCentreAccount
        then assign tPostingLine.tcCostCentreCode = if icNewCostCentreCode <> ? 
                                                    then icNewCostCentreCode
                                                    else tPostingLine.tcCostCentreCode
                    tPostingLine.CostCentre_ID    = 0.
        else assign tPostingLine.tcCostCentreCode = "":U
                    tPostingLine.CostCentre_ID    = 0. 
    end. /* if ilIsUpdateCostCentre */                
    
    /* =================================================================================================== */
    /* Change Project                                                                                      */
    /* =================================================================================================== */
    if ilIsUpdateProject
    then do:
        if tqGLForPostingLineCreation.tlGLIsProjectAccount
        then assign tPostingLine.tcProjectCode = if icNewProjectCode <> ? 
                                                 then icNewProjectCode
                                                 else tPostingLine.tcProjectCode
                    tPostingLine.Project_ID    = 0.
        else assign tPostingLine.tcProjectCode = "":U
                    tPostingLine.Project_ID    = 0. 
    end. /* if ilIsUpdateProject */
    
    /* =================================================================================================== */
    /* Change amount                                                                                       */
    /* =================================================================================================== */
    if ilIsUpdateAmount
    then do:
        assign tPostingLine.PostingLineCreditTC = idCreditTC
               tPostingLine.PostingLineCreditCC = idCreditCC
               tPostingLine.PostingLineCreditLC = idCreditLC
               tPostingLine.PostingLineDebitTC  = idDebitTC
               tPostingLine.PostingLineDebitCC  = idDebitCC
               tPostingLine.PostingLineDebitLC  = idDebitLC.
    
        /* Assignment of the LC and CC value is copied from the AddStandardPosting method */
        /* ========= */
        /* Assign LC */
        /* ========= */
        if tPostingLine.PostingLineDebitLC  = ? or
           tPostingLine.PostingLineCreditLC = ?
        then do:
            if tPostingLine.PostingLineExchangeRate = ? or 
               tPostingLine.PostingLineRateScale    = ?
            then do:
                if tPostingLine.Currency_ID = viCompanyLCId
                then assign tPostingLine.PostingLineDebitLC      = tPostingLine.PostingLineDebitTC
                            tPostingLine.PostingLineCreditLC     = tPostingLine.PostingLineCreditTC
                            tPostingLine.PostingLineExchangeRate = 1
                            tPostingLine.PostingLineRateScale    = 1.
                else do :
                    <M-59 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  tPosting.PostingDate (itValidityDate), 
                        output vdRate (odExchangeRate), 
                        output vdRateScale (odExchangeScaleFactor), 
                        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                    if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0  then Leave MAIN_BLOCK.
                    
                    assign tPostingLine.PostingLineExchangeRate = vdRate
                           tPostingLine.PostingLineRateScale    = vdRateScale.
                    
                    if tPostingLine.PostingLineDebitLC = ?
                    then assign tPostingLine.PostingLineDebitLC = 
                             <M-69 RoundAmount
                                (input  tPostingLine.PostingLineDebitTC * vdRate * vdRatescale (idUnroundedAmount), 
                                 input  viCompanyLCId (iiCurrencyID), 
                                 input  vcCompanyLC (icCurrencyCode)) in business>.
                    
                    if tPostingLine.PostingLineCreditLC = ?
                    then assign tPostingLine.PostingLineCreditLC = 
                             <M-23 RoundAmount
                                (input  tPostingLine.PostingLineCreditTC * vdRate * vdRateScale (idUnroundedAmount), 
                                 input  viCompanyLCId (iiCurrencyID), 
                                 input  vcCompanyLC (icCurrencyCode)) in business>.
                end. /* if tPostingLine.Currency_ID = viCompanyLCId */
            end.
            else assign tPostingLine.PostingLineDebitLC = 
                           <M-98 RoundAmount
                              (input  tPostingLine.PostingLineDebitTC * tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale (idUnroundedAmount), 
                               input  viCompanyLCId (iiCurrencyID), 
                               input  '':U (icCurrencyCode)) in BApplicationProperty>
                        tPostingLine.PostingLineCreditLC = 
                           <M-45 RoundAmount
                              (input  tPostingLine.PostingLineCreditTC * tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale (idUnroundedAmount), 
                               input  viCompanyLCId (iiCurrencyID), 
                               input  '':U (icCurrencyCode)) in BApplicationProperty>.
        end. /* if tPostingLine.PostingLineDebitLC  = ? or */
            
        /* ========= */
        /* Assign CC */
        /* ========= */
        if tPostingLine.PostingLineDebitCC  = ? or
           tPostingLine.PostingLineCreditCC = ?
        then do:               
            if tPostingLine.PostingLineCCRate  = ? or 
               tPostingLine.PostingLineCCScale = ?
            then do:           
                if viCompanyCCId = tPostingLine.Currency_ID
                then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitTC
                            tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditTC
                            tPostingLine.PostingLineCCRate   = 1
                            tPostingLine.PostingLineCCScale  = 1. 
                else if vlDomainIsStatutory = false
                     then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitLC
                                 tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditLC
                                 tPostingLine.PostingLineCCRate   = tPostingLine.PostingLineExchangeRate
                                 tPostingLine.PostingLineCCScale  = tPostingLine.PostingLineRateScale.
                     else do :
                        <M-95 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  tPosting.PostingDate (itValidityDate), 
                            output vdRate (odExchangeRate), 
                            output vdRateScale (odExchangeScaleFactor), 
                            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                         if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
                         if viFcReturnSuper < 0  then Leave MAIN_BLOCK.

                         assign tPostingLine.PostingLineCCRate  = vdRate
                                tPostingLine.PostingLineCCScale = vdRateScale.

                         if tPostingLine.PostingLineDebitCC = ?
                         then assign tPostingLine.PostingLineDebitCC = 
                                <M-64 RoundAmount
                                   (input  tPostingLine.PostingLineDebitTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                    input  viCompanyCCId (iiCurrencyID), 
                                    input  '':U (icCurrencyCode)) in BApplicationProperty>.
                
                        if tPostingLine.PostingLineCreditCC = ?
                        then assign tPostingLine.PostingLineCreditCC = 
                                <M-72 RoundAmount
                                   (input  tPostingLine.PostingLineCreditTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                    input  viCompanyCCId (iiCurrencyID), 
                                    input  '':U (icCurrencyCode)) in BApplicationProperty>.
                     end. /* Not if viCompanyCCId = viCompanyLCId */ 
            end. /* if tPostingLine.PostingLineCCRate  = ? or */ 
            else if vlDomainIsStatutory = false
                 then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitLC
                             tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditLC
                             tPostingLine.PostingLineCCRate   = tPostingLine.PostingLineExchangeRate
                             tPostingLine.PostingLineCCScale  = tPostingLine.PostingLineRateScale.
                 else assign tPostingLine.PostingLineDebitCC = 
                                <M-18 RoundAmount
                                   (input  tPostingLine.PostingLineDebitTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                    input  viCompanyCCId (iiCurrencyID), 
                                    input  '':U (icCurrencyCode)) in BApplicationProperty>
                             tPostingLine.PostingLineCreditCC = 
                                <M-87 RoundAmount
                                   (input  tPostingLine.PostingLineCreditTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                    input  viCompanyCCId (iiCurrencyID), 
                                    input  '':U (icCurrencyCode)) in BApplicationProperty>.
            
        end. /* if tPostingLine.PostingLineDebitCC  = ? or */
    end. /* if ilIsUpdateAmount */
end. /* MAIN_BLOCK */    

if ilIsUpdateAmount or
   ilIsUpdateCostCentre or
   ilIsUpdateDivision or
   ilIsUpdateGLAccount or
   ilIsUpdateProject
then assign tPostingLine.tc_Status = (if tPostingLine.tc_Status = "":U
                                      then "C":U
                                      else tPostingLine.tc_Status).

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
assign oiReturnStatus = viLocalReturnStatus.