project QadFinancials > class BBankEntry > method GetPossibleAllocationsDInvoiceCrossCy
Description
Calculate correct amount for the invoice allocation if the invoice comes from the differnet entity then entity of banking entry.
Parameters
iiCompanyID | input | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bbankentry.p)
/* ====================================================================================== *
* Method : GetPossibleAllocationsDInvoiceCrossCy *
* Description : Calculate correct amount for the invoice allocation if the invoice *
* comes from the differnet entity then entity of banking entry. *
* -------------------------------------------------------------------------------------- *
* THIS METHOD HAS TO BE IN THE SAME SEGMENT AS PARENT METHOD *
* ====================================================================================== */
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do on error undo, return:
/* ====================================================================================== *
* Precondition block *
* ====================================================================================== */
if not available tPossibleBankStateAlloc
then do:
assign vcMessage = #T-52'Missing record':255(69247)T-52#
vcContext = "available tPossibleBankStateAlloc = &1":U
vcContext = substitute(vcContext, available tPossibleBankStateAlloc).
<M-42 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-889195':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* This method can be executed only for Customer invoice */
if tPossibleBankStateAlloc.DInvoice_ID = 0 or
tPossibleBankStateAlloc.DInvoice_ID = ?
then do:
assign vcMessage = #T-43'This method can be used only for allocation of customer invoice.':255(71767716)T-43#.
<M-25 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-613540':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* ====================================================================================== *
* Get company's exchange rate shared set ID *
* ====================================================================================== */
<M-12 run StartCacher
(output vhFcComponent (ohCacher),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
<M-15 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-40'System cannot get ID of the Exchange Rate Shared Set.':255(588817158)T-40#.
<M-27 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'viExchangeRateSharedSetId':U (icFieldName),
input string(viExchangeRateSharedSetId) (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-458239':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
leave MAIN_BLOCK.
end.
/* ====================================================================================== *
* Get supplier invoice details *
* ====================================================================================== */
/* Get invoice details */
<Q-76 run DInvoiceForPayment (all) (Read) (NoCache)
(input ?, (CompanyId)
input tPossibleBankStateAlloc.DInvoice_ID, (DInvoiceId)
output dataset tqDInvoiceForPayment) in BDInvoice >
find tqDInvoiceForPayment where
tqDInvoiceForPayment.tiDInvoice_ID = tPossibleBankStateAlloc.DInvoice_ID
no-error.
if not available tqDInvoiceForPayment
then do:
assign vcMessage = #T-20'Cannot find the customer invoice based on its ID &1.':255(73172563)T-20#
vcMessage = substitute(vcMessage, tPossibleBankStateAlloc.DInvoice_ID).
<M-90 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tPossibleBankStateAlloc.DInvoice_ID':U (icFieldName),
input tPossibleBankStateAlloc.DInvoice_ID (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tPossibleBankStateAlloc.tc_Rowid (icRowid),
input 'qadfin-291124':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* ================================================================================================ *
* Calculate exchange rate only when it goes over the border of the domain. In this case following *
* situations can happend *
* - Currencies are the same/different but the system is using different exchange rate shared set *
* - Currencies are different even the same exchange rate shared set is used *
* ================================================================================================ */
if tqDInvoiceForPayment.tiLCCurrency_ID = viCompanyLCId and
tqDInvoiceForPayment.tiStatutoryCurrency_ID = viCompanyCCId and
tqDInvoiceForPayment.tiExchangeRateSharedSet_ID = viExchangeRateSharedSetId
then leave MAIN_BLOCK.
/* ================================================================================================ *
* 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 local currency of the invoice are the same as local currency of the payment and *
* transactional currencies are also the same */
if tqDInvoiceForPayment.tcCurrencyCode = tPossibleBankStateAlloc.tcCurrencyCode and
tqDInvoiceForPayment.tiLCCurrency_ID = viCompanyLCId
then assign tPossibleBankStateAlloc.tdDocExchangeRate = tqDInvoiceForPayment.tdDInvoiceExchangeRate
tPossibleBankStateAlloc.tdDocExchangeRateScale = tqDInvoiceForPayment.tdDInvoiceRateScale.
/* In all other cases calculate the exchange rate */
else do:
<M-63 run GetExchangeRate
(input iiCompanyID (iiCompanyID),
input tqDInvoiceForPayment.tiDInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tqDInvoiceForPayment.ttDInvoicePostingDate (itValidityDate),
output tPossibleBankStateAlloc.tdDocExchangeRate (odExchangeRate),
output tPossibleBankStateAlloc.tdDocExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
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 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 */
if tqDInvoiceForPayment.tcCurrencyCode = tPossibleBankStateAlloc.tcCurrencyCode and
tqDInvoiceForPayment.tiStatutoryCurrency_ID = viCompanyCCId and
tqDInvoiceForPayment.tiExchangeRateSharedSet_ID = viExchangeRateSharedSetId
then assign tPossibleBankStateAlloc.tdDocCCExchangeRate = tqDInvoiceForPayment.tdDInvoiceCCRate
tPossibleBankStateAlloc.tdDocCCExchangeRateScale = tqDInvoiceForPayment.tdDInvoiceCCScale.
/* If statutory currencies are different, take current exchange rate between TC and LC */
else do:
<M-1 run GetExchangeRate
(input iiCompanyID (iiCompanyID),
input tqDInvoiceForPayment.tiDInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
input tqDInvoiceForPayment.ttDInvoicePostingDate (itValidityDate),
output tPossibleBankStateAlloc.tdDocCCExchangeRate (odExchangeRate),
output tPossibleBankStateAlloc.tdDocCCExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave MAIN_BLOCK.
end.
end. /* MAIN_BLOCK */
/* Error handling */
assign oiReturnStatus = viLocalReturn.