Description
Get the IncSelLines (&stages) for the specified paysel_id
Parameters
icCurrencyCode | input | character | |
iiDPaySelID | input | integer | |
itDPaySelDate | input | date | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bdpaymentselection.p)
assign viDIncSelLineRowid = 0.
if not can-find (first tDPaySelLine) then do:
<M-37 run GetDDocumentInfo
(input icCurrencyCode (icCurrency),
output oiReturnStatus (oiReturnStatus)) in BDPaymentSelection>
return.
end.
/* calculate BC Rate for bank currency. */
if icCurrencyCode = vcCompanyLC
then assign vdBankRate = 1
vdBankRateScale = 1.
else do:
<M-50 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input icCurrencyCode (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input itDPaySelDate (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. /* end if icCurrencyCode = vcCompanyLC */
/* create tDIncSelLine records for existing PaySelLine records */
/* for each tqDPaySelLineByDPaySel break by tqDPaySelLineByDPaySel.tiBankNumber_ID: */
for each tDPaySelLine where tDPaySelLine.DPaySel_ID = iiDPaySelID break by tDPaySelLine.BankNumber_ID:
<M-23 run DPaySelLineCalcValues
(input tDPaySelLine.DPaySelLineObjectType (icDPaySelLineObjectType),
input tDPaySelLine.DPaySelLineParentObject_ID (iiDPaySelLineParentObject_ID),
output vcBusinessRelationCode (ocBusinessRelationCode),
output vcBusinessRelationName1 (ocBusinessRelationName1),
output vcCorporateGroupCode (ocCorporateGroupCode),
output vcDebtorCode (ocDebtorCode),
output vcInternalNumber (ocInternalNumber),
output vcExternalNumber (ocExternalNumber),
output vtDiscountDueDate (otDiscountDueDate),
output vdDiscountPercentage (odDiscountPercentage),
output vtInvoiceDate (otInvoiceDate),
output vtDueDate (otDueDate),
output vcInvoiceCurrencyCode (ocInvoiceCurrencyCode),
output vdOpenInvoiceAmountTC (odOpenInvoiceAmountTC),
output vdOriginalInvoiceAmountTC (odOriginalInvoiceAmountTC),
output vdOriginalInvoiceAmountNetTC (odOriginalInvoiceAmountNetTC),
output vdInvoiceRate (odInvoiceRate),
output vdInvoiceRateScale (odInvoiceRateScale),
input itDPaySelDate (itDPaySelDate),
output vcDivisionCode (ocDivisionCode),
output viMasterID (oiMasterID),
output vdNonDiscountableAmountTC (odNonDiscountableAmountTC),
output vcPaymentConditionPaymentType (ocPaymentConditionPaymentType),
output vdDefaultPaymentAmountTC (odDefaultPaymentAmountTC),
output vdDefaultDiscountAmountTC (odDefaultDiscountAmountTC),
output vcDInvoiceDIText (ocDInvoiceDIText),
output viDInvoicePostingYear (oiDInvoicePostingYear),
output vcJournalCode (ocJournalCode),
output viDInvoiceVoucher (oiDInvoiceVoucher),
output vcShipperInfo (ocShipperInfo),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
if viFcReturnSuper < 0 or oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
return.
end.
find tDIncSelLine where
tDIncSelLine.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID and
tDIncSelLine.tiBankNumberId = tDPaySelLine.BankNumber_ID
no-error.
if available tDIncSelLine
then next.
/* Corrections always have negative amounts */
if tDPaySelLine.DPaySelLineObjectType = {&INVOICETYPE-INVOICECORRECTION} or
tDPaySelLine.DPaySelLineObjectType = {&INVOICETYPE-CREDITNOTECORRECTION}
then assign vdOriginalInvoiceAmountTC = - vdOriginalInvoiceAmountTC.
create tDIncSelLine.
assign
tDIncSelLine.tc_Status = "":U
tDIncSelLine.tc_ParentRowid = tDPaySelLine.tc_ParentRowid
tDIncSelLine.tcInvoiceType = tDPaySelLine.DPaySelLineObjectType
tDIncSelLine.tiDInvoiceId = tDPaySelLine.DPaySelLineParentObject_ID
tDIncSelLine.tcBusinessRelationCode = vcBusinessRelationCode
tDIncSelLine.tcDebtorCode = vcDebtorCode
tDIncSelLine.tcBusinessRelationName1 = vcBusinessRelationName1
tDIncSelLine.tcCorporateGroupCode = vcCorporateGroupCode
tDIncSelLine.tcIncSelLineAmountCrDt = if vdOriginalInvoiceAmountTC > 0 and
vdOriginalInvoiceAmountTC <> ?
then {&CREDITDEBITABBREVIATION-CREDIT}
else {&CREDITDEBITABBREVIATION-DEBIT}
tDIncSelLine.tcInvoiceAmountCrDt = if vdOriginalInvoiceAmountTC > 0 and
vdOriginalInvoiceAmountTC <> ?
then {&CREDITDEBITABBREVIATION-DEBIT}
else {&CREDITDEBITABBREVIATION-CREDIT}
tDIncSelLine.tcInvoiceBalanceCrDt = if vdOriginalInvoiceAmountTC > 0 and
vdOriginalInvoiceAmountTC <> ?
then {&CREDITDEBITABBREVIATION-DEBIT}
else {&CREDITDEBITABBREVIATION-CREDIT}
tDIncSelLine.tcInvoiceNumber = vcInternalNumber
tDIncSelLine.ttDiscountDueDate = vtDiscountDueDate
tDIncSelLine.tdDiscountPercentage = vdDiscountPercentage
tDIncSelLine.tcPaymentConditionPayType = vcPaymentConditionPaymentType
tDIncSelLine.ttInvoiceDate = vtInvoiceDate
tDIncSelLine.ttDueDate = vtDueDate
tDIncSelLine.tcInvoiceCurrencyCode = vcInvoiceCurrencyCode
tDIncSelLine.tdInvoiceRate = vdInvoiceRate
tDIncSelLine.tdInvoiceRateScale = vdInvoiceRateScale
tDIncSelLine.tdInvoiceAmount = abs(vdOriginalInvoiceAmountTC)
tDIncSelLine.tdInvoiceBalance = abs(vdOpenInvoiceAmountTC)
tDIncSelLine.tdIncSelLineAmountTC = tDPaySelLine.DPaySelLineAmountTC
tDIncSelLine.tdIncSelLineDiscountTC = tDPaySelLine.DPaySelLineDiscountTC
tDIncSelLine.tdDefaultPaymentAmountTC = vdDefaultPaymentAmountTC
tDIncSelLine.tdDefaultDiscountAmountTC = vdDefaultDiscountAmountTC
tDIncSelLine.tdNonDiscAmtTC = vdNonDiscountableAmountTC
tDIncSelLine.tlIsSelected = true
viDIncSelLineRowid = viDIncSelLineRowid + 1
tDIncSelLine.tc_Rowid = tDPaySelLine.tc_Rowid /* string(viDIncSelLineRowid) */
tDIncSelLine.tiBankNumberId = tDPaySelLine.BankNumber_ID
tDIncSelLine.tcIncSelLineStatus = tDPaySelLine.DPaySelLineStatus
tDIncSelLine.tcPaymentConditionPayType = vcPaymentConditionPaymentType
tDIncSelLine.tcIncSelLineStatusTR = <M-38 GetLineStatusTranslation (input tDIncSelLine.tcIncSelLineStatus (icLineStatus)) in BDPaymentSelection>
tDIncSelLine.tdIncSelLineIntRate = tDPaySelLine.DPaySelLineIntRate
tDIncSelLine.ttDefaultDueDate = tDIncSelLine.ttDueDate
tDIncSelLine.tdDefaultIncSelLineIntRate = tDIncSelLine.tdIncSelLineIntRate
tDIncSelLine.tcDefaultIncLineStatus = tDIncSelLine.tcIncSelLineStatus
tDIncSelLine.tcDInvoiceDIText = vcDInvoiceDIText
tDIncSelLine.tiDInvoicePostingYear = viDInvoicePostingYear
tDIncSelLine.tcJournalCode = vcJournalCode
tDIncSelLine.tiDInvoiceVoucher = viDInvoiceVoucher
tDIncSelLine.tcShipperInfo = vcShipperInfo
tDIncSelLine.tdBankRate = vdBankRate
tDIncSelLine.tdBankRateScale = vdBankRateScale.
if tDPaySelLine.DPaySelLineObjectType = {&INVOICETYPE-INVOICECORRECTION} or
tDPaySelLine.DPaySelLineObjectType = {&INVOICETYPE-CREDITNOTECORRECTION}
then
do:
assign tDIncSelLine.tdInvoiceAmount = - tDIncSelLine.tdInvoiceAmount
tDIncSelLine.tdInvoiceBalance = - tDIncSelLine.tdInvoiceBalance.
end.
<Q-84 run DInvoiceByIds (all) (Read) (NoCache)
(input ?, (CompanyId)
input string(tDIncSelLine.tiDInvoiceId), (DInvoice_ID)
output dataset tqDInvoiceByIds) in BDInvoice>
find first tqDInvoiceByIds where
tqDInvoiceByIds.tiDInvoice_ID = tDIncSelLine.tiDInvoiceId
no-error .
if available tqDInvoiceByIds
then assign tDIncSelLine.tcCompanyCode = tqDInvoiceByIds.tcCompanyCode .
/* process any stage records */
<Q-79 run DPaySelLineStageByDPaySelLine (all) (Read) (NoCache)
(input tDPaySelLine.DPaySelLine_ID, (DPaySelLineID)
output dataset tqDPaySelLineStageByDPaySelLine) in BDPaymentSelection>
for each tqDPaySelLineStageByDPaySelLine
by tqDPaySelLineStageByDPaySelLine.tiDPaySelLine_ID:
create tDIncSelLineStage.
assign tDIncSelLineStage.tc_ParentRowid = tDIncSelLine.tc_Rowid
tDIncSelLineStage.tdOpenStageAmountTC = tqDPaySelLineStageByDPaySelLine.tdDInvoiceStageAmountTC
tDIncSelLineStage.tdOriginalStageAmountTC = tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgOrigAmtTC
tDIncSelLineStage.tdStageAllocAmountTC = tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgPaymAmtTC + tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgDiscAmtTC
tDIncSelLineStage.tdStageDiscountAmountTC = tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgDiscAmtTC
tDIncSelLineStage.tdStagePaymentAmountTC = tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgPaymAmtTC
tDIncSelLineStage.tiDInvoiceStageId = tqDPaySelLineStageByDPaySelLine.tiDInvoiceStage_ID
tDIncSelLineStage.tdStageDiscountPerc = tqDPaySelLineStageByDPaySelLine.tdDInvoiceStageDiscPerc
tDIncSelLineStage.ttStageDiscDate = tqDPaySelLineStageByDPaySelLine.ttDInvoiceStageDiscDate
tDIncSelLineStage.tcIncSelLineStageStatus = tqDPaySelLineStageByDPaySelLine.tcDPaySelLineStgStatus
tDIncSelLineStage.tcIncSelLineStageStatusTR = <M-32 GetLineStatusTranslation (input tDIncSelLineStage.tcIncSelLineStageStatus (icLineStatus)) in BDPaymentSelection>
tDIncSelLineStage.tdIncSelLineStageIntRate = tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgIntRate
tDIncSelLineStage.ttStageDueDate = tqDPaySelLineStageByDPaySelLine.ttDInvoiceStageDueDate
tDIncSelLineStage.tdDefaultIncSelLineStageIntRat = tDIncSelLineStage.tdIncSelLineStageIntRate
tDIncSelLineStage.ttDefaultIncSelLineStageDueDat = tDIncSelLineStage.ttStageDueDate
tDIncSelLineStage.tcDefaultIncSelLineStageStatus = tDIncSelLineStage.tcIncSelLineStageStatus.
/* Calculate discount amount */
if itDPaySelDate <= tDIncSelLineStage.ttStageDiscDate
then assign
tDIncSelLineStage.tdDefaultStageDiscountAmountTC = (tDIncSelLineStage.tdOpenStageAmountTC -
(vdNonDiscountableAmountTC * tDIncSelLineStage.tdStageDiscountPerc / 100)) *
(tDIncSelLineStage.tdStageDiscountPerc / 100)
tDIncSelLineStage.tdDefaultStageDiscountAmountTC = <M-39 RoundAmount
(input tDIncSelLineStage.tdDefaultStageDiscountAmountTC (idUnroundedAmount),
input ? (iiCurrencyID),
input vcInvoiceCurrencyCode (icCurrencyCode)) in BDPaymentSelection>
tDIncSelLineStage.tdDefaultStagePaymentAmountTC = tDIncSelLineStage.tdOpenStageAmountTC - tDIncSelLineStage.tdDefaultStageDiscountAmountTC.
else assign
tDIncSelLineStage.tdDefaultStageDiscountAmountTC = 0
tDIncSelLineStage.tdDefaultStagePaymentAmountTC = tDIncSelLineStage.tdOpenStageAmountTC.
assign vdDefaultPaymentAmountTC = vdDefaultPaymentAmountTC + tDIncSelLineStage.tdDefaultStagePaymentAmountTC
vdDefaultDiscountAmountTC = vdDefaultDiscountAmountTC + tDIncSelLineStage.tdDefaultStageDiscountAmountTC.
end.
assign tDIncSelLine.tdDefaultPaymentAmountTC = vdDefaultPaymentAmountTC
tDIncSelLine.tdDefaultDiscountAmountTC = vdDefaultDiscountAmountTC.
if tDPaySelLine.BankNumber_ID <> ? and tDPaySelLine.BankNumber_ID <> 0
then do:
if first-of(tDPaySelLine.BankNumber_ID)
then do:
<Q-93 run BankNumberByID (all) (Read) (Cache)
(input tDPaySelLine.BankNumber_ID, (BankNumber_ID)
input ?, (CompanyId)
output dataset tqBankNumberByID) in BBankNumber>
find first tqBankNumberByID no-error.
if available tqBankNumberByID
then assign tDIncSelLine.tcBankAccountNumber = if tqBankNumberByID.tcBankNumberFormatted <> "":U and tqBankNumberByID.tcBankNumberFormatted <> ? then tqBankNumberByID.tcBankNumberFormatted else tqBankNumberByID.tcBankNumber.
end.
else assign tDIncSelLine.tcBankAccountNumber = vcBankAccountNumber.
end.
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-98 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-88 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-60 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input tDIncSelLine.tcInvoiceCurrencyCode (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input itDPaySelDate (itValidityDate),
output vdDInvoiceRateInCurrentCny (odExchangeRate),
output vdDInvoiceRateScaleInCurrentCny (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
if viFcReturnSuper < 0 then return.
end. /* End if viBaseCurrInInvoice <> viCompanyLCId or vcExchangeRateSS <> vcExchangeRateSSInInvoice */
else if icCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode
then assign tDIncSelLine.tdBankRate = tDIncSelLine.tdInvoiceRate
tDIncSelLine.tdBankRateScale = tDIncSelLine.tdInvoiceRateScale.
end. /* End Cross company */
else if icCurrencyCode = tDIncSelLine.tcInvoiceCurrencyCode
then assign tDIncSelLine.tdBankRate = tDIncSelLine.tdInvoiceRate
tDIncSelLine.tdBankRateScale = tDIncSelLine.tdInvoiceRateScale.
assign tDIncSelLine.tdIncSelLineAmountBC = <M-20 RoundAmount
(input tDIncSelLine.tdIncSelLineAmountTC * vdDInvoiceRateInCurrentCny * vdDInvoiceRateScaleInCurrentCny / (tDIncSelLine.tdBankRate * tDIncSelLine.tdBankRateScale) (idUnroundedAmount),
input '':U (iiCurrencyID),
input icCurrencyCode (icCurrencyCode)) in BApplicationProperty>.
end.