project QadFinancials > class BJournalEntry > method LoadTemplate

Description

Load a template into current posting


Parameters


iiCompanyIdinputinteger
icTemplateCodeinputcharacterTemplateCode
icPostingTextinputcharacterPostingText
icPostingLineTextinputcharacterPosting Line Text. (When blank, template text will not be overwritten)
ilClearAllinputlogicalclear all amounts, quantities and currencies
icCurrencyCodeinputcharacter
idAmountTCinputdecimaltc
idAmountCCinputdecimalinput parameter for statutory currency amount
idExchangeRateinputdecimalExchangeRate (always multiply rate)
idQuantityinputdecimalQuantity
icDivisioninputcharacterSub-Account
icProjectinputcharacterproject
icCostCentreinputcharactercost centre
icSafConceptCodeinputcharacter
icSafCodeinputcharacter
ilAppendinputlogicaladd template lines to posting in stead of replace
ilSkipGLIsAutomaticAccountinputlogical
ilReplAnalInfoOnLastLineOnlyinputlogical
icPostingRowidinputcharactertposting.tc_Rowid
itPostingDateinputdatePosting Date from JE
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BJournalEntry.CreateEntriesPostingTemplate


program code (program1/bjournalentry.p)

/* Normalize input parameters */                                                       
if iiCompanyId    = 0    or iiCompanyId    = ? then assign iiCompanyId    = viCompanyId.
if icCurrencyCode = "":U or icCurrencyCode = ? then assign icCurrencyCode = vcCompanyLC.

/* Validate input parameters */
if icTemplateCode = "":U or icTemplateCode = ?
then return.

/* ================================================================= */
/* Lookup template                                                   */
/* ================================================================= */
<Q-1 run PostingTemplatePrim (all) (Read) (NoCache)
   (input iiCompanyId, (CompanyId)
    input 0, (TemplateID)
    input icTemplateCode, (TemplateCode)
    input 0, (PostingID)
    output dataset tqPostingTemplatePrim) in BPostingTemplate >
find first tqPostingTemplatePrim no-error.
if not available tqPostingTemplatePrim
then do:
    <M-2 run SetMessage
       (input  #T-14'The template code cannot be found.':100(2733)T-14# (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'QADFIN-3476':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    assign oiReturnStatus = -1.
    return.
end.

/*This is written to enable dataload calculate calcualted fields even when it is called multiple times with Keep Previous Data
  Flag as Yes*/    
for each  tAlreadyCalculatedRecords:
    delete  tAlreadyCalculatedRecords.
end. 

/* ================================================================= */
/* Load template                                                     */
/* ================================================================= */
<M-3 run DataLoad
   (input  '' (icRowids), 
    input  string (tqPostingTemplatePrim.tiPosting_ID) (icPkeys), 
    input  '' (icObjectIds), 
    input  '' (icFreeform), 
    input  yes (ilKeepPrevious), 
    output oiReturnStatus (oiReturnStatus)) in BJournalEntry>
if oiReturnStatus <> 0
then return.

find tPosting where 
     tPosting.tc_Rowid = icPostingRowid no-error.
if not available tPosting
then do:
    <M-4 run SetMessage
       (input  'Invalid Posting ID':U (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  icPostingRowid (icRowid), 
        input  'QADFIN-3477':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    assign oiReturnStatus = -1.
    return.
end.

find bTemplate where 
     bTemplate.Posting_ID = tqPostingTemplatePrim.tiPosting_ID no-error.
if not available bTemplate
then do:
    <M-5 run SetMessage
       (input  'Invalid Template ID':U (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  icPostingRowid (icRowid), 
        input  'QADFIN-3478':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    assign oiReturnStatus = -1.
    return.
end.

/* ================================================================= */
/* Update template                                                   */
/* ================================================================= */
assign vdTotalDebit                 = 0
       vdTotalQTY                   = 0
       vcLastDebitPostingLineRowId  = ?
       vcLastCreditPostingLineRowId = ?.
for each tPostingLine where 
         tPostingLine.tc_ParentRowid = bTemplate.tc_Rowid
    break by tPostingLine.PostingLineSequence:

    if not ilSkipGLIsAutomaticAccount and
       tPostingLine.tlGLIsAutomaticAccount
    then do:
        delete tPostingLine.
        vlNoBalance = yes.
        next.
    end.

    assign vdTotalDebit   = vdTotalDebit   + tPostingLine.PostingLineDebitTC
           vdTotalDebitCC = vdTotalDebitCC + tPostingLine.PostingLineDebitCC 
           vdTotalQTY     = vdTotalQTY     + tPostingLine.PostingLineQTY.

    /* Remembe last debit and last credit posting line where rest of amount to post is splitted up */
    if tPostingLine.PostingLineDebitTC <> 0
    then assign vcLastDebitPostingLineRowId  = tPostingLine.tc_Rowid.
    else assign vcLastCreditPostingLineRowId = tPostingLine.tc_Rowid.
    
    
    /* ========================================================================== */
    /* Replace new posting values entered by user                                 */
    /* ========================================================================== */

    /* ASSIGN THE POSTING DATE AVAILABLE ON THE JE */
    if itPostingDate <> ?    
    then assign tPosting.PostingDate = itPostingDate.

    /* Posting text */
    if icPostingLineText <> '':U and
       icPostingLineText <> ?
    then assign tPostingLine.PostingLineText = icPostingLineText.

    /* TC -> LC Exchange rate */
    if tPostingLine.tlPostingLineIsLocalCurrency = false
    then do:
         /* GET THE EXCHNAGE RATE AS PER THE JE POSTING DATE */
         <M-36 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 tPostingLine.PostingLineExchangeRate (odExchangeRate), 
             output tPostingLine.PostingLineRateScale (odExchangeScaleFactor), 
             output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then return.
    end.  /*tPostingLine.tlPostingLineIsLocalCurrency */

    /* TC -> SC Exchange rate */
    if vcCompanyCC = "":U or
       not vlDomainIsStatutory
    then assign tPostingLine.PostingLineCCRate  = tPostingLine.PostingLineExchangeRate
                tPostingLine.PostingLineCCScale = tPostingLine.PostingLineRateScale.
    else if vcCompanyCC = tPostingLine.tcCurrencyCode
    then assign tPostingLine.PostingLineCCRate  = 1
                tPostingLine.PostingLineCCScale = 1.
    else do:
        <M-16 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 tPostingLine.PostingLineCCRate (odExchangeRate), 
            output tPostingLine.PostingLineCCScale (odExchangeScaleFactor), 
            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 (not ilReplAnalInfoOnLastLineOnly) or
       (ilReplAnalInfoOnLastLineOnly and
        last(tPostingLine.PostingLineSequence))
    then do:
        /* Division */
        if icDivision                    <> ?    and
           icDivision                    <> "":U and
           tPostingLine.tcDivisionCode   <> ?    and
           tPostingLine.tcDivisionCode   <> "":U
        then assign tPostingLine.tcDivisionCode = icDivision
                    tPostingLine.Division_ID    = ?.
        
        /* Cost Centre */
        if icCostCentre                  <> ?    and
           icCostCentre                  <> "":U and
           tPostingLine.tcCostCentreCode <> ?    and
           tPostingLine.tcCostCentreCode <> "":U
        then assign tPostingLine.tcCostCentreCode = icCostCentre
                    tPostingLine.CostCentre_ID    = ?.

        /* Project */
        if icProject                     <> ?    and
           icProject                     <> "":U and
           tPostingLine.tcProjectCode    <> ?    and
           tPostingLine.tcProjectCode    <> "":U
            then assign tPostingLine.tcProjectCode        = icProject
                        tPostingLine.Project_ID           = ?
                        tPostingLine.tcProjectDescription = ?.

        /* Saf */    
        if icSafConceptCode <> ? and
           icSafCode <> ?
        then do:
            for each tPostingSaf where
                 tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid:
                if tPostingSaf.tcSafConceptCode = icSafConceptCode
                then assign tPostingSaf.tcSafCode = icSafCode.
            end. 
        end.
    end. /* if (not ilReplAnalInfoOnLastLineOnly) or */
end.

if ilClearAll
then do:
    for each tPostingLine where 
             tPostingLine.tc_ParentRowid = bTemplate.tc_Rowid:
        assign tPostingLine.PostingLineDebitTC  = 0
               tPostingLine.PostingLineDebitLC  = 0
               tPostingLine.PostingLineDebitCC  = 0
               tPostingLine.PostingLineCreditTC = 0
               tPostingLine.PostingLineCreditLC = 0
               tPostingLine.PostingLineCreditCC = 0
               tPostingLine.PostingLineQTY      = 0
               tPostingLine.tcCurrencyCode      = vcCompanyLC
               tPostingLine.Currency_ID         = viCompanyLCId.
    end.
end.
else if  vdTotalDebit <> 0
then do:
    for each tPostingLine where
             tPostingLine.tc_ParentRowid = bTemplate.tc_Rowid
        break by tPostingLine.PostingLineSequence:
        
        /* Calculate value in transactional currency */
        if idAmountTC <> 0
        then do:
            if tPostingLine.tc_Rowid = vcLastDebitPostingLineRowId and
               not vlNoBalance
            then assign tPostingLine.PostingLineDebitTC  = idAmountTC - vdTotalPostedDebitTC
                        tPostingLine.PostingLineCreditTC = 0.
            else if tPostingLine.tc_Rowid = vcLastCreditPostingLineRowId and
                    not vlNoBalance
            then assign tPostingLine.PostingLineDebitTC  = 0
                        tPostingLine.PostingLineCreditTC = idAmountTC - vdTotalPostedCreditTC.
            else assign tPostingLine.PostingLineDebitTC  = <M-17 RoundAmount
                                                              (input  tPostingLine.PostingLineDebitTC * idAmountTC / vdTotalDebit (idUnroundedAmount), 
                                                               input  0 (iiCurrencyID), 
                                                               input  tPostingLine.tcCurrencyCode (icCurrencyCode)) in business>
                        tPostingLine.PostingLineCreditTC = <M-18 RoundAmount
                                                              (input  tPostingLine.PostingLineCreditTC * idAmountTC / vdTotalDebit (idUnroundedAmount), 
                                                               input  0 (iiCurrencyID), 
                                                               input  tPostingLine.tcCurrencyCode (icCurrencyCode)) in business>.
        end. /* if idAmountTC <> 0 */
    
        /* Calculate value in local currency */
        if tPostingLine.tcCurrencyCode = vcCompanyLC
        then assign tPostingLine.PostingLineDebitLC  = tPostingLine.PostingLineDebitTC
                    tPostingLine.PostingLineCreditLC = tPostingLine.PostingLineCreditTC.
        else assign tPostingLine.PostingLineDebitLC  = <M-21 RoundAmount
                                                          (input  tPostingLine.PostingLineDebitTC * tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale (idUnroundedAmount), 
                                                           input  viCompanyLCId (iiCurrencyID), 
                                                           input  vcCompanyLC (icCurrencyCode)) in business>
                    tPostingLine.PostingLineCreditLC = <M-22 RoundAmount
                                                          (input  tPostingLine.PostingLineCreditTC * tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale (idUnroundedAmount), 
                                                           input  viCompanyLCId (iiCurrencyID), 
                                                           input  vcCompanyLC (icCurrencyCode)) in business>.
    
        /* Calculate value in consolidation currency */
        if idAmountCC = 0
        then do:
            if vcCompanyCC = "":U
            then assign tPostingLine.PostingLineDebitCC  = 0
                        tPostingLine.PostingLineCreditCC = 0.
            else if vcCompanyCC = tPostingLine.tcCurrencyCode
            then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitTC
                        tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditTC.
            else if vlDomainIsStatutory = false
            then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitLC
                        tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditLC.
            else assign tPostingLine.PostingLineDebitCC  = <M-19 RoundAmount
                                                              (input  tPostingLine.PostingLineDebitTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                                               input  viCompanyCCId (iiCurrencyID), 
                                                               input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>
                        tPostingLine.PostingLineCreditCC = <M-20 RoundAmount
                                                              (input  tPostingLine.PostingLineCreditTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                                               input  viCompanyCCId (iiCurrencyID), 
                                                               input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>.
        end.
        else do:
            if tPostingLine.tc_Rowid = vcLastDebitPostingLineRowId and
               not vlNoBalance
            then assign tPostingLine.PostingLineDebitCC  = idAmountCC - vdTotalPostedDebitCC
                        tPostingLine.PostingLineCreditCC = 0.
            else if tPostingLine.tc_Rowid = vcLastCreditPostingLineRowId and
                    not vlNoBalance
            then assign tPostingLine.PostingLineDebitCC  = 0
                        tPostingLine.PostingLineCreditCC = idAmountCC - vdTotalPostedCreditCC.
            else assign tPostingLine.PostingLineDebitCC  = <M-86 RoundAmount
                                                              (input  tPostingLine.PostingLineDebitCC * idAmountCC / vdTotalDebitCC (idUnroundedAmount), 
                                                               input  0 (iiCurrencyID), 
                                                               input  tPostingLine.tcCurrencyCode (icCurrencyCode)) in BApplicationProperty>
                        tPostingLine.PostingLineCreditCC = <M-69 RoundAmount
                                                              (input  tPostingLine.PostingLineCreditCC * idAmountCC / vdTotalDebitCC (idUnroundedAmount), 
                                                               input  0 (iiCurrencyID), 
                                                               input  tPostingLine.tcCurrencyCode (icCurrencyCode)) in BApplicationProperty>.
                                                               
            if vcCompanyCC <> tPostingLine.tcCurrencyCode
            then assign tPostingLine.PostingLineCCRate  = absolute(round( (tPostingLine.PostingLineDebitCC - tPostingLine.PostingLineCreditCC) / (tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC) , 10))
                        tPostingLine.PostingLineCCScale = 1.
                                                               
        end.

        if vdTotalQTY <> 0
        then assign tPostingLine.PostingLineQTY = round (tPostingLine.PostingLineQTY * idQuantity / vdTotalQTY, 2).
    
        /* Calculate total posted amount and balance also */
        assign vdTotalPostedDebitTC  = vdTotalPostedDebitTC  + tPostingLine.PostingLineDebitTC
               vdTotalPostedCreditTC = vdTotalPostedCreditTC + tPostingLine.PostingLineCreditTC
               vdTotalPostedDebitCC  = vdTotalPostedDebitCC  + tPostingLine.PostingLineDebitCC
               vdTotalPostedCreditCC = vdTotalPostedCreditCC + tPostingLine.PostingLineCreditCC
               vdBalanceTC           = vdBalanceTC + tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC
               vdBalanceLC           = vdBalanceLC + tPostingLine.PostingLineDebitLC - tPostingLine.PostingLineCreditLC
               vdBalanceCC           = vdBalanceCC + tPostingLine.PostingLineDebitCC - tPostingLine.PostingLineCreditCC.

        /* Ensure, created posting is really balanced not only in TC curency (which is ensured by other code) but also in LC, CC */
        if last (tPostingLine.PostingLineSequence) and not vlNoBalance
        then do:
            if tPostingLine.PostingLineCreditTC = 0
            then assign tPostingLine.PostingLineDebitTC  = tPostingLine.PostingLineDebitTC  - vdBalanceTC.
            else assign tPostingLine.PostingLineCreditTC = tPostingLine.PostingLineCreditTC + vdBalanceTC.
            
            if tPostingLine.PostingLineCreditLC = 0
            then assign tPostingLine.PostingLineDebitLC  = tPostingLine.PostingLineDebitLC  - vdBalanceLC.
            else assign tPostingLine.PostingLineCreditLC = tPostingLine.PostingLineCreditLC + vdBalanceLC.
            
            if tPostingLine.PostingLineCreditCC = 0
            then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitCC  - vdBalanceCC.
            else assign tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditCC + vdBalanceCC.
        end.
    end. /* for each tPostingLine where */
end. /* else if  vdTotalDebit <> 0 and */

/* ================================================================= */
/* Remove current posting                                            */
/* ================================================================= */
for each tPostingLine where
         tPostingLine.tc_ParentRowid = tPosting.tc_Rowid
         by tPostingLine.PostingLineSequence:

    if ilAppend or 
       (not ilSkipGLIsAutomaticAccount and
        tPostingLine.tlGLIsAutomaticAccount)
    then assign viLine = tPostingLine.PostingLineSequence.
    else do:
            
        for each tPostingSaf where tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid:
            if tPostingSaf.tc_Status = "N":U
            then delete tPostingSaf.
            else assign tPostingSaf.tc_Status = "D":U.
        end.
    
        for each tPostingVat where tPostingVat.tc_ParentRowid = tPostingLine.tc_Rowid:
            if tPostingVat.tc_Status = "N":U
            then delete tPostingVat.
            else assign tPostingVat.tc_Status = "D":U.
        end.

        for each tPostingWHT where tPostingWHT.tc_ParentRowid = tPostingLine.tc_Rowid:
            if tPostingWHT.tc_Status = "N":U
            then delete tPostingWHT.
            else assign tPostingWHT.tc_Status = "D":U.
        end.
        
        if tPostingLine.tc_Status = "N":U
        then delete tPostingLine.
        else assign tPostingLine.tc_Status = "D":U.

    end.
end.

/* ================================================================= */
/* Add template                                                      */
/* ================================================================= */
for each tPostingLine where
         tPostingLine.tc_ParentRowid = bTemplate.tc_Rowid
         by tPostingLine.PostingLineSequence:

    if ilAppend = no and 
       ilSkipGLIsAutomaticAccount = no and 
       tPostingLine.tlGLIsAutomaticAccount
    then next.

    find t_iPostingLine where
         t_iPostingLine.tc_Rowid = tPostingLine.tc_Rowid no-error.
    if available t_iPostingLine
    then delete t_iPostingLine.
    
    assign viLine        = viLine + 1
           vhFcComponent = vhFcPersistence
           vcOld         = tPostingLine.tc_Rowid.

    assign tPostingLine.PostingLine_ID      = <M-8 GetNextValue (input  'ObjectNumber':U (icSequence)) in persistence>
           tPostingLine.PostingLineSequence = viLine
           tPostingLine.PostingLineMaster_ID = 0
           tPostingLine.PostingLineTransaction_ID = 0
           tPostingLine.tcAllocationType    = "":U
           tPostingLine.tcAllocationKey     = "":U
           tPostingLine.Posting_ID          = tPosting.Posting_ID
           tPostingLine.tc_ParentRowid      = tPosting.tc_Rowid
           tPostingLine.tc_Status           = "N":U.
    assign tPostingLine.tc_Rowid            = <M-9 GetNumberForNew () in BJournalEntry>.

    for each tPostingSaf where tPostingSaf.tc_ParentRowid = vcOld:

        find t_iPostingSaf where
             t_iPostingSaf.tc_Rowid = tPostingSaf.tc_Rowid no-error.
        if available t_iPostingSaf
        then delete t_iPostingSaf.
        
        assign vhFcComponent = vhFcPersistence.
        assign tPostingSaf.PostingSaf_ID  = <M-10 GetNextValue (input  'ObjectNumber':U (icSequence)) in persistence>
               tPostingSaf.PostingLine_ID = tPostingLine.PostingLine_ID
               tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid
               tPostingSaf.tc_Status      = "N":U.
        assign tPostingSaf.tc_Rowid       = <M-11 GetNumberForNew () in BJournalEntry>.
    end.

    for each tPostingVat where tPostingVat.tc_ParentRowid = vcOld:

        find t_iPostingVat where
             t_iPostingVat.tc_Rowid = tPostingVat.tc_Rowid no-error.
        if available t_iPostingVat
        then delete t_iPostingVat.
        
        assign vhFcComponent = vhFcPersistence.
        assign tPostingVat.PostingVat_ID  = <M-12 GetNextValue (input  'ObjectNumber':U (icSequence)) in persistence>
               tPostingVat.PostingLine_ID = tPostingLine.PostingLine_ID
               tPostingVat.tc_ParentRowid = tPostingLine.tc_Rowid
               tPostingVat.tc_Status      = "N":U.
        assign tPostingVat.tc_Rowid       = <M-13 GetNumberForNew () in BJournalEntry>.
    end.

    /* For creating template for tPostingWHT, a new tPostingVat line will be created and the data */
    /* in tPostingWHT will be moved into tPostingVat table.                                       */
    /* Because all validations in BPosting and BJournalEntry, which are available for PostingVat, */
    /* are totally available for PostingWHT data, so it is no need for adding the similar         */
    /* validation logic to check tPostingWHT data. If there's data in tPostingWHT,                */
    /* they should be moved in tPostingVat to go through validateComponent.                       */
    /* In preSave, the copied data in tPostingVat will be moved back to tPostingWHT to save.      */
    for each tPostingWHT where tPostingWHT.tc_ParentRowid = vcOld:

        find t_iPostingWHT where
             t_iPostingWHT.tc_Rowid = tPostingWHT.tc_Rowid no-error.
        if available t_iPostingWHT
        then delete t_iPostingWHT.
        
        assign vhFcComponent = vhFcPersistence.

        <M-48 run AddDetailLine
           (input  'PostingVat' (icTable), 
            input  tPostingLine.tc_Rowid (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>

        assign tPostingVat.PostingLine_ID             = tPostingLine.PostingLine_ID
               tPostingVat.Currency_ID                = tPostingWHT.Currency_ID
               tPostingVat.PeriodMark_ID              = tPostingWHT.PeriodMark_ID
               tPostingVat.Vat_ID                     = tPostingWHT.Vat_ID
               tPostingVat.PostingVatBaseCreditCC     = tPostingWHT.PostingWHTBaseCreditCC
               tPostingVat.PostingVatBaseCreditLC     = tPostingWHT.PostingWHTBaseCreditLC
               tPostingVat.PostingVatBaseCreditTC     = tPostingWHT.PostingWHTBaseCreditTC
               tPostingVat.PostingVatBaseDebitCC      = tPostingWHT.PostingWHTBaseDebitCC
               tPostingVat.PostingVatBaseDebitLC      = tPostingWHT.PostingWHTBaseDebitLC
               tPostingVat.PostingVatBaseDebitTC      = tPostingWHT.PostingWHTBaseDebitTC
               tPostingVat.PostingVatExchangeRate     = tPostingWHT.PostingWHTExchangeRate
               tPostingVat.PostingVatInOut            = tPostingWHT.PostingWHTInOut
               tPostingVat.PostingVatOwnTaxDeclarat   = tPostingWHT.PostingWHTOwnTaxDeclarat
               tPostingVat.PostingVatOwnTaxIDFeder    = tPostingWHT.PostingWHTOwnTaxIDFeder
               tPostingVat.PostingVatOwnTaxIDMisc1    = tPostingWHT.PostingWHTOwnTaxIDMisc1
               tPostingVat.PostingVatOwnTaxIDMisc2    = tPostingWHT.PostingWHTOwnTaxIDMisc2
               tPostingVat.PostingVatOwnTaxIDMisc3    = tPostingWHT.PostingWHTOwnTaxIDMisc3
               tPostingVat.PostingVatOwnTaxIDState    = tPostingWHT.PostingWHTOwnTaxIDState
               tPostingVat.PostingVatRateScale        = tPostingWHT.PostingWHTRateScale
               tPostingVat.PostingVatTaxCreditCC      = tPostingWHT.PostingWHTTaxCreditCC
               tPostingVat.PostingVatTaxCreditLC      = tPostingWHT.PostingWHTTaxCreditLC
               tPostingVat.PostingVatTaxCreditTC      = tPostingWHT.PostingWHTTaxCreditTC
               tPostingVat.PostingVatTaxDebitCC       = tPostingWHT.PostingWHTTaxDebitCC
               tPostingVat.PostingVatTaxDebitLC       = tPostingWHT.PostingWHTTaxDebitLC
               tPostingVat.PostingVatTaxDebitTC       = tPostingWHT.PostingWHTTaxDebitTC
               tPostingVat.PostingVatTaxIDFeder       = tPostingWHT.PostingWHTTaxIDFeder
               tPostingVat.PostingVatTaxIDMisc1       = tPostingWHT.PostingWHTTaxIDMisc1
               tPostingVat.PostingVatTaxIDMisc2       = tPostingWHT.PostingWHTTaxIDMisc2
               tPostingVat.PostingVatTaxIDMisc3       = tPostingWHT.PostingWHTTaxIDMisc3
               tPostingVat.PostingVatTaxIDState       = tPostingWHT.PostingWHTTaxIDState
               tPostingVat.PostingVatTaxPointDate     = tPostingWHT.PostingWHTTaxPointDate
               tPostingVat.PostingVatTaxTransType     = tPostingWHT.PostingWHTTaxTransType
               tPostingVat.PostingVatTransType        = tPostingWHT.PostingWHTTransType
               tPostingVat.FromTxzTaxZone             = tPostingWHT.PostingWHTFromTxzTaxZone
               tPostingVat.ToTxzTaxZone               = tPostingWHT.PostingWHTToTxzTaxZone
               tPostingVat.tcCurrencyCode             = tPostingWHT.tcCurrencyCode
               tPostingVat.tcDomainCode               = tPostingWHT.tcDomainCode
               tPostingVat.tcVatCode                  = tPostingWHT.tcVatCode
               tPostingVat.tcVatInOut                 = tPostingWHT.tcVatInOut
               tPostingVat.tdFullCreditTC             = tPostingWHT.tdFullCreditTC
               tPostingVat.tdFullDebitTC              = tPostingWHT.tdFullDebitTC
               tPostingVat.TxclTaxCls                 = tPostingWHT.PostingWHTTxclTaxCls
               tPostingVat.TxenvTaxEnv                = tPostingWHT.PostingWHTTxenvTaxEnv
               tPostingVat.TxtyTaxType                = tPostingWHT.PostingWHTTxtyTaxType
               tPostingVat.Txutaxusage                = tPostingWHT.PostingWHTTxutaxusage.
        delete tPostingWHT.
    end.
    
    <M-84 run LoadVatTemplate
       (input  iiCompanyId (iiCompanyID), 
        input  tPostingLine.tc_Rowid (icParentRowid), 
        input  idAmountTC (idAmountTC), 
        input  vdTotalDebit (idTotalDebit), 
        input  tPosting.PostingDate (itPostingDate), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.        
    if oiReturnStatus < 0
    then return.    
end.

find t_iPosting where
     t_iPosting.tc_Rowid = bTemplate.tc_Rowid no-error.
if available t_iPosting
then delete t_iPosting.

delete bTemplate.

/* ============================================================================================================ */
/* Assign vcTemplateLoadedList :                                                                                */
/* chr(4) separated list of the Company-id and Template-codes that have been loaded into postings               */
/* of current business-class-instance. The Company-id and Template-code are chr(2) separated.                   */
/* (this is used for saving updated template).                                                                  */
/* Example: 001<chr(2)>TemplateA<chr(4)>002<chr(2)>TemplateB                                                    */
/* ============================================================================================================ */

assign vcTemplateLoadedList = (if vcTemplateLoadedList = "":U or
                                  vcTemplateLoadedList = ?
                               then "":U
                               else vcTemplateLoadedList + chr(4)) + 
                               string(iiCompanyId) + chr(2) + icTemplateCode.