project QadFinancials > class BPosting > method RemovePostingFromInstance

Description

remove the posting from the instance : delete posting and postinglines and also release the number


Parameters


iiPostingIDinputintegerID of the posting to be deleted from instance
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.RemovePosting
method BPosting.ValidateComponentReversingPosting
method BJournalEntry.CreateReplaceEntry
method BJournalEntry.CreateReverseEntry


program code (program6/bposting.p)

/* Error handling */
assign oiReturnStatus = -98
       viLocalReturn  = 0.

MAIN_BLOCK:
do on error undo, return:

    /* ================================================================================================================================== */
    /* get the posting (use buffer for delete as there can be already other methods in same segment expecting correct record in t_tables) */
    /* ================================================================================================================================== */
    find first bPosting where
               bPosting.Posting_ID = iiPostingID
               no-error.
    if not available bPosting 
    then do:
        assign oiReturnStatus = 0.
        return.
    end.

    /* ======================== */
    /* delete the posting lines */
    /* ======================== */
    for each bPostingLine where
             bPostingLine.tc_ParentRowid  = bPosting.tc_Rowid :
        
        for each bPostingSaf where
                 bPostingSaf.tc_ParentRowid = bPostingLine.tc_Rowid:
            delete bPostingSaf.
        end.

        for each bPostingVat where
                 bPostingVat.tc_ParentRowid = bPostingLine.tc_Rowid:
            delete bPostingVat.
        end.

        for each bPostingWHT where
                 bPostingWHT.tc_ParentRowid = bPostingLine.tc_Rowid:
            delete bPostingWHT.
        end.

        for each bPostingVatDelay where
                 bPostingVatDelay.tc_ParentRowid = bPostingLine.tc_Rowid:
            delete bPostingVatDelay.
        end.
    
        delete bPostingLine.
    end. /* for each bPostingLine where */

        
    /* ========================== */
    /* release the posting number */
    /* ========================== */
    if (bPosting.tc_Status = "N" or
       bPosting.tc_Status = "C" and
       can-find(t_iPosting where
                t_iPosting.tc_Rowid         = bPosting.tc_Rowid        and
                (t_iPosting.PostingYear    <> bPosting.PostingYear   or
                 t_iPosting.tcJournalCode  <> bPosting.tcJournalCode or
                 t_iPosting.PostingVoucher <> bPosting.PostingVoucher))) and
        (bPosting.PostingVoucher <> 0 and bPosting.PostingVoucher <> ?)
    then do :
        /* Start&Open BNumber (AddToTrx=false) as in a loop below we will be calling BNumber repetively and this */
        /* is more performing then using vhFcComponent=?. BNumber will be closed and stopped after the loop      */
        if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ?
        then do :
            <I-16 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "false"
                 &CLASS                = "BNumber"}>
        end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
        <M-1 run ReleaseNumber
           (input  bPosting.Company_ID (iiCompanyId), 
            input  bPosting.PostingYear (iiNumbrYear), 
            input  bPosting.tcJournalCode (icNumbrType), 
            input  bPosting.PostingVoucher (iiNumbr), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viExternalReturnStatus (oiReturnStatus)) in BNumber>
        /* Close&Stop BNumber that is started with a different transaction before the previous loop   */
        if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ?
        then do :
            <I-75 {bFcCloseAndStopInstance
                 &CLASS           = "BNumber"}>
        end. /* if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ? */            
        if viExternalReturnStatus < 0 or 
           (viExternalReturnStatus > 0 and viLocalReturn = 0)
        then assign viLocalReturn = viExternalReturnStatus.
        if viExternalReturnStatus < 0 then leave MAIN_BLOCK.
    end.

    /* ================== */
    /* delete the posting */
    /* ================== */
    delete bPosting.

    /* ====================================== */
    /* delete posting also from t_s... tables */
    /* ====================================== */
    for each bsPosting where
             bsPosting.Posting_ID = iiPostingID:
        for each bsPostingLine where
                 bsPostingLine.tc_ParentRowid  = bsPosting.tc_Rowid :
            
            for each bsPostingSaf where
                     bsPostingSaf.tc_ParentRowid = bsPostingLine.tc_Rowid:
                delete bsPostingSaf.
            end.
    
            for each bsPostingVat where
                     bsPostingVat.tc_ParentRowid = bsPostingLine.tc_Rowid:
                delete bsPostingVat.
            end.

            for each bsPostingWHT where
                     bsPostingWHT.tc_ParentRowid = bsPostingLine.tc_Rowid:
                delete bsPostingWHT.
            end.
    
            for each bsPostingVatDelay where
                     bsPostingVatDelay.tc_ParentRowid = bsPostingLine.tc_Rowid:
                delete bsPostingVatDelay.
            end.
        
            delete bsPostingLine.
        end. /* for each bsPostingLine where */

        delete bsPosting.
    end. /* for each bsPosting where */
end. /* MAIN_BLOCK */

/* Error handling */
assign oiReturnStatus = viLocalReturn.