project QadFinancials > class BDDocument > method AdditionalUpdatesPostingDocExchangeRate
Description
This method calcualtes exchange rate of payment
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bddocument.p)
/* ====================================================================================== *
* Method : AdditionalUpdatesPostingDocExchangeRate *
* Description : This method calculates exchange rate of Payment *
* If there is only one invoice, exchange rate is overtaken from this *
* Invoice *
* If there is multiple invoces, exchange rate is calculated as ratio *
* between sum of allocated TC and LC (same for TC-SC) *
* Precondition : Same segmeng as AdditionalUpdatesPosting *
* -------------------------------------------------------------------------------------- *
* Parameters : *
* ====================================================================================== */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do on error undo, return:
/* Pre-validation block */
if not available tDDocument
then do:
assign vcMessage = #T-86'There is missing tDDocument record.':255(805595960)T-86#
viLocalReturn = -1.
<M-13 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-648974':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
leave MAIN_BLOCK.
end.
/* If there is only one invoice, take exchange rate from it */
find tDDocumentInvoiceXref where
tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid and
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC <> 0 and
(tDDocumentInvoiceXref.tc_Status <> "D":U or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INIT} or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-BOUNCED} or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-VOID})
no-error.
if available tDDocumentInvoiceXref
then do:
assign vdAllocTC = - tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
vdAllocDiscountTC = (if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
then tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC
else - tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC)
vdPaymentTC = vdAllocTC - vdAllocDiscountTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC
vdPaymentCC = <M-62 RoundAmount
(input (vdAllocTC - vdAllocDiscountTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC) * tDDocumentInvoiceXref.tdCCExchangeRate * tDDocumentInvoiceXref.tdCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BDDocument>
vdPaymentLC = <M-10 RoundAmount
(input (vdAllocTC - vdAllocDiscountTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC) * tDDocumentInvoiceXref.tdLCExchangeRate * tDDocumentInvoiceXref.tdLCExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BDDocument>
tDDocument.DDocumentExchangeRate = tDDocumentInvoiceXref.tdLCExchangeRate
tDDocument.DDocumentRateScale = tDDocumentInvoiceXref.tdLCExchangeRateScale
tDDocument.DDocumentCCRate = tDDocumentInvoiceXref.tdCCExchangeRate
tDDocument.DDocumentCCScale = tDDocumentInvoiceXref.tdCCExchangeRateScale
tDDocument.DDocumentOriginalDebitTC = vdPaymentTC
tDDocument.DDocumentOriginalDebitCC = vdPaymentCC
tDDocument.DDocumentOriginalDebitLC = vdPaymentLC
tDDocument.DDocumentOriginalCreditTC = 0
tDDocument.DDocumentOriginalCreditCC = 0
tDDocument.DDocumentOriginalCreditLC = 0
tDDocument.tc_Status = (if tDDocument.tc_Status = "":U then "C":U else tDDocument.tc_Status).
create tDivisionDDoc.
assign tDivisionDDoc.tcDivisionCode = tDDocumentInvoiceXref.tcDivisionCode
tDivisionDDoc.tdAmountTC = tDDocument.DDocumentOriginalDebitTC
tDivisionDDoc.tdAmountCC = tDDocument.DDocumentOriginalDebitCC
tDivisionDDoc.tdAmountLC = tDDocument.DDocumentOriginalDebitLC
tDivisionDDoc.tlIsOnlyOneInvoice = true
tDivisionDDoc.tdLCExchangeRate = tDDocumentInvoiceXref.tdLCExchangeRate
tDivisionDDoc.tdLCExchangeRateScale = tDDocumentInvoiceXref.tdLCExchangeRateScale
tDivisionDDoc.tdCCExchangeRate = tDDocumentInvoiceXref.tdCCExchangeRate
tDivisionDDoc.tdCCExchangeRateScale = tDDocumentInvoiceXref.tdCCExchangeRateScale.
end. /* if available tDDocumentInvoiceXref */
/* If there is multiple allocations or exchange rate has not been retrieved, then calculated it from *
total allocated amount TC->LC, TC->CC */
else do:
assign vdDocumentTC = 0
vdDocumentCC = 0
vdDocumentLC = 0.
for each tDDocumentInvoiceXref where
tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid and
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC <> 0 and
(tDDocumentInvoiceXref.tc_Status <> "D":U or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INIT} or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-BOUNCED} or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-VOID}):
assign vdAllocTC = - tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
vdAllocDiscountTC = (if tDDocumentInvoiceXref.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
then tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC
else - tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC)
vdPaymentTC = vdAllocTC - vdAllocDiscountTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC
vdPaymentCC = <M-53 RoundAmount
(input (vdAllocTC - vdAllocDiscountTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC) * tDDocumentInvoiceXref.tdCCExchangeRate * tDDocumentInvoiceXref.tdCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BDDocument>
vdPaymentLC = <M-74 RoundAmount
(input (vdAllocTC - vdAllocDiscountTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC) * tDDocumentInvoiceXref.tdLCExchangeRate * tDDocumentInvoiceXref.tdLCExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BDDocument>
vdDocumentTC = vdDocumentTC + vdPaymentTC
vdDocumentCC = vdDocumentCC + vdPaymentCC
vdDocumentLC = vdDocumentLC + vdPaymentLC.
/* Store payment amount by division */
find tDivisionDDoc where
tDivisionDDoc.tcDivisionCode = tDDocumentInvoiceXref.tcDivisionCode
no-error.
if not available tDivisionDDoc
then do:
create tDivisionDDoc.
assign tDivisionDDoc.tcDivisionCode = tDDocumentInvoiceXref.tcDivisionCode
tDivisionDDoc.tdAmountTC = 0
tDivisionDDoc.tdAmountCC = 0
tDivisionDDoc.tdAmountLC = 0
tDivisionDDoc.tlIsOnlyOneInvoice = true
tDivisionDDoc.tdLCExchangeRate = 0
tDivisionDDoc.tdLCExchangeRateScale = 0
tDivisionDDoc.tdCCExchangeRate = 0
tDivisionDDoc.tdCCExchangeRateScale = 0.
end.
else assign tDivisionDDoc.tlIsOnlyOneInvoice = false.
assign tDivisionDDoc.tdAmountTC = tDivisionDDoc.tdAmountTC + vdPaymentTC
tDivisionDDoc.tdAmountCC = tDivisionDDoc.tdAmountCC + vdPaymentCC
tDivisionDDoc.tdAmountLC = tDivisionDDoc.tdAmountLC + vdPaymentLC
tDivisionDDoc.tdLCExchangeRate = tDDocumentInvoiceXref.tdLCExchangeRate
tDivisionDDoc.tdLCExchangeRateScale = tDDocumentInvoiceXref.tdLCExchangeRateScale
tDivisionDDoc.tdCCExchangeRate = tDDocumentInvoiceXref.tdCCExchangeRate
tDivisionDDoc.tdCCExchangeRateScale = tDDocumentInvoiceXref.tdCCExchangeRateScale.
end. /* of for each tDDocumentInvoiceXref where */
assign tDDocument.DDocumentOriginalDebitTC = vdDocumentTC
tDDocument.DDocumentOriginalDebitCC = vdDocumentCC
tDDocument.DDocumentOriginalDebitLC = vdDocumentLC
tDDocument.DDocumentOriginalCreditTC = 0
tDDocument.DDocumentOriginalCreditCC = 0
tDDocument.DDocumentOriginalCreditLC = 0
tDDocument.DDocumentExchangeRate = vdDocumentLC / vdDocumentTC
tDDocument.DDocumentRateScale = 1
tDDocument.DDocumentCCRate = vdDocumentCC / vdDocumentTC
tDDocument.DDocumentCCScale = 1
tDDocument.tc_Status = (if tDDocument.tc_Status = "":U then "C":U else tDDocument.tc_Status).
/* Calculate exchange rates of the invoices by division if there were more invoices *
* for same division, otherwise keep the exchange rate of the invoice */
for each tDivisionDDoc where
tDivisionDDoc.tlIsOnlyOneInvoice = false:
assign tDivisionDDoc.tdLCExchangeRate = tDivisionDDoc.tdAmountLC / tDivisionDDoc.tdAmountTC
tDivisionDDoc.tdLCExchangeRateScale = 1
tDivisionDDoc.tdCCExchangeRate = tDivisionDDoc.tdAmountCC / tDivisionDDoc.tdAmountTC
tDivisionDDoc.tdCCExchangeRateScale = 1.
end.
end. /* else do: */
/* ======================================================================================================== *
* During AdditionalUpdates payment amount is recalcualted based on the real allocations. Therefore check *
* again, whether payment amount is NOT negative *
* ======================================================================================================== */
if tDDocument.DDocumentOriginalDebitTC < 0
then do:
assign vcMessage = #T-70'Total payment amount (allocated amount) cannot be negative (&1/&2/&3 - &4)':255(631795290)T-70#
vcMessage = substitute(vcMessage, tDDocument.DDocumentYear, tDDocument.DDocumentType, tDDocument.DDocumentNumber, tDDocument.DDocumentReference).
<M-87 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'DDocument.DDocumentOriginalDebitTC':U (icFieldName),
input string(tDDocument.DDocumentOriginalDebitTC) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tDDocument.tc_Rowid (icRowid),
input 'qadfin-468033':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
end. /* MAIN_BLOCK */
assign oiReturnStatus = viLocalReturn.