project QadFinancials > class BCInvoice > method StopExternalInstances
Description
Stop instances that are started in AdditionalUpdates as part of current transaction
Parameters
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program/bcinvoice.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 CreateCInvoicemovements and its submethods) */
/* that are the originating ones for the requests for the CrossCompany-daemon */
/* ============================================================================================================ */
if viBJournalEntryCIID <> 0 and
viBJournalEntryCIID <> ?
then do:
for each tPostingLinesForQCrossCompany:
if vcListPostingLinesForQCrossCy = "":U
then assign vcListPostingLinesForQCrossCy = string(tPostingLinesForQCrossCompany.tiPostingLineID).
else assign vcListPostingLinesForQCrossCy = vcListPostingLinesForQCrossCy + "," + string(tPostingLinesForQCrossCompany.tiPostingLineID).
/* if vcListPostingLinesForQCrossCy > 10000, load the data to prevent vcListPostingLinesForQCrossCy to get out of 32K limit */
if length(vcListPostingLinesForQCrossCy, "CHARACTER") > 10000 or
(vcListCAPostingsCreatedInAddUpd <> "":U and
vcListCAPostingsCreatedInAddUpd <> ?)
then do:
<I-18 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
<M-38 run MarkInstanceDataAsDeleted
(input vcListCAPostingsCreatedInAddUpd (icPostingIDToDelete),
input vcListPostingLinesForQCrossCy (icPostingLineIDToDelete),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
<I-93 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
assign vcListPostingLinesForQCrossCy = "":U.
end. /* if length(vcListPostingLinesForQCrossCy, "CHARACTER") > 10000 or */
end. /* for each tPostingLinesForQCrossCompany */
if (vcListPostingLinesForQCrossCy <> "":U and
vcListPostingLinesForQCrossCy <> ?) or
(vcListCAPostingsCreatedInAddUpd <> "":U and
vcListCAPostingsCreatedInAddUpd <> ?)
then do:
<I-70 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
<M-57 run MarkInstanceDataAsDeleted
(input vcListCAPostingsCreatedInAddUpd (icPostingIDToDelete),
input vcListPostingLinesForQCrossCy (icPostingLineIDToDelete),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
<I-20 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
assign vcListPostingLinesForQCrossCy = "":U.
end. /* if (vcListPostingLinesForQCrossCy <> "":U and */
end. /* if viBJournalEntryCIID <> 0 and */
empty temp-table tPostingLinesForQCrossCompany.
/* 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 tcinvoicemovement 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 tCInvoice where
tCInvoice.LinkedCInvoice_ID <> 0 and
tCInvoice.LinkedCInvoice_ID <> ?,
each btCInvoice where
btCInvoice.CInvoice_ID = tCInvoice.LinkedCInvoice_ID :
/* remove movement of invoice from instance */
for each tCInvoiceMovement where
tCInvoiceMovement.tc_ParentRowid = btCInvoice.tc_Rowid and
tCInvoiceMovement.tc_Status = "N":U and
tCInvoiceMovement.CInvoiceMovementType = {&MOVEMENTTYPE-MOVEMENT} :
find t_iCInvoiceMovement where
t_iCInvoiceMovement.tc_Rowid = tCInvoiceMovement.tc_Rowid
no-error.
if available t_iCInvoiceMovement
then delete t_iCInvoiceMovement.
delete tCInvoiceMovement.
end.
/* remove movement of credit note from instance */
for each tCInvoiceMovement where
tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceMovement.tc_Status = "N":U and
tCInvoiceMovement.CInvoiceMovementType = {&MOVEMENTTYPE-MOVEMENT} :
find t_iCInvoiceMovement where
t_iCInvoiceMovement.tc_Rowid = tCInvoiceMovement.tc_Rowid
no-error.
if available t_iCInvoiceMovement
then delete t_iCInvoiceMovement.
delete tCInvoiceMovement.
end.
/* remove all related tables for btcinvoice from instance */
for each tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = btCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status = "N":U:
for each tCInvoiceBankPayCode where
tCInvoiceBankPayCode.tc_ParentRowid = tCInvoiceBank.tc_Rowid and
tCInvoiceBankPayCode.tc_Status = "N":U:
find t_iCInvoiceBankPayCode where
t_iCInvoiceBankPayCode.tc_Rowid = tCInvoiceBankPayCode.tc_Rowid
no-error.
if available t_iCInvoiceBankPaycode
then delete t_iCInvoiceBankPayCode.
delete tCInvoiceBankPayCode.
end.
find t_iCInvoiceBank where
t_iCInvoiceBank.tc_Rowid = tCInvoiceBank.tc_Rowid
no-error.
if available t_iCInvoiceBank
then delete t_iCInvoiceBank.
delete tCInvoiceBank.
end.
for each tCInvoicePO where
tCInvoicePO.tc_ParentRowid = btCInvoice.tc_Rowid and
tCInvoicePO.tc_Status = "N":U:
find t_iCInvoicePO where
t_iCInvoicePO.tc_Rowid = tCInvoicePO.tc_Rowid
no-error.
if available t_iCInvoicePO
then delete t_iCInvoicePO.
delete tCInvoicePO.
end.
for each tCInvoicePosting where
tCInvoicePosting.tc_ParentRowid = btCInvoice.tc_Rowid and
tCInvoicePosting.tc_Status = "N":U:
find t_iCInvoicePosting where
t_iCInvoicePosting.tc_Rowid = tCInvoicePosting.tc_Rowid
no-error.
if available t_iCInvoicePosting
then delete t_iCInvoicePosting.
delete tCInvoicePosting.
end.
for each tCInvoiceStage where
tCInvoiceStage.tc_ParentRowid = btCInvoice.tc_Rowid and
tCInvoiceStage.tc_Status = "N":U:
find t_iCInvoiceStage where
t_iCInvoiceStage.tc_Rowid = tCInvoiceStage.tc_Rowid
no-error.
if available t_iCInvoiceStage
then delete t_iCInvoiceStage.
delete tCInvoiceStage.
end.
for each tCInvoiceVat where
tCInvoiceVat.tc_ParentRowid = btCInvoice.tc_Rowid and
tCInvoiceVat.tc_Status = "N":U:
find t_iCInvoiceVat where
t_iCInvoiceVat.tc_Rowid = tCInvoiceVat.tc_Rowid
no-error.
if available t_iCInvoiceVat
then delete t_iCInvoiceVat.
delete tCInvoiceVat.
end.
find t_iCInvoice where
t_iCInvoice.tc_Rowid = btCInvoice.tc_Rowid
no-error.
if available t_iCInvoice
then delete t_iCInvoice.
delete btCInvoice.
end.
/* QCInvoiceMovements */
if viBQCInvoiceMovementID <> 0
then do:
<I-4 {bFcStopInstance
&CLASS = "BQCInvoiceMovement"}>
assign viBQCInvoiceMovementID = 0.
end.
/* CrossCyPostings */
if viBQCrossCyPostingID <> 0
then do :
<I-5 {bFcStopInstance
&CLASS = "BQCrossCyPosting"}>
assign viBQCrossCyPostingID = 0.
end.
/* WorkObjects */
if viBWorkObjectID <> 0
then do :
<I-6 {bFcStopInstance
&CLASS = "BWorkObject"}>
assign viBWorkObjectID = 0.
end.
/* APMatching */
if viBAPMatchingCIID <> 0
then do:
<I-7 {bFcStopInstance
&CLASS = "BAPMatching"}>
assign viBAPMatchingCIID = 0.
end.
/* DocumentLink */
if viBDocumentLinkCIID <> 0
then do:
<I-8 {bFcStopInstance
&CLASS = "BDocumentLink"}>
assign viBDocumentLinkCIID = 0.
end.
/* BWithHoldingTax */
if viBWithholdingTaxBCIID <> 0 and
viBWithholdingTaxBCIID <> ?
then do :
<I-9 {bFcStopInstance
&CLASS = "BWithholdingTax"}>
assign viBWithholdingTaxBCIID = 0.
end. /* if viBWithholdingTaxBCIID <> 0 and */
<ANCESTOR-CODE>