| ilInvoiceIsInitial | input | logical | |
| ilKeepPo | input | logical | Keep the po records, not delete them. When you change the supplier, then this parameter will be false, otherwise true, except when receiver matching is false |
| oiReturnStatus | output | integer | Return status of the method. |
/* ======================================================================================== */
/* 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 reinitialize everything */
/* ======================================================================================== */
assign oiReturnStatus = -98.
empty temp-table tTaxDetailCInvoice.
for each tCInvoice where
tCInvoice.tc_Status <> "D":U:
assign tCInvoice.CInvoiceBalanceCreditTC = 0
tCInvoice.CInvoiceBalanceDebitTC = 0
tCInvoice.CInvoiceBalanceCreditLC = 0
tCInvoice.CInvoiceBalanceDebitLC = 0
tCInvoice.CInvoiceBalanceCreditCC = 0
tCInvoice.CInvoiceBalanceDebitCC = 0
tCInvoice.CInvoiceBalanceTC = 0
tCInvoice.CInvoiceBalanceLC = 0
tCInvoice.CInvoiceBalanceCC = 0
tCInvoice.CInvoiceIsOpen = true.
for each tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid :
for each tCInvoiceBankPayCode where
tCInvoiceBankPayCode.tc_ParentRowid = tCInvoiceBank.tc_Rowid:
if tCInvoiceBankPayCode.tc_Status = "N":U
then delete tCInvoiceBankPayCode.
else assign tCInvoiceBankPayCode.tc_Status = "D":U.
end.
if tCInvoiceBank.tc_Status = "N":U
then delete tCInvoiceBank.
else assign tCInvoiceBank.tc_Status = "D":U.
end.
for each tCInvoiceMovement where
tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid :
if tCInvoiceMovement.tc_Status = "N":U
then delete tCInvoiceMovement.
else assign tCInvoiceMovement.tc_Status = "D":U.
end.
if not ilKeepPo
then do:
for each tCInvoicePO where
tCInvoicePO.tc_ParentRowid = tCInvoice.tc_Rowid :
if tCInvoicePO.tc_Status = "N":U
then delete tCInvoicePO.
else assign tCInvoicePO.tc_Status = "D":U.
end.
end.
for each tCInvoicePosting where
tCInvoicePosting.tc_ParentRowid = tCInvoice.tc_Rowid :
if tCInvoicePosting.tc_Status = "N":U
then delete tCInvoicePosting.
else assign tCInvoicePosting.tc_Status = "D":U.
end.
for each tCInvoiceStage where
tCInvoiceStage.tc_ParentRowid = tCInvoice.tc_Rowid :
if tCInvoiceStage.tc_Status = "N":U
then delete tCInvoiceStage.
else assign tCInvoiceStage.tc_Status = "D":U.
end.
for each tCInvoiceVat where
tCInvoiceVat.tc_ParentRowid = tCInvoice.tc_Rowid :
if tCInvoiceVat.tc_Status = "N":U
then delete tCInvoiceVat.
else assign tCInvoiceVat.tc_Status = "D":U.
end.
for each tCInvoiceWHT where
tCInvoiceWHT.tc_ParentRowid = tCInvoice.tc_Rowid :
if tCInvoiceWHT.tc_Status = "N":U
then delete tCInvoiceWHT.
else assign tCInvoiceWHT.tc_Status = "D":U.
end.
end.
if (viBJournalEntryCIID = 0 or viBJournalEntryCIID = ?) and ilInvoiceIsInitial = false
then do:
assign oiReturnStatus = -3.
<M-3 run SetMessage
(input trim(#T-4'Internal error. The system cannot reinitialize all related tables when no posting instance is available.':250(63310)t-4#) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-6455':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
Return.
end.
/*POSTINGS ARE CREATED FOR NON INITIAL INVOICES HENCE CALL CLEARDATA ONLY FOR NON INITIAL INVOICES */
if not ilInvoiceIsInitial
then Do:
/* ======================================================================== */
/* make instance of posting empty */
/* clear all tables of the posting, so posting, postingline, postingvat, .. */
/* ======================================================================== */
<I-1 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
<M-2 run ClearData (output viExternalStatus (oiReturnStatus)) in BJournalEntry>
<I-6 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
/* ================================================================================== */
/* 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 = viBJournalEntryCIID.
<I-16 {bFcOpenInstance
&CLASS = "transaction"}>
/* Get all the instances of BJournalEntry belonging to this transaction */
<M-82 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 viBJournalEntryCIID = integer (entry (viCnt,vcListBJournalEntryInstIDs,',')).
if viBJournalEntryCIID = viBJournalEntryIDTemp
then next.
<I-27 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
<M-74 run ClearData (output viExternalstatus (oiReturnStatus)) in BJournalEntry>
<M-60 run RemoveInstance
(input viBJournalEntryCIID (iiInstanceNr),
output viExternalStatus (oiReturnStatus)) in Transaction>
<I-70 {bFcCloseAndStopInstance
&CLASS = "BJournalEntry"}>
if viExternalStatus <> 0 then assign oiReturnStatus = viExternalStatus.
if viExternalStatus < 0 then leave.
end. /* do */
<I-26 {bFcCloseInstance
&CLASS = "transaction"}>
assign viBJournalEntryCIID = viBJournalEntryIDTemp.
end. /* if viTransactionID <> 0 */
end. /* if not ilInvoiceIsInitial */
if viExternalStatus <> 0 then assign oiReturnStatus = viExternalStatus.
if viExternalStatus < 0 then return.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.