project QadFinancials > class BDDocument > method ValidateComponentPreInvXrefDI
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bddocument.p)
/* ====================================================================================== *
* Method : ValidateComponentPreInvoiceXrefDI *
* Description : Complete calcualted fields in DDocumentInvoiceXrefTable *
* -------------------------------------------------------------------------------------- *
* Parameters : *
* ====================================================================================== */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do on error undo, leave:
/* ====================================================================================== *
* Get company's exchange rate shared set ID *
* ====================================================================================== */
<M-75 run StartCacher
(output vhFcComponent (ohCacher),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
<M-36 run GetIntegerValueFromSession
(input viSessionID (iiSessionId),
input 'SharedSetForEXCHANGERATE':U (icDataItemName),
output viExchangeRateSharedSetId (oiValue),
output viFcReturnSuper (oiReturnStatus)) in Cacher>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign vcMessage = #T-20'System cannot get ID of the Exchange Rate Shared Set.':255(588817158)T-20#.
<M-69 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'viExchangeRateSharedSetId':U (icFieldName),
input viExchangeRateSharedSetId (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input t_sDDocumentInvoiceXref.tc_Rowid (icRowid),
input 'qadfin-866923':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
leave MAIN_BLOCK.
end.
/* ====================================================================================== *
* Get Customer invoice details *
* ====================================================================================== */
<Q-7 run DInvoiceForPayment (all) (Read) (NoCache)
(input ?, (CompanyId)
input t_sDDocumentInvoiceXref.DInvoice_ID, (DInvoiceId)
output dataset tqDInvoiceForPayment) in BDInvoice >
find tqDInvoiceForPayment where
tqDInvoiceForPayment.tiDInvoice_ID = t_sDDocumentInvoiceXref.DInvoice_ID
no-error.
if not available tqDInvoiceForPayment
then do:
assign vcMessage = #T-44'Cannot find the supplier invoice based on its ID &1.':255(999890415)T-44#
vcMessage = substitute(vcMessage, t_sDDocumentInvoiceXref.DInvoice_ID).
<M-91 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tDDocumentInvoiceXref.DInvoice_ID':U (icFieldName),
input t_sDDocumentInvoiceXref.DInvoice_ID (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sDDocumentInvoiceXref.tc_Rowid (icRowid),
input 'qadfin-749047':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* ====================================================================================== *
* If exchange rates are alreday assigned, skip this assignment *
* ====================================================================================== */
if t_sDDocumentInvoiceXref.tdLCExchangeRate = 0 or
t_sDDocumentInvoiceXref.tdLCExchangeRate = ? or
t_sDDocumentInvoiceXref.tdLCExchangeRateScale = 0 or
t_sDDocumentInvoiceXref.tdLCExchangeRateScale = ? or
t_sDDocumentInvoiceXref.tdCCExchangeRate = 0 or
t_sDDocumentInvoiceXref.tdCCExchangeRate = ? or
t_sDDocumentInvoiceXref.tdCCExchangeRateScale = 0 or
t_sDDocumentInvoiceXref.tdCCExchangeRateScale = ?
then do:
/* ================================================================================================ *
* Calculate LC exchange rate which will be used for allocation posting *
* 1. If local currency of invoice entity and payment entity are the same, take it from Invoice *
* 2. In all other cases calculate exchange rate valid in the entity payment is executed *
* ================================================================================================ */
/* If transaction currency of the invoice is the same as local currency of the payment */
if tqDInvoiceForPayment.tiDInvoiceCurrency_ID = viCompanyLCId
then assign t_sDDocumentInvoiceXref.tdLCExchangeRate = 1
t_sDDocumentInvoiceXref.tdLCExchangeRateScale = 1.
/* If local currency of the invoice are the same as local currency of the payment */
else if tqDInvoiceForPayment.tiLCCurrency_ID = viCompanyLCId
then assign t_sDDocumentInvoiceXref.tdLCExchangeRate = tqDInvoiceForPayment.tdDInvoiceExchangeRate
t_sDDocumentInvoiceXref.tdLCExchangeRateScale = tqDInvoiceForPayment.tdDInvoiceRateScale.
/* If local currencies are different, take current exchange rate between TC and LC */
else do:
<M-19 run GetExchangeRate
(input ? (iiCompanyID),
input tqDInvoiceForPayment.tiDInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tqDInvoiceForPayment.ttDInvoicePostingDate (itValidityDate),
output t_sDDocumentInvoiceXref.tdLCExchangeRate (odExchangeRate),
output t_sDDocumentInvoiceXref.tdLCExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end.
/* ================================================================================================ *
* Calculate CC exchange rate which will be used for allocation posting *
* 1. If statutory currency of invoice entity and exchange rate shared set of the invoice and *
* and payment entity are the same, take it from Invoice *
* 2. In all other cases calculate exchange rate valid in the entity payment is executed *
* ================================================================================================ */
/* If transaction currency of the invoice is the same as statutory currency of the payment */
if tqDInvoiceForPayment.tiDInvoiceCurrency_ID = viCompanyCCId
then assign t_sDDocumentInvoiceXref.tdCCExchangeRate = 1
t_sDDocumentInvoiceXref.tdCCExchangeRateScale = 1.
/* If statutory currencies are different, take current exchange rate between TC and LC */
else if not vlDomainIsStatutory
then assign t_sDDocumentInvoiceXref.tdCCExchangeRate = t_sDDocumentInvoiceXref.tdLCExchangeRate
t_sDDocumentInvoiceXref.tdCCExchangeRateScale = t_sDDocumentInvoiceXref.tdLCExchangeRateScale.
/* If statutory currency of the invoice are the same as statutory currency of the payment and *
* both entities are using the same Exchange Rate Shared set, take it from the invoice */
else if tqDInvoiceForPayment.tiStatutoryCurrency_ID = viCompanyCCId and
tqDInvoiceForPayment.tiExchangeRateSharedSet_ID = viExchangeRateSharedSetId
then assign t_sDDocumentInvoiceXref.tdCCExchangeRate = tqDInvoiceForPayment.tdDInvoiceCCRate
t_sDDocumentInvoiceXref.tdCCExchangeRateScale = tqDInvoiceForPayment.tdDInvoiceCCScale.
else do:
<M-26 run GetExchangeRate
(input ? (iiCompanyID),
input tqDInvoiceForPayment.tiDInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
input tqDInvoiceForPayment.ttDInvoicePostingDate (itValidityDate),
output t_sDDocumentInvoiceXref.tdCCExchangeRate (odExchangeRate),
output t_sDDocumentInvoiceXref.tdCCExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end.
end. /* of If exchange rates are alreday assigne, skip this assignment */
end. /* MAIN_BLOCK */
/* Error handling */
assign oiReturnStatus = viLocalReturn.