| tDIOpenBalanceDeduction | input-output | temp-table | |
| iiBJournalEntryId | input | integer | Instance of BJournalEntry |
| iiPostingId | input | integer | Posting ID |
| ocNewRecordInfo | output | character | new record information rowid, dinvoice_id, rowid, dinvoice_id |
| tDIDeduction | input | temp-table | |
| oiReturnStatus | output | integer | Return status of the method. |
QadFinancials
/* replace unknown value */
if iiBJournalEntryId = ? then assign iiBJournalEntryId = 0.
if iiPostingID = ? then assign iiPostingID= 0.
/* exception handling */
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
empty temp-table tDIMovement.
empty temp-table tDInvoiceStageUpdates.
empty temp-table tDefaultSystemSafDI.
find first tDIOpenBalanceDeduction where tDIOpenBalanceDeduction.tcDebtorCode <> "":U no-error.
if not available tDIOpenBalanceDeduction then return.
/*start the component BDeductionCat*/
<I-34 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BDeductionCat"}>
assign vdDInvoiceAmountCC = tDIOpenBalanceDeduction.tdInvoiceAmountCC
tDIOpenBalanceDeduction.tiInvoiceVoucher = 0
tDIOpenBalanceDeduction.tcNormalPaymentConditionCode = '':U.
/*Create Deduction Invoice and deduction postings on deduction daybook. */
<M-90 run CreateDInvoices
(input-output tDIOpenBalanceDeduction (tDIOpenBalance),
input iiBJournalEntryId (iiBJournalEntryId),
input iiPostingID (iiPostingId),
output ocNewRecordInfo (ocNewRecordInfo),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
/* exception handling */
if viFcReturnSuper < 0 then
do:
/*close instance */
<I-57 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
return.
end.
assign viLocalReturnStatus = viFcReturnSuper.
find first tDIOpenBalanceDeduction where tDIOpenBalanceDeduction.tcDebtorCode <> "":U no-error.
if not available tDIOpenBalanceDeduction then return.
assign vcPostingHeaderRowId = '':U.
find first tDInvoice where
tDInvoice.tc_Status = "N":U and
tDInvoice.DInvoice_ID = tDIOpenBalanceDeduction.tiInvoiceId no-lock no-error.
if not available tDInvoice then
do:
/*close instance */
<I-63 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
return.
end.
/* set the due date of the deduction invoice */
/*
<M-21 run DefaultDuedatesForDeduction
(input tDInvoice.tcNormalPaymentConditionCode (icPaymentConditionCode),
input ? (iiPaymentConditionID),
input tDInvoice.DInvoiceDate (itDInvoiceDate),
input ? (iiDInvoiceRowID),
input tDIOpenBalance.tdInvoiceAmountTC (idDInvoiceOriginalTC),
input tDIOpenBalance.tcTCCurrencyCode (icCurrencyCode),
output tDInvoice.DInvoiceDueDate (otDInvoiceDueDate),
output vtDInvoiceDiscountDueDate (otDInvoiceDiscountDueDate),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
*/
if viFcReturnSuper < 0
then do:
/*close instance */
<I-29 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
return.
end.
/*process the deduction detail information and build the movement inital data.
where tDIDeduction.tc_ParentRowid = tDIOpenBalanceDeduction.tcKey */
for each tDIDeduction no-lock:
/*Validate DeductionCat line id */
<M-47 run ValDeductionCatLine
(input-output tDIDeduction.DeductionCatLine_ID (biDeductionCatLineID),
input '':U (icTargetFieldName),
input '':U (icRowid),
input tDIDeduction.tcDeductionCatCode (icDeductionCatCode),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then do:
/*close instance */
<I-6 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
return.
end.
else do: assign viLocalReturnStatus = viFcReturnSuper.
end.
/*Create Deduction detail information. */
<M-14 run AddDetailLine
(input 'DInvoiceDeduction':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then do:
/*close instance */
<I-33 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
return.
end.
else do: assign viLocalReturnStatus = viFcReturnSuper.
end.
assign tDInvoiceDeduction.DeductionCatLine_ID = tDIDeduction.DeductionCatLine_ID
tDInvoiceDeduction.DInvoiceDeductionStatus = tDIDeduction.DInvoiceDeductionStatus
tDInvoiceDeduction.DInvoiceDeductionCC = tDIDeduction.DInvoiceDeductionCC
tDInvoiceDeduction.DInvoiceDeductionTC = tDIDeduction.DInvoiceDeductionTC
tDInvoiceDeduction.PaidDInvoice_ID = tDIDeduction.PaidDInvoice_ID
tDInvoiceDeduction.DInvoiceDeductionComment = tDIDeduction.DInvoiceDeductionComment
tDInvoiceDeduction.DInvoiceDeductionSequence = tDIDeduction.DInvoiceDeductionSequence
tDInvoiceDeduction.DInvoiceDeductionCustRef = if tDIDeduction.DInvoiceDeductionCustRef = ? then '' else tDIDeduction.DInvoiceDeductionCustRef
tDInvoiceDeduction.DInvoiceDeductionPromotionCode = if tDIDeduction.DInvoiceDeductionPromotionCode = ? then '' else tDIDeduction.DInvoiceDeductionPromotionCode
tDInvoiceDeduction.DInvoiceDeductionLC = tDIDeduction.DInvoiceDeductionLC
tDInvoiceDeduction.DInvoiceDeductionCreateDate = today.
/*Check if autowirte-off */
if tDIDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-WRITE-OFF}
then do:
if vcPostingHeaderRowId = '':U then
do:
/*get the posting header tc_RowId. */
find first tDInvoicePosting where tDInvoicePosting.tc_Status = 'N':U
and tDInvoicePosting.DInvoice_ID = tDIOpenBalanceDeduction.tiInvoiceId no-lock no-error.
if not available tDInvoicePosting then
do:
/*close instance */
<I-40 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
return.
end.
assign viPostingId = tDInvoicePosting.Posting_ID.
/* Get Row Id of Posting Header in BJournalPosting */
/* start journal entry instance */
if iiBJournalEntryId = 0 or iiBJournalEntryId = ?
then do:
<I-5 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BJournalEntry"}>
assign vlBJEIsStartedFromDI = true.
end.
else do:
<I-96 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end.
<M-67 run PassRowIdBasedOnPostingIdInInstance
(input viPostingId (iiPostingId),
output vcPostingHeaderRowId (ocPostingRowId),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0
then do:
/*close instance */
<I-16 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
<I-763 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
end.
/*create DIMovement. */
create tDIMovement.
assign tDIMovement.tiDInvoiceId = tDInvoice.DInvoice_ID
tDIMovement.tcGLAccountDivisionCode = ""
tDIMovement.tcPostingRowId = vcPostingHeaderRowId
tDIMovement.tlMovementIsForDraft = false
tDIMovement.tlIsUndoPayment = false
tDIMovement.tdAmountCreditTC = tDIDeduction.DInvoiceDeductionTC
tDIMovement.tdAmountDebitTC = 0.
end.
end. /*end tDIDeduction*/
/*Create DInvoice Movements and Posting */
if can-find(first tDIMovement) then
do:
<M-49 run CreateDInvoiceMovements
(input-output tDIMovement (tDIMovement),
input tDInvoiceStageUpdates (tDInvoiceStageUpdates),
input-output iiBJournalEntryId (biBJournalEntryId),
input false (ilClearData),
input tDInvoice.DInvoicePostingDate (itPaymentTaxPointDate),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then do:
/*close instance */
<I-15 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
return.
end.
else do: assign viLocalReturnStatus = viFcReturnSuper.
end.
end.
/*Start the journal entry instance */
/*create di movements will close the journalentry instance */
/*need to re-open the instance*/
if iiBJournalEntryId = 0 or iiBJournalEntryId = ?
then do:
<I-77 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BJournalEntry"}>
assign vlBJEIsStartedFromDI = true.
end.
else do:
<I-71 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end.
/*add posting on the expense control account to the same posting header*/
for each tDInvoiceDeduction where tDInvoiceDeduction.DInvoiceDeductionStatus = {&INVOICEDEDUCTSTATUS-WRITE-OFF}
and tDInvoiceDeduction.tc_ParentRowid = tDInvoice.tc_Rowid no-lock:
/*get deduction expense account and validate the account */
<M-64 run ApiGetExpenseSubCCAndSAF
(input tDInvoiceDeduction.DeductionCatLine_ID (iiDeductionCatLineID),
output tDefaultSystemSafDI (tDeductionSaf),
output vcDeductionCostCentreCode (ocCostCentreCode),
output vcDeductionDivisionCode (ocDivisionCode),
output vcDeductionGLCode (ocGLCode),
output viFcReturnSuper (oiReturnStatus)) in BDeductionCat>
if viFcReturnSuper < 0
then do:
<I-78 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
/*close journal entry instance */
<I-7 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
else
do:
assign viLocalReturnStatus = viFcReturnSuper.
end.
<M-36 run AddStandardPosting
(input vcPostingHeaderRowId (icPostingtcRowid),
input vcDeductionGLCode (icGLCode),
input vcDeductionDivisionCode (icDivisionCode),
input vcDeductionCostCentreCode (icCostCentreCode),
input '':U (icCostCentreText),
input '':U (icProjectCode),
input '':U (icProjectText),
input '':U (icIntercoBusinessRelationCode),
input tDInvoice.tcCurrencyCode (icCurrencyCode),
input tDInvoiceDeduction.DInvoiceDeductionTC (idDebitTC),
input tDInvoiceDeduction.DInvoiceDeductionLC (idDebitLC),
input tDInvoiceDeduction.DInvoiceDeductionCC (idDebitCC),
input 0 (idDebitPC),
input 0 (idCreditTC),
input 0 (idCreditLC),
input 0 (idCreditCC),
input 0 (idCreditPC),
input 0 (idQty),
input tDIOpenBalanceDeduction.tcPostingText (icLineText),
input '':U (icSafText),
input tDefaultSystemSafDI (tDefaultSafs),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input tDInvoice.DInvoiceExchangeRate (idExchangeRate),
input tDInvoice.DInvoiceRateScale (idExchangeRateScale),
input tDInvoice.DInvoiceCCRate (idPostingLineCCRate),
input tDInvoice.DInvoiceCCScale (idPostingLineCCScale),
output viPostingLineId (oiPostingLineId),
input 0 (iiSafStructureId),
input '':U (icSafStructureCode),
input ? (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 then
do:
<I-24 {tFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
<I-37 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
end. /*tDInvoiceDeduction*/
<I-28 {bFcCloseAndStopInstance
&CLASS = "BDeductionCat"}>
/* ========================================================================================================= */
/* Normally we would here close BJournalEntry we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
assign oiReturnStatus = viLocalReturnStatus.