From 0e98f64b40f1685b7b20e58e4a8a1f136401206d Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 3 Sep 2013 08:51:00 +0200 Subject: [PATCH] Customer Payment: fixed missing charge amount during edition, fixed submit button name. --- includes/banking.inc | 3 ++- sales/customer_payments.php | 26 +++++++++++------------- sales/includes/db/cust_trans_db.inc | 7 +++++-- sales/includes/db/payment_db.inc | 31 +++++++++++++++++++++++++++++ sales/view/view_receipt.php | 10 +++++----- 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/includes/banking.inc b/includes/banking.inc index 21dbb8f..0641dd5 100644 --- a/includes/banking.inc +++ b/includes/banking.inc @@ -163,7 +163,8 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am { $trans = get_customer_trans($trans_no, $type); $pyt_trans = get_customer_trans($pyt_no, $pyt_type); - $ar_ap_act = $trans['receivables_account']; + $cust_accs = get_branch_accounts($trans['branch_code']); + $ar_ap_act = $cust_accs['receivables_account']; $person_id = $trans['debtor_no']; $curr = $trans['curr_code']; $date = sql2date($trans['tran_date']); diff --git a/sales/customer_payments.php b/sales/customer_payments.php index 88487ab..5490625 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -306,24 +306,22 @@ if (isset($_GET['trans_no']) && $_GET['trans_no'] > 0 ) $_POST['bank_account'] = $myrow["bank_act"]; $_POST['ref'] = $myrow["reference"]; $old_ref = $myrow["reference"]; - //$_POST['charge'] = $myrow[""]; + $charge = get_cust_bank_charge(ST_CUSTPAYMENT, $_POST['trans_no']); + $_POST['charge'] = price_format($charge); $_POST['DateBanked'] = sql2date($myrow['tran_date']); $_POST["amount"] = price_format($myrow['Total'] - $myrow['ov_discount']); + $_POST["bank_amount"] = price_format($myrow['bank_amount']+$charge); $_POST["discount"] = price_format($myrow['ov_discount']); $_POST["memo_"] = get_comments_string(ST_CUSTPAYMENT,$_POST['trans_no']); - if (!isset($_POST['charge'])) // first page call + //Prepare allocation cart + if (isset($_POST['trans_no']) && $_POST['trans_no'] > 0 ) + $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,$_POST['trans_no']); + else { - //Prepare allocation cart - if (isset($_POST['trans_no']) && $_POST['trans_no'] > 0 ) - $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,$_POST['trans_no']); - else - { - $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,0); - $Ajax->activate('alloc_tbl'); - } + $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,0); + $Ajax->activate('alloc_tbl'); } - } //---------------------------------------------------------------------------------------------- @@ -342,7 +340,7 @@ start_form(); if ($new) customer_list_row(_("From Customer:"), 'customer_id', null, false, true); else { - label_cells(_("From Customer:"), $_POST['customer_name'], "class='label'"); + label_cells(_("From Customer:"), $_SESSION['alloc']->person_name, "class='label'"); hidden('customer_id', $_POST['customer_id']); } @@ -409,9 +407,9 @@ start_form(); end_table(1); if ($new) - submit_center('AddPaymentItem', _("Update Payment"), true, '', 'default'); - else submit_center('AddPaymentItem', _("Add Payment"), true, '', 'default'); + else + submit_center('AddPaymentItem', _("Update Payment"), true, '', 'default'); br(); diff --git a/sales/includes/db/cust_trans_db.inc b/sales/includes/db/cust_trans_db.inc index 4f92807..79aa50a 100644 --- a/sales/includes/db/cust_trans_db.inc +++ b/sales/includes/db/cust_trans_db.inc @@ -120,13 +120,16 @@ function get_customer_trans($trans_id, $trans_type) ."ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total," ."cust.name AS DebtorName, cust.address, " ."cust.curr_code, " - ."cust.tax_id "; + ."cust.tax_id, " + ."com.memo_"; if ($trans_type == ST_CUSTPAYMENT) { // 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, - ".TB_PREF."bank_accounts.account_type AS BankTransType "; + ".TB_PREF."bank_accounts.account_type AS BankTransType, + ".TB_PREF."bank_accounts.bank_curr_code, + ".TB_PREF."bank_trans.amount as bank_amount"; } if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) { diff --git a/sales/includes/db/payment_db.inc b/sales/includes/db/payment_db.inc index 873e838..81ea49c 100644 --- a/sales/includes/db/payment_db.inc +++ b/sales/includes/db/payment_db.inc @@ -134,5 +134,36 @@ function void_customer_payment($type, $type_no) commit_transaction(); } +/* + Retrieve bank charge amount from GL postings for customer payment. + . Bank charge is not stored explicitly in database as of 2.3.xx + . Due to roundings the retrieved charge can differ from the original amount when bank_curr!=home_curr && bank_curr!=cust_curr +*/ +function get_cust_bank_charge($type, $trans_no) +{ + + // restore charge amount from amounts in bank currency if possible, otherwise calculate from GL posting with exchange rate used for amount posting + $sql = "SELECT IF(act.bank_curr_code=home_curr.value, charge.amount, + IF(act.bank_curr_code=debtor.curr_code, -(trans.amount-ar.ov_amount+ar.ov_discount), + IFNULL(charge.amount*trans.amount/pmt.amount, 0))) + FROM ".TB_PREF."bank_trans trans + LEFT JOIN ".TB_PREF."bank_accounts act ON trans.bank_act=act.id + LEFT JOIN ".TB_PREF."sys_prefs charge_act ON charge_act.name='bank_charge_act' + LEFT JOIN ".TB_PREF."sys_prefs home_curr ON home_curr.name='curr_default' + LEFT JOIN ".TB_PREF."gl_trans charge ON charge.type=trans.type AND charge.type_no=trans.trans_no AND charge.account=charge_act.value + LEFT JOIN ".TB_PREF."gl_trans pmt ON pmt.type=trans.type AND pmt.type_no=trans.trans_no AND pmt.account=act.account_code + LEFT JOIN ".TB_PREF."debtors_master debtor ON trans.person_id=debtor.debtor_no AND trans.person_type_id=".PT_CUSTOMER." + LEFT JOIN ".TB_PREF."debtor_trans ar ON trans.type=ar.type AND trans.trans_no=ar.trans_no + WHERE pmt.amount!=0 AND charge.amount!=0 AND trans.amount!=0 + AND trans.type=".db_escape($type)." AND trans.trans_no=".db_escape($trans_no); + + $result = db_query($sql, "cannot retrieve bank charge"); + + if (!db_num_rows($result)) + return 0; + + $myrow = db_fetch($result); + return $myrow['0']; +} ?> \ No newline at end of file diff --git a/sales/view/view_receipt.php b/sales/view/view_receipt.php index f829fda..09e9e51 100644 --- a/sales/view/view_receipt.php +++ b/sales/view/view_receipt.php @@ -36,18 +36,18 @@ echo "
"; start_table(TABLESTYLE, "width=80%"); start_row(); label_cells(_("From Customer"), $receipt['DebtorName'], "class='tableheader2'"); -label_cells(_("Into Bank Account"), $receipt['bank_account_name'], "class='tableheader2'"); +label_cells(_("Reference"), $receipt['reference'], "class='tableheader2'"); label_cells(_("Date of Deposit"), sql2date($receipt['tran_date']), "class='tableheader2'"); end_row(); start_row(); -label_cells(_("Payment Currency"), $receipt['curr_code'], "class='tableheader2'"); +label_cells(_("Customer Currency"), $receipt['curr_code'], "class='tableheader2'"); label_cells(_("Amount"), price_format($receipt['Total'] - $receipt['ov_discount']), "class='tableheader2'"); label_cells(_("Discount"), price_format($receipt['ov_discount']), "class='tableheader2'"); end_row(); start_row(); -label_cells(_("Payment Type"), - $bank_transfer_types[$receipt['BankTransType']], "class='tableheader2'"); -label_cells(_("Reference"), $receipt['reference'], "class='tableheader2'", "colspan=4"); +label_cells(_("Into Bank Account"), $receipt['bank_account_name'].' ['.$receipt['bank_curr_code'].']', "class='tableheader2'"); +label_cells(_("Bank Amount"), price_format($receipt['bank_amount']), "class='tableheader2'"); +label_cells(_("Payment Type"), $bank_transfer_types[$receipt['BankTransType']], "class='tableheader2'"); end_row(); comments_display_row(ST_CUSTPAYMENT, $trans_id); -- 2.30.2