Description
Assign the Statutory Currency Amounts based on the amounts in TC and the exchange Rate between TC and the newly entered SC.
Split into detail method, because main method would get to big.
Parameters
ocErrorMessage | output | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/tsetstatutorycurrency.p)
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
STATCURRDETBLOCK:
do on error undo, return:
/* CDocument */
for each Company of Domains,
each CDocument of Company exclusive-lock Transaction:
assign CDocument.CDocumentOriginalDebitCC = 0
CDocument.CDocumentOriginalCreditCC = 0
CDocument.CDocumentCCRate = 0
CDocument.CDocumentCCScale = 0.
for each CDocumentInvoiceXRef where
CDocumentInvoiceXRef.CDocument_ID = CDocument.CDocument_ID
exclusive-lock :
/* CInvoice */
for each CInvoice where
CInvoice.CInvoice_ID = CDocumentInvoiceXRef.CInvoice_ID
no-lock:
/* Calculate the Amount of the document based on the allocated amount in the XRef table */
assign vdAmountCC = (absolute(CDocumentInvoiceXRef.CDocumentInvoiceXRefAlloTC) - absolute(CDocumentInvoiceXRef.CDocumentInvoiceXRefDiscTC)) * CInvoice.CInvoiceCCRate * CInvoice.CInvoiceCCScale
vdAmountCC = <M-26 RoundSCAmount (input vdAmountCC (idUnroundedAmount)) in TSetStatutoryCurrency>.
/* Check if the original amount on the invoice was posted as a negative, if so change the sign of our absolute amount */
if CInvoice.CInvoiceOriginalDebitTC < 0 or CInvoice.CInvoiceOriginalCreditTC < 0
then assign vdAmountCC = vdAmountCC * -1.
if CInvoice.CInvoiceOriginalDebitTC <> 0 and CInvoice.CInvoiceOriginalDebitTC <> ?
then assign CDocument.CDocumentOriginalCreditCC = CDocument.CDocumentOriginalCreditCC - vdAmountCC.
else assign CDocument.CDocumentOriginalCreditCC = CDocument.CDocumentOriginalCreditCC + vdAmountCC.
/* Get Exchange Rates for Tax using the date of the last Posting linked to the CDoc - use creation date of CDoc when there is no Posting yet */
assign vtExchangeDate = ?.
For each CDocumentPostingLine of CDocument no-lock,
each PostingLine of CDocumentPostingLine no-lock
by PostingLine.PostingDate descending :
Assign vtExchangeDate = PostingLine.PostingDate.
Leave.
End. /* For each CDocumentPostingLine of CDocument no-lock */
if vtExchangeDate = ?
then assign vtExchangeDate = CDocument.LastModifiedDate.
<M-97 run GetExchangeRate
(input CInvoice.CInvoiceCurrency_ID (iiFromCurrencyID),
input viNewSCID (iiToCurrencyID),
input viTXExchangeRateTypeID (iiExchangeRateTypeID),
input vtExchangeDate (itDate),
input viExchangeRateSharedSetID (iiSharedSetID),
output vdRate (odExchangeRate),
output vdScale (odExchangeRateScale),
output ocErrorMessage (ocErrorMessage),
output viFcReturnSuper (oiReturnStatus)) in TSetStatutoryCurrency>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave STATCURRDETBLOCK.
/* Assign the WHT CC-field and Rate */
assign CDocumentInvoiceXref.CDocumentInvoiceXRefWHTAmtCC = <M-690 RoundSCAmount (input CDocumentInvoiceXref.CDocumentInvoiceXRefWHTAmtTC * vdRate * vdScale (idUnroundedAmount)) in TSetStatutoryCurrency>
CDocumentInvoiceXref.CDocumentInvoiceXRefWHTCCRate = vdRate
CDocumentInvoiceXref.CDocumentInvoiceXRefWHTCCScale = vdScale.
end. /* CInvoice */
/* DInvoice */
for each DInvoice where
DInvoice.DInvoice_ID = CDocumentInvoiceXRef.DInvoice_ID
no-lock:
/* Calculate the Amount of the document based on the allocated amount in the XRef table */
assign vdAmountCC = (absolute(CDocumentInvoiceXRef.CDocumentInvoiceXRefAlloTC) - absolute(CDocumentInvoiceXRef.CDocumentInvoiceXRefDiscTC)) * DInvoice.DInvoiceCCRate * DInvoice.DInvoiceCCScale
vdAmountCC = <M-27 RoundSCAmount (input vdAmountCC (idUnroundedAmount)) in TSetStatutoryCurrency>.
/* Check if the original amount on the invoice was posted as a negative, if so change the sign of our absolute amount */
if DInvoice.DInvoiceOriginalDebitTC < 0 or DInvoice.DInvoiceOriginalCreditTC < 0
then assign vdAmountCC = vdAmountCC * -1.
if DInvoice.DInvoiceOriginalDebitTC <> 0 and DInvoice.DInvoiceOriginalDebitTC <> ?
then assign CDocument.CDocumentOriginalDebitCC = CDocument.CDocumentOriginalDebitCC + vdAmountCC.
else assign CDocument.CDocumentOriginalCreditCC = CDocument.CDocumentOriginalCreditCC + vdAmountCC.
end. /* DInvoice */
end. /* CDocumentInvoiceXRef */
/* Assign Rate */
if CDocument.CDocumentOriginalCreditTC = 0
then assign CDocument.CDocumentCCRate = 0
CDocument.CDocumentCCScale = 0.
else assign CDocument.CDocumentCCRate = CDocument.CDocumentOriginalCreditCC / CDocument.CDocumentOriginalCreditTC
CDocument.CDocumentCCScale = 1.
end. /* CDocument */
/* CCollection */
for each Company of Domains,
each CCollection of Company exclusive-lock Transaction:
assign CCollection.CCollectionBalanceCC = 0
CCollection.CCollectionBalanceCreditCC = 0
CCollection.CCollectionBalanceDebitCC = 0
CCollection.CCollectionOrigCreditCC = 0
CCollection.CCollectionOrigDebitCC = 0.
for each CDocument where
CDocument.CCollection_ID = CCollection.CCollection_ID
no-lock:
assign CCollection.CCollectionOrigDebitCC = CCollection.CCollectionOrigDebitCC + CDocument.CDocumentOriginalDebitCC
CCollection.CCollectionOrigCreditCC = CCollection.CCollectionOrigCreditCC + CDocument.CDocumentOriginalCreditCC.
if CDocument.CDocumentIsOpen = true
then assign CCollection.CCollectionBalanceCC = CCollection.CCollectionBalanceCC + (CDocument.CDocumentOriginalDebitCC - CDocument.CDocumentOriginalCreditCC)
CCollection.CCollectionBalanceDebitCC = CCollection.CCollectionBalanceDebitCC + CDocument.CDocumentOriginalDebitCC
CCollection.CCollectionBalanceCreditCC = CCollection.CCollectionBalanceCreditCC + CDocument.CDocumentOriginalCreditCC.
end. /* for each CDocument where */
end. /* CCollection */
end. /* STATCURRDETBLOCK */
assign oiReturnStatus = viLocalReturnStatus.