5 include_once($path_to_root . "/includes/session.inc");
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");
11 include_once($path_to_root . "/gl/includes/gl_db.inc");
12 include_once($path_to_root . "/includes/banking.inc");
15 if ($use_popup_windows)
16 $js .= get_js_open_window(800, 500);
18 $js .= get_js_date_picker();
19 page(_("Bank Statement"), false, false, "", $js);
21 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
23 //------------------------------------------------------------------------------------------------
27 start_table("class='tablestyle_noborder'");
29 bank_accounts_list_cells(_("Account:"), 'bank_account', null);
31 date_cells(_("From:"), 'TransAfterDate', null, -30);
32 date_cells(_("To:"), 'TransToDate');
34 submit_cells('Show',_("Show"));
39 //------------------------------------------------------------------------------------------------
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";
53 $result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
55 $act = get_bank_account($_POST["bank_account"]);
56 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
58 start_table($table_style);
60 $th = array(_("Type"), _("#"), _("Reference"), _("Type"), _("Date"),
61 _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), "");
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");
68 start_row("class='inquirybg'");
69 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransAfterDate']."</b>", "colspan=5");
70 $bfw_row = db_fetch_row($before_qty);
72 display_debit_or_credit_cells($bfw);
76 $running_total = $bfw;
78 $k = 0; //row colour counter
79 while ($myrow = db_fetch($result))
82 alt_table_row_color($k);
84 $running_total += $myrow["amount"];
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"]));
107 start_row("class='inquirybg'");
108 label_cell("<b>" . _("Ending Balance")." - ". $_POST['TransToDate']. "</b>", "colspan=5");
109 display_debit_or_credit_cells($running_total);
114 //------------------------------------------------------------------------------------------------