From 72998423b6010dfd9a07025f836eef56736a7037 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Mon, 8 Jul 2019 21:54:13 +0200 Subject: [PATCH] Supplier Invoice: on form opening currency was not displayed for foreign supplier. --- includes/ui/ui_view.inc | 8 +++++++- purchasing/includes/db/invoice_db.inc | 12 +++++++----- purchasing/includes/ui/invoice_ui.inc | 8 +++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 35363f89..59fa6888 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -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 diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 16050242..0a7f360b 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -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"]; diff --git a/purchasing/includes/ui/invoice_ui.inc b/purchasing/includes/ui/invoice_ui.inc index e21c1adf..ef4b8128 100644 --- a/purchasing/includes/ui/invoice_ui.inc +++ b/purchasing/includes/ui/invoice_ui.inc @@ -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:"), "" . $supplier_currency . ""); - exchange_rate_display($company_currency, $supplier_currency, $_POST['tran_date']); + label_row(_("Supplier's Currency:"), "" . $supp_trans->currency . ""); + exchange_rate_display($company_currency, $supp_trans->currency, $_POST['tran_date']); } label_row(_("Tax Group:"), $supp_trans->tax_description); -- 2.30.2