return $value>0 ? price_format($value) : '';
}
+function bank_fee($row)
+{
+ $value = -$row["charge"];
+ return $value > 0 ? price_format($value) : '';
+}
+
function fmt_person($trans)
{
return get_counterparty_name($trans["type"], $trans["trans_no"]);
_("Date") => 'date',
_("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'),
_("Credit") => array('align'=>'right','insert'=>true, 'fun'=>'fmt_credit'),
+ _("Bank fees") => array('align'=>'right','insert'=>true, 'fun'=>'bank_fee'),
_("Person/Item") => array('fun'=>'fmt_person'),
_("Memo") => array('fun'=>'fmt_memo'),
array('insert'=>true, 'fun'=>'gl_view'),
function get_sql_for_bank_account_reconcile($bank_account, $date)
{
$sql = "SELECT bt.type, trans_no, ref, trans_date,
- amount, person_id, person_type_id, reconciled, bt.id, c.memo_
+ amount, charge, person_id, person_type_id, reconciled, bt.id, c.memo_
FROM ".TB_PREF."bank_trans bt
LEFT JOIN ".TB_PREF."comments c ON c.type = bt.type AND c.id = bt.trans_no
WHERE bank_act = ".db_escape($bank_account) . "
// $date_ is display date (non-sql)
function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_,
- $amount, $person_type_id, $person_id, $currency="", $rate=0)
+ $amount, $charge=0, $person_type_id=0, $person_id=0, $currency="", $rate=0)
{
$sqlDate = date2sql($date_);
$amount_bank = round2($amount_bank, user_price_dec());
$sql = "INSERT INTO ".TB_PREF."bank_trans (type, trans_no, bank_act, ref,
- trans_date, amount, person_type_id, person_id) ";
+ trans_date, amount, charge, person_type_id, person_id) ";
$sql .= "VALUES ($type, $trans_no, '$bank_act', ".db_escape($ref).", '$sqlDate',
- ".db_escape($amount_bank).", ".db_escape($person_type_id)
+ ".db_escape($amount_bank).", ".db_escape($charge).", ".db_escape($person_type_id)
.", ". db_escape($person_id).")";
db_query($sql, "The bank transaction could not be inserted");
$sql = "SELECT trans_no
FROM ".TB_PREF."bank_trans
WHERE type=".db_escape($type)
- ." AND trans_no=".db_escape($type_no);
+ ." AND trans_no=".db_escape($type_no)
+ ." AND (amount!=0 OR charge!=0)";
$result = db_query($sql, "Cannot retreive a bank transaction");
return (db_num_rows($result) > 0);
AND ISNULL(v.date_)
AND trans_date >= '$from'
AND trans_date <= '$to'
- AND amount != 0
+ AND (amount != 0 OR charge != 0)
ORDER BY trans_date, t.id";
return db_query($sql,"The transactions for '" . $bank_account . "' could not be retrieved");
function get_balance_before_for_bank_account($bank_account, $from)
{
$from = date2sql($from);
- $sql = "SELECT SUM(amount)
+ $sql = "SELECT SUM(amount+charge)
FROM ".TB_PREF."bank_trans
WHERE bank_act=".db_escape($bank_account) . "
AND trans_date < '$from'";
begin_transaction(__FUNCTION__, func_get_args());
$sql = "UPDATE ".TB_PREF."bank_trans
- SET amount=0
+ SET amount=0, charge=0
WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
db_query($sql, "could not void bank transactions for type=$type and trans_no=$type_no");
$balance += $delta_amount;
- $sql = "SELECT sum(amount) as amount, trans_date, trans_no, type
+ $sql = "SELECT SUM(amount+charge) as amount, trans_date, trans_no, type
FROM ".TB_PREF."bank_trans
WHERE bank_act=".db_escape($bank_account);
if ($date)
$moves = get_bank_trans($type, $type_no);
while ($trans = db_fetch($moves)) {
if ($trans['amount'] > 0) { // skip transfer input part
- return check_bank_account_history(-$trans['amount'], $trans['bank_act'], sql2date($trans['trans_date'])) == null;
+ return check_bank_account_history(-$trans['amount']-$trans['charge'], $trans['bank_act'], sql2date($trans['trans_date'])) == null;
}
}
return true;
-($amount + $charge), $currency);
add_bank_trans($trans_type, $trans_no, $from_account, $ref,
- $date_, -($amount + $charge),
+ $date_, -$amount, -$charge,
PT_MISC, $person_id, $currency);
if ($SysPrefs->auto_currency_revaluation())
{
0, 0, _("Exchange Variance"), -$total);
add_bank_trans($trans_type, $trans_no, $to_account, $ref,
- $date_, $to_amount, PT_MISC, $person_id);
+ $date_, $to_amount, 0, PT_MISC, $person_id);
if ($SysPrefs->auto_currency_revaluation())
{
void_transaction(ST_BANKTRANSFER, $trans_no, Today(), _("Document reentered."));
void_gl_trans(ST_BANKTRANSFER, $trans_no, true);
$new_trans_no = add_bank_transfer(
- $from_account, $to_account, $date_, $amount,
+ $from_account, $to_account, $date_, $amount, $charge,
$ref, $memo_, $charge, $target_amount
);
commit_transaction();
// do the source account postings
add_bank_trans($trans_type, $trans_no, $from_account, $ref,
- $cart->tran_date, -$total_amount,
+ $cart->tran_date, -$total_amount, 0,
$person_type_id, $person_id,
$currency);
$total = 0;
if ($is_bank_to)
{
add_bank_trans($trans_type, $trans_no, $is_bank_to, $ref,
- $cart->tran_date, $gl_item->amount,
+ $cart->tran_date, $gl_item->amount, 0,
$person_type_id, $person_id, $currency);
if ($do_exchange_variance)
{
start_table(TABLESTYLE);
$th = array(_("Type"), _("#"), _("Reference"), _("Date"),
- _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), _("Memo"), "", "");
+ _("Debit"), _("Credit"), _("Fee"), _("Balance"), _("Person/Item"), _("Memo"), "", "");
table_header($th);
$bfw = get_balance_before_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate']);
-$credit = $debit = 0;
+$credit = $debit = $charges = 0;
start_row("class='inquirybg' style='font-weight:bold'");
label_cell(_("Opening Balance")." - ".$_POST['TransAfterDate'], "colspan=4");
display_debit_or_credit_cells($bfw);
alt_table_row_color($k);
- $running_total += $myrow["amount"];
+ $running_total += $myrow["amount"]+$myrow["charge"];
$trandate = sql2date($myrow["trans_date"]);
label_cell($systypes_array[$myrow["type"]]);
label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
label_cell($trandate);
display_debit_or_credit_cells($myrow["amount"]);
+ amount_cell(-$myrow['charge']);
amount_cell($running_total);
label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
$debit += $myrow["amount"];
else
$credit += $myrow["amount"];
-
+ $credit += $myrow["charge"];
+ $charges += $myrow["charge"];
if ($j == 12)
{
$j = 1;
amount_cell($debit);
amount_cell(-$credit);
//display_debit_or_credit_cells($running_total);
+amount_cell(-$charges);
amount_cell($debit+$credit);
label_cell("", "colspan=4");
end_row();
// update bank ledger if used
foreach($bank_trans as $bank_id => $amount)
add_bank_trans($this->trans_type, $this->order_id, $bank_id, $this->reference,
- $this->tran_date, $amount, 0, "", $this->currency);
+ $this->tran_date, $amount, 0, 0, "", $this->currency);
// add AP/AR for journal transaction
if ($this->trans_type == ST_JOURNAL)
start_table(TABLESTYLE, "width='80%'");
$th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
- _("Left to Allocate"), _("This Allocation"));
+ _("Left to Allocate"), _("Discount"), _("This Payment"), _("Allocated"));
table_header($th);
$k = $total_allocated = 0;
$alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
amount_cell(abs($alloc_row['Total']));
amount_cell(abs($alloc_row['Total']) - $alloc_row['alloc']);
+ amount_cell($alloc_row['discount']);
+ amount_cell($alloc_row['amt']-$alloc_row['discount']);
amount_cell($alloc_row['amt']);
end_row();
$total_allocated += $alloc_row['amt'];
}
start_row();
- label_cell(_("Total Allocated:"), "align=right colspan=5");
+ label_cell(_("Total Allocated:"), "align=right colspan=7");
amount_cell($total_allocated);
end_row();
if ($show_summary)
{
start_row();
- label_cell(_("Left to Allocate:"), "align=right colspan=5");
+ label_cell(_("Left to Allocate:"), "align=right colspan=7");
$total = round2($total, user_price_dec());
amount_cell($total - $total_allocated);
end_row();
if ($is_bank_to)
{
add_bank_trans(ST_JOURNAL, $journal_id, $is_bank_to, "",
- $date, -$amount, PT_WORKORDER, $wo_id, get_company_currency());
+ $date, -$amount, 0, PT_WORKORDER, $wo_id, get_company_currency());
}
add_journal(ST_JOURNAL, $journal_id, $amount, $date, get_company_currency(), $ref, '', 1, $date, $date);
/*now enter the bank_trans entry */
add_bank_trans(ST_SUPPAYMENT, $payment_id, $bank_account, $ref,
- $date_, -($bank_amount + $bank_charge), PT_SUPPLIER, $supplier_id);
+ $date_, -$bank_amount, -$bank_charge, PT_SUPPLIER, $supplier_id);
add_comments(ST_SUPPAYMENT, $payment_id, $date_, $memo_);
{
// it's a payment so also get the bank account
$sql .= ", account.bank_name, account.bank_account_name, account.bank_curr_code,
- account.account_type AS BankTransType, bank_trans.amount AS bank_amount,
+ account.account_type AS BankTransType, bank_trans.amount AS bank_amount, bank_trans.charge AS bank_charge,
bank_trans.ref ";
}
trans.supplier_id,
supplier.address,
amt,
+ alloc.discount,
supp_reference
FROM ".TB_PREF."supp_trans as trans,"
.TB_PREF."suppliers as supplier,"
start_table(TABLESTYLE2, "width='80%'");
start_row();
-label_cells(_("To Supplier"), $receipt['supplier_name'], "class='tableheader2'");
-label_cells(_("From Bank Account"), $receipt['bank_account_name'], "class='tableheader2'");
-label_cells(_("Date Paid"), sql2date($receipt['tran_date']), "class='tableheader2'");
-end_row();
-start_row();
-if ($show_currencies)
- label_cells(_("Payment Currency"), $receipt['bank_curr_code'], "class='tableheader2'");
+$act = $show_currencies ? $receipt['bank_account_name'].' '.$receipt['bank_curr_code'] : $receipt['bank_account_name'];
+label_cells(_("From Bank Account"), $act, "class='tableheader2'");
label_cells(_("Amount"), number_format2(-$receipt['bank_amount'], user_price_dec()), "class='tableheader2'");
-if ($receipt['ov_discount'] != 0)
- label_cells(_("Discount"), number_format2(-$receipt['ov_discount']*$receipt['rate'], user_price_dec()), "class='tableheader2'");
-else
- label_cells(_("Payment Type"), $bank_transfer_types[$receipt['BankTransType']], "class='tableheader2'");
+label_cells(_("Bank Fee"), number_format2(-$receipt['bank_charge'], user_price_dec()), "class='tableheader2'");
end_row();
+
start_row();
-if ($show_currencies)
-{
- label_cells(_("Supplier's Currency"), $receipt['curr_code'], "class='tableheader2'");
-}
-if ($show_both_amounts)
- label_cells(_("Amount"), number_format2(-$receipt['Total'], user_price_dec()), "class='tableheader2'");
+$supp = $show_currencies ? $receipt['supplier_name'].' '.$receipt['curr_code'] : $receipt['supplier_name'];
+label_cells(_("To Supplier"), $supp, "class='tableheader2'");
label_cells(_("Reference"), $receipt['ref'], "class='tableheader2'");
+label_cells(_("Date Paid"), sql2date($receipt['tran_date']), "class='tableheader2'");
end_row();
-if ($receipt['ov_discount'] != 0)
-{
- start_row();
- label_cells(_("Payment Type"), $bank_transfer_types[$receipt['BankTransType']], "class='tableheader2'");
- end_row();
-}
+
+start_row();
+ label_cells(_("Discount"), number_format2(-$receipt['ov_discount']*$receipt['rate'], user_price_dec()), "class='tableheader2'");
+ label_cells(_("Tottal settled"), number_format2(-$receipt['Total'], user_price_dec()), "class='tableheader2'");
+end_row();
+
comments_display_row(ST_SUPPAYMENT, $trans_no);
end_table(1);
function get_bank_balance_to($to, $account)
{
$to = date2sql($to);
- $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act='$account'
+ $sql = "SELECT SUM(amount+charge) FROM ".TB_PREF."bank_trans WHERE bank_act='$account'
AND trans_date < '$to'";
$result = db_query($sql, "The starting balance on hand could not be calculated");
$row = db_fetch_row($result);
WHERE bank_act = '$account'
AND trans_date >= '$from'
AND trans_date <= '$to'
+ AND (amount !=0 OR charge !=0)
ORDER BY trans_date, id";
return db_query($sql,"The transactions for '$account' could not be retrieved");
$rep = new FrontReport(_('Bank Statement'), "BankStatement", user_pagesize(), 9, $orientation);
$dec = user_price_dec();
- $cols = array(0, 90, 120, 170, 225, 350, 400, 460, 520);
+ $cols = array(0, 90, 120, 170, 225, 350, 400, 450, 500, 550);
- $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
+ $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
$headers = array(_('Type'), _('#'), _('Reference'), _('Date'), _('Person/Item'),
- _('Debit'), _('Credit'), _('Balance'));
+ _('Debit'), _('Credit'), _('Fee'), _('Balance'));
$account = get_bank_account($acc);
$act = $account['bank_account_name']." - ".$account['bank_curr_code']." - ".$account['bank_account_number'];
$rep->TextCol(0, 3, $act);
$rep->TextCol(3, 5, _('Opening Balance'));
if ($prev_balance > 0.0)
- $rep->AmountCol(5, 6, abs($prev_balance), $dec);
+ $rep->AmountCol(5, 6, $prev_balance, $dec);
else
- $rep->AmountCol(6, 7, abs($prev_balance), $dec);
+ $rep->AmountCol(6, 7, -$prev_balance, $dec);
$rep->Font();
$total = $prev_balance;
$rep->NewLine(2);
- $total_debit = $total_credit = 0;
+ $total_debit = $total_credit = $charges = 0;
if ($rows > 0)
{
// Keep a running total as we loop through
{
if ($zero == 0 && $myrow['amount'] == 0.0)
continue;
- $total += $myrow['amount'];
+ $total += $myrow['amount']+$myrow['charge'];
+ $charges += $myrow['charge'];
+ $amount = abs($myrow['amount']);
$rep->TextCol(0, 1, $systypes_array[$myrow["type"]]);
$rep->TextCol(1, 2, $myrow['trans_no']);
$rep->TextCol(4, 5, get_counterparty_name($myrow["type"], $myrow["trans_no"], false));
if ($myrow['amount'] > 0.0)
{
- $rep->AmountCol(5, 6, abs($myrow['amount']), $dec);
- $total_debit += abs($myrow['amount']);
+ $rep->AmountCol(5, 6, $amount, $dec);
+ $total_debit += $amount;
}
else
{
- $rep->AmountCol(6, 7, abs($myrow['amount']), $dec);
- $total_credit += abs($myrow['amount']);
+ $rep->AmountCol(6, 7, $amount, $dec);
+ $total_credit += $amount;
}
- $rep->AmountCol(7, 8, $total, $dec);
+ if ($myrow['charge'])
+ $rep->AmountCol(7, 8, -$myrow['charge'], $dec);
+ $rep->AmountCol(8, 9, $total, $dec);
$rep->NewLine();
if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
{
}
// Print totals for the debit and credit columns.
- $rep->TextCol(3, 5, _("Total Debit / Credit"));
+ $rep->TextCol(3, 5, _("Total Debit / Credit / Fees"));
$rep->AmountCol(5, 6, $total_debit, $dec);
$rep->AmountCol(6, 7, $total_credit, $dec);
+ $rep->AmountCol(7, 8, -$charges, $dec);
$rep->NewLine(2);
$rep->Font('bold');
$rep->TextCol(3, 5, _("Ending Balance"));
if ($total > 0.0)
- $rep->AmountCol(5, 6, abs($total), $dec);
+ $rep->AmountCol(5, 6, $total, $dec);
else
- $rep->AmountCol(6, 7, abs($total), $dec);
+ $rep->AmountCol(6, 7, -$total, $dec);
$rep->Font();
$rep->Line($rep->row - $rep->lineHeight + 4);
$rep->NewLine(2, 1);
function get_bank_balance_to($to, $account)
{
$to = date2sql($to);
- $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act='$account'
+ $sql = "SELECT SUM(amount+charge) FROM ".TB_PREF."bank_trans WHERE bank_act='$account'
AND trans_date < '$to'";
$result = db_query($sql, "The starting balance on hand could not be calculated");
$row = db_fetch_row($result);
WHERE trans.bank_act = '$account'
AND trans_date >= '$from'
AND trans_date <= '$to'
+ AND (amount !=0 OR charge !=0)
ORDER BY trans_date,trans.id";
return db_query($sql,"The transactions for '$account' could not be retrieved");
$rep = new FrontReport(_('Bank Statement w/Reconcile'), "BankStatementReconcile", user_pagesize(), 9, "L");
$dec = user_price_dec();
- $cols = array(0, 90, 120, 170, 225, 450, 500, 550, 600, 660, 700);
+ $cols = array(0, 90, 120, 170, 225, 400, 450, 500, 550, 600, 660, 700);
- $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'center', 'left');
+ $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right', 'center', 'left');
$headers = array(_('Type'), _('#'), _('Reference'), _('Date'), _('Person/Item'),
- _('Debit'), _('Credit'), _('Balance'), _('Reco Date'), _('Narration'));
+ _('Debit'), _('Credit'), _('Fee Incl.'), _('Balance'), _('Reco Date'), _('Narration'));
$account = get_bank_account($acc);
$act = $account['bank_account_name']." - ".$account['bank_curr_code']." - ".$account['bank_account_number'];
$rep->NewLine(2);
// Keep a running total as we loop through
// the transactions.
- $total_debit = $total_credit = 0;
+ $total_debit = $total_credit = $charges = 0;
if ($rows > 0)
{
while ($myrow=db_fetch($trans))
{
- $total += $myrow['amount'];
+ $total += $myrow['amount']+$myrow['charge'];
+ $charges += $myrow['charge'];
+ $amount = abs($myrow['amount']);
$rep->TextCol(0, 1, $systypes_array[$myrow["type"]]);
$rep->TextCol(1, 2, $myrow['trans_no']);
$rep->TextCol(4, 5, payment_person_name($myrow["person_type_id"],$myrow["person_id"], false));
if ($myrow['amount'] > 0.0)
{
- $rep->AmountCol(5, 6, abs($myrow['amount']), $dec);
- $total_debit += abs($myrow['amount']);
+ $rep->AmountCol(5, 6, $amount, $dec);
+ $total_debit += $amount;
}
else
{
- $rep->AmountCol(6, 7, abs($myrow['amount']), $dec);
- $total_credit += abs($myrow['amount']);
+ $rep->AmountCol(6, 7, $amount, $dec);
+ $total_credit += $amount;
}
- $rep->AmountCol(7, 8, $total, $dec);
+ if ($myrow['charge'])
+ $rep->AmountCol(7, 8, -$myrow['charge'], $dec);
+
+ $rep->AmountCol(8, 9, $total, $dec);
if ($myrow["reconciled"] && $myrow["reconciled"] != '0000-00-00')
- $rep->DateCol(8, 9, $myrow["reconciled"], true);
- $rep->TextCol(9, 10, $myrow['memo_']);
+ $rep->DateCol(9, 10, $myrow["reconciled"], true);
+ $rep->TextCol(10, 11, $myrow['memo_']);
$rep->NewLine();
if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
{
}
// Print totals for the debit and credit columns.
- $rep->TextCol(3, 5, _("Total Debit / Credit"));
+ $rep->TextCol(3, 5, _("Total Debit / Credit / Fees"));
$rep->AmountCol(5, 6, $total_debit, $dec);
$rep->AmountCol(6, 7, $total_credit, $dec);
+ $rep->AmountCol(7, 8, -$charges, $dec);
$rep->NewLine(2);
$rep->Font('bold');
$rep->TextCol(3, 5, _("Ending Balance"));
if ($total > 0.0)
- $rep->AmountCol(5, 6, abs($total), $dec);
+ $rep->AmountCol(5, 6, $total, $dec);
else
- $rep->AmountCol(6, 7, abs($total), $dec);
+ $rep->AmountCol(6, 7, -$total, $dec);
$rep->Font();
$rep->NewLine(2);
// Calculate Bank Balance as per reco
$date = date2sql($to);
- $sql = "SELECT SUM(IF(reconciled<='$date' AND reconciled !='0000-00-00', amount, 0)) as reconciled,
+ $sql = "SELECT SUM(IF(reconciled<='$date' AND reconciled !='0000-00-00', amount+charge, 0)) as reconciled,
SUM(amount) as books_total
FROM ".TB_PREF."bank_trans trans
WHERE bank_act=".db_escape($account['id'])."
$rep->NewLine(2);
$rep->Line($rep->row - $rep->lineHeight + 4);
- $rep->NewLine(2, 1);
+ $rep->NewLine(2, 1);
}
$rep->End();
$_POST['BranchID'] = $myrow["branch_code"];
$_POST['bank_account'] = $myrow["bank_act"];
$_POST['ref'] = $myrow["reference"];
- $charge = get_cust_bank_charge(ST_CUSTPAYMENT, $_POST['trans_no']);
- $_POST['charge'] = price_format($charge);
+ $_POST['charge'] = price_format(-$myrow['bank_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["bank_amount"] = price_format($myrow['bank_amount']);
$_POST["discount"] = price_format($myrow['ov_discount']);
$_POST["memo_"] = get_comments_string(ST_CUSTPAYMENT,$_POST['trans_no']);
$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.bank_curr_code,
- ".TB_PREF."bank_trans.amount as bank_amount";
+ bt.amount as bank_amount, bt.charge bank_charge";
}
if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) {
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";
+ $sql .= ", ".TB_PREF."bank_trans bt, ".TB_PREF."bank_accounts";
}
if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) {
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
- AND ".TB_PREF."bank_trans.amount != 0
- AND ".TB_PREF."bank_accounts.id=".TB_PREF."bank_trans.bank_act ";
+ $sql .= " AND bt.trans_no =".db_escape($trans_id)."
+ AND bt.type=$trans_type
+ AND bt.amount != 0
+ AND ".TB_PREF."bank_accounts.id=bt.bank_act ";
}
if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) {
// it's an invoice so also get the shipper
/*now enter the bank_trans entry */
add_bank_trans(ST_CUSTPAYMENT, $payment_no, $bank_account, $ref,
- $date_, $bank_amount - $charge, PT_CUSTOMER, $customer_id);
+ $date_, $bank_amount, -$charge, PT_CUSTOMER, $customer_id);
add_comments(ST_CUSTPAYMENT, $payment_no, $date_, $memo_);
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'];
-}
-
echo "<br>";
start_table(TABLESTYLE, "width='80%'");
start_row();
+label_cells(_("Into Bank Account"), $receipt['bank_account_name'].' ['.$receipt['bank_curr_code'].']', "class='tableheader2'");
+label_cells(_("Bank Amount"), price_format($receipt['bank_amount']+$receipt['bank_charge']), "class='tableheader2'");
+label_cells(_("Bank Fee"), price_format(abs($receipt['bank_charge'])), "class='tableheader2'");
+end_row();
+start_row();
label_cells(_("From Customer"), $receipt['DebtorName'], "class='tableheader2'");
label_cells(_("Reference"), $receipt['reference'], "class='tableheader2'");
label_cells(_("Date of Deposit"), sql2date($receipt['tran_date']), "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(_("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);
end_table(1);
LEFT JOIN `0_supp_trans` trans ON trans.`type`=sa.`trans_type_to` AND trans.`trans_no`=sa.`trans_no_to`
SET sa.discount=pay.ov_discount
WHERE pay.ov_discount != 0 AND pay.ov_amount+pay.ov_discount = trans.ov_amount+trans.ov_gst;
+
+# bank charge stored in bank_trans
+ALTER TABLE `0_bank_trans` ADD COLUMN `charge` double DEFAULT 0 AFTER `amount`;
+
+UPDATE `0_bank_trans` bt
+ LEFT JOIN (SELECT trans.type, trans.trans_no, 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))) amount
+ FROM 0_bank_trans trans
+ LEFT JOIN `0_bank_accounts` act ON trans.bank_act=act.id
+ LEFT JOIN `0_sys_prefs` charge_act ON charge_act.name='bank_charge_act'
+ LEFT JOIN `0_sys_prefs` home_curr ON home_curr.name='curr_default'
+ LEFT JOIN `0_gl_trans` charge ON charge.type=trans.`type` AND charge.type_no=trans.trans_no AND charge.account=charge_act.`value`
+ LEFT JOIN `0_gl_trans` pmt ON pmt.type=trans.type AND pmt.type_no=trans.trans_no AND pmt.account=act.account_code
+ LEFT JOIN `0_debtors_master` debtor ON trans.person_id=debtor.debtor_no AND trans.person_type_id=2
+ LEFT JOIN `0_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) charges ON bt.`type`=charges.`type` AND bt.`trans_no`=charges.`trans_no`
+ SET bt.charge=IFNULL(-charges.amount,0),
+ bt.amount=bt.amount+IFNULL(charges.amount,0);
`ref` varchar(40) DEFAULT NULL,
`trans_date` date NOT NULL DEFAULT '0000-00-00',
`amount` double DEFAULT NULL,
+ `charge` double DEFAULT NULL,
`dimension_id` int(11) NOT NULL DEFAULT '0',
`dimension2_id` int(11) NOT NULL DEFAULT '0',
`person_type_id` int(11) NOT NULL DEFAULT '0',
-- Data of table `0_bank_trans` --
INSERT INTO `0_bank_trans` VALUES
-('1', '12', '1', '2', '001/2018', '2018-05-10', '6240', '0', '0', '2', '1', NULL),
-('2', '12', '2', '2', '002/2018', '2018-05-07', '300', '0', '0', '2', '1', NULL),
-('3', '12', '3', '2', '003/2018', '2018-05-07', '0', '0', '0', '2', '1', NULL),
-('4', '1', '1', '1', '001/2018', '2018-05-07', '-5', '0', '0', '0', 'Goods received', NULL),
-('5', '12', '4', '2', '001/2019', '2019-01-21', '1250', '0', '0', '2', '1', NULL);
+('1', '12', '1', '2', '001/2018', '2018-05-10', '6240', '0', '0', '0', '2', '1', NULL),
+('2', '12', '2', '2', '002/2018', '2018-05-07', '300', '0', '0', '0', '2', '1', NULL),
+('3', '12', '3', '2', '003/2018', '2018-05-07', '0', '0', '0', '0', '2', '1', NULL),
+('4', '1', '1', '1', '001/2018', '2018-05-07', '-5', '0', '0', '0', '0', 'Goods received', NULL),
+('5', '12', '4', '2', '001/2019', '2019-01-21', '1250', '0', '0', '0', '2', '1', NULL);
-- Structure of table `0_bom` --
`ref` varchar(40) DEFAULT NULL,
`trans_date` date NOT NULL DEFAULT '0000-00-00',
`amount` double DEFAULT NULL,
+ `charge` double DEFAULT NULL,
`dimension_id` int(11) NOT NULL DEFAULT '0',
`dimension2_id` int(11) NOT NULL DEFAULT '0',
`person_type_id` int(11) NOT NULL DEFAULT '0',