Bug 0001669: get_exchange_rate not raising error
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 18 Aug 2012 21:53:12 +0000 (23:53 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 18 Aug 2012 21:53:12 +0000 (23:53 +0200)
gl/bank_transfer.php
gl/gl_bank.php
includes/data_checks.inc
inventory/prices.php
inventory/purchasing_data.php
purchasing/po_entry_items.php
purchasing/supplier_payment.php
sales/customer_payments.php
sales/sales_order_entry.php

index f84dd09e10873f1820a603c447e99bb8e1652ced..439d6b6e0e63982bd79bb6d0d7def31a619174b0 100644 (file)
@@ -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;
 }
index 97f67ddcb9815f7d123358d9ede77175a8467ded..b11dcd34de20367a65d500e7428027584b030206 100644 (file)
@@ -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']);
index 798e84c4b5c10070a4526a2ccbc7a2ad987b0898..67768b937df6d1f3eff7662b8258b76fa71e7ece 100644 (file)
@@ -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");
index dfac2aa5a4c6b01c27da23ba0ab1cdca1f7948b7..861b7daabbe3aee70f1d8b0393335aa4a8b46f8c 100644 (file)
@@ -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)
        {
index 0a7a01c3d02be91c6cae1fe1610af77d2ae9b32e..38a50dea97211cebc83e33fa18970cb0f9e0bb52 100644 (file)
@@ -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)
        {
index 4a3101dc7bf33b645f37c0f261470507f05752c5..d14769b10af55340e69188cbae0a100cecec03d9 100644 (file)
@@ -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."));
index ed8f5a089a9c50302c9e7614358e2e68b31fe496..28f890a0fcc04a25cd8d23e03c4dd7e70f359fe8 100644 (file)
@@ -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"]))
index f5d1f011a5e9a1ec4347023e295c3c45bf721738..34a862b1fc93e39c468bdfd73d46b8bdc69f7f60 100644 (file)
@@ -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');
 
index af29a1dda56653804117e5148152663d92069c2f..a49ff9af4f9b9b1647d4ab1515d73293708f88e0 100644 (file)
@@ -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.");