Merged changes from stable branch up to 2.3.12
[fa-stable.git] / sales / customer_payments.php
index e268dd22d73f75d0160416ab27bbb6b05e958ee6..e1b672c9ae37cd69c5b2e563307faf5296daeff0 100644 (file)
@@ -179,7 +179,7 @@ function can_process()
                return false;
        }
        if (isset($_POST['charge']) && input_num('charge') > 0) {
-               $charge_acct = get_company_pref('bank_charge_act');
+               $charge_acct = get_bank_charge_account($_POST['bank_account']);
                if (get_gl_account($charge_acct) == false) {
                        display_error(_("The Bank Charge Account has not been set in System and General GL Setup."));
                        set_focus('charge');
@@ -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');
 
@@ -249,11 +251,6 @@ if (isset($_POST['ref']) && $_SESSION['alloc']->trans_no == 0) // added by Joe t
 }
 $new = $_SESSION['alloc']->trans_no == 0;
 
-if (list_updated('customer_id') || ($new && list_updated('bank_account'))) {
-  $_SESSION['alloc']->read();
-  $_POST['memo_'] = $_POST['amount'] = $_POST['discount'] = '';
-  $Ajax->activate('alloc_tbl');
-}
 //----------------------------------------------------------------------------------------------
 
 if (isset($_POST['AddPaymentItem'])) {
@@ -344,6 +341,12 @@ start_form();
                hidden('customer_id', $_POST['customer_id']);
        }
 
+       if (list_updated('customer_id') || ($new && list_updated('bank_account'))) {
+               $_SESSION['alloc']->read();
+               $_POST['memo_'] = $_POST['amount'] = $_POST['discount'] = '';
+               $Ajax->activate('alloc_tbl');
+       }
+
        if (!isset($_POST['charge'])) // first page call
        {
                //Prepare allocation cart