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 ***********************************************************************/
12 $page_security = 'SA_BANKTRANSVIEW';
13 $path_to_root="../..";
14 include_once($path_to_root . "/includes/session.inc");
16 include_once($path_to_root . "/includes/date_functions.inc");
17 include_once($path_to_root . "/includes/ui.inc");
18 include_once($path_to_root . "/includes/data_checks.inc");
20 include_once($path_to_root . "/gl/includes/gl_db.inc");
21 include_once($path_to_root . "/includes/banking.inc");
24 if ($use_popup_windows)
25 $js .= get_js_open_window(800, 500);
27 $js .= get_js_date_picker();
28 page(_("Bank Statement"), false, false, "", $js);
30 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
32 //-----------------------------------------------------------------------------------
37 $Ajax->activate('trans_tbl');
39 //------------------------------------------------------------------------------------------------
42 start_table("class='tablestyle_noborder'");
44 bank_accounts_list_cells(_("Account:"), 'bank_account', null);
46 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
47 date_cells(_("To:"), 'TransToDate');
49 submit_cells('Show',_("Show"),'','', 'default');
54 //------------------------------------------------------------------------------------------------
57 $date_after = date2sql($_POST['TransAfterDate']);
58 $date_to = date2sql($_POST['TransToDate']);
59 if (!isset($_POST['bank_account']))
60 $_POST['bank_account'] = "";
61 $sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
62 WHERE ".TB_PREF."bank_trans.bank_act = '" . $_POST['bank_account'] . "'
63 AND trans_date >= '$date_after'
64 AND trans_date <= '$date_to'
65 ORDER BY trans_date,".TB_PREF."bank_trans.id";
67 $result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
69 div_start('trans_tbl');
70 $act = get_bank_account($_POST["bank_account"]);
71 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
73 start_table($table_style);
75 $th = array(_("Type"), _("#"), _("Reference"), _("Date"),
76 _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), "");
79 $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act='" . $_POST['bank_account'] . "'
80 AND trans_date < '$date_after'";
81 $before_qty = db_query($sql, "The starting balance on hand could not be calculated");
83 start_row("class='inquirybg'");
84 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransAfterDate']."</b>", "colspan=4");
85 $bfw_row = db_fetch_row($before_qty);
87 display_debit_or_credit_cells($bfw);
89 label_cell("", "colspan=2");
92 $running_total = $bfw;
94 $k = 0; //row colour counter
95 while ($myrow = db_fetch($result))
98 alt_table_row_color($k);
100 $running_total += $myrow["amount"];
102 $trandate = sql2date($myrow["trans_date"]);
103 label_cell($systypes_array[$myrow["type"]]);
104 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
105 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
106 label_cell($trandate);
107 display_debit_or_credit_cells($myrow["amount"]);
108 amount_cell($running_total);
109 label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
110 label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
122 start_row("class='inquirybg'");
123 label_cell("<b>" . _("Ending Balance")." - ". $_POST['TransToDate']. "</b>", "colspan=4");
124 display_debit_or_credit_cells($running_total);
126 label_cell("", "colspan=2");
130 //------------------------------------------------------------------------------------------------