project QadFinancials > class BOpenItemAdjustment > method OIAdjCommitSubOpenItemAdj

Description

OIAdjCommitSubOpenItemAdj: submethod of IAdjCommitSub because it could not contain all the code.
This method will do the creation of the records in this class


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BOpenItemAdjustment.OIAdjCommitSub


program code (program8/bopenitemadjustment.p)

    /* ================================================================================================= */
    /* Note: this method needs top be executed before the new invoices and the movements on the invoices */
    /* and their associated posting-lines are created. Reason: we here go through all posting-lines of   */
    /* the posting and we only want to get the manualy entered posting-lines at this moment in time      */
    /* ================================================================================================= */
    
    /* ==================================================== */
    /* Exception handling - Start Block                     */
    /* ==================================================== */
    assign oiReturnStatus      = -98
           viLocalReturnStatus = 0.
    OIADJUSTBLOCK: DO :
        
        /* ============================================================================================ */
        /* Create the OIAdjust header based upon the 'Main'-data-items that are defined on class-level. */
        /* Note: The data in the instance is already cleared by the parent-method (by callingClearData) */
        /* ============================================================================================ */
        <M-70 run AddDetailLine
           (input  'OIAdjust':U (icTable), 
            input  '':U (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave OIADJUSTBLOCK.
        assign tOIAdjust.Company_ID                 = viMainPostingCompanyID
               tOIAdjust.Posting_ID                 = viMainPostingID
               tOIAdjust.OIAdjustPostingYear        = viMainPostingYear
               tOIAdjust.OIAdjustPostingPeriod      = viMainPostingPeriod
               tOIAdjust.OIAdjustPostingJournalCode = vcMainPostingJournalCode
               tOIAdjust.OIAdjustPostingVoucher     = viMainPostingVoucher
               tOIAdjust.OIAdjustPostingDate        = vtMainPostingDate
               tOIAdjust.OIAdjustPostingJournalType = vcMainPostingJournalTypeCode
               tOIAdjust.OIAdjustDescription        = vcMainDescription
               tOIAdjust.OIAdjustComment            = "":U.
        
        /* ============================================================================================ */
        /* Create the OIAdjustLn-records based upon temp-table tOIAdj                                   */
        /* Add the invoice-reference (yr/jrnl/voucher) to the comment-field on the header               */
        /* ============================================================================================ */
        for each tOIAdj :
            <M-71 run AddDetailLine
               (input  'OIAdjustLn':U (icTable), 
                input  tOIAdjust.tc_Rowid (icParentRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            if viFcReturnSuper <> 0 
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 
            then Leave OIADJUSTBLOCK.
            assign viOIAdjustLnInvYear        = integer(entry(1,tOIAdj.tcInvoiceNumberReference,"/":U))
                   vcOIAdjustLnInvJournalCode = entry(2,tOIAdj.tcInvoiceNumberReference,"/":U)
                   viOIAdjustLnInvVoucher     = integer(entry(3,tOIAdj.tcInvoiceNumberReference,"/":U))
                   no-error.
            if error-status:error
            then do :
                assign viLocalReturnStatus  = -3
                       vcMsgOIAdj           = trim(substitute(#T-74'Internal error. The system was unable to extract the invoice year, invoice daybook, and invoice voucher from the reference (&1).':255(70210)t-74#,tOIAdj.tcInvoiceNumberReference)).
                if error-status:num-messages > 0
                then assign vcMsgOIAdj = vcMsgOIAdj + chr(10) + 
                                         trim(substitute(#T-75'Detailed info: &1 (&2)':252(70208)T-75#,error-status:Get-Message(1),string(error-status:Get-Number(1)))).
                <M-76 run SetMessage
                   (input  vcMsgOIAdj (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QadFin-8289':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
                Leave OIADJUSTBLOCK.
            end. /* if error-status:error */
            /* Indicate if the balance or movement is positive or not */
            if ((tOIAdj.tcNewBalanceCrDt   = {&CREDITDEBITABBREVIATION-CREDIT} and
                 tOIAdj.tdInvoiceBalanceTC < tOIAdj.tdNewBalanceTC) or
                (tOIAdj.tcNewBalanceCrDt   = {&CREDITDEBITABBREVIATION-DEBIT} and
                 tOIAdj.tdInvoiceBalanceTC > tOIAdj.tdNewBalanceTC))
            then assign viMovementSignConverter = -1. 
            else assign viMovementSignConverter = +1.
            if tOIAdj.tcNewBalanceCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
            then assign viBalanceSignConverter = -1. 
            else assign viBalanceSignConverter = +1.
            
            /* Create the data */
            assign tOIAdjustLn.CInvoice_ID                  = (if tOIAdj.tcInvoiceOrigin = {&INVOICEORIGIN-CREDITOR} then tOIAdj.tiInvoiceID else 0)
                   tOIAdjustLn.DInvoice_ID                  = (if tOIAdj.tcInvoiceOrigin = {&INVOICEORIGIN-DEBTOR}   then tOIAdj.tiInvoiceID else 0)
                   tOIAdjustLn.InvMovementPostingLine_ID    = tOIAdj.tiInvMovementPostingLineID
                   tOIAdjustLn.JournalEntryPostingLine_ID   = 0
                   tOIAdjustLn.OIAdjustLnInvYear            = viOIAdjustLnInvYear
                   tOIAdjustLn.OIAdjustLnInvJournalCode     = vcOIAdjustLnInvJournalCode
                   tOIAdjustLn.OIAdjustLnInvVoucher         = viOIAdjustLnInvVoucher
                   tOIAdjustLn.OIAdjustLnInvIdentifier      = tOIAdj.tcInvoiceNumberReference
                   tOIAdjustLn.OIAdjustLnInvReference       = tOIAdj.tcCInvoiceReference
                   tOIAdjustLn.OIAdjustLnInvDate            = tOIAdj.ttInvoiceDate
                   tOIAdjustLn.OIAdjustLnInvCompanyCode     = tOIAdj.tcCompanyCode
                   tOIAdjustLn.OIAdjustLnInvCredDebCode     = tOIAdj.tcCredDebEmplCode
                   tOIAdjustLn.OIAdjustLnInvType            = tOIAdj.tcInvoiceType
                   tOIAdjustLn.OIAdjustLnGLCode             = tOIAdj.tcInvoiceControlGLCode
                   tOIAdjustLn.OIAdjustLnCurrencyCode       = tOIAdj.tcInvoiceCurrencyCode
                   tOIAdjustLn.OIAdjustLnOrigBalanceAmtTC   = tOIAdj.tdInvoiceBalanceTC * viBalanceSignConverter
                   tOIAdjustLn.OIAdjustLnMovementAmtTC      = tOIAdj.tdAdjustmentAmountTC * viMovementSignConverter
                   tOIAdjustLn.OIAdjustLnPaymentDiscTC      = (tOIAdj.tdAdjustmentDiscountAmountTC - tOIAdj.tdTaxDiscountAmountTC) * viMovementSignConverter * -1
                   tOIAdjustLn.OIAdjustLnTaxDiscTC          = tOIAdj.tdTaxDiscountAmountTC * viMovementSignConverter * -1
                   tOIAdjustLn.OIAdjustLnNewBalanceAmtTC    = tOIAdj.tdNewBalanceTC * viBalanceSignConverter
                   tOIAdjustLn.OIAdjustLnBaseCurrencyCode   = vcCompanyLC
                   tOIAdjustLn.OIAdjustLnOrigBalanceAmtLC   = tOIAdj.tdInvoiceBalanceLC * viBalanceSignConverter
                   tOIAdjustLn.OIAdjustLnMovementAmtLC      = tOIAdj.tdAdjustmentAmountLC * viMovementSignConverter
                   tOIAdjustLn.OIAdjustLnPaymentDiscLC      = (tOIAdj.tdAdjustmentDiscountAmountLC - tOIAdj.tdTaxDiscountAmountLC) * viMovementSignConverter * -1
                   tOIAdjustLn.OIAdjustLnTaxDiscLC          = tOIAdj.tdTaxDiscountAmountLC * viMovementSignConverter * -1
                   tOIAdjustLn.OIAdjustLnNewBalanceAmtLC    = tOIAdj.tdNewBalanceTC * tOIAdj.tdInvoiceExchangeRate * viBalanceSignConverter
                   tOIAdjustLn.OIAdjustLnType               = (if tOIAdj.tcInvoiceOrigin = {&INVOICEORIGIN-DEBTOR}
                                                               then if tOIAdj.tlIsNewOpenItem
                                                                    then {&OIADJUSTLNTYPE-DINEW}
                                                                    else {&OIADJUSTLNTYPE-DIMOV}
                                                               else if tOIAdj.tlIsNewOpenItem
                                                                    then {&OIADJUSTLNTYPE-CINEW}
                                                                    else {&OIADJUSTLNTYPE-CIMOV})
                   tOIAdjustLn.OIAdjustLnWHTAmtTC           = tOIAdj.tdAdjustmentWHTAmountTC
                   tOIAdjustLn.OIAdjustLnWHTAmtLC           = tOIAdj.tdAdjustmentWHTAmountLC
                   tOIAdjustLn.OIAdjustLnWHTAmtCC           = <M-30 RoundAmount
                                                                 (input  tOIAdj.tdAdjustmentWHTAmountTC * tOIAdj.tdAdjustmentWHTCCRate * tOIAdj.tdAdjustmentWHTCCScale (idUnroundedAmount), 
                                                                  input  viCompanyCCId (iiCurrencyID), 
                                                                  input  vcCompanyCC (icCurrencyCode)) in BOpenItemAdjustment>
                   tOIAdjustLn.OIAdjustLnWHTPerc            = tOIAdj.tdAdjustmentWHTPerc      
                   tOIAdjustLn.OIAdjustLnWHTTxFeeTC         = tOIAdj.tdAdjustmentWHTTaxFeeTC
                   tOIAdjustLn.OIAdjustLnWHTLCRate          = tOIAdj.tdAdjustmentWHTLCRate
                   tOIAdjustLn.OIAdjustLnWHTLCScale         = tOIAdj.tdAdjustmentWHTLCScale
                   tOIAdjustLn.OIAdjustLnWHTCCRate          = tOIAdj.tdAdjustmentWHTCCRate
                   tOIAdjustLn.OIAdjustLnWHTCCScale         = tOIAdj.tdAdjustmentWHTCCScale
                   tOIAdj.tiOIAdjustLnId                    = tOIAdjustLn.OIAdjustLn_ID.
            /* Add the invoice to the comment-field on the header */
            assign viOIAdjustCommentLength = length(tOIAdjust.OIAdjustComment,"Character":U).
            if viOIAdjustCommentLength = 0
            then assign tOIAdjust.OIAdjustComment = trim(tOIAdj.tcInvoiceNumberReference).
            else if viOIAdjustCommentLength < 225
                 then assign tOIAdjust.OIAdjustComment = tOIAdjust.OIAdjustComment + ", ":U + trim(tOIAdj.tcInvoiceNumberReference).
                 else if index(tOIAdjust.OIAdjustComment,"...":U) = 0
                      then assign tOIAdjust.OIAdjustComment = tOIAdjust.OIAdjustComment + ", ...":U.

            /*Update Deduction Status*/
            if tOIAdjustLn.DInvoice_ID > 0 and tOIAdjustLn.OIAdjustLnInvType = {&INVOICETYPE-DEDUCTION} then
            do:
                /* ====================== */
                /* Start / Open BDInvoice */
                /* ====================== */
                if viBDInvoiceInOIAID = 0 or viBDInvoiceInOIAID = ?
                then do:
                    <I-94 {bFcStartAndOpenInstance
                          &ADD-TO-TRANSACTION   = "true"
                          &CLASS                = "BDInvoice"}>
                    assign vlBDInvoiceIsStartedFromOIAdj = true.    
                end.
                else do:
                    <I-21 {bFcOpenInstance
                           &CLASS           = "BDInvoice"}>
                end.

                <M-46 run UpdateDInvoiceDeductionStatus
                   (input  tOIAdjustLn.DInvoice_ID (iiDInvoiceID), 
                    input  tOIAdj.tdAdjustmentPaidTC (idPaidAmount), 
                    output oiReturnStatus (oiReturnStatus)) in BDInvoice>

                 <I-6 {bFcCloseInstance
                      &CLASS           = "BDInvoice"}>
            end.    


        end. /* for each tOIAdj */
            
        /* ============================================================================================ */
        /* Get all non-deleted posting-lines from BJE: this should reflect manualy entered JE-lines     */
        /* Create a OIAdjustLn-record for each of these posting-lines                                   */
        /* ============================================================================================ */
        <I-68 {bFcOpenInstance
             &CLASS           = "BJournalEntry"}>
        BJEACCESSBLOCK : DO :
            <M-77 run GetPostingLineDataForPosting
               (input  vcMainPostingTcRowid (icPostingTcRowid), 
                input  viMainPostingID (iiPostingID), 
                output tPostingLineMinimalDataOIAdj (tPostingLineMinimalData), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper <> 0 
            then assign viJournalEntryBlockError = viFcReturnSuper.
            if viFcReturnSuper < 0 
            then Leave BJEACCESSBLOCK.
            for each tPostingLineMinimalDataOIAdj : 
                <M-78 run AddDetailLine
                   (input  'OIAdjustLn':U (icTable), 
                    input  tOIAdjust.tc_Rowid (icParentRowid), 
                    output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
                if viFcReturnSuper <> 0 
                then assign viJournalEntryBlockError = viFcReturnSuper.
                if viFcReturnSuper < 0 
                then Leave BJEACCESSBLOCK.
                assign tOIAdjustLn.CInvoice_ID                  = 0
                       tOIAdjustLn.DInvoice_ID                  = 0
                       tOIAdjustLn.InvMovementPostingLine_ID    = 0
                       tOIAdjustLn.JournalEntryPostingLine_ID   = tPostingLineMinimalDataOIAdj.tiPostingLineID  
                       tOIAdjustLn.OIAdjustLnGLCode             = tPostingLineMinimalDataOIAdj.tcPostingLineGLCode
                       tOIAdjustLn.OIAdjustLnCurrencyCode       = tPostingLineMinimalDataOIAdj.tcPostingLineCurrencyCode
                       tOIAdjustLn.OIAdjustLnOrigBalanceAmtTC   = 0
                       tOIAdjustLn.OIAdjustLnMovementAmtTC      = tPostingLineMinimalDataOIAdj.tdPostingLineDebitTC - tPostingLineMinimalDataOIAdj.tdPostingLineCreditTC
                       tOIAdjustLn.OIAdjustLnPaymentDiscTC      = 0
                       tOIAdjustLn.OIAdjustLnTaxDiscTC          = 0
                       tOIAdjustLn.OIAdjustLnNewBalanceAmtTC    = 0
                       tOIAdjustLn.OIAdjustLnBaseCurrencyCode   = vcCompanyLC
                       tOIAdjustLn.OIAdjustLnOrigBalanceAmtLC   = 0
                       tOIAdjustLn.OIAdjustLnMovementAmtLC      = tPostingLineMinimalDataOIAdj.tdPostingLineDebitLC - tPostingLineMinimalDataOIAdj.tdPostingLineCreditLC
                       tOIAdjustLn.OIAdjustLnPaymentDiscLC      = 0
                       tOIAdjustLn.OIAdjustLnTaxDiscLC          = 0
                       tOIAdjustLn.OIAdjustLnNewBalanceAmtLC    = 0
                       tOIAdjustLn.OIAdjustLnType               = {&OIADJUSTLNTYPE-JE}.
            end. /* tPostingLineMinimalDataOIAdj */
        END. /* BJEACCESSBLOCK */
        <I-69 {bFcCloseInstance
             &CLASS           = "BJournalEntry"}>                       
        if viJournalEntryBlockError <> 0 
        then assign viLocalReturnStatus = viJournalEntryBlockError.
        if viJournalEntryBlockError < 0 
        then Leave OIADJUSTBLOCK.
        
        /* =========================================================== */
        /* Call the Validations and AdditionalUpdates in our own class */
        /* =========================================================== */
        <M-79 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave OIADJUSTBLOCK.
        <M-80 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave OIADJUSTBLOCK.
        
    END. /* OIADJUSTBLOCK */    
    
    /* ==================================================== */
    /* Exception handling                                   */
    /* ==================================================== */
    assign oiReturnStatus = viLocalReturnStatus.