project QadFinancials > class BOpenItemAdjustment > method OIAdjCommitSub

Description

OIAdjCommit; Save the whole adjustment


Parameters


ilStopProcessingWhenWarninginputlogicalSet this parameter to TRUE if you want to stop processing during Submit of Open Item Adjustment. In this case this warning appears on the UI and user can decide what to do.
This parameter is used for workaround as this component is not implemented in standard manner.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BOpenItemAdjustment.OIAdjCommit


program code (program8/bopenitemadjustment.p)

/* ================== */
    /* Exception handling */
    /* ================== */
    assign oiReturnStatus = -98.
    
    
    /* =============================================================== */
    /* Error in case we do no longer have an instance of BJournalEntry */
    /* Also check if the "Main" data-items are valid                   */
    /* =============================================================== */
    if viBJournalEntryID            = 0    or viBJournalEntryID             = ? or
       viMainPostingCompanyID       = 0    or viMainPostingCompanyID        = ? or
       viMainPostingID              = 0    or viMainPostingID               = ? or
       viMainPostingVoucher         = 0    or viMainPostingVoucher          = ? or 
       viMainPostingYear            = 0    or viMainPostingYear             = ? or 
       viMainPostingPeriod          = 0    or viMainPostingPeriod           = ? or 
       vcMainPostingJournalCode     = "":U or vcMainPostingJournalCode      = ? or 
       vcMainPostingJournalTypeCode = "":U or vcMainPostingJournalTypeCode  = ? or 
       vcMainPostingTcRowid         = "":U or vcMainPostingTcRowid          = ? 
    then do :   
        assign oiReturnStatus = -1
               vcMsgOIAdj     = trim(#T-214'System error: unable to commit the transaction due to missing Posting information.':255(69568)T-214#) + " ":U + trim(#T-178'Details':25(853)T-178#) + ";":U + chr(10) + 
                                trim(substitute(#T-202'Journal entry ID: &1.':255(69569)T-202#,string(viBJournalEntryID))) + chr(10) + 
                                trim(substitute(#T-221'Posting Company ID: &1.':255(69635)t-221#,string(viMainPostingCompanyID))) + chr(10) + 
                                trim(substitute(#T-203'Posting ID: &1.':255(2935)T-203#,string(viMainPostingID))) + chr(10) + 
                                trim(substitute(#T-204'Posting Year: &1.':255(69570)T-204#,string(viMainPostingYear))) + chr(10) + 
                                trim(substitute(#T-216'Posting Daybook: &1.':255(69571)t-216#,vcMainPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-217'Posting Invoice: &1.':255(69572)t-217#,string(viMainPostingVoucher))) + chr(10) + 
                                trim(substitute(#T-220'Posting Daybook Type: &1.':255(69574)t-220#,vcMainPostingJournalTypeCode)) + chr(10) + 
                                trim(substitute(#T-218'Posting Row ID: &1.':255(69573)t-218#,vcMainPostingTcRowid)) + chr(10) + 
                                trim(substitute(#T-219'Posting Period: &1.':255(69575)T-219#,string(viMainPostingPeriod))). 
        <M-157 run SetMessage (input  vcMsgOIAdj (icMessage), 
                          input  '':U (icArguments), 
                          input  '':U (icFieldName), 
                          input  '':U (icFieldValue), 
                          input  'S':U (icType), 
                          input  1 (iiSeverity), 
                          input  '':U (icRowid), 
                          input  'QadFin-5570':U (icFcMsgNumber), 
                          input  '' (icFcExplanation), 
                          input  '' (icFcIdentification), 
                          input  '' (icFcContext), 
                          output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        return.
    end. /* if viBJournalEntryID */
    
    
    /* ================================================================================================================== */
    /* Creation of the records in this class: needs to be done before any other call creates posting-lines in the posting */
    /* ================================================================================================================== */
    <M-222 run OIAdjCommitSubOpenItemAdj  (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
    if viFcReturnSuper <> 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 or
           viFcReturnSuper > 0 and ilStopProcessingWhenWarning
        then do :
            <M-224 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            return.
        end. /* if viFcReturnSuper < 0 */
    end. /* if viFcReturnSuper <> 0 */
    
    
    /* ====================================================== */
    /* Create the adjustments and the NewOpenItem in BCI      */
    /* Call ValidateBC and AdditionalUpdates in the component */
    /* ====================================================== */
    if can-find (first tOIAdj where tOIAdj.tcInvoiceOrigin = {&INVOICEORIGIN-CREDITOR})
    then do :   
        <M-132 run OIAdjCommitSubCInvoice  (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        if viFcReturnSuper <> 0 
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 or
               viFcReturnSuper > 0 and ilStopProcessingWhenWarning
            then do :
                <M-133 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
                return.
            end. /* if viFcReturnSuper < 0 */
        end. /* if viFcReturnSuper <> 0 */     
    end. /* if can-find */
    
    
    /* ====================================================== */
    /* Create the adjustments and the NewOpenItem in BDI      */
    /* Call ValidateBC and AdditionalUpdates in the component */
    /* ====================================================== */
    if can-find (first tOIAdj where tOIAdj.tcInvoiceOrigin = {&INVOICEORIGIN-DEBTOR})
    then do :   
        <M-134 run OIAdjCommitSubDInvoice  (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        if viFcReturnSuper <> 0 
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 or
               viFcReturnSuper > 0 and ilStopProcessingWhenWarning
            then do :
                <M-135 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
                return.
            end. /* if viFcReturnSuper < 0 */
       end. /* if viFcReturnSuper <> 0 */ 
    end. /* if can-find */
    
    
    /* ============================================================================================= */
    /* Check wether the OpenBalance that we had on the UI (tOIAdj) is still the same in the database */
    /* This should be done as close as possible after the last DataLoad (incl called methods)        */
    /* ============================================================================================= */
    <M-141 run OIAdjCommitSubOptimisticLock  (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
    if viFcReturnSuper <> 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 or
           viFcReturnSuper > 0 and ilStopProcessingWhenWarning
        then do :
            <M-150 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            return.
        end. /* if viFcReturnSuper < 0 */
    end. /* if viFcReturnSuper <> 0 */
    
    
    /* =============================================================================================== */
    /* Posting has to be balanced from here on // Call the ValidateBC and the AdditionalUpdates in BJE */ 
    /* =============================================================================================== */
    if vlBJEIsStartedFromOIAdj = true
    then do:
        <I-136 {bFcOpenInstance
            &CLASS           = "BJournalEntry"}>
        <M-137 run SetPublicData
           (input  'vlPostingMustBeBalanced':U (icDataList), 
            input  'true':U (icValueList), 
            output viExternalError (oiReturnStatus)) in BJournalEntry>
        if viExternalError < 0 or 
           viExternalError > 0 and ilStopProcessingWhenWarning
        then do :
            <I-139 {bFcCloseInstance
            &CLASS           = "BJournalEntry"}>
            assign oiReturnStatus = viExternalError
                   vcMsgOIAdj     = trim(substitute(#T-175'Internal error: cannot set a required property &1 in the journal entry component.':255(2938)t-175#,'vlPostingMustBeBalanced':U)). 
            <M-138 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-5562':U (icFcMsgNumber), 
                          input  '' (icFcExplanation), 
                          input  '' (icFcIdentification), 
                          input  '' (icFcContext), 
                          output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            <M-167 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Return.
        end. /* if viExternalError < 0  */
        <M-215 run CheckCrDbAmountsForRealizedProfitLossAccounts
           (input  viMainPostingID (iiPostingID), 
            output viExternalError (oiReturnStatus)) in BJournalEntry>
        if viExternalError = 0
        then do:
            /* update PostingOriginAddressCode */
            find first tOIAdj no-lock no-error.
            if available tOIAdj
            then do :
                assign vcInvoiceOrigin   = tOIAdj.tcInvoiceOrigin
                       vcCredDebEmplCode = tOIAdj.tcCredDebEmplCode.
                find first tOIAdj where tOIAdj.tcInvoiceOrigin   <> vcInvoiceOrigin or
                                        tOIAdj.tcCredDebEmplCode <> vcCredDebEmplCode
                                        no-lock no-error.
                if not available tOIAdj
                then do:
                    <M-226 run SetPostingOriginAddressCode
                       (input  vcMainPostingTcRowid (icPostingTcRowID), 
                        input  viMainPostingID (iiPostingID), 
                        input  vcCredDebEmplCode (icPostingOriginAddressCode), 
                        output viExternalError (oiReturnStatus)) in BJournalEntry>
                end. /* end of if not available */
            end. /* if available tOIAdj */
        end. /* if viExternalError = 0 */

        if viExternalError = 0
        then do:
            <M-95 run OIAdjCommitSubCheckPostingBalanceLCCC  (output viExternalError (oiReturnStatus)) in BOpenItemAdjustment>
            if viExternalError = 0
            then do:
                <M-148 run ValidateBCAndAdditionalUpdates  (output viExternalError (oiReturnStatus)) in BJournalEntry>
            end.
        end. /* if viExternalError = 0 */    
        if viExternalError < 0 or
           viExternalError > 0 and ilStopProcessingWhenWarning
        then do :
            if viExternalError < 0
            then assign vcMsgOIAdj = trim(substitute(#T-179'An error has occurred while validating the journal entry &1. See other messages for further details.':255(13290)t-179#,string(viExternalError)))
                        vcErrorWarning = "E":U.
            else assign vcMsgOIAdj = trim(substitute(#T-16'A warning has occurred while validating the journal entry &1. See other messages for further details.':150(1482493)T-16#,string(viExternalError)))
                        vcErrorWarning = "W":U.
            assign oiReturnStatus = viExternalError. 
            <M-174 run SetPublicData
               (input  'vlPostingMustBeBalanced':U (icDataList), 
                input  'false':U (icValueList), 
                output viExternalError (oiReturnStatus)) in BJournalEntry>
            <I-173 {bFcCloseInstance
                 &CLASS           = "BJournalEntry"}>
            <M-140 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  vcErrorWarning (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-5563':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            <M-168 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            Return.
        end. /* if viExternalError < 0  */
        <I-149 {bFcCloseInstance
             &CLASS           = "BJournalEntry"}>
    end. /* if vlBJEIsStartedFromOIAdj = true */
    
    
    /* ============================================================================================= */
    /* Check if we have an activie transaction                                                       */
    /* ============================================================================================= */
    if vlTransactionActive <> true
    then do :
        assign oiReturnStatus = -3
               vcMsgOIAdj     = trim(#T-176'Internal error: open item adjustments: no transaction is active.':255(2940)t-176#). 
        <M-162 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-5574':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        <M-169 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        Return.
    end. /* if vlTransactionActive <> true */
    if viTransactionId = 0 or 
       viTransactionId = ?
    then do :
        assign oiReturnStatus = -3
               vcMsgOIAdj     = trim(#T-177'Internal error: open item adjustments: no transaction ID found.':255(2941)t-177#). 
        <M-172 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-5575':U (icFcMsgNumber), 
                          input  '' (icFcExplanation), 
                          input  '' (icFcIdentification), 
                          input  '' (icFcContext), 
                          output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        <M-170 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        Return.
    end. /* if vlTransactionActive <> true */
    
    
    /* ==================================================================================== */
    /* Save the whole thing (including this class, BJE, BCI, BDI and their sub-classes);    */
    /* We indicate targetprocedure as the parent-insatnce because the transaction would     */
    /* otherwise close the instance of this class (BOpenItemAjsument)                       */
    /* ==================================================================================== */
    <I-163 {bFcOpenInstance
            &CLASS           = "Transaction"}>
    <M-164 run CommitTransaction
       (input  true (ilStop), 
        input  {&TARGETPROCEDURE} (ihParentInstance), 
        output vcDummy (ocInstances), 
        output viFcReturnSuper (oiReturnStatus)) in Transaction>
    if viFcReturnSuper < 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        <M-142 run StopExternalInstancesExceptBJE (output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
        <I-165 {bFcCloseInstance
            &CLASS           = "Transaction"}>
        return.
    end. /* if viFcReturnSuper <> 0 */
    <I-171 {bFcCloseAndStopInstance
            &CLASS           = "Transaction"}>
    assign vlTransactionActive = no.
    
    
    /* ================== */
    /* Exception handling */
    /* ================== */
    assign oiReturnStatus = 0.