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