Security update merged from 2.1.
[fa-stable.git] / gl / inquiry / bank_inquiry.php
1 <?php
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");
15
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");
19
20 include_once($path_to_root . "/gl/includes/gl_db.inc");
21 include_once($path_to_root . "/includes/banking.inc");
22
23 $js = "";
24 if ($use_popup_windows)
25         $js .= get_js_open_window(800, 500);
26 if ($use_date_picker)
27         $js .= get_js_date_picker();
28 page(_("Bank Statement"), false, false, "", $js);
29
30 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
31
32 //-----------------------------------------------------------------------------------
33 // Ajax updates
34 //
35 if (get_post('Show'))
36 {
37         $Ajax->activate('trans_tbl');
38 }
39 //------------------------------------------------------------------------------------------------
40
41 start_form();
42 start_table("class='tablestyle_noborder'");
43 start_row();
44 bank_accounts_list_cells(_("Account:"), 'bank_account', null);
45
46 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
47 date_cells(_("To:"), 'TransToDate');
48
49 submit_cells('Show',_("Show"),'','', 'default');
50 end_row();
51 end_table();
52 end_form();
53
54 //------------------------------------------------------------------------------------------------
55
56
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 = ".db_escape($_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";
66
67 $result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
68
69 div_start('trans_tbl');
70 $act = get_bank_account($_POST["bank_account"]);
71 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
72
73 start_table($table_style);
74
75 $th = array(_("Type"), _("#"), _("Reference"), _("Date"),
76         _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), "");
77 table_header($th);
78
79 $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act="
80         .db_escape($_POST['bank_account']) . "
81         AND trans_date < '$date_after'";
82 $before_qty = db_query($sql, "The starting balance on hand could not be calculated");
83
84 start_row("class='inquirybg'");
85 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransAfterDate']."</b>", "colspan=4");
86 $bfw_row = db_fetch_row($before_qty);
87 $bfw = $bfw_row[0];
88 display_debit_or_credit_cells($bfw);
89 label_cell("");
90 label_cell("", "colspan=2");
91
92 end_row();
93 $running_total = $bfw;
94 $j = 1;
95 $k = 0; //row colour counter
96 while ($myrow = db_fetch($result))
97 {
98
99         alt_table_row_color($k);
100
101         $running_total += $myrow["amount"];
102
103         $trandate = sql2date($myrow["trans_date"]);
104         label_cell($systypes_array[$myrow["type"]]);
105         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
106         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
107         label_cell($trandate);
108         display_debit_or_credit_cells($myrow["amount"]);
109         amount_cell($running_total);
110         label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
111         label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
112         end_row();
113
114         if ($j == 12)
115         {
116                 $j = 1;
117                 table_header($th);
118         }
119         $j++;
120 }
121 //end of while loop
122
123 start_row("class='inquirybg'");
124 label_cell("<b>" . _("Ending Balance")." - ". $_POST['TransToDate']. "</b>", "colspan=4");
125 display_debit_or_credit_cells($running_total);
126 label_cell("");
127 label_cell("", "colspan=2");
128 end_row();
129 end_table(2);
130 div_end();
131 //------------------------------------------------------------------------------------------------
132
133 end_page();
134
135 ?>