project QadFinancials > class BDInvoice > method ReInitializeEverything

Description

Reinitialize following tables : dinvoicebank, dinvoicebankpaycode, dinvoicemovement, dinvoiceopinfo, dinvoiceposting, dinvoicestage, dinvoicevat and posting, postingline, postingvat, .....


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bdinvoice.p)

/* ======================================================================================== */
/* not used for multiple instances                                                          */
/* it will delete all records in all other tables                                           */
/* needed to get the general tab more flexible                                              */
/* this is executed from ui after you said yes on the question to reinitialixe everything   */
/* ======================================================================================== */
assign oiReturnStatus = -98.

empty temp-table tTaxDetailDInvoice.

for each tDInvoice where 
         tDInvoice.tc_Status = "N":U :
         
    assign tDInvoice.DInvoiceBalanceCreditTC = 0
           tDInvoice.DInvoiceBalanceDebitTC  = 0
           tDInvoice.DInvoiceBalanceCreditLC = 0
           tDInvoice.DInvoiceBalanceDebitLC  = 0
           tDInvoice.DInvoiceBalanceCreditCC = 0
           tDInvoice.DInvoiceBalanceDebitCC  = 0
           tDInvoice.DInvoiceBalanceTC       = 0
           tDInvoice.DInvoiceBalanceLC       = 0
           tDInvoice.DInvoiceBalanceCC       = 0
           tDInvoice.DInvoiceIsOpen          = true.

    for each tDInvoiceBank where
              tDInvoiceBank.tc_ParentRowid = tDInvoice.tc_Rowid :
        for each tDInvoiceBankPayCode where
                 tDInvoiceBankPayCode.tc_ParentRowid = tDInvoiceBank.tc_Rowid:
             delete tDInvoiceBankPayCode.
        end.
        delete tDInvoiceBank.
    end.
    
    for each tDInvoiceMovement where
             tDInvoiceMovement.tc_ParentRowid = tDInvoice.tc_Rowid :
        delete tDInvoiceMovement.
    end.
    
    for each tDInvoiceOpInfo where
             tDInvoiceOpInfo.tc_ParentRowid = tDInvoice.tc_Rowid :
        delete tDInvoiceOpInfo.
    end.
    
    for each tDInvoicePosting where
             tDInvoicePosting.tc_ParentRowid = tDInvoice.tc_Rowid :
        delete tDInvoicePosting.
    end.
    
    for each tDInvoiceStage where
             tDInvoiceStage.tc_ParentRowid = tDInvoice.tc_Rowid :
        delete tDInvoiceStage.
    end.
    
    for each tDInvoiceVat where
             tDInvoiceVat.tc_ParentRowid = tDInvoice.tc_Rowid :
        delete tDInvoiceVat.
    end.

end. /* for each tDInvoice */

if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ?
then do:
    assign vcMessage      = trim(#T-1'Internal error. The system cannot reinitialize all related tables when no posting instance is available.':250(63310)t-1#)
           oiReturnStatus = -3.
    
    <M-2 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-6458':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    Return.
end.

/* ======================================================================== */
/* make instance of posting empty                                           */
/* clear all tables of the posting, so posting, postingline, postingvat, .. */      
/* ======================================================================== */
<I-3 {bFcOpenInstance
            &CLASS           = "BJournalEntry"}>
<M-4 run ClearData
   (output viExternalstatus (oiReturnStatus)) in BJournalEntry>
<I-5 {bFcCloseInstance
            &CLASS           = "BJournalEntry"}>     
if viExternalStatus <> 0 then assign oiReturnStatus = viExternalStatus.
if viExternalStatus < 0 then return.

/* ================================================================================== */
/* make instance of crosscy posting empty and remove the insance from the transaction */
/* clear all tables of the posting, so posting, postingline, postingvat, ..           */      
/* ================================================================================== */
if viTransactionID <> 0
then do:
    assign vcListBJournalEntryInstIDs = ''
           viBJournalEntryIDTemp      = viBJournalEntryDIID.

    <I-29 {bFcOpenInstance
         &CLASS           = "transaction"}>
         
    /* Get all the instances of BJournalEntry belonging to this transaction */
    <M-65 run GetInstances
       (input  'BJournalEntry':U (icClass), 
        output vcListBJournalEntryInstIDs (ocInstances), 
        output viExternalStatus (oiReturnStatus)) in Transaction>
    if viExternalStatus <> 0 then assign oiReturnStatus = viExternalStatus.
    if viExternalStatus < 0 then return.

    /* Treat the Cross Company Posting */
    do viCnt = 2 to num-entries (vcListBJournalEntryInstIDs,',') by 2 :

        assign viBJournalEntryDIID = integer (entry (viCnt,vcListBJournalEntryInstIDs,',')).
        if viBJournalEntryDIID = viBJournalEntryIDTemp
        then next.

        <I-36 {bFcOpenInstance
             &CLASS           = "BJournalEntry"}>        
        <M-48 run ClearData  (output viExternalstatus (oiReturnStatus)) in BJournalEntry>        
        <M-44 run RemoveInstance
           (input  viBJournalEntryDIID (iiInstanceNr), 
            output viExternalStatus (oiReturnStatus)) in Transaction>        
        <I-88 {bFcCloseAndStopInstance
             &CLASS           = "BJournalEntry"}>    
             
        if viExternalStatus <> 0 then assign oiReturnStatus = viExternalStatus.
        if viExternalStatus < 0 then leave.             
                  
    end. /* do */

    <I-72 {bFcCloseInstance
         &CLASS           = "transaction"}>
     
    assign viBJournalEntryDIID = viBJournalEntryIDTemp.
         
end. /* if viTransactionID <> 0 */

if oiReturnStatus = -98
then assign oiReturnStatus = 0.