2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
13 // ----------------------------------------------------------------
17 // Title: Bank Accounts Transactions
18 // ----------------------------------------------------------------
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 //----------------------------------------------------------------------------------------------------
28 // trial_inquiry_controls();
29 print_bank_transactions();
31 //----------------------------------------------------------------------------------------------------
33 function get_bank_balance_to($to, $account)
36 $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act='$account'
37 AND trans_date < '$to'";
38 $result = db_query($sql, "The starting balance on hand could not be calculated");
39 $row = db_fetch_row($result);
43 function get_bank_transactions($from, $to, $account)
45 $from = date2sql($from);
47 $sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
48 WHERE ".TB_PREF."bank_trans.bank_act = '$account'
49 AND trans_date >= '$from'
50 AND trans_date <= '$to'
51 ORDER BY trans_date,".TB_PREF."bank_trans.id";
53 return db_query($sql,"The transactions for '$account' could not be retrieved");
56 function print_bank_transactions()
60 $acc = $_POST['PARAM_0'];
61 $from = $_POST['PARAM_1'];
62 $to = $_POST['PARAM_2'];
63 $comments = $_POST['PARAM_3'];
64 $destination = $_POST['PARAM_4'];
68 include_once($path_to_root . "/reporting/includes/excel_report.inc");
69 $filename = "BankStatement.xml";
73 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
74 $filename = "BankStatement.pdf";
77 $rep = new FrontReport(_('Bank Statement'), $filename, user_pagesize());
78 $dec = user_price_dec();
80 $cols = array(0, 90, 110, 170, 225, 350, 400, 460, 520);
82 $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
84 $headers = array(_('Type'), _('#'), _('Reference'), _('Date'), _('Person/Item'),
85 _('Debit'), _('Credit'), _('Balance'));
87 $account = get_bank_account($acc);
88 $act = $account['bank_account_name']." - ".$account['bank_curr_code']." - ".$account['bank_account_number'];
89 $params = array( 0 => $comments,
90 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
91 2 => array('text' => _('Bank Account'),'from' => $act,'to' => ''));
94 $rep->Info($params, $cols, $headers, $aligns);
98 $prev_balance = get_bank_balance_to($from, $account["id"]);
100 $trans = get_bank_transactions($from, $to, $account['id']);
102 $rows = db_num_rows($trans);
103 if ($prev_balance != 0.0 || $rows != 0)
106 $rep->TextCol(0, 3, $act);
107 $rep->TextCol(3, 5, _('Opening Balance'));
108 if ($prev_balance > 0.0)
109 $rep->AmountCol(5, 6, abs($prev_balance), $dec);
111 $rep->AmountCol(6, 7, abs($prev_balance), $dec);
113 $total = $prev_balance;
117 while ($myrow=db_fetch($trans))
119 $total += $myrow['amount'];
121 $rep->TextCol(0, 1, systypes::name($myrow["type"]));
122 $rep->TextCol(1, 2, $myrow['trans_no']);
123 $rep->TextCol(2, 3, $myrow['ref']);
124 $rep->DateCol(3, 4, $myrow["trans_date"], true);
125 $rep->TextCol(4, 5, payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"], false));
126 if ($myrow['amount'] > 0.0)
127 $rep->AmountCol(5, 6, abs($myrow['amount']), $dec);
129 $rep->AmountCol(6, 7, abs($myrow['amount']), $dec);
130 $rep->AmountCol(7, 8, $total, $dec);
132 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
134 $rep->Line($rep->row - 2);
141 $rep->TextCol(3, 5, _("Ending Balance"));
143 $rep->AmountCol(5, 6, abs($total), $dec);
145 $rep->AmountCol(6, 7, abs($total), $dec);
147 $rep->Line($rep->row - $rep->lineHeight + 4);