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.*,name AS BankTransType FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_trans_types
39 WHERE ".TB_PREF."bank_trans.bank_act = '$account'
40 AND trans_date >= '$from'
41 AND trans_date <= '$to'
42 AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
43 ORDER BY trans_date,".TB_PREF."bank_trans.id";
45 return db_query($sql,"The transactions for '$account' could not be retrieved");
48 function print_bank_transactions()
52 include_once($path_to_root . "reporting/includes/pdf_report.inc");
54 $rep = new FrontReport(_('Bank Statement'), "BankStatement.pdf", user_pagesize());
56 $acc = $_POST['PARAM_0'];
57 $from = $_POST['PARAM_1'];
58 $to = $_POST['PARAM_2'];
59 $comments = $_POST['PARAM_3'];
61 $dec = user_price_dec();
63 $cols = array(0, 90, 110, 170, 225, 270, 350, 400, 460, 520);
65 $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
67 $headers = array(_('Type'), _('#'), _('Reference'), _('Date'), _('Type'), _('Person/Item'),
68 _('Debit'), _('Credit'), _('Balance'));
70 $account = get_bank_account($acc);
71 $act = $account['bank_account_name']." - ".$account['bank_curr_code']." - ".$account['bank_account_number'];
72 $params = array( 0 => $comments,
73 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
74 2 => array('text' => _('Bank Account'),'from' => $act,'to' => ''));
77 $rep->Info($params, $cols, $headers, $aligns);
81 $prev_balance = get_bank_balance_to($from, $account["account_code"]);
83 $trans = get_bank_transactions($from, $to, $account['account_code']);
85 $rows = db_num_rows($trans);
86 if ($prev_balance != 0.0 || $rows != 0)
89 $rep->TextCol(0, 3, $act);
90 $rep->TextCol(3, 5, _('Opening Balance'));
91 if ($prev_balance > 0.0)
92 $rep->TextCol(6, 7, number_format2(abs($prev_balance), $dec));
94 $rep->TextCol(7, 8, number_format2(abs($prev_balance), $dec));
96 $total = $prev_balance;
100 while ($myrow=db_fetch($trans))
102 $total += $myrow['amount'];
104 $rep->TextCol(0, 1, systypes::name($myrow["type"]));
105 $rep->TextCol(1, 2, $myrow['trans_no']);
106 $rep->TextCol(2, 3, $myrow['ref']);
107 $rep->TextCol(3, 4, sql2date($myrow["trans_date"]));
108 $rep->TextCol(4, 5, $myrow['BankTransType']);
109 $rep->TextCol(5, 6, payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"], false));
110 if ($myrow['amount'] > 0.0)
111 $rep->TextCol(6, 7, number_format2(abs($myrow['amount']), $dec));
113 $rep->TextCol(7, 8, number_format2(abs($myrow['amount']), $dec));
114 $rep->TextCol(8, 9, number_format2($total, $dec));
116 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
118 $rep->Line($rep->row - 2);
125 $rep->TextCol(3, 5, _("Ending Balance"));
127 $rep->TextCol(6, 7, number_format2(abs($total), $dec));
129 $rep->TextCol(7, 8, number_format2(abs($total), $dec));
131 $rep->Line($rep->row - $rep->lineHeight + 4);