project QadFinancials > class BQCrossCyPosting > method ApiProcessQCrossCyPostingCalcAmountCI
Description
Calculate LC and C 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-41 run CInvoiceByCyIDYearJrnlVchr (all) (Read) (NoCache)
(input ?, (CompanyId)
input tQCrossCyPosting.CInvoice_ID, (CInvoiceId)
input ?, (PeriodYear)
input ?, (JournalId)
input ?, (JournalCode)
input ?, (Voucher)
output dataset tqCInvoiceByCyIDYearJrnlVchr) in BCInvoice>
find tqCInvoiceByCyIDYearJrnlVchr where
tqCInvoiceByCyIDYearJrnlVchr.tiCInvoice_ID = tQCrossCyPosting.CInvoice_ID
no-error.
if not available tqCInvoiceByCyIDYearJrnlVchr
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 'CInvoice.CInvoice_ID':U (icFieldName),
input tQCrossCyPosting.CInvoice_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. /* if not available tqCInvoiceByCyIDYearJrnlVchr */
/* 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(tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitTC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditTC)).
/* In case the LC amounts are filled but the LC of the originating-transaction differs from LC of the company of the invoice then the LC amounts do not make sense and as such we will empty them so they get re-assgined again in this method */
/* In case the CC amounts are filled but the CC of the originating-transaction differs from CC of the company of the invoice then the CC amounts do not make sense and as such we will empty them so they get re-assgined again in this method */
/* We will read the LC and CC of the Originating transaction and the LC and CC of the Invoice and if they do not match or cannot be found then we will reset the amounts */
if (tQCrossCyPosting.QCrossCyPostingAmountLC <> 0 and
tQCrossCyPosting.QCrossCyPostingAmountLC <> ?) Or
(tQCrossCyPosting.QCrossCyPostingAmountCC <> 0 and
tQCrossCyPosting.QCrossCyPostingAmountCC <> ?)
then do :
<Q-50 run CompanyForCurrencyDet (all) (Read) (Cache)
(input tQCrossCyPosting.OriginatorCompany_ID, (CompanyId)
input ?, (CompanyCode)
output dataset tqCompanyForCurrencyDet) in BCompany>
Find first tqCompanyForCurrencyDet where
tqCompanyForCurrencyDet.tiCompany_ID = tQCrossCyPosting.OriginatorCompany_ID
no-lock no-error.
if available tqCompanyForCurrencyDet
then assign viOriginatingCompanyLCID = tqCompanyForCurrencyDet.tiCurrency_ID
viOriginatingCompanyCCID = tqCompanyForCurrencyDet.tiStatutoryCurrency_ID.
<Q-11 run CompanyForCurrencyDet (all) (Read) (Cache)
(input tqCInvoiceByCyIDYearJrnlVchr.tiCompany_ID, (CompanyId)
output dataset tqCompanyForCurrencyDet) in BCompany>
Find first tqCompanyForCurrencyDet where
tqCompanyForCurrencyDet.tiCompany_ID = tqCInvoiceByCyIDYearJrnlVchr.tiCompany_ID
no-lock no-error.
if available tqCompanyForCurrencyDet
then assign viInvoiceCompanyLCID = tqCompanyForCurrencyDet.tiCurrency_ID
viInvoiceCompanyCCID = tqCompanyForCurrencyDet.tiStatutoryCurrency_ID.
if (tQCrossCyPosting.QCrossCyPostingAmountLC <> 0 and
tQCrossCyPosting.QCrossCyPostingAmountLC <> ?) and
(viOriginatingCompanyLCID <> viInvoiceCompanyLCID or
viOriginatingCompanyLCID = 0 or
viOriginatingCompanyLCID = ? or
viInvoiceCompanyLCID = 0 or
viInvoiceCompanyLCID = ?)
then assign tQCrossCyPosting.QCrossCyPostingAmountLC = 0.
if (tQCrossCyPosting.QCrossCyPostingAmountCC <> 0 and
tQCrossCyPosting.QCrossCyPostingAmountCC <> ?) and
(viOriginatingCompanyCCID <> viInvoiceCompanyCCID or
viOriginatingCompanyCCID = 0 or
viOriginatingCompanyCCID = ? or
viInvoiceCompanyCCID = 0 or
viInvoiceCompanyCCID = ?)
then assign tQCrossCyPosting.QCrossCyPostingAmountCC = 0.
end. /* if tQCrossCyPosting.QCrossCyPostingAmountLC <> 0 and */
/* ==================== */
/* Code for WHT records */
/* ==================== */
if tQCrossCyPosting.QCrossCyPostingIsWHT = true
then do:
/* Get VAT rate when we are dealing with a WHT record */
if tQCrossCyPosting.Currency_ID <> viCompanyLCId
then do:
<M-38 run GetExchangeRate
(input ? (iiCompanyID),
input tQCrossCyPosting.Currency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-VAT} (icExchangeRateTypeCode),
input tQCrossCyPosting.QCrossCyPostingPaymentDate (itValidityDate),
output vdVatLCExchangeRate (odExchangeRate),
output vdVatLCRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
if viFcReturnSuper <> 0 and viLocalReturn >= 0
then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0
then leave MAIN_BLOCK.
end. /* if tQCrossCyPosting.Currency_ID <> viCompanyLCId and */
/* Calculate LC amounts */
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.
else assign odTCLCExchangeRate = vdVatLCExchangeRate
odTCLCExchangeRateScale = vdVatLCRateScale
odDebitLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then <M-77 RoundAmount
(input tQCrossCyPosting.QCrossCyPostingAmountTC * odTCLCExchangeRate * odTCLCExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BQCrossCyPosting>
else 0
odCreditLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then <M-21 RoundAmount
(input tQCrossCyPosting.QCrossCyPostingAmountTC * odTCLCExchangeRate * odTCLCExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BQCrossCyPosting>
else 0.
/* Get CC VAT rate when we are dealing with a WHT record */
if tQCrossCyPosting.Currency_ID <> viCompanyCCId and
vlDomainIsStatutory = true
then do:
<M-33 run GetExchangeRate
(input ? (iiCompanyID),
input tQCrossCyPosting.Currency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-VAT} (icExchangeRateTypeCode),
input tQCrossCyPosting.QCrossCyPostingPaymentDate (itValidityDate),
output vdVatCCExchangeRate (odExchangeRate),
output vdVatCCRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
if viFcReturnSuper <> 0 and viLocalReturn >= 0
then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0
then leave MAIN_BLOCK.
end. /* if tQCrossCyPosting.Currency_ID <> viCompanyCCId and */
/* Calculate CC amounts */
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 assign odTCCCExchangeRate = vdVatCCExchangeRate
odTCCCExchangeRateScale = vdVatCCRateScale
odDebitCC = <M-88 RoundAmount
(input odDebitTC * odTCCCExchangeRate * odTCCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BQCrossCyPosting>
odCreditCC = <M-95 RoundAmount
(input odCreditTC * odTCCCExchangeRate * odTCCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BQCrossCyPosting>.
end. /* if tQCrossCyPosting.QCrossCyPostingIsWHT = true */
/* ======================== */
/* Code for Non-WHT Records */
/* ======================== */
else do:
/* 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 = (tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitLC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditLC)
/ (tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitTC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditTC)
odTCLCExchangeRateScale = 1
odDebitLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitLC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditLC
else 0
odCreditLC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditLC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitLC
else 0.
else assign odTCLCExchangeRate = tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceExchangeRate
odTCLCExchangeRateScale = tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceRateScale
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 = (tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitCC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditCC)
/ (tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitTC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditTC)
odTCCCExchangeRateScale = 1
odDebitCC = if tQCrossCyPosting.CrossCompanyGLIsCredit = false
then tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitCC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditCC
else 0
odCreditCC = if tQCrossCyPosting.CrossCompanyGLIsCredit = true
then tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceCreditCC - tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceBalanceDebitCC
else 0.
else assign odTCCCExchangeRate = tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceCCRate
odTCCCExchangeRateScale = tqCInvoiceByCyIDYearJrnlVchr.tdCInvoiceCCScale
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
odTCCCExchangeRate = tQCrossCyPosting.QCrossCyPostingAmountCC / tQCrossCyPosting.QCrossCyPostingAmountTC
odTCCCExchangeRateScale = 1.
end. /* else do: (non-wht records) */
end. /* MAIN_BLOCK */
assign oiReturnStatus = viLocalReturn.