4 // ----------------------------------------------------------------
8 // Title: Bank Accounts Transactions
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
20 print_bank_transactions();
22 //----------------------------------------------------------------------------------------------------
24 function get_bank_balance_to($to, $account)
27 $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act='$account'
28 AND trans_date < '$to'";
29 $result = db_query($sql, "The starting balance on hand could not be calculated");
30 $row = db_fetch_row($result);
34 function get_bank_transactions($from, $to, $account)
36 $from = date2sql($from);
38 $sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
39 WHERE ".TB_PREF."bank_trans.bank_act = '$account'
40 AND trans_date >= '$from'
41 AND trans_date <= '$to'
42 ORDER BY trans_date,".TB_PREF."bank_trans.id";
44 return db_query($sql,"The transactions for '$account' could not be retrieved");
47 function print_bank_transactions()
51 include_once($path_to_root . "reporting/includes/pdf_report.inc");
53 $rep = new FrontReport(_('Bank Statement'), "BankStatement.pdf", user_pagesize());
55 $acc = $_POST['PARAM_0'];
56 $from = $_POST['PARAM_1'];
57 $to = $_POST['PARAM_2'];
58 $comments = $_POST['PARAM_3'];
60 $dec = user_price_dec();
62 $cols = array(0, 90, 110, 170, 225, 350, 400, 460, 520);
64 $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
66 $headers = array(_('Type'), _('#'), _('Reference'), _('Date'), _('Person/Item'),
67 _('Debit'), _('Credit'), _('Balance'));
69 $account = get_bank_account($acc);
70 $act = $account['bank_account_name']." - ".$account['bank_curr_code']." - ".$account['bank_account_number'];
71 $params = array( 0 => $comments,
72 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
73 2 => array('text' => _('Bank Account'),'from' => $act,'to' => ''));
76 $rep->Info($params, $cols, $headers, $aligns);
80 $prev_balance = get_bank_balance_to($from, $account["id"]);
82 $trans = get_bank_transactions($from, $to, $account['id']);
84 $rows = db_num_rows($trans);
85 if ($prev_balance != 0.0 || $rows != 0)
88 $rep->TextCol(0, 3, $act);
89 $rep->TextCol(3, 5, _('Opening Balance'));
90 if ($prev_balance > 0.0)
91 $rep->TextCol(6, 7, number_format2(abs($prev_balance), $dec));
93 $rep->TextCol(7, 8, number_format2(abs($prev_balance), $dec));
95 $total = $prev_balance;
99 while ($myrow=db_fetch($trans))
101 $total += $myrow['amount'];
103 $rep->TextCol(0, 1, systypes::name($myrow["type"]));
104 $rep->TextCol(1, 2, $myrow['trans_no']);
105 $rep->TextCol(2, 3, $myrow['ref']);
106 $rep->TextCol(3, 4, sql2date($myrow["trans_date"]));
107 $rep->TextCol(4, 5, payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"], false));
108 if ($myrow['amount'] > 0.0)
109 $rep->TextCol(5, 6, number_format2(abs($myrow['amount']), $dec));
111 $rep->TextCol(6, 7, number_format2(abs($myrow['amount']), $dec));
112 $rep->TextCol(7, 8, number_format2($total, $dec));
114 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
116 $rep->Line($rep->row - 2);
123 $rep->TextCol(3, 5, _("Ending Balance"));
125 $rep->TextCol(6, 7, number_format2(abs($total), $dec));
127 $rep->TextCol(7, 8, number_format2(abs($total), $dec));
129 $rep->Line($rep->row - $rep->lineHeight + 4);