Dear sirs, I've an invoice report that shows the invoice amount and calculates the VAT over it. We work in EUR. We also want that when the currency is USD calculates the VAT with the change of the day that we register the invoice or the most approximate. The code is this:
CustAmount:="Sales Invoice Line".Amount;
IF ("Sales Invoice Header"."Currency Code" = '') THEN
AmountLCY:=CustAmount
ELSE
AmountLCY:=CurrExchRate.ExchangeAmtFCYToLCY(
WORKDATE,"Sales Invoice Header"."Currency Code",CustAmount,"Sales Invoice Header"."Currency Factor");
ProfitLCY := AmountLCY - CostLCY;
IF AmountLCY <> 0 THEN
ProfitPct := ROUND(100 * ProfitLCY / AmountLCY,0.1);
CustAmonut, AmountLCY, ProfitPct are decimal variables
It works perfectly, but we noticed that takes the exchange of the present day, not when we registered the invoice, then, of course, the amount changes every time that we print the invoice. What I have to change in this code to get the exchange of the day that we registered the invoice?.
Thanks and regards.
Comments
Thanks.
It is not the right solution to take exchange rate. On creating invoices the user is able to change the exchange rate (for many good reasons), so in posted invoices, the currency rate will be different.
By luck, the Currency factor is in the Header ("Sales Invoice Header"."Currency Factor").
Other problem, this Currency Factor is 0 if the Currency Code is empty (if in your example, the invoice is in EUR). But this point is very easy to solve.
But oh my foes and oh my friends, it gives a lovely light
Thanks again for help.