Customer Payment: fixed missing charge amount during edition, fixed submit button...
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 3 Sep 2013 06:51:00 +0000 (08:51 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 3 Sep 2013 06:53:03 +0000 (08:53 +0200)
includes/banking.inc
sales/customer_payments.php
sales/includes/db/cust_trans_db.inc
sales/includes/db/payment_db.inc
sales/view/view_receipt.php

index 21dbb8f6fc85516bc819ce47427cf5d00993e835..0641dd59d2dfd22624e3d9f96b9ec44d9b3a4f32 100644 (file)
@@ -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']);
index 88487aba6ec76c27c6a72042281ac19f6937aeb2..549062589b3f52b97c2edd7f733441c537a77221 100644 (file)
@@ -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();
 
index 4f92807a468ea3a831f2e8cad3f7921ff8c17be2..79aa50ab3555eb47ed2d19ec7001912074b02196 100644 (file)
@@ -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) {
index 873e8389784a69e55b2a8d9e1f591a592122df87..81ea49ce6ba625f96639eeff9d388ad9612ecc2c 100644 (file)
@@ -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
index f829fda5f0855d1fdf3573c22d7c12b602383bb7..09e9e51ec190698dde0e8f9e533d8977de043970 100644 (file)
@@ -36,18 +36,18 @@ echo "<br>";
 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);