Merged all main trunk bugfixes up to release 2.0.5
[fa-stable.git] / sales / customer_payments.php
index 03639e75482a03983bf9c3c89b23af3a34b7a138..9f8b79027a8ef4e6252d596914bfe32ec4bfa521 100644 (file)
@@ -84,6 +84,18 @@ function can_process()
                return false;
        }
 
+       if (isset($_POST['_ex_rate']) && !check_num('_ex_rate', 0.000001))
+       {
+               display_error(_("The exchange rate must be numeric and greater than zero."));
+               set_focus('_ex_rate');
+               return false;
+       }
+
+       if ($_POST['discount'] == "") 
+       {
+               $_POST['discount'] = 0;
+       }
+
        if (!check_num('discount')) {
                display_error(_("The entered discount is not a valid number."));
                set_focus('discount');
@@ -118,9 +130,18 @@ if (isset($_POST['_DateBanked_changed'])) {
 //----------------------------------------------------------------------------------------------
 
 if (isset($_POST['AddPaymentItem'])) {
+       
+       $cust_currency = get_customer_currency($_POST['customer_id']);
+       $bank_currency = get_bank_account_currency($_POST['bank_account']);
+       $comp_currency = get_company_currency();
+       if ($comp_currency != $bank_currency && $bank_currency != $cust_currency)
+               $rate = 0;
+       else
+               $rate = input_num('_ex_rate');
+
        $payment_no = write_customer_payment(0, $_POST['customer_id'], $_POST['BranchID'],
                $_POST['bank_account'], $_POST['DateBanked'], $_POST['ref'],
-               input_num('amount'), input_num('discount'), $_POST['memo_']);
+               input_num('amount'), input_num('discount'), $_POST['memo_'], $rate);
        meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_no");
 }
 
@@ -195,7 +216,7 @@ function display_item_form()
                $bank_currency = get_bank_account_currency($_POST['bank_account']);
 
                if ($cust_currency != $bank_currency) {
-                       exchange_rate_display($cust_currency, $bank_currency, $_POST['DateBanked']);
+                       exchange_rate_display($bank_currency, $cust_currency, $_POST['DateBanked'], true);
                }
 
                text_row(_("Reference:"), 'ref', null, 20, 40);