9c627670b8e5a3681888936413fa3863a66d7cbc
[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 = 8;
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 = '" . $_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='" . $_POST['bank_account'] . "'
80         AND trans_date < '$date_after'";
81 $before_qty = db_query($sql, "The starting balance on hand could not be calculated");
82
83 start_row("class='inquirybg'");
84 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransAfterDate']."</b>", "colspan=4");
85 $bfw_row = db_fetch_row($before_qty);
86 $bfw = $bfw_row[0];
87 display_debit_or_credit_cells($bfw);
88 label_cell("");
89 label_cell("", "colspan=2");
90
91 end_row();
92 $running_total = $bfw;
93 $j = 1;
94 $k = 0; //row colour counter
95 while ($myrow = db_fetch($result))
96 {
97
98         alt_table_row_color($k);
99
100         $running_total += $myrow["amount"];
101
102         $trandate = sql2date($myrow["trans_date"]);
103         label_cell(systypes::name($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_types::person_name($myrow["person_type_id"],$myrow["person_id"]));
110         label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
111         end_row();
112
113         if ($j == 12)
114         {
115                 $j = 1;
116                 table_header($th);
117         }
118         $j++;
119 }
120 //end of while loop
121
122 start_row("class='inquirybg'");
123 label_cell("<b>" . _("Ending Balance")." - ". $_POST['TransToDate']. "</b>", "colspan=4");
124 display_debit_or_credit_cells($running_total);
125 label_cell("");
126 label_cell("", "colspan=2");
127 end_row();
128 end_table(2);
129 div_end();
130 //------------------------------------------------------------------------------------------------
131
132 end_page();
133
134 ?>