Merged changes form stable branch up to 2.3.13
[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"), isset($_GET['bank_account']), 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 if (isset($_GET['bank_account']))
42         $_POST['bank_account'] = $_GET['bank_account'];
43
44 start_form();
45 start_table(TABLESTYLE_NOBORDER);
46 start_row();
47 bank_accounts_list_cells(_("Account:"), 'bank_account', null);
48
49 date_cells(_("From:"), 'TransAfterDate', '', null, -$_SESSION["wa_current_user"]->prefs->transaction_days());
50 date_cells(_("To:"), 'TransToDate');
51
52 submit_cells('Show',_("Show"),'','', 'default');
53 end_row();
54 end_table();
55 end_form();
56
57 //------------------------------------------------------------------------------------------------
58
59 if (!isset($_POST['bank_account']))
60         $_POST['bank_account'] = "";
61
62 $result = get_bank_trans_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate'], $_POST['TransToDate']);     
63
64 div_start('trans_tbl');
65 $act = get_bank_account($_POST["bank_account"]);
66 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
67
68 start_table(TABLESTYLE);
69
70 $th = array(_("Type"), _("#"), _("Reference"), _("Date"),
71         _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), _("Memo"), "");
72 table_header($th);
73
74 $bfw = get_balance_before_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate']);
75
76 $credit = $debit = 0;
77 start_row("class='inquirybg' style='font-weight:bold'");
78 label_cell(_("Opening Balance")." - ".$_POST['TransAfterDate'], "colspan=4");
79 display_debit_or_credit_cells($bfw);
80 label_cell("");
81 label_cell("", "colspan=2");
82
83 end_row();
84 $running_total = $bfw;
85 if ($bfw > 0 ) 
86         $debit += $bfw;
87 else 
88         $credit += $bfw;
89 $j = 1;
90 $k = 0; //row colour counter
91 while ($myrow = db_fetch($result))
92 {
93
94         alt_table_row_color($k);
95
96         $running_total += $myrow["amount"];
97
98         $trandate = sql2date($myrow["trans_date"]);
99         label_cell($systypes_array[$myrow["type"]]);
100         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
101         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
102         label_cell($trandate);
103         display_debit_or_credit_cells($myrow["amount"]);
104         amount_cell($running_total);
105         label_cell(get_counterparty_name($myrow["type"], $myrow["trans_no"]));
106         label_cell(get_comments_string($myrow["type"], $myrow["trans_no"]));
107         label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
108         end_row();
109         if ($myrow["amount"] > 0 ) 
110                 $debit += $myrow["amount"];
111         else 
112                 $credit += $myrow["amount"];
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' style='font-weight:bold'");
124 label_cell(_("Ending Balance")." - ". $_POST['TransToDate'], "colspan=4");
125 amount_cell($debit);
126 amount_cell(-$credit);
127 //display_debit_or_credit_cells($running_total);
128 amount_cell($debit+$credit);
129 label_cell("");
130 label_cell("", "colspan=2");
131 end_row();
132 end_table(2);
133 div_end();
134 //------------------------------------------------------------------------------------------------
135
136 end_page();
137
138 ?>