Bank Payment/Bank Deposit: removed sparse sign from settled amount input, fixed sign...
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 24 Sep 2013 11:24:58 +0000 (13:24 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 24 Sep 2013 11:24:58 +0000 (13:24 +0200)
Fixed amounts displayed in header for customer/supplier bank payments.

gl/gl_bank.php
gl/includes/db/gl_db_banking.inc
gl/includes/ui/gl_bank_ui.inc
purchasing/includes/db/supp_trans_db.inc
sales/includes/db/cust_trans_db.inc

index af38223f0116419aa2e122689396798098dedcbf..00ce078363d9d2e134252aa86f41ce680c13abcc 100644 (file)
@@ -208,8 +208,9 @@ function create_cart($type, $trans_no)
 }
 //-----------------------------------------------------------------------------------------------
 
-if (isset($_POST['Process']))
+function check_trans()
 {
+       global $Refs;
 
        $input_error = 0;
 
@@ -279,11 +280,15 @@ if (isset($_POST['Process']))
        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']);
+       if (in_array(get_post('PayType'), array(PT_SUPPLIER, PT_CUSTOMER)) && (input_num('settled_amount') <= 0)) {
+               display_error(_("Settled amount have to be positive number."));
+               set_focus('person_id');
+               $input_error = 1;
+       }
+       return $input_error;
 }
 
-if (isset($_POST['Process']))
+if (isset($_POST['Process']) && !check_trans())
 {
        begin_transaction();
 
index 13fbd6de688a201682d1cb57b01dd77dc4e37438..1e4f4305514583a44802a9af68451d4e8893c7d3 100644 (file)
@@ -284,10 +284,11 @@ function add_bank_transfer($from_account, $to_account, $date_,
 //     Add bank payment or deposit to database.
 //
 //     $from_account - bank account id
-//  $item - transaction cart (line item's amounts in bank account's currency)
+//  $items - transaction cart (line amounts in bank account's currency); negative for deposit
 //  $person_type_id - defines type of $person_id identifiers
 //  $person_id - supplier/customer/other id
-// $person_detail_id - customer branch id or not used
+//  $person_detail_id - customer branch id or not used
+//  $settled_amount - settled amount in AR/AP (if applicable) in customer/supplier currency (always non-negative number)
 //
 // returns an array of (inserted trans type, trans no)
 //
@@ -328,14 +329,14 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
     if ($person_type_id == PT_CUSTOMER)
     {
        // we need to add a customer transaction record
-
                // convert to customer currency
                if (!isset($settled_amount)) // leaved for backward/ext compatibility 
-                       $cust_amount = exchange_from_to($total_amount, $currency, get_customer_currency($person_id), $date_);
+                       $cust_amount = exchange_from_to(abs($total_amount), $currency, get_customer_currency($person_id), $date_);
                else
                        $cust_amount = $settled_amount;
-               // we need to negate it too
-               $cust_amount = -$cust_amount;
+
+               if ($trans_type == ST_BANKPAYMENT)
+                       $cust_amount = -$cust_amount;
 
                $trans_no = write_customer_trans($trans_type, 0, $person_id, $person_detail_id, $date_,
                $ref, $cust_amount);
@@ -346,12 +347,12 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
        // we need to add a supplier transaction record
                // convert to supp currency
                if (!isset($settled_amount)) // leaved for for backward/ext compatibility 
-                       $supp_amount = exchange_from_to($total_amount, $currency, get_supplier_currency($person_id), $date_);
+                       $supp_amount = exchange_from_to(abs($total_amount), $currency, get_supplier_currency($person_id), $date_);
                else
                        $supp_amount = $settled_amount;
 
-               // we need to negate it too
-               $supp_amount = -$supp_amount;
+               if ($trans_type == ST_BANKPAYMENT)
+                       $supp_amount = -$supp_amount;
 
                $trans_no = write_supp_trans($trans_type, 0, $person_id, $date_, '',
                        $ref, "", $supp_amount, 0, 0);
index 7ea96e1f6c4f53de415b714c98d4bb6f9222c43c..7d98271b88462c99ef6964fb9b668989caf915f7 100644 (file)
@@ -305,7 +305,7 @@ function gl_options_controls($order)
        if ($person_curr != $bank_curr)
        {
                $_POST['settled_amount'] =
-                       price_format($order->gl_items_total() / get_exchange_rate_from_to($bank_curr, $person_curr, get_post('date_')));
+                       price_format(abs($order->gl_items_total() / get_exchange_rate_from_to($bank_curr, $person_curr, get_post('date_'))));
                amount_row($type == PT_CUSTOMER ? _("Settled AR Amount:") :  _("Settled AP Amount:"),
                         'settled_amount', null, null, $person_curr, user_price_dec());
        }
index ddbdc9e7d9808be9db0d55428de84c6c90bdbf22..468020530aa04b5c60c3b58a0414e0afe9bb8d18 100644 (file)
@@ -55,7 +55,7 @@ function get_supp_trans($trans_no, $trans_type=-1)
        $sql = "SELECT ".TB_PREF."supp_trans.*, (".TB_PREF."supp_trans.ov_amount+".TB_PREF."supp_trans.ov_gst+".TB_PREF."supp_trans.ov_discount) AS Total,
                ".TB_PREF."suppliers.supp_name AS supplier_name, ".TB_PREF."suppliers.curr_code AS curr_code ";
 
-       if ($trans_type == ST_SUPPAYMENT)
+       if ($trans_type == ST_SUPPAYMENT || $trans_type == ST_BANKPAYMENT)
        {
                // it's a payment so also get the bank account
                $sql .= ", ".TB_PREF."bank_accounts.bank_name, ".TB_PREF."bank_accounts.bank_account_name, ".TB_PREF."bank_accounts.bank_curr_code,
@@ -65,7 +65,7 @@ function get_supp_trans($trans_no, $trans_type=-1)
 
        $sql .= " FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers ";
 
-       if ($trans_type == ST_SUPPAYMENT)
+       if ($trans_type == ST_SUPPAYMENT || $trans_type == ST_BANKPAYMENT)
        {
                // it's a payment so also get the bank account
                $sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts";
@@ -77,7 +77,7 @@ function get_supp_trans($trans_no, $trans_type=-1)
        if ($trans_type > 0)
                $sql .= " AND ".TB_PREF."supp_trans.type=".db_escape($trans_type);
 
-       if ($trans_type == ST_SUPPAYMENT)
+       if ($trans_type == ST_SUPPAYMENT || $trans_type == ST_BANKPAYMENT)
        {
                // it's a payment so also get the bank account
                $sql .= " AND ".TB_PREF."bank_trans.trans_no =".db_escape($trans_no)."
index 0b9663507e0d5c9d559ae56ddcb79d9f73b1f11d..efb6b25f97fa0139177d3e57309fd140de6474a1 100644 (file)
@@ -125,7 +125,7 @@ function get_customer_trans($trans_id, $trans_type)
                ."cust.tax_id, "
                ."com.memo_";
 
-       if ($trans_type == ST_CUSTPAYMENT) {
+       if ($trans_type == ST_CUSTPAYMENT || $trans_type == ST_BANKDEPOSIT) {
                // it's a payment so also get the bank account
                // Chaitanya : Added bank_act to support Customer Payment Edit
                $sql .= ",bank_act,".TB_PREF."bank_accounts.bank_name, ".TB_PREF."bank_accounts.bank_account_name,
@@ -150,7 +150,7 @@ function get_customer_trans($trans_id, $trans_type)
                                        LEFT JOIN ".TB_PREF."shippers ON ".TB_PREF."shippers.shipper_id=trans.ship_via, 
                                        ".TB_PREF."debtors_master cust";
 
-       if ($trans_type == ST_CUSTPAYMENT) {
+       if ($trans_type == ST_CUSTPAYMENT || $trans_type == ST_BANKDEPOSIT) {
                // it's a payment so also get the bank account
                $sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts";
        }
@@ -166,7 +166,7 @@ function get_customer_trans($trans_id, $trans_type)
                AND trans.type=".db_escape($trans_type)."
                AND trans.debtor_no=cust.debtor_no";
 
-       if ($trans_type == ST_CUSTPAYMENT) {
+       if ($trans_type == ST_CUSTPAYMENT || $trans_type == ST_BANKDEPOSIT) {
                // it's a payment so also get the bank account
                $sql .= " AND ".TB_PREF."bank_trans.trans_no =".db_escape($trans_id)."
                        AND ".TB_PREF."bank_trans.type=$trans_type