Supplier Invoice: on form opening currency was not displayed for foreign supplier.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 8 Jul 2019 19:54:13 +0000 (21:54 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 8 Jul 2019 19:54:13 +0000 (21:54 +0200)
includes/ui/ui_view.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/ui/invoice_ui.inc

index 35363f896bd519e2792499ab0e241f37e9589401..59fa6888b0f256c6ff63f2cc8dd59d588c643f49 100644 (file)
@@ -270,7 +270,7 @@ function check_ui_refresh($name=null)
 // When there is no exrate for today, 
 // gets it form ECB and stores in local database.
 //
-function exchange_rate_display($from_currency, $to_currency, $date_, $force_edit=false)
+function exchange_rate_display($from_currency=null, $to_currency=null, $date_, $force_edit=false)
 {
     global $Ajax, $SysPrefs;
 
@@ -281,6 +281,12 @@ function exchange_rate_display($from_currency, $to_currency, $date_, $force_edit
                $rate = input_num('_ex_rate');
                if (check_ui_refresh() || !$rate) { // readonly or ui context changed
                        $comp_currency = get_company_currency();
+
+                       if (!isset($from_currency))
+                               $from_currency = $comp_currency;
+                       if (!isset($to_currency))
+                               $to_currency = $comp_currency;
+
                        if ($from_currency == $comp_currency)
                                $currency = $to_currency;
                        else
index 1605024261687c0ee5b4e45c0a4fdf8bbf2a4b61..0a7f360b647af2638404c59b4d0347aded6f0de5 100644 (file)
@@ -19,7 +19,7 @@ function read_supplier_details_to_trans(&$supp_trans, $supplier_id)
        $sql = "SELECT supp.supp_name, terms.terms, terms.days_before_due, supp.dimension_id, supp.dimension2_id,
                terms.day_in_following_month, supp.tax_included,
                supp.tax_group_id, tax_group.name AS tax_group_name,
-               supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit
+               supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit, curr_code
                FROM ".TB_PREF."suppliers supp LEFT JOIN "
                        .TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id, "
                        .TB_PREF."payment_terms terms, "
@@ -56,6 +56,7 @@ function read_supplier_details_to_trans(&$supp_trans, $supplier_id)
        $supp_trans->tax_group_id = $myrow['tax_group_id'];
        $supp_trans->dimension = $myrow['dimension_id'];
        $supp_trans->dimension2 = $myrow['dimension2_id'];
+       $supp_trans->currency = $myrow['curr_code'];
  
 }
 
@@ -142,7 +143,7 @@ function add_supp_invoice(&$supp_trans)
        } else
                $allocs = get_po_prepayments($supp_trans);
 
-       add_new_exchange_rate($supplier['curr_code'], $supp_trans->tran_date, $supp_trans->ex_rate);
+       add_new_exchange_rate($supp_trans->currency, $supp_trans->tran_date, $supp_trans->ex_rate);
 
     foreach ($taxes as $n => $taxitem)
     {
@@ -170,7 +171,7 @@ function add_supp_invoice(&$supp_trans)
        }
 
     $date_ = $supp_trans->tran_date;
-       $ex_rate = get_exchange_rate_from_home_currency($supplier['curr_code'], $date_);
+       $ex_rate = get_exchange_rate_from_home_currency($supp_trans->currency, $date_);
 
     /*First insert the invoice into the supp_trans table*/
        $invoice_id = write_supp_trans($trans_type, 0, $supp_trans->supplier_id, $date_, $supp_trans->due_date,
@@ -304,7 +305,7 @@ function add_supp_invoice(&$supp_trans)
                                        $dim, $dim2, $taxfree_line, $supp_trans->supplier_id);
                        else
                        {
-                               $ex_rate = get_exchange_rate_from_home_currency($supplier['curr_code'], $old_date);
+                               $ex_rate = get_exchange_rate_from_home_currency($supp_trans->currency, $old_date);
                                $old_value = get_tax_free_price_for_item($entered_grn->item_code, $entered_grn->this_quantity_inv * $old_price, 
                                          $supp_trans->tax_group_id, $supp_trans->tax_included);
 
@@ -448,7 +449,7 @@ function get_tax_overrides($trans_type, $trans_no)
 
 function read_supp_invoice($trans_no, $trans_type, &$supp_trans)
 {
-       $sql = "SELECT trans.*, supp_name, dimension_id, dimension2_id
+       $sql = "SELECT trans.*, supp_name, dimension_id, dimension2_id, curr_code
                FROM ".TB_PREF."supp_trans trans,"
                        .TB_PREF."suppliers sup
                WHERE trans_no = ".db_escape($trans_no)." AND type = ".db_escape($trans_type)."
@@ -473,6 +474,7 @@ function read_supp_invoice($trans_no, $trans_type, &$supp_trans)
                $supp_trans->tax_included = $trans_row["tax_included"];
                $supp_trans->dimension = $trans_row["dimension_id"];
                $supp_trans->dimension2 = $trans_row["dimension2_id"];
+               $supp_trans->currency = $trans_row["curr_code"];
 
                $id = $trans_row["trans_no"];
 
index e21c1adf02f1b03cd1f2954f6e10a06db5acd38d..ef4b812846d63dc7e4cf756ca729ac444a4c38f9 100644 (file)
@@ -146,14 +146,12 @@ function invoice_header(&$supp_trans)
 
        set_global_supplier($_POST['supplier_id']);
 
-       $supplier_currency = get_supplier_currency($supp_trans->supplier_id);
-
        $company_currency = get_company_currency();
 
-       if ($supplier_currency != $company_currency)
+       if ($supp_trans->currency != $company_currency)
        {
-        label_row(_("Supplier's Currency:"), "<b>" . $supplier_currency . "</b>");
-               exchange_rate_display($company_currency, $supplier_currency, $_POST['tran_date']);
+        label_row(_("Supplier's Currency:"), "<b>" . $supp_trans->currency . "</b>");
+               exchange_rate_display($company_currency, $supp_trans->currency, $_POST['tran_date']);
        }
 
        label_row(_("Tax Group:"), $supp_trans->tax_description);