Moved all SQL statements from PHP files into relevant *_db.inc files.
[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(_($help_context = "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 if (!isset($_POST['bank_account']))
57         $_POST['bank_account'] = "";
58
59 $result = get_bank_trans_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate'], $_POST['TransToDate']);     
60
61 div_start('trans_tbl');
62 $act = get_bank_account($_POST["bank_account"]);
63 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
64
65 start_table($table_style);
66
67 $th = array(_("Type"), _("#"), _("Reference"), _("Date"),
68         _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), "");
69 table_header($th);
70
71 $bfw = get_balance_before_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate']);
72
73 start_row("class='inquirybg'");
74 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransAfterDate']."</b>", "colspan=4");
75 display_debit_or_credit_cells($bfw);
76 label_cell("");
77 label_cell("", "colspan=2");
78
79 end_row();
80 $running_total = $bfw;
81 $j = 1;
82 $k = 0; //row colour counter
83 while ($myrow = db_fetch($result))
84 {
85
86         alt_table_row_color($k);
87
88         $running_total += $myrow["amount"];
89
90         $trandate = sql2date($myrow["trans_date"]);
91         label_cell($systypes_array[$myrow["type"]]);
92         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
93         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
94         label_cell($trandate);
95         display_debit_or_credit_cells($myrow["amount"]);
96         amount_cell($running_total);
97         label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
98         label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
99         end_row();
100
101         if ($j == 12)
102         {
103                 $j = 1;
104                 table_header($th);
105         }
106         $j++;
107 }
108 //end of while loop
109
110 start_row("class='inquirybg'");
111 label_cell("<b>" . _("Ending Balance")." - ". $_POST['TransToDate']. "</b>", "colspan=4");
112 display_debit_or_credit_cells($running_total);
113 label_cell("");
114 label_cell("", "colspan=2");
115 end_row();
116 end_table(2);
117 div_end();
118 //------------------------------------------------------------------------------------------------
119
120 end_page();
121
122 ?>