project QadFinancials > class BQCrossCyPosting > method ApiProcessQCrossCyPostingCalcAmountDI
Description
Calculate LC and CC amounts based on TC
Parameters
odDebitLC | output | decimal | |
odCreditLC | output | decimal | |
odDebitCC | output | decimal | |
odCreditCC | output | decimal | |
odDebitTC | output | decimal | |
odCreditTC | output | decimal | |
odTCLCExchangeRate | output | decimal | |
odTCLCExchangeRateScale | output | decimal | |
odTCCCExchangeRate | output | decimal | |
odTCCCExchangeRateScale | output | decimal | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bqcrosscyposting.p)
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do:
/* Precondition */
if not available tQCrossCyPosting
then do:
assign vcMessage = #T-98'Missing record.':255(70965)T-98#.
<M-1 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-9796':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* Get the invoice details */
<Q-20 run DInvoiceByDebtStatusCurr (all) (Read) (NoCache)
(input ?, (CompanyId)
input tQCrossCyPosting.DInvoice_ID, (DInvoiceId)
input ?, (DebtorId)
input ?, (SkipRowId)
input ?, (DebtorCode)
input ?, (CurrencyCode)
input ?, (DInvoiceIsOpen)
input ?, (DInvoiceType)
input ?, (CurrencyId)
input ?, (DInvoiceIsSelected)
input ?, (DInvoiceBalanceDebitTC)
output dataset tqDInvoiceByDebtStatusCurr) in BDInvoice >
find tqDInvoiceByDebtStatusCurr where
tqDInvoiceByDebtStatusCurr.tiDInvoice_ID = tQCrossCyPosting.DInvoice_ID
no-error.
if not available tqDInvoiceByDebtStatusCurr
then do:
assign vcMessage = #T-72'Cannot read Supplier Invoice definition.':255(317435161)T-72#.
<M-2 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'DInvoice.DInvoice_ID':U (icFieldName),
input tQCrossCyPosting.DInvoice_ID (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9797':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* Assign TC amounts */
assign odDebitTC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tQCrossCyPosting.QCrossCyPostingAmountTC
else 0
odCreditTC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tQCrossCyPosting.QCrossCyPostingAmountTC
else 0.
/* Check, if this is the last payment of the invoice */
assign vlIsLastPayment = (abs(tQCrossCyPosting.QCrossCyPostingAmountTC) = abs(tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitTC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditTC)).
/* Calculate LC amounts */
if tQCrossCyPosting.QCrossCyPostingAmountLC = 0 or
tQCrossCyPosting.QCrossCyPostingAmountLC = ?
then do:
if tQCrossCyPosting.Currency_ID = viCompanyLCId
then assign odDebitLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tQCrossCyPosting.QCrossCyPostingAmountTC
else 0
odCreditLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tQCrossCyPosting.QCrossCyPostingAmountTC
else 0
odTCLCExchangeRate = 1
odTCLCExchangeRateScale = 1.
/* Is this is the last movement of invoice */
else if vlIsLastPayment
then assign odTCLCExchangeRate = (tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitLC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditLC)
/ (tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitTC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditTC)
odTCLCExchangeRateScale = 1
odDebitLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitLC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditLC
else 0
odCreditLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditLC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitLC
else 0.
else assign odTCLCExchangeRate = tqDInvoiceByDebtStatusCurr.tdDInvoiceExchangeRate
odTCLCExchangeRateScale = tqDInvoiceByDebtStatusCurr.tdDInvoiceRateScale
odDebitLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then <M-3 RoundAmount
(input tQCrossCyPosting.QCrossCyPostingAmountTC * odTCLCExchangeRate * odTCLCExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BQCrossCyPosting>
else 0
odCreditLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then <M-4 RoundAmount
(input tQCrossCyPosting.QCrossCyPostingAmountTC * odTCLCExchangeRate * odTCLCExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BQCrossCyPosting>
else 0.
end. /* if tQCrossCyPosting.QCrossCyPostingAmountLC = 0 or */
else assign odDebitLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tQCrossCyPosting.QCrossCyPostingAmountLC
else 0
odCreditLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tQCrossCyPosting.QCrossCyPostingAmountLC
else 0
odTCLCExchangeRate = tQCrossCyPosting.QCrossCyPostingAmountLC / tQCrossCyPosting.QCrossCyPostingAmountTC
odTCLCExchangeRateScale = 1.
/* Calculate CC amounts */
if tQCrossCyPosting.QCrossCyPostingAmountCC = 0 or
tQCrossCyPosting.QCrossCyPostingAmountCC = ?
then do:
if vlDomainIsStatutory = false
then assign odDebitCC = odDebitLC
odCreditCC = odCreditLC.
else if tQCrossCyPosting.Currency_ID = viCompanyCCId
then assign odDebitCC = odDebitTC
odCreditCC = odCreditTC
odTCCCExchangeRate = 1
odTCCCExchangeRateScale = 1.
else if vlIsLastPayment
then assign odTCCCExchangeRate = (tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitCC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditCC)
/ (tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitTC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditTC)
odTCCCExchangeRateScale = 1
odDebitCC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitCC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditCC
else 0
odCreditCC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceCreditCC - tqDInvoiceByDebtStatusCurr.tdDInvoiceBalanceDebitCC
else 0.
else assign odTCCCExchangeRate = tqDInvoiceByDebtStatusCurr.tdDInvoiceCCRate
odTCCCExchangeRateScale = tqDInvoiceByDebtStatusCurr.tdDInvoiceCCScale
odDebitCC = <M-5 RoundAmount
(input odDebitTC * odTCCCExchangeRate * odTCCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BQCrossCyPosting>
odCreditCC = <M-6 RoundAmount
(input odCreditTC * odTCCCExchangeRate * odTCCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BQCrossCyPosting>.
end. /* if tQCrossCyPosting.QCrossCyPostingAmountCC = 0 or */
else assign odDebitCC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tQCrossCyPosting.QCrossCyPostingAmountCC
else 0
odCreditCC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tQCrossCyPosting.QCrossCyPostingAmountCC
else 0.
end. /* MAIN_BLOCK */
assign oiReturnStatus = viLocalReturn.