Parameters
icCurrency | input | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bdpaymentselection.p)
for each tDPaySel where tDPaySel.DPaySelStatus <> {&DOCUMENTSTATUS-INIT}:
<Q-30 run DDocumentXrefByDPaySelID (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tDPaySel.DPaySel_ID, (DPaySel_ID)
output dataset tqDDocumentXrefByDPaySelID) in BDDocument>
if tDPaySel.tcBankCurrencyCode = vcCompanyLC
then assign vdBankRate = 1
vdBankRateScale = 1.
else do:
<M-6 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input tDPaySel.tcBankCurrencyCode (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tDPaySel.DPaySelDate (itValidityDate),
output vdBankRate (odExchangeRate),
output vdBankRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
if viFcReturnSuper < 0 or oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
for each tqDDocumentXrefByDPaySelID:
<Q-81 run DInvoiceByAllocationInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input ?, (BusinessRelationCode)
input tqDDocumentXrefByDPaySelID.tiDInvoice_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>
for each tqDInvoiceByAllocationInfo:
create tDIncSelLine.
/* on UI */
assign tDIncSelLine.tc_Status = "":U
tDIncSelLine.tlIsSelected = true
tDIncSelLine.tc_Rowid = tqDInvoiceByAllocationInfo.tc_Rowid
tDIncSelLine.tcIncSelLineStatus = tqDDocumentXrefByDPaySelID.tcDDocumentStatus
tDIncSelLine.tcIncSelLineStatusTR = <M-56 GetLineStatusTranslation (input tDIncSelLine.tcIncSelLineStatus (icLineStatus)) in BDPaymentSelection>
tDIncSelLine.tcInvoiceType = tqDInvoiceByAllocationInfo.tcDInvoiceType
tDIncSelLine.tcInvoiceNumber = string(tqDInvoiceByAllocationInfo.tiPeriodYear) + "/":U +
tqDInvoiceByAllocationInfo.tcJournalCode + "/":U +
string(tqDInvoiceByAllocationInfo.tiDInvoiceVoucher, "999999999":U)
tDIncSelLine.ttInvoiceDate = tqDInvoiceByAllocationInfo.ttDInvoiceDate
tDIncSelLine.ttDueDate = tqDInvoiceByAllocationInfo.ttDInvoiceDueDate
tDIncSelLine.tcInvoiceCurrencyCode = tqDInvoiceByAllocationInfo.tcCurrencyCode
tDIncSelLine.tcCompanyCode = tqDInvoiceByAllocationInfo.tcCompanyCode
tDIncSelLine.tdInvoiceAmount = abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC
- tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC)
tDIncSelLine.tcInvoiceAmountCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> 0 and
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> ?
then {&CREDITDEBITABBREVIATION-DEBIT}
else {&CREDITDEBITABBREVIATION-CREDIT}
tDIncSelLine.tdInvoiceBalance = abs(tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC
- tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC)
tDIncSelLine.tcInvoiceBalanceCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> 0 and
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> ?
then {&CREDITDEBITABBREVIATION-DEBIT}
else {&CREDITDEBITABBREVIATION-CREDIT}
tDIncSelLine.tdIncSelLineAmountTC = if (tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-INVOICE} and
tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefAlloTC < 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-CREDITNOTE} and
tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefAlloTC < 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-DEDUCTION} and
tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefAlloTC < 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} and
tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefAlloTC > 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} and
tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefAlloTC > 0)
then (- tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefAlloTC - tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefDiscTC + tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefIntTC)
else (tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefAlloTC - tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefDiscTC + tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefIntTC)
tDIncSelLine.tdIncSelLineDiscountTC = tqDDocumentXrefByDPaySelID.tdDDocumentInvoiceXrefDiscTC
tDIncSelLine.tcIncSelLineAmountCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> 0 and
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> ?
then {&CREDITDEBITABBREVIATION-CREDIT}
else {&CREDITDEBITABBREVIATION-DEBIT}
tDIncSelLine.tcBusinessRelationCode = tqDInvoiceByAllocationInfo.tcBusinessRelationCode
tDIncSelLine.tcBusinessRelationName1 = tqDInvoiceByAllocationInfo.tcBusinessRelationName1
tDIncSelLine.tcCorporateGroupCode = tqDInvoiceByAllocationInfo.tcCorporateGroupCode
tDIncSelLine.tdIncSelLineIntRate = tqDInvoiceByAllocationInfo.tdPaymentConditionLateInt
tDIncSelLine.tcDInvoiceDIText = tqDInvoiceByAllocationInfo.tcDInvoiceDIText
tDIncSelLine.tiDInvoicePostingYear = year(tqDInvoiceByAllocationInfo.ttDInvoicePostingDate)
tDIncSelLine.tcJournalCode = tqDInvoiceByAllocationInfo.tcJournalCode
tDIncSelLine.tiDInvoiceVoucher = tqDInvoiceByAllocationInfo.tiDInvoiceVoucher
tDIncSelLine.tcDebtorCode = tqDInvoiceByAllocationInfo.tcDebtorCode
tDIncSelLine.tcShipperInfo = tqDInvoiceByAllocationInfo.tcDInvoiceShipperList
/* Not on UI */
tDIncSelLine.tiDInvoiceId = tqDInvoiceByAllocationInfo.tiDInvoice_ID
tDIncSelLine.ttDiscountDueDate = tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
tDIncSelLine.tdDiscountPercentage = if tqDDocumentXrefByDPaySelID.ttDDocumentDueDate <= tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
then tqDInvoiceByAllocationInfo.tdPaymentConditionPercentage
else 0
tDIncSelLine.tcPaymentConditionPayType = tqDInvoiceByAllocationInfo.tcPaymentConditionPaymentTyp
tDIncSelLine.tdInvoiceRate = tqDInvoiceByAllocationInfo.tdDInvoiceExchangeRate
tDIncSelLine.tdInvoiceRateScale = tqDInvoiceByAllocationInfo.tdDInvoiceRateScale
tDIncSelLine.ttDefaultDueDate = tDIncSelLine.ttDueDate
tDIncSelLine.tdDefaultIncSelLineIntRate = tDIncSelLine.tdIncSelLineIntRate
tDIncSelLine.tcDefaultIncLineStatus = tDIncSelLine.tcIncSelLineStatus
tDIncSelLine.tdBankRate = vdBankRate
tDIncSelLine.tdBankRateScale = vdBankRateScale.
/* Corrections always have negative amounts */
if tDIncSelLine.tcInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} or tDIncSelLine.tcInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then assign tDIncSelLine.tdInvoiceAmount = - tDIncSelLine.tdInvoiceAmount
tDIncSelLine.tdInvoiceBalance = - tDIncSelLine.tdInvoiceBalance.
assign vdDInvoiceRateInCurrentCny = tDIncSelLine.tdInvoiceRate
vdDInvoiceRateScaleInCurrentCny = tDIncSelLine.tdInvoiceRateScale.
/* When cross-company, if base currency is different or sharedset is different,
it cannot use invoice rate, need to get new rate.
*/
if tDIncSelLine.tcCompanyCode <> vcCompanyCode
then do:
/* Get current exchange rate shared set */
if vcExchangeRateSS = ? or vcExchangeRateSS = '':U
then do:
<Q-78 run CompanyCurrSSByIDCodeSSType (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&SHAREDSETTYPE-EXCHANGERATE}, (SharedSetType)
input ?, (CompanyCode)
output dataset tqCompanyCurrSSByIDCodeSSType) in BCompany>
find first tqCompanyCurrSSByIDCodeSSType no-error.
if available tqCompanyCurrSSByIDCodeSSType then
assign vcExchangeRateSS = tqCompanyCurrSSByIDCodeSSType.tcSharedSetCode.
end. /* End if vcExchangeRateSS = ? or vcExchagneRateSS = '':U */
/* Get invoice's company base currency and exchangerate sharedset code */
<Q-86 run CompanyCurrSSByIDCodeSSType (all) (Read) (NoCache)
(input ?, (CompanyId)
input {&SHAREDSETTYPE-EXCHANGERATE}, (SharedSetType)
input tDIncSelLine.tcCompanyCode, (CompanyCode)
output dataset tqCompanyCurrSSByIDCodeSSType) in BCompany>
find first tqCompanyCurrSSByIDCodeSSType no-error.
if available tqCompanyCurrSSByIDCodeSSType then
assign vcExchangeRateSSInInvoice = tqCompanyCurrSSByIDCodeSSType.tcSharedSetCode
viBaseCurrInInvoice = tqCompanyCurrSSByIDCodeSSType.tiCurrency_ID.
/* Check if sharedset code different or base currency different, need to get the rate
based on the current company.
bank currency same as invoice currency, directly use invoice rate as bank rate
*/
if viBaseCurrInInvoice <> viCompanyLCId or vcExchangeRateSS <> vcExchangeRateSSInInvoice
then do:
/* convert the invoice curreny to current base currency */
<M-90 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input tDIncSelLine.tcInvoiceCurrencyCode (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tDPaySel.DPaySelDate (itValidityDate),
output vdDInvoiceRateInCurrentCny (odExchangeRate),
output vdDInvoiceRateScaleInCurrentCny (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
end. /* End if viBaseCurrInInvoice <> viCompanyLCId or vcExchangeRateSS <> vcExchangeRateSSInInvoice */
else if tDPaySel.tcBankCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode
then assign tDIncSelLine.tdBankRate = tDIncSelLine.tdInvoiceRate
tDIncSelLine.tdBankRateScale = tDIncSelLine.tdInvoiceRateScale.
end. /* End Cross company */
else if tDPaySel.tcBankCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode
then assign tDIncSelLine.tdBankRate = tDIncSelLine.tdInvoiceRate
tDIncSelLine.tdBankRateScale = tDIncSelLine.tdInvoiceRateScale.
/* calculate BC Amount */
assign tDIncSelLine.tdIncSelLineAmountBC = <M-73 RoundAmount
(input tDIncSelLine.tdIncSelLineAmountTC * vdDInvoiceRateInCurrentCny * vdDInvoiceRateScaleInCurrentCny / (tDIncSelLine.tdBankRate * tDIncSelLine.tdBankRateScale) (idUnroundedAmount),
input 0 (iiCurrencyID),
input icCurrency (icCurrencyCode)) in BApplicationProperty>.
/* process any stage records */
<Q-5 run DDocInvoiceXrefStageByID (all) (Read) (NoCache)
(input tqDDocumentXrefByDPaySelID.tiDDocumentInvoiceXref_ID, (DDocumentInvoiceXrefId)
input ?, (DDocInvoiceXrefStageId)
output dataset tqDDocInvoiceXrefStageByID) in BDDocument>
for each tqDDocInvoiceXrefStageByID
by tqDDocInvoiceXrefStageByID.tiDDocumentInvoiceXref_ID:
<Q-84 run DInvoiceStageByID (first) (Read) (NoCache)
(input tqDDocInvoiceXrefStageByID.tiDInvoiceStage_ID, (DInvoiceStageID)
output dataset tqDInvoiceStageByID) in BDInvoice>
find first tqDinvoiceStageByID no-error.
if available tqDinvoiceStageByID
then do:
create tDIncSelLineStage.
/* On UI */
assign tDIncSelLineStage.tc_ParentRowid = tDIncSelLine.tc_Rowid
tDIncSelLineStage.tlIsSelected = yes
tDIncSelLineStage.tdStageAllocAmountTC = tqDDocInvoiceXrefStageByID.tdDDocInvoiceXrefStageAlloTC
tDIncSelLineStage.tdStagePaymentAmountTC = tqDDocInvoiceXrefStageByID.tdDDocInvoiceXrefStageAlloTC - tqDDocInvoiceXrefStageByID.tdDDocInvoiceXrefStageDiscTC
tDIncSelLineStage.tdStageDiscountAmountTC = tqDDocInvoiceXrefStageByID.tdDDocInvoiceXrefStageDiscTC
tDIncSelLineStage.tdOriginalStageAmountTC = tqDInvoiceStageByID.tdDInvoiceStageAmountTC
tDIncSelLineStage.ttStageDueDate = tqDInvoiceStageByID.ttDInvoiceStageDueDate
tDIncSelLineStage.ttStageDiscDate = tqDInvoiceStageByID.ttDInvoiceStageDiscDate
tDIncSelLineStage.tdStageDiscountPerc = tqDInvoiceStageByID.tdDInvoiceStageDiscPerc
/* Not on UI*/
tDIncSelLineStage.tiDInvoiceStageId = tqDInvoiceStageByID.tiDInvoiceStage_ID .
end. /* if available tqDinvoiceStageByID */
end. /* for each tqDDocInvoiceXrefStageByID */
end. /* for each tqDInvoiceByAllocationInfo */
end. /* for each tqDDocumentXrefByDPaySelID */
end. /* for each tDPaySel */