Description
Allocate open invoices to the Customer Payment
Parameters
tDocInvoiceXref | input | temp-table | |
tDocInvoiceStageXref | input | temp-table | |
iiDocumentId | input | integer | |
icParentRowId | input | character | |
idUnAllocatedAmount | input | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bddocument.p)
/* ===================================================================*/
/* Allocate invoice to DDocument */
/* ===================================================================*/
find first tDocInvoiceXref no-error.
if not available tDocInvoiceXref and idUnAllocatedAmount = 0
then do:
assign vcMessage = trim(#T-1'The system cannot find invoices for the check.':255(999890588)T-1#).
<M-2 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7602':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign oiReturnStatus = -1.
return.
end. /* if not available tDocInvoiceXref */
for each tDocInvoiceXref on error undo, throw:
/* For selected invoice, if it has been allocated to previous DDoc in the same bankimport file, then skip it */
find first tDDocumentInvoiceXref where
tDDocumentInvoiceXref.DInvoice_ID = tDocInvoiceXref.tiDInvoiceId no-error.
if available tDDocumentInvoiceXref
then next.
<M-3 run AddDetailLine
(input 'DDocumentInvoiceXref':U (icTable),
input icParentRowId (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign tDDocumentInvoiceXref.DDocument_ID = iiDocumentId
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC = tDocInvoiceXref.tdInvoiceRefAlloTC
tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC = tDocInvoiceXref.tdInvoiceRefDiscTC
tDDocumentInvoiceXref.DInvoice_ID = tDocInvoiceXref.tiDInvoiceId
tDDocumentInvoiceXref.tcCurrencyCode = tDocInvoiceXref.tcInvoiceRefCurrencyCode
tDDocumentInvoiceXref.tcAllocAmountCrDt = tDocInvoiceXref.tcAmountCrDt
tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC = tDocInvoiceXref.tdInvoiceRefIntTC.
/*set cc rate, if not it will result in the ddocumentccrate as 0 */
if vlDomainIsStatutory = false then
do:
assign tDDocumentInvoiceXref.tdCCExchangeRate = 1
tDDocumentInvoiceXref.tdCCExchangeRateScale = 1.
end.
else do:
if tDDocumentInvoiceXref.tcCurrencyCode = vcCompanyCC then
do:
assign tDDocumentInvoiceXref.tdCCExchangeRate = 1
tDDocumentInvoiceXref.tdCCExchangeRateScale = 1.
end.
else do:
if tDDocumentInvoiceXref.tcCurrencyCode <> vcPreviousCC or vdDDocumentXrefCCRate = 0 or
vdDDocumentXrefCCRate = ?
then
do:
assign vcPreviousCC = tDDocumentInvoiceXref.tcCurrencyCode.
<M-64 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input tDDocumentInvoiceXref.tcCurrencyCode (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
input tDDocument.ttPostingDate (itValidityDate),
output vdDDocumentXrefCCRate (odExchangeRate),
output vdDDocumentXrefCCScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
assign tDDocumentInvoiceXref.tdCCExchangeRate = vdDDocumentXrefCCRate
tDDocumentInvoiceXref.tdCCExchangeRateScale = vdDDocumentXrefCCScale.
end.
end.
<Q-77 run DInvoiceByAllocationInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input ?, (BusinessRelationCode)
input tDDocumentInvoiceXref.DInvoice_ID, (DInvoiceID)
input ?, (DInvoiceDescription)
input ?, (DebtorCode)
input ?, (CurrencyCode)
input ?, (DInvoiceIsOpen)
input ?, (DInvoiceAmountTCMinimum)
input ?, (DInvoiceAmountTCMaximum)
input ?, (PeriodYearMinimum)
input ?, (JournalCode)
input ?, (PeriodYear)
input ?, (Voucher)
input ?, (DInvoiceTSMNumber)
input ?, (ShipperCode)
input ?, (CorporateGroupCode)
input ?, (CompIsOICrossCy)
input ?, (Debtor_ID)
input ?, (DInvoiceIsSelected)
input ?, (BillNumber)
input ?, (BillYear)
output dataset tqDInvoiceByAllocationInfo) in BDInvoice>
find first tqDInvoiceByAllocationInfo where
tqDInvoiceByAllocationInfo.tiDInvoice_ID = tDDocumentInvoiceXref.DInvoice_ID
no-error.
if available tqDInvoiceByAllocationInfo
then assign tDDocumentInvoiceXref.tiDInvoicePostingId = tqDInvoiceByAllocationInfo.tiPosting_ID
tDDocumentInvoiceXref.ttDInvoiceDate = tqDInvoiceByAllocationInfo.ttDInvoicePostingDate.
for each tDocInvoiceStageXref where
tDocInvoiceStageXref.tiDInvoiceId = tDDocumentInvoiceXref.DInvoice_ID
on error undo, throw:
<M-72 run AddDetailLine
(input 'DDocInvoiceXrefStage':U (icTable),
input tDDocumentInvoiceXref.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
assign tDDocInvoiceXrefStage.DDocInvoiceXrefStageAlloTC = tDocInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC
tDDocInvoiceXrefStage.DDocInvoiceXrefStageDiscTC = tDocInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC
tDDocInvoiceXrefStage.DDocInvoiceXrefStagePaidAmtTC = tDocInvoiceStageXref.tdDDocInvoiceXrefStageAllocTC - tDocInvoiceStageXref.tdDDocInvoiceXrefStageDiscTC
tDDocInvoiceXrefStage.DInvoiceStage_ID = tDocInvoiceStageXref.tiDInvoiceStageId
tDDocInvoiceXrefStage.tiDInvoice_ID = tDocInvoiceStageXref.tiDInvoiceId
tDDocInvoiceXrefStage.DDocumentInvoiceXref_ID = tDDocumentInvoiceXref.DDocumentInvoiceXref_ID.
end. /* for each tDocInvoiceStageXref */
end. /* for each tDocInvoiceXref */
/* ===================================================================*/
/* Create prepayment to DDocument */
/* ===================================================================*/
if idUnAllocatedAmount <> 0
then do:
<M-25 run AddDetailLine
(input 'DDocumentInvoiceXref':U (icTable),
input icParentRowId (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign tDDocumentInvoiceXref.DDocument_ID = iiDocumentId
tDDocumentInvoiceXref.DInvoice_ID = 0
tDDocumentInvoiceXref.tcDInvoiceType = {&INVOICETYPE-PREPAYMENT}
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC = idUnAllocatedAmount
tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
tDDocumentInvoiceXref.tcDInvoiceBalanceCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC = 0
tDDocumentInvoiceXref.tdDInvoiceBalance = idUnAllocatedAmount.
find first tDDocument where tDDocument.tc_Rowid = icParentRowId no-error.
if available tDDocument then
assign tDDocumentInvoiceXref.tcCurrencyCode = tDDocument.tcCurrencyCode
tDDocumentInvoiceXref.tcDInvoiceReference = tDDocument.DDocumentBankImpRef
tDDocumentInvoiceXref.tcBusinessRelationCode = tDDocument.tcBusinessRelationCode
tDDocumentInvoiceXref.tcDebtorCode = tDDocument.tcDebtorCode.
/* Find default for prepayment */
<M-84 run DefaultValuesPrepayment
(input icParentRowId (icRowId),
output vcCostCentreCode (ocCostCentreCode),
output vcProjectCode (ocProjectCode),
output vcDivisionCode (ocDivisionCode),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
assign tDDocumentInvoiceXref.tcCostCentreCode = vcCostCentreCode
tDDocumentInvoiceXref.tcProjectCode = vcProjectCode
tDDocumentInvoiceXref.tcDivisionCode = vcDivisionCode.
end.