{
$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']);
$_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');
}
-
}
//----------------------------------------------------------------------------------------------
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']);
}
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();
."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) {
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
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);