From a1a9a2a460289e07f74f10ca96de513668c885aa Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sat, 18 Aug 2012 23:53:12 +0200 Subject: [PATCH] Bug 0001669: get_exchange_rate not raising error --- gl/bank_transfer.php | 6 ++++++ gl/gl_bank.php | 2 ++ includes/data_checks.inc | 13 +++++++++++++ inventory/prices.php | 2 ++ inventory/purchasing_data.php | 2 ++ purchasing/po_entry_items.php | 3 ++- purchasing/supplier_payment.php | 2 ++ sales/customer_payments.php | 2 ++ sales/sales_order_entry.php | 2 ++ 9 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gl/bank_transfer.php b/gl/bank_transfer.php index f84dd09..439d6b6 100644 --- a/gl/bank_transfer.php +++ b/gl/bank_transfer.php @@ -184,6 +184,12 @@ function check_valid_entries() set_focus('ToBankAccount'); return false; } + + if (!db_has_currency_rates(get_bank_account_currency($_POST['FromBankAccount']), $_POST['DatePaid'])) + return false; + + if (!db_has_currency_rates(get_bank_account_currency($_POST['ToBankAccount']), $_POST['DatePaid'])) + return false; return true; } diff --git a/gl/gl_bank.php b/gl/gl_bank.php index 97f67dd..b11dcd3 100644 --- a/gl/gl_bank.php +++ b/gl/gl_bank.php @@ -278,6 +278,8 @@ if (isset($_POST['Process'])) set_focus('person_id'); $input_error = 1; } + if (!db_has_currency_rates(get_bank_account_currency($_POST['bank_account']), $_POST['date_'], true)) + $input_error = 1; if ($input_error == 1) unset($_POST['Process']); diff --git a/includes/data_checks.inc b/includes/data_checks.inc index 798e84c..67768b9 100644 --- a/includes/data_checks.inc +++ b/includes/data_checks.inc @@ -41,6 +41,19 @@ function check_db_has_currencies($msg) } } +function db_has_currency_rates($currency, $date_, $msg=false) +{ + $date = date2sql($date_); + + if (is_company_currency($currency)) + return 1; + $ret = check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."exchange_rates WHERE curr_code = '$currency' && date_ <= '$date'"); + if ($ret == 0 && $msg) + display_error(sprintf(_("Cannot retrieve exchange rate for currency %s as of %s. Please add exchange rate manually on Exchange Rates page."), + $currency, $date_), true); + return $ret; +} + function db_has_sales_types() { return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."sales_types"); diff --git a/inventory/prices.php b/inventory/prices.php index dfac2aa..861b7da 100644 --- a/inventory/prices.php +++ b/inventory/prices.php @@ -70,6 +70,8 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') display_error( _("The price entered must be numeric.")); set_focus('price'); } + elseif(!db_has_currency_rates($_POST['curr_abrev'], Today(), true)) + $input_error = 1; if ($input_error != 1) { diff --git a/inventory/purchasing_data.php b/inventory/purchasing_data.php index 0a7a01c..38a50de 100644 --- a/inventory/purchasing_data.php +++ b/inventory/purchasing_data.php @@ -50,6 +50,8 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') display_error( _("The conversion factor entered was not numeric. The conversion factor is the number by which the price must be divided by to get the unit price in our unit of measure.")); set_focus('conversion_factor'); } + elseif(!db_has_currency_rates(get_supplier_currency($_POST['supplier_id']), Today(), true)) + $input_error = 1; if ($input_error == 0) { diff --git a/purchasing/po_entry_items.php b/purchasing/po_entry_items.php index 4a3101d..d14769b 100644 --- a/purchasing/po_entry_items.php +++ b/purchasing/po_entry_items.php @@ -391,7 +391,8 @@ function can_commit() set_focus('StkLocation'); return false; } - + if (!db_has_currency_rates($_SESSION['PO']->curr_code, $_POST['OrderDate'])) + return false; if ($_SESSION['PO']->order_has_items() == false) { display_error (_("The order cannot be placed because there are no lines entered on this order.")); diff --git a/purchasing/supplier_payment.php b/purchasing/supplier_payment.php index ed8f5a0..28f890a 100644 --- a/purchasing/supplier_payment.php +++ b/purchasing/supplier_payment.php @@ -210,6 +210,8 @@ function check_inputs() return false; } + if (!db_has_currency_rates(get_supplier_currency($_POST['supplier_id']), $_POST['DatePaid'], true)) + return false; $_SESSION['alloc']->amount = -input_num('amount'); if (isset($_POST["TotalNumberOfAllocs"])) diff --git a/sales/customer_payments.php b/sales/customer_payments.php index f5d1f01..34a862b 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -211,6 +211,8 @@ function can_process() set_focus('discount'); return false; } + if (!db_has_currency_rates(get_customer_currency($_POST['customer_id']), $_POST['DateBanked'], true)) + return false; $_SESSION['alloc']->amount = input_num('amount'); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index af29a1d..a49ff9a 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -404,6 +404,8 @@ function can_process() { set_focus('ref'); return false; } + if (!db_has_currency_rates($_SESSION['Items']->customer_currency, $_POST['OrderDate'])) + return false; if ($_SESSION['Items']->get_items_total() < 0) { display_error("Invoice total amount cannot be less than zero."); -- 2.30.2