From f840050289f0dd5f6c8ffc4fc6c4b8199bb86e01 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 24 Sep 2013 13:24:58 +0200 Subject: [PATCH] Bank Payment/Bank Deposit: removed sparse sign from settled amount input, fixed sign in AR/AP record; Fixed amounts displayed in header for customer/supplier bank payments. --- gl/gl_bank.php | 13 +++++++++---- gl/includes/db/gl_db_banking.inc | 19 ++++++++++--------- gl/includes/ui/gl_bank_ui.inc | 2 +- purchasing/includes/db/supp_trans_db.inc | 6 +++--- sales/includes/db/cust_trans_db.inc | 6 +++--- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/gl/gl_bank.php b/gl/gl_bank.php index af38223f..00ce0783 100644 --- a/gl/gl_bank.php +++ b/gl/gl_bank.php @@ -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(); diff --git a/gl/includes/db/gl_db_banking.inc b/gl/includes/db/gl_db_banking.inc index 13fbd6de..1e4f4305 100644 --- a/gl/includes/db/gl_db_banking.inc +++ b/gl/includes/db/gl_db_banking.inc @@ -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); diff --git a/gl/includes/ui/gl_bank_ui.inc b/gl/includes/ui/gl_bank_ui.inc index 7ea96e1f..7d98271b 100644 --- a/gl/includes/ui/gl_bank_ui.inc +++ b/gl/includes/ui/gl_bank_ui.inc @@ -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()); } diff --git a/purchasing/includes/db/supp_trans_db.inc b/purchasing/includes/db/supp_trans_db.inc index ddbdc9e7..46802053 100644 --- a/purchasing/includes/db/supp_trans_db.inc +++ b/purchasing/includes/db/supp_trans_db.inc @@ -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)." diff --git a/sales/includes/db/cust_trans_db.inc b/sales/includes/db/cust_trans_db.inc index 0b966350..efb6b25f 100644 --- a/sales/includes/db/cust_trans_db.inc +++ b/sales/includes/db/cust_trans_db.inc @@ -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 -- 2.30.2