Changed API for input/lists functions, added empty hints when needed
[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
25 start_form();
26
27 start_table("class='tablestyle_noborder'");
28 start_row();
29 bank_accounts_list_cells(_("Account:"), 'bank_account', null);
30
31 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
32 date_cells(_("To:"), 'TransToDate');
33
34 submit_cells('Show',_("Show"));
35 end_row();
36 end_table();
37 end_form();
38
39 //------------------------------------------------------------------------------------------------
40
41
42 $date_after = date2sql($_POST['TransAfterDate']);
43 $date_to = date2sql($_POST['TransToDate']);
44 if (!isset($_POST['bank_account']))
45         $_POST['bank_account'] = "";
46 $sql = "SELECT ".TB_PREF."bank_trans.*,name AS BankTransType FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_trans_types
47         WHERE ".TB_PREF."bank_trans.bank_act = '" . $_POST['bank_account'] . "'
48         AND trans_date >= '$date_after'
49         AND trans_date <= '$date_to'
50         AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
51         ORDER BY trans_date,".TB_PREF."bank_trans.id";
52
53 $result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
54
55 $act = get_bank_account($_POST["bank_account"]);
56 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
57
58 start_table($table_style);
59
60 $th = array(_("Type"), _("#"), _("Reference"), _("Type"), _("Date"),
61         _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), "");
62 table_header($th);      
63
64 $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act='" . $_POST['bank_account'] . "'
65         AND trans_date < '$date_after'";
66 $before_qty = db_query($sql, "The starting balance on hand could not be calculated");
67
68 start_row("class='inquirybg'");
69 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransAfterDate']."</b>", "colspan=5");
70 $bfw_row = db_fetch_row($before_qty);
71 $bfw = $bfw_row[0];
72 display_debit_or_credit_cells($bfw);
73 label_cell("");
74
75 end_row();
76 $running_total = $bfw;
77 $j = 1;
78 $k = 0; //row colour counter
79 while ($myrow = db_fetch($result)) 
80 {
81
82         alt_table_row_color($k);
83
84         $running_total += $myrow["amount"];
85
86         $trandate = sql2date($myrow["trans_date"]);
87         label_cell(systypes::name($myrow["type"]));
88         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
89         label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
90         label_cell($myrow["BankTransType"]);
91         label_cell($trandate);
92         display_debit_or_credit_cells($myrow["amount"]);
93         amount_cell($running_total);
94         label_cell(payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"]));
95         label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
96         end_row();
97
98         if ($j == 12)
99         {
100                 $j = 1;
101                 table_header($th);      
102         }
103         $j++;
104 }
105 //end of while loop
106
107 start_row("class='inquirybg'");
108 label_cell("<b>" . _("Ending Balance")." - ". $_POST['TransToDate']. "</b>", "colspan=5");
109 display_debit_or_credit_cells($running_total);
110 label_cell("");
111 end_row();
112 end_table(2);
113
114 //------------------------------------------------------------------------------------------------
115
116 end_page();
117
118 ?>