project QadFinancials > class BJournalEntry > method CreateRecEntryPostingTemplate

Description

Create Template Posting (Based on existing posting header and template).


Parameters


iiCompanyIdinputinteger
icTemplateCodeinputcharacterTemplate Code
iiRecEntryLineIdinputinteger
icPostingTextinputcharacterPosting Text
idAmountLCinputdecimalAmount lc
icJournalCodeinputcharacterDaybook Code
itPostingDateinputdateposting date
iiPeriodIDinputintegerPeriod ID
ocPostingTcRowidoutputcharacterPosting Rowid of new posting
tChangedEntryLineinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BJournalEntry.CreateRecEntryPosting


program code (program7/bjournalentry.p)

/* ============================================================== */
/* WARNING: Make sure that no instance is loaded when calling     */
/*          this method.                                          */
/* This method will load an instance of the template posting      */
/* By using method SetNewStatus, the template posting will be     */
/* transformed to the recurring entry posting.                    */
/* ============================================================== */

MAIN_BLOCK:
do on error undo, return:

    assign oiReturnStatus      = -98
           viLocalReturnStatus = 0.

    /* ================================================================ */
    /* PART I. Validate the input-parameters + Load Template            */
    /* ================================================================ */
    if idAmountLC  = ?                    then assign idAmountLC = 0.
    if iiCompanyId = 0 or iiCompanyId = ? then assign iiCompanyId = viCompanyId.

    /* =================== */
    /* Validate the Period */
    /* =================== */
    if iiPeriodID = ? or
       iiPeriodID = 0
    then do:
        assign vcMsgJE = trim(#T-36'You must enter the GL period.':150(337)T-36#).
        <M-23 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  '3':U (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-1023':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.

    <Q-31 run PeriodByYearPeriod (all) (Read) (NoCache)
       (input iiCompanyId, (CompanyId)
        input ?, (PeriodYear)
        input ?, (PeriodPeriod)
        input iiPeriodID, (PeriodId)
        output dataset tqPeriodByYearPeriod) in BPeriod >
    find tqPeriodByYearPeriod no-lock no-error.
    if not available tqPeriodPrim
    then do:
        assign vcMsgJE = trim(#T-37'The GL period cannot be found.':150(2749)T-37#).
        <M-25 run SetMessage (input  vcMsgJE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  iiPeriodID (icFieldValue),
                     input  'E':U (icType),
                     input  '3':U (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1024':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.
 
    /* ========================= */
    /* Validate the Journal Code */
    /* ========================= */
    if icJournalCode = ? or
       icJournalCode = '':U
    then do:
        assign vcMsgJE = trim(#T-38'You must enter a daybook code.':150(2750)T-38#).
        <M-26 run SetMessage (input  vcMsgJE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  '3':U (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1025':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.

    <Q-27 run JournalPrim (all) (Read) (NoCache)
       (input iiCompanyId, (CompanyId)
        input icJournalCode, (JournalCode)
        input ?, (JournalID)
        output dataset tqJournalPrim) in BJournal >
    find tqJournalPrim no-lock no-error.
    if not available tqJournalPrim
    then do:
        assign vcMsgJE = trim(substitute(#T-39'The daybook code &1 cannot be found.':150(2751)T-39#, trim(icJournalCode))).
        <M-28 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  icJournalCode (icFieldValue), 
            input  'E':U (icType), 
            input  '3':U (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-1026':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.
    
    /* ========================= */
    /* Validate the posting date */
    /* ========================= */
    if itPostingDate = ?
    then do:
        assign vcMsgJE = trim(#T-40'You must enter the posting date.':150(340)T-40#).
        <M-29 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  '3':U (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-1027':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.

    /* ========================= */
    /* Validate the Posting Text */
    /* ========================= */
    if icPostingText = ? or
       icPostingText = '':U
    then do:
        assign vcMsgJE = trim(#T-41'You must enter the posting text.':150(2753)T-41#).
        <M-1 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  '3':U (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-1015':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.
    
    /* ========================== */                                
    /* Validate the Template Code */
    /* ========================== */        
    if icTemplateCode = ? or
       icTemplateCode = '':U
    then do:
        assign vcMsgJE = trim(#T-42'You must enter the posting template code.':150(2754)T-42#).
        <M-2 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  '3':U (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-1017':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.
 
    <Q-3 run PostingTemplatePrim (all) (Read) (NoCache)
       (input iiCompanyId, (CompanyId)
        input ?, (TemplateID)
        input icTemplateCode, (TemplateCode)
        input ?, (PostingID)
        output dataset tqPostingTemplatePrim) in BPostingTemplate >
    find tqPostingTemplatePrim no-error.
    if not available tqPostingTemplatePrim
    then do:
        assign vcMsgJE = trim(substitute(#T-43'The posting template &1 cannot be found.':150(2755)T-43#, trim(icTemplateCode))).
        <M-4 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  icTemplateCode (icFieldValue), 
            input  'E':U (icType), 
            input  '3':U (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-1018':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.   
 
    /* ========================================================================================================= */
    /* Create new posting based on template - Load Template and set to new status                                */
    /* ========================================================================================================= */
    <M-10 run DataLoad
       (input  '':U (icRowids), 
        input  string(tqPostingTemplatePrim.tiPosting_ID) (icPkeys), 
        input  '':U (icObjectIds), 
        input  '' (icFreeform), 
        input  true (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
    if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
    
    find tPosting where
         tPosting.Posting_ID = tqPostingTemplatePrim.tiPosting_ID and
         tPosting.tc_Status <> 'D':U
         no-error.
    if not available tPosting
    then do:
        assign vcMsgJE = trim(#T-44'The template cannot be retrieved.':255(2756)T-44#) + chr(10) + 
                         trim(substitute(#T-45'Template ID: &1.':150(2757)T-45#, trim(string(tqPostingTemplatePrim.tiPosting_ID)))).
        <M-11 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  string(tqPostingTemplatePrim.tiPosting_ID) (icFieldValue), 
            input  'E':U (icType), 
            input  '3':U (iiSeverity), 
            input  tqPostingTemplatePrim.tiPosting_ID (icRowid), 
            input  'QADFIN-1016':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>            
        assign viLocalReturnStatus = -1.
        leave MAIN_BLOCK.
    end.

    /* Mark the loaded posting instance as a new instance */
    <M-30 run SetNewStatus  (output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
    if viLocalReturnStatus < 0 then leave MAIN_BLOCK.

    /* ================================================================ */
    /* PART II. Update Template Posting                                 */
    /* ================================================================ */
    /* Update the posting header data */
    assign tPosting.Period_ID           = tqPeriodByYearPeriod.tiPeriod_ID
           tPosting.PostingYear         = tqPeriodByYearPeriod.tiPeriodYear
           tPosting.PostingPeriod       = tqPeriodByYearPeriod.tiPeriodPeriod
           tPosting.PostingYearPeriod   = tqPeriodByYearPeriod.tiPeriodYear * 100 + tqPeriodByYearPeriod.tiPeriodPeriod
           tPosting.PeriodMark_ID       = tqPeriodByYearPeriod.tiPeriodMark_ID
           tPosting.PostingDate         = itPostingDate
           tPosting.PostingAddGLNbrDate = itPostingDate
           tPosting.PostingValueDate    = itPostingDate
           tPosting.PostingText         = icPostingText
           tPosting.PostingVoucher      = 0
           tPosting.tcTemplateCode      = '':U
           tPosting.tlSaveAsTemplate    = false
           ocPostingTcRowid             = tPosting.tc_Rowid
           tPosting.CreatorUsr_ID       = viUsrId
           tPosting.tcUsrLogin          = vcUserLogin.
    
    /* ====================================================================== */
    /* Assign Posting Number (voucher) & Journal by calling GetPostingNumber  */
    /* As this call also updates tPosting.tcJournalCode, we have to make sure */
    /* that tPosting.tcReportingJournalCode is assigned the same value        */
    /* ====================================================================== */
    <M-55 run GetPostingNumber
       (input  tPosting.tc_Rowid (ictcRowid), 
        input  tPosting.PostingYear (iiYear), 
        input  icJournalCode (icJournalCode), 
        output viFcCount1 (oiVoucher), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
    if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
    assign tPosting.tcReportingJournalCode = tPosting.tcJournalCode.
    
    /* ============================== */
    /* Pre-actions for posting lines  */
    /* ============================== */
    assign vcLastDebitPostingLineRowId  = ?
           vcLastCreditPostingLineRowId = ?
           vcLastPostingLineRowId       = ?
           vcPostingLineCurrencyCode    = ?
           vlPostingHasOneCurrOnly      = true
           vdTotalDebitLC               = 0
           vdTotalDebitCC               = 0
           vdTotalDebitTC               = 0
           vdTotalCreditTC              = 0
           vdTotalQty                   = 0.

    for each tPostingLine where 
             tPostingLine.tc_ParentRowid = tPosting.tc_Rowid and
             tPostingLine.tc_Status     <> 'D':U :   
        
        /* ============================================== */
        /* Calculate total debit amount                   */
        /* ============================================== */
        assign vdTotalDebitLC  = vdTotalDebitLC  + tPostingLine.PostingLineDebitLC
               vdTotalDebitCC  = vdTotalDebitCC  + tPostingLine.PostingLineDebitCC
               vdTotalDebitTC  = vdTotalDebitTC  + tPostingLine.PostingLineDebitTC
               vdTotalCreditTC = vdTotalCreditTC + tPostingLine.PostingLineCreditTC
               vdTotalQty      = vdTotalQty      + tPostingLine.PostingLineQTY.
               

        /* ========================================================================= */
        /* Check, if the posting has only one transaction currency                   */
        /* ========================================================================= */
        if vcPostingLineCurrencyCode <> ? and
           vcPostingLineCurrencyCode <> tPostingLine.tcCurrencyCode
        then assign vlPostingHasOneCurrOnly = false.
        else assign vcPostingLineCurrencyCode = tPostingLine.tcCurrencyCode.


        /* ========================================================================= */
        /* Remember last credit and debit posting lines                              */
        /* ========================================================================= */
        if tPostingLine.PostingLineDebitTC <> 0
        then assign vcLastDebitPostingLineRowId  = tPostingLine.tc_Rowid.
        else assign vcLastCreditPostingLineRowId = tPostingLine.tc_Rowid.
        
        assign vcLastPostingLineRowId = tPostingLine.tc_Rowid.
        
    
        /* Turn New-OI-Allocations into Linked-OI-Allocations */
        if tPostingLine.tcAllocationType = "N":U
        then assign tPostingLine.tcAllocationType = "L":U.
    
        assign tPostingLine.PostingLineMaster_ID      = 0
               tPostingLine.PostingLineTransaction_ID = 0.
        
    end. /* For each tPostingLine of Template */

    /* ============================================== */
    /* Apply new amounts                              */
    /* ============================================== */
    if vdTotalDebitLC <> idAmountLC
    then do:
        assign vdTotalPostedDebitLC  = 0
               vdTotalPostedCreditLC = 0
               vdTotalPostedDebitCC  = 0
               vdTotalPostedCreditCC = 0
               vdTotalPostedDebitTC  = 0
               vdTotalPostedCreditTC = 0.
        
        for each tPostingLine where
                 tPostingLine.tc_ParentRowid = tPosting.tc_Rowid and
                 tPostingLine.tc_Status     <> 'D':U:
    
            /* ========================================================================= */
            /* User can do manual change of posting, apply amount of it                  */
            /* ========================================================================= */
            assign vcPostingLineKey = substitute("&1-&2":U,
                                                 iiRecEntryLineId,
                                                 tPostingLine.PostingLineSequence).
            find first tChangedEntryLine where 
                       tChangedEntryLine.tc_Rowid = vcPostingLineKey
                       no-error.
            
            /* ========================================================================= */
            /* Update LC value of posting lines                                          */
            /* ========================================================================= */
            /* if amount of the line was entered by user -> take this value -> but value was entered in TC */
            if available tChangedEntryLine
            then do:
                if tPostingLine.tcCurrencyCode = vcCompanyLC
                then assign tPostingLine.PostingLineDebitLC  = tChangedEntryLine.PostingLineDebitTC
                            tPostingLine.PostingLineCreditLC = tChangedEntryLine.PostingLineCreditTC.
                else assign tPostingLine.PostingLineDebitLC  = tChangedEntryLine.PostingLineDebitTC * tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale
                            tPostingLine.PostingLineCreditLC = tChangedEntryLine.PostingLineCreditTC * tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale.
           end.

            /* if this is last posting line, calculate balance to be posted */
            else if tPostingLine.tc_Rowid = vcLastCreditPostingLineRowId
            then assign tPostingLine.PostingLineCreditLC = idAmountLC - vdTotalPostedCreditLC
                        tPostingLine.PostingLineDebitLC  = 0. 

            else if tPostingLine.tc_Rowid = vcLastDebitPostingLineRowId
            then assign tPostingLine.PostingLineCreditLC = 0
                        tPostingLine.PostingLineDebitLC  = idAmountLC - vdTotalPostedDebitLC.
            

            /* Calculate proportional amount */
            else assign tPostingLine.PostingLineDebitLC  = tPostingLine.PostingLineDebitLC  * idAmountLC / vdTotalDebitLC
                        tPostingLine.PostingLineCreditLC = tPostingLine.PostingLineCreditLC * idAmountLC / vdTotalDebitLC.
            
            
             /* Round LC amount */
             assign tPostingLine.PostingLineDebitLC  = <M-56 RoundAmount
                                                         (input  tPostingLine.PostingLineDebitLC (idUnroundedAmount), 
                                                          input  viCompanyLCId (iiCurrencyID), 
                                                          input  vcCompanyLC (icCurrencyCode)) in business>                                                                   
                    tPostingLine.PostingLineCreditLC = <M-57 RoundAmount
                                                          (input  tPostingLine.PostingLineCreditLC (idUnroundedAmount), 
                                                           input  viCompanyLCId (iiCurrencyID), 
                                                           input  vcCompanyLC (icCurrencyCode)) in business>.


            /* ========================================================================= */
            /* Update TC value of posting lines                                          */
            /* ========================================================================= */
            /* If user entered amounts of posting lines manually, just take this values */
            if available tChangedEntryLine 
            then assign tPostingLine.PostingLineDebitTC  = tChangedEntryLine.PostingLineDebitTC
                        tPostingLine.PostingLineCreditTC = tChangedEntryLine.PostingLineCreditTC.                            
    
            /* Calculate new TC amounts by total amount if user doesn't manually change the posting line */
            else if tPostingLine.tcCurrencyCode = vcCompanyLC
            then assign tPostingLine.PostingLineDebitTC  = tPostingLine.PostingLineDebitLC
                        tPostingLine.PostingLineCreditTC = tPostingLine.PostingLineCreditLC.

            else assign tPostingLine.PostingLineDebitTC  = tPostingLine.PostingLineDebitLC /
                                                           (tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale)
                        tPostingLine.PostingLineCreditTC = tPostingLine.PostingLineCreditLC / 
                                                           (tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale).

            /* Round TC amount */
            assign tPostingLine.PostingLineDebitTC = <M-58 RoundAmount
                                                        (input  tPostingLine.PostingLineDebitTC (idUnroundedAmount), 
                                                         input  0 (iiCurrencyID), 
                                                         input  tPostingLine.tcCurrencyCode (icCurrencyCode)) in business>           
                   tPostingLine.PostingLineCreditTC = <M-59 RoundAmount
                                                         (input  tPostingLine.PostingLineCreditTC (idUnroundedAmount), 
                                                          input  0 (iiCurrencyID), 
                                                          input  tPostingLine.tcCurrencyCode (icCurrencyCode)) in business>. 
    
    
    
            /* ========================================================================= */
            /* Update CC value of posting lines                                          */
            /* ========================================================================= */
            if vcCompanyCC = ""
            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 do: 
                assign tPostingLine.PostingLineDebitCC  = <M-51 RoundAmount
                                                             (input  tPostingLine.PostingLineDebitTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                                              input  viCompanyCCId (iiCurrencyID), 
                                                              input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>
                       tPostingLine.PostingLineCreditCC = <M-52 RoundAmount
                                                             (input  tPostingLine.PostingLineCreditTC * tPostingLine.PostingLineCCRate * tPostingLine.PostingLineCCScale (idUnroundedAmount), 
                                                              input  viCompanyCCId (iiCurrencyID), 
                                                              input  vcCompanyCC (icCurrencyCode)) in BApplicationProperty>.
            end. /* else do */
    
            /* ========================================================================= */
            /* Calculate total posted amount                                             */
            /* ========================================================================= */
            assign vdTotalPostedDebitLC  = vdTotalPostedDebitLC  + tPostingLine.PostingLineDebitLC 
                   vdTotalPostedCreditLC = vdTotalPostedCreditLC + tPostingLine.PostingLineCreditLC
                   vdTotalPostedDebitCC  = vdTotalPostedDebitCC  + tPostingLine.PostingLineDebitCC
                   vdTotalPostedCreditCC = vdTotalPostedCreditCC + tPostingLine.PostingLineCreditCC
                   vdTotalPostedDebitTC  = vdTotalPostedDebitTC  + tPostingLine.PostingLineDebitTC
                   vdTotalPostedCreditTC = vdTotalPostedCreditTC + tPostingLine.PostingLineCreditTC.
            
            
            /* ============================================================================= */
            /* If this is the last posting line, ensure the whole posting is nicely balanced */
            /* ============================================================================= */
            if vcLastPostingLineRowId = tPostingLine.tc_Rowid
            then do:
                /* Balance CC amount */
                if tPostingLine.PostingLineDebitCC <> 0
                then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitCC  + (vdTotalPostedCreditCC - vdTotalPostedDebitCC).
                else assign tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditCC + (vdTotalPostedDebitCC  - vdTotalPostedCreditCC).
                
                /* Balance TC amount */
                if vlPostingHasOneCurrOnly and
                   vdTotalDebitTC = vdTotalCreditTC                   
                then do:
                    if tPostingLine.PostingLineDebitLC <> 0
                    then assign tPostingLine.PostingLineDebitTC  = tPostingLine.PostingLineDebitTC  + (vdTotalPostedCreditTC - vdTotalPostedDebitTC).
                    else assign tPostingLine.PostingLineCreditTC = tPostingLine.PostingLineCreditTC + (vdTotalPostedDebitTC  - vdTotalPostedCreditTC).
               end.
            end. /* if vcLastPostingLineRowId = tPostingLine.tc_Rowid */
            
            <M-24 run LoadVatTemplate
               (input  tPosting.Company_ID (iiCompanyID), 
                input  tPostingLine.tc_Rowid (icParentRowid), 
                input  idAmountLC (idAmountTC), 
                input  vdTotalDebitLC (idTotalDebit), 
                input  tPosting.PostingDate (itPostingDate), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>       
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
            if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
        end. /* For each tPostingLine of template */
    end. /* if vdTotalDebitLC <> 0 and */
end. /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturnStatus.