project QadFinancials > class BBankEntry > method StopExternalInstances

Description

Stop instances that are started in AdditionalUpdates as part of current transaction


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.AdditionalUpdates
method BBankEntry.ValidateComponent


program code (program/bbankentry.p)

    /* ========================================================================== */
    /* Stop the different components but only after running a method that returns */
    /* the IDs of all linked postings for the newly created stuff                 */
    /* ========================================================================== */
    assign vcPostingIdToDelete     = "":U
           vcPostingLineIDToDelete = "":U
           vcAllPostingIdToDelete = "":U
           vcAllPostingLineIDToDelete = "":U. 
    
    /* ========= */
    /* BCInvoice */
    /* ========= */
    if viBCInvoiceBEID <> 0 and viBCInvoiceBEID <> ?
    then do:
        <I-1 {bFcOpenInstance
            &CLASS           = "BCInvoice"}>
        <M-2 run GetPostingInfoOfInstance (output vcPostingIdToDelete (ocPostingIDs), 
                                   output vcPostingLineIDToDelete (ocPostingLineIDs), 
                                   output viExternalReturnStatus (oiReturnStatus)) in BCInvoice> 
        <I-3 {bFcCloseAndStopInstance
            &CLASS           = "BCInvoice"}>
        if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
        if viExternalReturnStatus < 0 
        then do :
            assign vcMessage      = trim(substitute(#T-34'An error has occurred when retrieving the posting information of the supplier invoice &1.':200(346)T-34#, string(viFcReturnSuper))). 
            <M-4 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-6914':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            return.
        end.
        assign vcAllPostingIdToDelete     = if vcAllPostingIDToDelete = "":U then vcPostingIDToDelete else vcAllPostingIDToDelete + ",":U + vcPostingIDToDelete
               vcAllPostingLineIDToDelete = if vcAllPostingLineIDToDelete = "":U then vcPostingLineIDToDelete else vcAllPostingLineIDToDelete + ",":U + vcPostingLineIDToDelete
               viBCInvoiceBEID             = 0.
    end.
    
    /* ========= */
    /* BDInvoice */
    /* ========= */
    if viBDInvoiceBEID <> 0 and viBDInvoiceBEID <> ?
    then do:
        <I-5 {bFcOpenInstance
            &CLASS           = "BDInvoice"}>
        <M-6 run GetPostingInfoOfInstance (output vcPostingIdToDelete (ocPostingIDs), 
                                   output vcPostingLineIDToDelete (ocPostingLineIDs), 
                                   output viExternalReturnStatus (oiReturnStatus)) in BDInvoice>
        <I-7 {bFcCloseAndStopInstance
            &CLASS           = "BDInvoice"}>
        if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
        if viExternalReturnStatus < 0 
        then do :
            assign vcMessage      = trim(substitute(#T-35'An error has occurred when retrieving the posting information of the customer invoice &1.':200(347)T-35#, string(viFcReturnSuper))). 
            <M-8 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-6915':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            return.
        end.
        assign vcAllPostingIdToDelete     = if vcAllPostingIDToDelete = "":U then vcPostingIDToDelete else vcAllPostingIDToDelete + ",":U + vcPostingIDToDelete
               vcAllPostingLineIDToDelete = if vcAllPostingLineIDToDelete = "":U then vcPostingLineIDToDelete else vcAllPostingLineIDToDelete + ",":U + vcPostingLineIDToDelete
               viBDInvoiceBEID            = 0.
    end.
    
    /* ========== */
    /* BCDocument */
    /* ========== */
    if viBCDocumentBEID <> 0 and viBCDocumentBEID <> ?
    then do:
        <I-9 {bFcOpenInstance
            &CLASS           = "BCDocument"}>
        <M-13 run GetPostingInfoOfInstance (output vcPostingLineIDToDelete (ocPostingLineIDs), 
                                    output viExternalReturnStatus (oiReturnStatus)) in BCDocument>
        <I-14 {bFcCloseAndStopInstance
            &CLASS           = "BCDocument"}>
        if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
        if viExternalReturnStatus < 0 
        then do :
            assign vcMessage      = trim(substitute(#T-37'An error has occurred when retrieving the posting information of the supplier payment: &1.':200(349)T-37#, string(viFcReturnSuper))). 
            <M-15 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-6917':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            return.
        end.
        assign vcAllPostingLineIDToDelete = if vcAllPostingLineIDToDelete = "":U then vcPostingLineIDToDelete else vcAllPostingLineIDToDelete + ",":U + vcPostingLineIDToDelete
               viBCDocumentBEID           = 0.
    end.

    /* ========== */
    /* BDDocument */
    /* ========== */
    if viBDDocumentBEID <> 0 and viBDDocumentBEID <> ?
    then do:
        <I-16 {bFcOpenInstance
            &CLASS           = "BDDocument"}>
        <M-20 run GetPostingInfoOfInstance (output vcPostingLineIDToDelete (ocPostingLineIDs), 
                                    output viExternalReturnStatus (oiReturnStatus)) in BDDocument>
        <I-21 {bFcCloseAndStopInstance
            &CLASS           = "BDDocument"}>
        if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
        if viExternalReturnStatus < 0 
        then do :
            assign vcMessage      = trim(substitute(#T-39'An error has occurred when retrieving the posting information of the customer payment: &1.':200(17356)T-39#, string(viFcReturnSuper))). 
            <M-22 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-6919':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            return.
        end.
        assign vcAllPostingLineIDToDelete = if vcAllPostingLineIDToDelete = "":U then vcPostingLineIDToDelete else vcAllPostingLineIDToDelete + ",":U + vcPostingLineIDToDelete
               viBDDocumentBEID           = 0.
    end.  
    
    /* ===================== */
    /* Add bank posting line */
    /* ===================== */
    assign vcAllPostingLineIDToDelete = if vcAllPostingLineIDToDelete = "":U then vcBankPostingLineId else vcAllPostingLineIDToDelete + ",":U + vcBankPostingLineId.
    
    /* ======================================================================================================== */                                                                                                               
    /* posting of unallocated lines where you have execute allocate and then press cancel, must also be deleted */
    /* as this method is called from ValidateComponent and from AdditioanlUpdates methods, we do this for both  */
    /* tBankStateLine as t_ssBankStateLine                                                                      */
    /* ======================================================================================================== */                                                                                                               
    for each tBankStateLine where
             tbankstateline.tc_status           <> "D":U and
             tBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-UNALLOC} and
             tBankStateLine.tiPostingVoucher    <> 0 :
        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) )
        then do:
            assign vcAllPostingIdToDelete    = if vcAllPostingIDToDelete = "":U then string(tBankStateLine.Posting_ID) else vcAllPostingIDToDelete + ",":U + string(tBankStateLine.Posting_ID)
                   tBankStateLine.Posting_ID = 0.
        end.
    end. /* for each tBankStateLine */
    for each t_sBankStateLine where
             t_sbankstateline.tc_status           <> "D":U and
             t_sBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-UNALLOC} and
             t_sBankStateLine.tiPostingVoucher    <> 0:
        if not can-find(first t_sBankStateAlloc where
                              t_sBankStateAlloc.tc_ParentRowid = t_sBankStateLine.tc_Rowid and
                              (t_sBankStateAlloc.tc_Status = "N":U or t_sbankstatealloc.tc_status = "C":U))
        then do:
            if not can-do (vcAllPostingIDToDelete,string(t_sBankStateLine.Posting_ID))
            then assign vcAllPostingIdToDelete    = if vcAllPostingIDToDelete = "":U then string(t_sBankStateLine.Posting_ID) else vcAllPostingIDToDelete + ",":U + string(t_sBankStateLine.Posting_ID)
                        t_sBankStateLine.Posting_ID = 0.
        end.
    end. /* for each t_sBankStateLine */

    /* ====================================================== */
    /* Mark the postings of the stopped components as deleted */
    /* ====================================================== */
    if INTEGER(entry(1,vcAllPostingLineIDToDelete)) > 0 or
       INTEGER(entry(1,vcAllPostingIDToDelete)) > 0 and
       viBJournalEntryBEID <> 0 and 
       viBJournalEntryBEID <> ?
    then do:
        if vhBJournalEntryBEInst               = ? or
        not valid-handle(vhBJournalEntryBEInst)
        then do:
            <I-23 {bFcOpenInstance
                 &CLASS           = "BJournalEntry"}>
        end.

        <M-24 run MarkInstanceDataAsDeleted
           (input  vcAllPostingIdToDelete (icPostingIDToDelete), 
            input  vcAllPostingLineIDToDelete (icPostingLineIDToDelete), 
            output viExternalReturnStatus (oiReturnStatus)) in BJournalEntry>

        if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
        if viExternalReturnStatus < 0 
        then do :
            <I-25 {bFcCloseInstance
            &CLASS           = "BJournalEntry"}>
            assign vcMessage      = trim(substitute(#T-40'An error has occurred when trying to mark the posting and posting lines as Deleted: &1.':200(350)T-40#, string(viFcReturnSuper))). 
            <M-26 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-6920':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            return.
        end.

        /* if there is no posting info then remove JE instance otherwise you get Data to be saved must be validated */
        <M-27 run CheckIfThereIsSomethingInInstance
           (output vlPostingFound (olPostingFound), 
            output viExternalReturnStatus (oiReturnStatus)) in BJournalEntry>

        <I-28 {bFcCloseInstance
            &CLASS           = "BJournalEntry"}>
        if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
        if viExternalReturnStatus < 0 
        then do :
            assign vcMessage      = trim(substitute(#T-41'An error has occurred when trying to mark the posting and posting lines as Deleted: &1.':200(350)T-41#, string(viFcReturnSuper))). 
            <M-29 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-6921':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            return.
        end.
        if not vlPostingFound
        then do:
            if viTransactionID = 0 or viTransactionID = ?
            then do:
                <I-30 {bFcStartAndOpenInstance
                     &ADD-TO-TRANSACTION   = "true"
                     &CLASS                = "Transaction"}>
            end.
            else do:
                <I-31 {bFcOpenInstance
                     &CLASS           = "Transaction"}> 
            end.

            <M-32 run RemoveInstance
               (input  viBJournalEntryBEID (iiInstanceNr), 
                output viFcReturnSuper (oiReturnStatus)) in Transaction>

            <I-33 {bFcCloseInstance
                 &CLASS           = "Transaction"}>
        end. /* if not vlPostingFound */
    end. /* if (vcAllPostingLineIDToDelete <> "":U or */
    
    /* ================================== */
    /* Stop the BWithHoldingTax component */
    /* ================================== */
    if vlBWHTBEWasStartedHere               and
       viBWithholdingTaxBankingEntryID <> 0 and
       viBWithholdingTaxBankingEntryID <> ?
    then do:
        <I-93 {bFcStopInstance
             &CLASS           = "BWithholdingTax"}>
    
        assign viBWithholdingTaxBankingEntryID = 0
               vlBWHTBEWasStartedHere          = false.
    end. /* if vlBWHTBEWasStartedHere and */
    
<ANCESTOR-CODE>