Implemented attachments for Bank Account, and redesign of Bank Accounts to a tabbed...
[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/db_pager.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
20
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
22 include_once($path_to_root . "/includes/banking.inc");
23
24 $js = "";
25 if ($SysPrefs->use_popup_windows)
26         $js .= get_js_open_window(800, 500);
27 if (user_use_date_picker())
28         $js .= get_js_date_picker();
29 page(_($help_context = "Bank Account Inquiry"), isset($_GET['bank_account']) && !isset($_GET['TransAfterDate']), false, "", $js, false, "", true);
30
31 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
32
33 //-----------------------------------------------------------------------------------
34 // Ajax updates
35 //
36 if (get_post('Show'))
37 {
38         $Ajax->activate('trans_tbl');
39 }
40 //------------------------------------------------------------------------------------------------
41
42 if (isset($_GET['bank_account']))
43         $_POST['bank_account'] = $_GET['bank_account'];
44
45 start_form();
46 start_table(TABLESTYLE_NOBORDER);
47 start_row();
48 if (!$page_nested)
49         bank_accounts_list_cells(_("Account:"), 'bank_account', null);
50
51 date_cells(_("From:"), 'TransAfterDate', '', null, -user_transaction_days());
52 date_cells(_("To:"), 'TransToDate');
53
54 submit_cells('Show',_("Show"),'', '', 'default');
55 end_row();
56 end_table();
57 end_form();
58
59 //------------------------------------------------------------------------------------------------
60
61 if (!isset($_POST['bank_account']))
62         $_POST['bank_account'] = "";
63
64 $result = get_bank_trans_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate'], $_POST['TransToDate']);     
65
66 div_start('trans_tbl');
67 if (!$page_nested)
68 {
69         $act = get_bank_account($_POST["bank_account"]);
70         display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
71 }
72
73 start_table(TABLESTYLE);
74
75 $th = array(_("Type"), _("#"), _("Reference"), _("Date"),
76         _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), _("Memo"), "", "");
77 table_header($th);
78
79 $bfw = get_balance_before_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate']);
80
81 $credit = $debit = 0;
82 start_row("class='inquirybg' style='font-weight:bold'");
83 label_cell(_("Opening Balance")." - ".$_POST['TransAfterDate'], "colspan=4");
84 display_debit_or_credit_cells($bfw);
85 label_cell("");
86 label_cell("", "colspan=4");
87
88 end_row();
89 $running_total = $bfw;
90 if ($bfw > 0 ) 
91         $debit += $bfw;
92 else 
93         $credit += $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
111         label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
112
113         label_cell(get_comments_string($myrow["type"], $myrow["trans_no"]));
114         label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
115         if (!$page_nested)
116                 label_cell(trans_editor_link($myrow["type"], $myrow["trans_no"]));
117
118         end_row();
119         if ($myrow["amount"] > 0 ) 
120                 $debit += $myrow["amount"];
121         else 
122                 $credit += $myrow["amount"];
123
124         if ($j == 12)
125         {
126                 $j = 1;
127                 table_header($th);
128         }
129         $j++;
130 }
131 //end of while loop
132
133 start_row("class='inquirybg' style='font-weight:bold'");
134 label_cell(_("Ending Balance")." - ". $_POST['TransToDate'], "colspan=4");
135 amount_cell($debit);
136 amount_cell(-$credit);
137 //display_debit_or_credit_cells($running_total);
138 amount_cell($debit+$credit);
139 label_cell("", "colspan=4");
140 end_row();
141 end_table(2);
142 div_end();
143 //------------------------------------------------------------------------------------------------
144
145 end_page();
146