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 //-----------------------------------------------------------------------------------
28 $Ajax->activate('trans_tbl');
30 //------------------------------------------------------------------------------------------------
33 start_table("class='tablestyle_noborder'");
35 bank_accounts_list_cells(_("Account:"), 'bank_account', null);
37 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
38 date_cells(_("To:"), 'TransToDate');
40 submit_cells('Show',_("Show"),'','', true);
45 //------------------------------------------------------------------------------------------------
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.*,name AS BankTransType FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_trans_types
53 WHERE ".TB_PREF."bank_trans.bank_act = '" . $_POST['bank_account'] . "'
54 AND trans_date >= '$date_after'
55 AND trans_date <= '$date_to'
56 AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
57 ORDER BY trans_date,".TB_PREF."bank_trans.id";
59 $result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
61 div_start('trans_tbl');
62 $act = get_bank_account($_POST["bank_account"]);
63 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
65 start_table($table_style);
67 $th = array(_("Type"), _("#"), _("Reference"), _("Type"), _("Date"),
68 _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), "");
71 $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act='" . $_POST['bank_account'] . "'
72 AND trans_date < '$date_after'";
73 $before_qty = db_query($sql, "The starting balance on hand could not be calculated");
75 start_row("class='inquirybg'");
76 label_cell("<b>"._("Opening Balance")." - ".$_POST['TransAfterDate']."</b>", "colspan=5");
77 $bfw_row = db_fetch_row($before_qty);
79 display_debit_or_credit_cells($bfw);
83 $running_total = $bfw;
85 $k = 0; //row colour counter
86 while ($myrow = db_fetch($result))
89 alt_table_row_color($k);
91 $running_total += $myrow["amount"];
93 $trandate = sql2date($myrow["trans_date"]);
94 label_cell(systypes::name($myrow["type"]));
95 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
96 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
97 label_cell($myrow["BankTransType"]);
98 label_cell($trandate);
99 display_debit_or_credit_cells($myrow["amount"]);
100 amount_cell($running_total);
101 label_cell(payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"]));
102 label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
114 start_row("class='inquirybg'");
115 label_cell("<b>" . _("Ending Balance")." - ". $_POST['TransToDate']. "</b>", "colspan=5");
116 display_debit_or_credit_cells($running_total);
121 //------------------------------------------------------------------------------------------------