project QadFinancials > class BBankEntry > method AdditionalUpdatesInvDeductions

Description

AdditionalUpdatesInvDeductions: method that takes creates the deductions


Parameters


iiPostingPeriodYearinputintegerPosting year
iiPostingPeriodPeriodinputintegerPosting Period
icPostingJournalCodeinputcharacterPosting Journal Code
iiPostingVoucherinputintegerPosting voucher
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.AdditionalUpdatesInv


program code (program4/bbankentry.p)

    /* =================================================== */
    /* This method is a submethod of AddtionaUpdatesInv as */
    /* that method could not contain all the program-code  */
    /* =================================================== */
    
    /* ========================= */
    /* Set default return-status */
    /* ========================= */
    assign oiReturnStatus = -98
           viDInvoiceDeductionRowID = 0.
    empty temp-table ttDefaultSafs.
    /* ================================ */
    /* Check whether need to continue   */
    /* ================================ */
    if not can-find (first tBankStateAlloc where
             tBankStateAlloc.tc_ParentRowid   = tBankStateLine.tc_Rowid     and
             (tBankStateAlloc.tc_Status       = "N":U or 
               tBankStateAlloc.tc_Status       = "C":U
              ) and tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DEDUCTIONINV} 
             and (tBankStateAlloc.DInvoice_ID = 0 or tBankStateAlloc.DInvoice_ID = ?))
    then do:
         assign oiReturnStatus = 0.
         return.
    end.
    
    /*get deduction daybook */
    find first tBankState where tBankState.tc_Rowid = tBankStateLine.tc_ParentRowid no-error.
    
    if not available tBankState then return.
    
    assign vcDInvoiceDescription = string(tBankStateLine.tiPostingPeriodYear) + "/":U +
                                   string(tBankStateLine.tcPostingJournalCode) + "/":U +
                                   string(tBankStateLine.tiPostingVoucher, "999999999":U)+ "/":U.
                                   

    <M-8 run AdditionalUpdatesGetDeductionJournalCode
       (input  tBankState.tcGLCode (icBankGLAccount), 
        output vcDeductionJournalCode (ocDeductionJournalCode), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    if viFcReturnSuper < 0 then return.
    
    /*get system account "Deduction"*/
    <Q-56 run GLByGLSystemType (all) (Read) (Cache)
       (input viCompanyID, (CompanyId)
        input {&GLSYSTEMTYPE-DEDUCTION}, (GLSystemTypeCode)
        input {&GLTYPECODE-SYST}, (GlTypeCode)
        input ?, (GlIsDivisionAccount)
        output dataset tqGLByGLSystemType) in BGL>
        
    find first tqGLByGLSystemType where
                       tqGLByGLSystemType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-DEDUCTION} and
                       tqGLByGLSystemType.tcGLTypeCode       = {&GLTYPECODE-SYST}
                       no-error.
    if not available tqGLByGLSystemType
    then do:  
                  assign vcMessage = trim(#T-77'The system account for Deduction Suspends has not been defined':255(352726945)T-77#). 
                  <M-95 run SetMessage
                     (input  vcMessage (icMessage), 
                      input  '':U (icArguments), 
                      input  '':U (icFieldName), 
                      input  '':U (icFieldValue), 
                      input  'E' (icType), 
                      input  3 (iiSeverity), 
                      input  '':U (icRowid), 
                      input  'qadfin-629740':U (icFcMsgNumber), 
                      input  '':U (icFcExplanation), 
                      input  '':U (icFcIdentification), 
                      input  '':U (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BBankEntry> 
         
                if viFcReturnSuper < 0 or oiReturnStatus  = 0
                then assign oiReturnStatus = viFcReturnSuper.
        
                if viFcReturnSuper < 0
                then return.
           
    end. 


    /* ============================================================================ */
    /* Go though all allocations of the current BE-Line that refer to a deduction   */
    /* ============================================================================ */
    for each tBankStateAlloc where
             tBankStateAlloc.tc_ParentRowid   = tBankStateLine.tc_Rowid     and
             (tBankStateAlloc.tc_Status       = "N":U or
              tBankStateAlloc.tc_Status       = "C":U)                      and
             tBankStateAlloc.BankStateAllocType = {&BANKSTATEALLOCTYPE-DEDUCTIONINV}
             and (tBankStateAlloc.DInvoice_ID = 0 or tBankStateAlloc.DInvoice_ID = ?):
        empty temp-table tBankOpenBalance.
        empty temp-table tDIDeductions.
        /* ================================================= */
        /* Create a record in the base-table for prepayments */
        /* ================================================= */
        create  tBankOpenBalance.
        assign  tBankOpenBalance.tiCompanyId             = tBankStateAlloc.Company_ID
                tBankOpenBalance.tcAction                = {&DAEMONACTION-SAVE}
                tBankOpenBalance.tcInvoiceType           = {&INVOICETYPE-DEDUCTION}
                tBankOpenBalance.tcTransferAccountGLCode = tBankState.tcGLCode
                tBankOpenBalance.tiPeriodYear            = iiPostingPeriodYear
                tBankOpenBalance.tiPeriodPeriod          = iiPostingPeriodPeriod
                tBankOpenBalance.tcJournalCode           = vcDeductionJournalCode
                tBankOpenBalance.tiInvoiceVoucher        = iiPostingVoucher
                tBankOpenBalance.ttInvoiceDate           = tBankStateAlloc.ttDocInvDate
                tBankOpenBalance.ttInvoiceTaxPointDate   = tBankStateAlloc.ttDocInvDate
                tBankOpenBalance.tcCreditorCode          = "":U
                tBankOpenBalance.tcDebtorCode            = tBankStateAlloc.tcDocCredDebEmplCode
                tBankOpenBalance.tcInvoiceDescription    = vcDInvoiceDescription + tBankStateAlloc.tcDocDescription
                tBankOpenBalance.tcDivisionCode          = tBankStateAlloc.tcDocDivisionCode
                tBankOpenBalance.tcProjectCode           = tBankStateAlloc.tcDocProjectCode
                tBankOpenBalance.tcCostCentreCode        = tBankStateAlloc.tcDocCostCentreCode
                tBankOpenBalance.ttPostingDate           = tBankStateLine.BankStateLinePostingDate
                tBankOpenBalance.tcPostingType           = {&POSTINGTYPE-DEBIT}
                tBankOpenBalance.tdInvoiceAmountTC       = tBankStateAlloc.BankStateAllocAmountTC
                tBankOpenBalance.tdInvoiceAmountLC       = tBankStateAlloc.BankStateAllocAmountLC
                tBankOpenBalance.tdExchangeRateTCLC      = (if tBankStateAlloc.tcDocCurrencyCode = vcCompanyLC and
                                                               (tBankStateAlloc.tdDocExchangeRate  = 0 or
                                                                tBankStateAlloc.tdDocExchangeRate  = ?)
                                                            then 1
                                                            else tBankStateAlloc.tdDocExchangeRate)
                tBankOpenBalance.tdExchangeRateScale     = (if tBankStateAlloc.tcDocCurrencyCode = vcCompanyLC and
                                                               (tBankStateAlloc.tdDocExchangeRateScale   = 0 or
                                                                tBankStateAlloc.tdDocExchangeRateScale = ?)
                                                            then 1
                                                            else tBankStateAlloc.tdDocExchangeRateScale)
                tBankOpenBalance.tdExchangeRateTCCC      = (if tBankStateAlloc.tcDocCurrencyCode = vcCompanyCC
                                                            then 1 
                                                            else tBankStateAlloc.BankStateAllocCCRate)
                tBankOpenBalance.tdCCExchangeRateScale   = (if tBankStateAlloc.tcDocCurrencyCode = vcCompanyCC 
                                                            then 1
                                                            else tBankStateAlloc.BankStateAllocCCScale)
                tBankOpenBalance.tiInvoiceVoucher        = 0
                tBankOpenBalance.tcPostingText           = vcDInvoiceDescription + tBankStateAlloc.tcDocDescription
                tBankOpenBalance.tlOnlyControlAccount    = true
                tBankOpenBalance.tcTCCurrencyCode        = tBankStateAlloc.tcDocCurrencyCode
                tBankOpenBalance.tcKey                   = string(rowid(tBankOpenBalance))
                tBankOpenBalance.tcInvoiceReference      = tBankStateAlloc.tcDocDescription
                vcPostingOriginAddressCode               = tBankStateAlloc.tcDocCredDebEmplCode.

                
            /* =============================== */
            /* Create CC Record                */
            /* =============================== */
            if vlDomainIsStatutory <> true
            then assign tBankOpenBalance.tdInvoiceAmountCC  = tBankOpenBalance.tdInvoiceAmountLC
                        tBankOpenBalance.tdExchangeRateTCCC = tBankOpenBalance.tdExchangeRateTCLC
                        tBankOpenBalance.tdCCExchangeRateScale = tBankOpenBalance.tdExchangeRateScale.
            else do:
                if tBankStateAlloc.tcDocCurrencyCode = vcCompanyCC
                then assign tBankOpenBalance.tdInvoiceAmountCC = tBankOpenBalance.tdInvoiceAmountTC.
                else do:
                    if vcCompanyLC = vcCompanyCC
                    then assign tBankOpenBalance.tdInvoiceAmountCC = tBankOpenBalance.tdInvoiceAmountLC
                                tBankOpenBalance.tdExchangeRateTCCC = tBankOpenBalance.tdExchangeRateTCLC
                                tBankOpenBalance.tdCCExchangeRateScale = tBankOpenBalance.tdExchangeRateScale.
                    else do:
                         <M-27 run GetExchangeRate
                            (input  tBankStateLine.Company_ID (iiCompanyID), 
                             input  ? (iiFromCurrencyID), 
                             input  tBankStateAlloc.tcDocCurrencyCode (icFromCurrencyCode), 
                             input  viCompanyCCId (iiToCurrencyID), 
                             input  ? (icToCurrencyCode), 
                             input  ? (iiExchangeRateTypeID), 
                             input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                             input  tBankStateAlloc.ttDocInvDate (itValidityDate), 
                             output vdCCRate (odExchangeRate), 
                             output vdCCRateScale (odExchangeScaleFactor), 
                             output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                        if viFcReturnSuper < 0 or
                           oiReturnStatus  = 0
                        then assign oiReturnStatus = viFcReturnSuper.
            
                        if viFcReturnSuper < 0
                        then return.
                        
                        assign    tBankOpenBalance.tdExchangeRateTCCC    = vdCCRate
                                  tBankOpenBalance.tdCCExchangeRateScale = vdCCRateScale
                                  tBankOpenBalance.tdInvoiceAmountCC = <M-71 RoundAmount
                                                                          (input  tBankOpenBalance.tdInvoiceAmountTC * vdCCRate * vdCCRateScale (idUnroundedAmount), 
                                                                           input  viCompanyCCId (iiCurrencyID), 
                                                                           input  vcCompanyCC (icCurrencyCode)) in BBankEntry>.
                    end. /* else do: */
                end. /* else do: */
            end. /* IF  vcCompanyCC = "":U or vcCompanyCC = ? */  

        /* =============================== */
        /* Extended assignments for the DI */
        /* =============================== */
        if tBankStateAlloc.tcDocCredDebEmplCode <> "":U
        then do:
                
            /*Set up credit terms for prepayments per domain(PrepayPaymentCondition_ID), so that when prepayments are created these credit terms 
            are used instead of the customer's default credit terms*/
            assign vhFcComponent = ?
                   vcPaymentConditionCode = '':U.

            <M-31 run GetDeductPrepayCreditTerm
               (input  tBankOpenBalance.tcInvoiceType (icInvoiceType), 
                output vcPaymentConditionCode (ocPaymentConditionCode), 
                output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>

            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0) then
                assign oiReturnStatus = viFcReturnSuper.
       
            if viFcReturnSuper < 0
                then return.

            assign tBankOpenBalance.tcNormalPaymentConditionCode = vcPaymentConditionCode
                  tBankOpenBalance.ttInvoiceDueDate               = tBankStateAlloc.ttDocDueDate
                  tBankOpenBalance.ttInvoiceDiscountDueDate       = tBankStateAlloc.ttDocDiscountDueDate.



            if (tBankOpenBalance.ttInvoiceDueDate         = ? or
                    tBankOpenBalance.ttInvoiceDiscountDueDate = ?) and
                    tBankOpenBalance.tcNormalPaymentConditionCode <> "":U
            then do:
                assign vhFcComponent            = ?
                           vtInvoiceDueDate         = ?
                           vtInvoiceDiscountDueDate = ?.

                <M-37 run CalculateDueDiscountDate
                       (input  ? (iiPaymentConditionID), 
                        input  tBankOpenBalance.tcNormalPaymentConditionCode (icPaymentConditionCode), 
                        input  tBankStateAlloc.ttDocInvDate (itInvoiceDate), 
                        output vtInvoiceDueDate (otDueDate), 
                        output vtInvoiceDiscountDueDate (otDiscountDate), 
                        output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>



                if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 
                then return.

                if tBankOpenBalance.ttInvoiceDueDate = ?
                then assign tBankOpenBalance.ttInvoiceDueDate = vtInvoiceDueDate.
                if tBankOpenBalance.ttInvoiceDiscountDueDate = ?
                then assign tBankOpenBalance.ttInvoiceDiscountDueDate = vtInvoiceDiscountDueDate.

            end.
         /*      
            <Q-1 run DebtorByDebtor (all) (Read) (NoCache)
               (input tBankStateAlloc.Company_ID, (CompanyId)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
                input ?, (DebtorId)
                input tBankStateAlloc.tcDocCredDebEmplCode, (DebtorCode)
                output dataset tqDebtorByDebtor) in BDebtor>

            find first tqDebtorByDebtor no-error.
            if available tqDebtorByDebtor
            then do:

                assign tBankOpenBalance.tcNormalPaymentConditionCode   = tqDebtorByDebtor.tcNormalPaymentConditionCode
                       tBankOpenBalance.ttInvoiceDueDate               = tBankStateAlloc.ttDocDueDate
                       tBankOpenBalance.ttInvoiceDiscountDueDate       = tBankStateAlloc.ttDocDiscountDueDate.

                if (tBankOpenBalance.ttInvoiceDueDate         = ? or
                    tBankOpenBalance.ttInvoiceDiscountDueDate = ?) and
                    tBankOpenBalance.tcNormalPaymentConditionCode <> "":U
                then do:
                    assign vhFcComponent            = ?
                           vtInvoiceDueDate         = ?
                           vtInvoiceDiscountDueDate = ?.

                    <M-30 run CalculateDueDiscountDate
                       (input  tqDebtorByDebtor.tiNormalPaymentCondition_ID (iiPaymentConditionID), 
                        input  tqDebtorByDebtor.tcNormalPaymentConditionCode (icPaymentConditionCode), 
                        input  tBankStateAlloc.ttDocInvDate (itInvoiceDate), 
                        output vtInvoiceDueDate (otDueDate), 
                        output vtInvoiceDiscountDueDate (otDiscountDate), 
                        output viFcReturnSuper (oiReturnStatus)) in BPaymentCondition>

                    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0 
                    then return.

                    if tBankOpenBalance.ttInvoiceDueDate = ?
                    then assign tBankOpenBalance.ttInvoiceDueDate = vtInvoiceDueDate.
                    if tBankOpenBalance.ttInvoiceDiscountDueDate = ?
                    then assign tBankOpenBalance.ttInvoiceDiscountDueDate = vtInvoiceDiscountDueDate.

                end. /* if tBankOpenBalance.tcDiscountPaymentConditionCode <> "":U */
            end. /* if available tqDebtorByDebtor */
        */
        end. /* if tBankStateAlloc.BankStateAllocType    = {&BANKSTATEALLOCTYPE-NDINV} and */

        /* ==================================== */
        /* Build the Deduction Detail           */
        /* ==================================== */ 
        for each tApiDInvoiceDeductionBE where tApiDInvoiceDeductionBE.tc_ParentRowid = tBankStateAlloc.tcDInvoiceDeductionParentRowID no-lock:
          if tBankOpenBalance.tcTCCurrencyCode = vcCompanyLC then
                assign vdDInvoiceDeductionLC = tApiDInvoiceDeductionBE.DInvoiceDeductionTC.
          else
          do:
                assign vdDInvoiceDeductionLC =   <M-85 RoundAmount
                                                    (input  tApiDInvoiceDeductionBE.DInvoiceDeductionTC * tBankOpenBalance.tdExchangeRateTCLC * tBankOpenBalance.tdExchangeRateScale (idUnroundedAmount), 
                                                     input  viCompanyLCId (iiCurrencyID), 
                                                     input  vcCompanyLC (icCurrencyCode)) in BBankEntry>.
          end.
          if vcCompanyCC = "":U or
             vcCompanyCC = ?
          then assign vdDInvoiceDeductionCC = 0.
          else
          if tBankOpenBalance.tcTCCurrencyCode = vcCompanyCC
          then assign vdDInvoiceDeductionCC  = tApiDInvoiceDeductionBE.DInvoiceDeductionTC.
          else
          if vlDomainIsStatutory = false
          then assign vdDInvoiceDeductionCC = vdDInvoiceDeductionLC.
          else do:
               assign vdDInvoiceDeductionCC =    <M-96 RoundAmount
                                                    (input  tApiDInvoiceDeductionBE.DInvoiceDeductionTC * vdCCRate * vdCCRateScale (idUnroundedAmount), 
                                                     input  viCompanyCCId (iiCurrencyID), 
                                                     input  vcCompanyLC (icCurrencyCode)) in BBankEntry>.
          end. 
           assign viDInvoiceDeductionRowID = viDInvoiceDeductionRowID - 1.
           create tDIDeductions.
           assign tDIDeductions.DeductionCatLine_ID = tApiDInvoiceDeductionBE.DeductionCatLine_ID
                  tDIDeductions.DInvoiceDeductionTC = tApiDInvoiceDeductionBE.DInvoiceDeductionTC
                  tDIDeductions.DInvoiceDeductionLC = vdDInvoiceDeductionLC
                  tDIDeductions.DInvoiceDeductionCC = vdDInvoiceDeductionCC
                  tDIDeductions.tcDeductionCatCode  = tApiDInvoiceDeductionBE.tcDeductionCatCode
                  tDIDeductions.tc_Rowid = string(viDInvoiceDeductionRowID)
                  tDIDeductions.tc_ParentRowid = tBankOpenBalance.tcKey
                  tDIDeductions.PaidDInvoice_ID = if tApiDInvoiceDeductionBE.PaidDInvoice_ID = ? then 0 else tApiDInvoiceDeductionBE.PaidDInvoice_ID
                  tDIDeductions.DInvoiceDeductionComment = tApiDInvoiceDeductionBE.DInvoiceDeductionComment
                  tDIDeductions.DInvoiceDeductionSequence = tApiDInvoiceDeductionBE.DInvoiceDeductionSequence
                  tDIDeductions.DInvoiceDeductionCustRef = if tApiDInvoiceDeductionBE.DInvoiceDeductionCustRef = ? then '' else tApiDInvoiceDeductionBE.DInvoiceDeductionCustRef
                  tDIDeductions.DInvoiceDeductionPromotionCode = if tApiDInvoiceDeductionBE.DInvoiceDeductionPromotionCode = ? then '' else tApiDInvoiceDeductionBE.DInvoiceDeductionPromotionCode
                  tDIDeductions.DInvoiceDeductionStatus = tApiDInvoiceDeductionBE.DInvoiceDeductionStatus.
        end. 
          
    
        /* ====================================== */
        /* Create the CI-Deductions when needed */
        /* ====================================== */
        
        <M-19 run CreateDInvoicesDeduction
                (input-output tBankOpenBalance (tDIOpenBalanceDeduction), 
                 input  viBJournalEntryBEID (iiBJournalEntryId), 
                 input  0 (iiPostingId), 
                 output vcNewRecordInfo (ocNewRecordInfo), 
                 input  tDIDeductions (tDIDeduction), 
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>  
            
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then do:
                assign vcMessage      = trim(substitute(#T-36'Error &1 occurred when creating the new customer invoice for bank statement line &2. See other messages for more information.':150(317)T-36#,string(viFcReturnSuper),string(tBankStateLine.BankStateLineNumber))).
                <M-86 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-909462':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                Return.
         end. /* if viFcReturnSuper < 0  */ 
         assign tBankStateAlloc.DInvoice_ID = integer(entry(2,vcNewRecordInfo)).
       
     

         /*Create POSTING ON DEDUCTION SUSPEND ACCOUNT */
         /*--------------------------------------------*/
         find first tBankOpenBalance no-error.
         assign vdAmountLC = tBankOpenBalance.tdInvoiceAmountLC
                vdAmountCC = tBankOpenBalance.tdInvoiceAmountCC.
                vcDeductionPostingText    = string(iiPostingPeriodYear) + "/":U +
                                                     tBankOpenBalance.tcJournalCode + "/":U +
                                                     string(tBankOpenBalance.tiInvoiceVoucher, "999999999":U) + "/":U +
                                                     tBankOpenBalance.tcInvoiceReference.
         /*start BJournalEntry */
         if viBJournalEntryBEID = 0 or
                               viBJournalEntryBEID = ?
         then do:
                   <I-6 {bFcStartAndOpenInstance
                        &ADD-TO-TRANSACTION   = "true"
                        &CLASS                = "BJournalEntry"}>
                                
         end.
         else do:
                   <I-23 {bFcOpenInstance
                        &CLASS           = "BJournalEntry"}>
         end.            
         <M-89 run AddStandardPosting
            (input  tBankStateLine.tcPostingRowId (icPostingtcRowid), 
             input  tqGLByGLSystemType.tcGLCode (icGLCode), 
             input  ? (icDivisionCode), 
             input  ? (icCostCentreCode), 
             input  ? (icCostCentreText), 
             input  ? (icProjectCode), 
             input  ? (icProjectText), 
             input  ? (icIntercoBusinessRelationCode), 
             input  tBankOpenBalance.tcTCCurrencyCode (icCurrencyCode), 
             input  tBankOpenBalance.tdInvoiceAmountTC (idDebitTC), 
             input  vdAmountLC (idDebitLC), 
             input  vdAmountCC (idDebitCC), 
             input  0 (idDebitPC), 
             input  0 (idCreditTC), 
             input  0 (idCreditLC), 
             input  0 (idCreditCC), 
             input  0 (idCreditPC), 
             input  0 (idQty), 
             input  vcDeductionPostingText (icLineText), 
             input  ? (icSafText), 
             input  ttDefaultSafs (tDefaultSafs), 
             input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
             input  tBankOpenBalance.tdExchangeRateTCLC (idExchangeRate), 
             input  tBankOpenBalance.tdExchangeRateScale (idExchangeRateScale), 
             input  tBankOpenBalance.tdExchangeRateTCCC (idPostingLineCCRate), 
             input  tBankOpenBalance.tdCCExchangeRateScale (idPostingLineCCScale), 
             output viPostingLineId (oiPostingLineId), 
             input  ? (iiSafStructureId), 
             input  ? (icSafStructureCode), 
             input  ? (icAllocationKey), 
             input  false (ilLinkedCrCyDaemonReqExists), 
             output viFcReturnSuper (oiReturnStatus)) in BJournalEntry> 
        
           if viFcReturnSuper < 0 or oiReturnStatus  = 0
           then assign oiReturnStatus = viFcReturnSuper.
            
           if viFcReturnSuper < 0
           then do:
                <I-79 {bFcCloseInstance
                           &CLASS           = "BJournalEntry"}>
                return.
           end.
           
           /* ========================================================================================================= */
           /* Normally we would here close BJournalEntry but we will not do it for performance                          */
           /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
           /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
           /* appserver that is executed after each call to the appserver                                               */
           /* ========================================================================================================= */

           
    end. /* for each tBankStateAlloc where*/  
            
    /* update posting origin Address Code */
    if viBJournalEntryBEID = 0 or
       viBJournalEntryBEID = ?
    then do:
        <I-98 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION   = "true"
             &CLASS                = "BJournalEntry"}>
                                
    end.
    else do:
        <I-93 {bFcOpenInstance
             &CLASS           = "BJournalEntry"}>
    end. 
    <M-84 run UpdatePostingOriginAddressCode
       (input  tBankStateLine.tcPostingRowId (icPostingRowId), 
        input  vcPostingOriginAddresscode (icPostingOriginAddressCode), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then do:
            assign vcMessage      = trim(substitute(#T-68'Error &1 occurred when updating the posting header for bank state line (&2). See other messages for more information.':150(59315)T-68#, string(viFcReturnSuper), string(tBankStateLine.BankStateLineNumber))).
            <M-64 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-347056':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            Return.
     end. /* if viFcReturnSuper < 0  */ 
     /*no close instance for journalentry, since it will be closed by caller.*/

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