project QadFinancials > class BDInvoice > 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 BDInvoice.AdditionalUpdates
method BDInvoice.ApiSetDeductionStatus
method BDInvoice.ApiUpdateCInvoiceWithNewBank
method BDInvoice.ApiUpdateDInvoiceOpInfo
method BDInvoice.CreateDInvoiceMovements
method BDInvoice.CreateDIPosting
method BDInvoice.LoadDIPosting
method BDInvoice.UpdateDeductionDetail
method BDInvoice.ValidateComponentAllBank


program code (program/bdinvoice.p)

/* ============================================================================================================ */ 
    /* We do not stop BJournalEntry because it is used before any validation gets executed and it should persist in */
    /* case of errors because otherwise all the posting-info (including the lines) is lost!                         */
    /* We do remove the CA-posting if there is any because this posting is create by submethods of AddtionalUpdates */
    /* Similarly, we also remove the posting-lines (created in method CreateDInvoicemovements and its submethods)   */
    /* that are the originating ones for the requests for the CrossCompany-daemon                                   */
    /* ============================================================================================================ */
    if viBJournalEntryDIID             <> 0 and 
       viBJournalEntryDIID             <> ? and 
       ((vcListDIPostingLinesForQCrossCy <> "":U and 
         vcListDIPostingLinesForQCrossCy <> ?) Or
        (vcListDAPostingsCreatedInAddUpd <> "":U and 
         vcListDAPostingsCreatedInAddUpd <> ?))
    then do:
        <I-1 {bFcOpenInstance
             &CLASS           = "BJournalEntry"}>
        <M-2 run MarkInstanceDataAsDeleted
           (input  vcListDAPostingsCreatedInAddUpd (icPostingIDToDelete), 
            input  vcListDIPostingLinesForQCrossCy (icPostingLineIDToDelete), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        <I-3 {bFcCloseInstance
             &CLASS           = "BJournalEntry"}>
    end.
    
    /* If - with a previous save that failed because the PostSave returned an error - a posting was made in */
    /* method AdditionalUpdates and not by the UI, then the instance data is wrong */
    /* for example : when creating a credit note, that results in an error, */
    /* the tdinvoicemovement records for the invoice and the credit note are created, we need to remove them */
    /* from instance otherwise problems with second save */
    /* We need to remove that posting as we would otherwise create a second posting and get stuck with the */
    /* first posting that has got no posting-lines */
    /* We have to do this here because we cannot call StopExternalInstances from method PostSave because */
    /* that would result in problems with the transaction */
    for each tDInvoice where
             tDInvoice.LinkedDInvoice_ID <> 0 and
             tDInvoice.LinkedDInvoice_ID <> ?,
        each btDInvoice where
             btDInvoice.DInvoice_ID = tDInvoice.LinkedDInvoice_ID :
    
        /* remove movement of invoice from instance */
        for each tDInvoiceMovement where
                 tDInvoiceMovement.tc_ParentRowid       = btDInvoice.tc_Rowid and
                 tDInvoiceMovement.tc_Status            = "N":U and
                 tDInvoiceMovement.DInvoiceMovementType = {&MOVEMENTTYPE-MOVEMENT} :
            find t_iDInvoiceMovement where
                 t_iDInvoiceMovement.tc_Rowid = tDInvoiceMovement.tc_Rowid
                 no-error.
            if available t_iDInvoiceMovement
            then delete t_iDInvoiceMovement.
            delete tDInvoiceMovement.
        end.
        /* remove movement of credit note from instance */
        for each tDInvoiceMovement where
                 tDInvoiceMovement.tc_ParentRowid       = tDInvoice.tc_Rowid and
                 tDInvoiceMovement.tc_Status            = "N":U and
                 tDInvoiceMovement.DInvoiceMovementType = {&MOVEMENTTYPE-MOVEMENT} :
            find t_iDInvoiceMovement where
                 t_iDInvoiceMovement.tc_Rowid = tDInvoiceMovement.tc_Rowid
                 no-error.
            if available t_iDInvoiceMovement
            then delete t_iDInvoiceMovement.
            delete tDInvoiceMovement.
        end.
    
        /* remove all related tables for btdinvoice from instance */
        for each tDInvoiceBank where
                 tDInvoiceBank.tc_ParentRowid   = btDInvoice.tc_Rowid and
                 tDInvoiceBank.tc_Status        = "N":U:
    
            for each tDInvoiceBankPayCode where
                     tDInvoiceBankPayCode.tc_ParentRowid    = tDInvoiceBank.tc_Rowid and
                     tDInvoiceBankPayCode.tc_Status         = "N":U:
                find t_iDInvoiceBankPayCode where
                     t_iDInvoiceBankPayCode.tc_Rowid = tDInvoiceBankPayCode.tc_Rowid
                     no-error.
                if available t_iDInvoiceBankPaycode
                then delete t_iDInvoiceBankPayCode.
                delete tDInvoiceBankPayCode.
            end.
    
            find t_iDInvoiceBank where
                 t_iDInvoiceBank.tc_Rowid = tDInvoiceBank.tc_Rowid
                 no-error.
            if available t_iDInvoiceBank
            then delete t_iDInvoiceBank.
            delete tDInvoiceBank.
        end.
    
        for each tDInvoiceOpInfo where
                 tDInvoiceOpInfo.tc_ParentRowid = btDInvoice.tc_Rowid and
                 tDInvoiceOpInfo.tc_Status      = "N":U:
            find t_iDInvoiceOpInfo where
                 t_iDInvoiceOpInfo.tc_Rowid = tDInvoiceOpInfo.tc_Rowid
                 no-error.
            if available t_iDInvoiceOpInfo
            then delete t_iDInvoiceOpInfo.
            delete tDInvoiceOpInfo.
        end.
    
        for each tDInvoicePosting where
                 tDInvoicePosting.tc_ParentRowid    = btDInvoice.tc_Rowid and
                 tDInvoicePosting.tc_Status         = "N":U:
            find t_iDInvoicePosting where
                 t_iDInvoicePosting.tc_Rowid = tDInvoicePosting.tc_Rowid
                 no-error.
            if available t_iDInvoicePosting
            then delete t_iDInvoicePosting.
            delete tDInvoicePosting.
        end.
    
        for each tDInvoiceStage where
                 tDInvoiceStage.tc_ParentRowid  = btDInvoice.tc_Rowid and
                 tDInvoiceStage.tc_Status       = "N":U:
            find t_iDInvoiceStage where
                 t_iDInvoiceStage.tc_Rowid = tDInvoiceStage.tc_Rowid
                 no-error.
            if available t_iDInvoiceStage
            then delete t_iDInvoiceStage.
            delete tDInvoiceStage.
        end.
                 
        for each tDInvoiceVat where
                 tDInvoiceVat.tc_ParentRowid    = btDInvoice.tc_Rowid and
                 tDInvoiceVat.tc_Status         = "N":U:
            find t_iDInvoiceVat where
                 t_iDInvoiceVat.tc_Rowid = tDInvoiceVat.tc_Rowid
                 no-error.
            if available t_iDInvoiceVat
            then delete t_iDInvoiceVat.
            delete tDInvoiceVat.
        end.
    
        find t_iDInvoice where
             t_iDInvoice.tc_Rowid = btDInvoice.tc_Rowid
             no-error.
        if available t_iDInvoice
        then delete t_iDInvoice.
        delete btDInvoice.
    end.
    
    if viBQDInvoiceMovementID <> 0 and 
       viBQDInvoiceMovementID <> ?
    then do:
        <I-4 {bFcStopInstance
                &CLASS           = "BQDInvoiceMovement"}>
        assign viBQDInvoiceMovementID = 0.
    end.
    
    if viBQCrossCyPostingDIID <> 0 and 
       viBQCrossCyPostingDIID <> ?
    then do :
        <I-5 {bFcStopInstance
                &CLASS           = "BQCrossCyPosting"}>
        assign viBQCrossCyPostingDIID = 0.
    end.
    
    if viBDebtorFromDIID <> 0 and 
       viBDebtorFromDIID <> ?
    then do :
        <I-6 {bFcStopInstance
                &CLASS           = "BDebtor"}>
        assign viBDebtorFromDIID = 0.
    end.  /* if viBDebtorFromDIID <> 0 and  */
    
    
    if viBPaymentFormatDIID <> 0 and 
       viBPaymentFormatDIID <> ?
    then do :
        <I-7 {bFcStopInstance
                &CLASS           = "BPaymentFormat"}>
        assign viBPaymentFormatDIID = 0.
    end.  /* if viBDebtorFromDIID <> 0 and  */
    
    
    <ANCESTOR-CODE>