Topic: Add Currency Symbol at Invoice Top

How do I add currency symbol at Invoice top Total --> Total in USD or Total in HKD

I have browse thru the header.inc and rep107

Re: Add Currency Symbol at Invoice Top

Hi there,

I have similar requests from users.  When Invoice is not in home currency (SGD), we need to show extra info to convert the GST and Total amount in home currency.  Below is an example:

The invoice amount is in USD  (the home currency is SGD:)
======================================
Sub-total:    6,500.00
Shipping:             0.00
GST TAX (7%):         455.00
TOTAL INVOICE: 6,955.00

Additional Lines to be shown on the invoice if it is not in home currency. “//” denotes comment:
============================================================
Home Currency: SGD
Exch Rate: 1.22
GST TAX:  555.10       //This is GST in SGD (455 * 1.22)
Total Invoice: 8485.10     // This is Total invoice (6955 * 1.22)

---------
I managed to get the additional lines printed on the invoice.  However, I couldn’t extract the correct exchange rate (the exchange rate kept showing “1”) therefore the results of the calculations are wrong..  I have added the following lines to rep107.php.    I use the function “function get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_)” in banking.inc.   I spent many hours trying to figure out the issue of the exchange rate but I failed to get the correct rate. 

I have 2 issues:

1.     Is the “$date_” in this function (“function get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_)” ) used for selecting the exchange rate?   How do I make sure that the exchange rate selected is the same as the invoice used to update the GL? What if the date does not match the date in the exchange rate table, would it simply uses “1” or it will use the rate in the earlier date?

2.    I would appreciate it if someone could help me  in correcting the codes below which I modified in rep107.php:

        $rep->Font(+1);     // increate the font size
                 $rep->TextCol(0, 5, _("Home Currency:"), -2);     // Line 1 text
        $from_curr_code = get_company_currency();   // From currency USD
        $to_curr_code = $myrow['curr_code'];         //To currency SGD
        $rep->TextCol(1, 4, $from_curr_code, -2);   // Line 1 next to “Home Currecny”: Foreign currency
        $rep->NewLine(1);
        $date_ = $myrow['document_date'];    // Not sure if this is correct??? When tested, it shows nothing.
        $exchrate = number_format2(get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_),$dec);  // this is the function from banking.inc
        $rep->TextCol(0, 6, _("Exch Rate: "), -2);  // Line 2 text
        $rep->TextCol(1, 4, $exchrate, -50); // Line 2, next to “Exch Rate”
        $rep->NewLine(1);
        $rep->TextCol(0, 6, _("GST: "), -2); //Line 3 text
        $DisplayTax1 = number_format2(($DisplayTax * $exchrate),$dec);
        $rep->TextCol(1, 4, $DisplayTax1, -50); //GST amount in home currency (SGD)
        $rep->NewLine(1);
        $rep->TextCol(0, 2, _("Total Invoice: "), -2);  //Line 4 text
        $DisplayTotal1 = number_format2(($sign*($myrow["ov_freight"] + $myrow["ov_gst"] +
        $myrow["ov_amount"]+$myrow["ov_freight_tax"])*$exchrate),$dec);
        $rep->TextCol(1, 4, $DisplayTotal1, -70);


Thanks!

Re: Add Currency Symbol at Invoice Top

If SGD is the home currency, get the exchange rate of the alternate currency say USD here. The exchange rate of the home currency will always be "1". The Supplier / Customer Currency needs to be used for the Supplier / Customer Invoice respectively.

4 (edited by mark0300 04/14/2015 02:18:16 am)

Re: Add Currency Symbol at Invoice Top

Thanks for your reply...

Sorry for dumping a long message in my last post.  What I would like to achieve is to use the function below ((get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_),)  to get the exchange rate based on the Invoice date. The date is the key item to get the correct exch rate.

      $exchrate = number_format2(get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_),$dec);  // this is the function from banking.inc

I am able to get the from (USD) and to  (SGD) curr codes, but I couldn't get the date to apply to the function "get_exchange_rate_from_to($from_curr_code, $to_curr_code, $date_)".   I keep getting "1.0000" in return.

Or is there other functions I could use to achieve the same results?

Thanks again.

Re: Add Currency Symbol at Invoice Top

The function get_exchange_rate_from_to() calls the following functions in the same file includes/banking.inc:
1. get_exchange_rate_to_home_currency($from_curr_code, $date_)
2. get_exchange_rate_from_home_currency($currency_code, $date_)
The first one is the arithmetic inverse of the second one.

All currency exchange rates in FA are relative to the home currency.

The sql used in the second function (lines 91, 92)  is:

SELECT rate_buy, max(date_) as date_ FROM ".TB_PREF."exchange_rates WHERE curr_code = ".db_escape($currency_code)."
                AND date_ <= '$date' GROUP BY rate_buy ORDER BY date_ Desc LIMIT 1

The date_ <= $date is key to the record being pulled out.
Should it not be for all future transactions by making it date_ >= $date ?

After all, when we get an exchange rate from a provider (YAHOO, ECB, BLOOMBERG, GOOGLE, etc) it should be for all future transactions till the next one is obtained and not for all past transactions.

@joe: your take?

Re: Add Currency Symbol at Invoice Top

No, the implementation is correct. Has been so since about 2005.

/Joe

Re: Add Currency Symbol at Invoice Top

Thanks for the policy decision - any rationale?

Re: Add Currency Symbol at Invoice Top

If you want to get an exchange rate from a currency, FA tries to get the latest date rate up to and included the date given.

This is the way it shall work, right?

Joe

Re: Add Currency Symbol at Invoice Top

If the autoupdate is enabled, then what you state is acceptable as a current exchange rate would have been acquired. If not, only an older exchange rate would be available and may be used for the current transaction as would obtain if it is withing a few days of no significant change.

If the date_ >= $date is used, then the Order by Desc should be Order by Asc. Should there be a dictate to use the old exchange rate if autoupdate is disabled with an option to update for that specific time alone as well otherwise?