6 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
12 include_once($path_to_root . "/gl/includes/gl_db.inc");
16 $js = get_js_date_picker();
18 page(_("Trial Balance"), false, false, "", $js);
20 //----------------------------------------------------------------------------------------------------
25 $Ajax->activate('balance_tbl');
29 function gl_inquiry_controls()
33 start_table("class='tablestyle_noborder'");
35 date_cells(_("From:"), 'TransFromDate', '', null, -30);
36 date_cells(_("To:"), 'TransToDate');
37 check_cells(_("No zero values"), 'NoZero', null);
39 submit_cells('Show',_("Show"),'','', true);
44 //----------------------------------------------------------------------------------------------------
46 function get_balance($account, $from, $to, $from_incl=true, $to_incl=true) {
48 $sql = "SELECT SUM(amount) As TransactionSum FROM ".TB_PREF."gl_trans
49 WHERE account='$account'";
53 $from_date = date2sql($from);
55 $sql .= " AND tran_date >= '$from_date'";
57 $sql .= " AND tran_date > '$from_date'";
62 $to_date = date2sql($to);
64 $sql .= " AND tran_date <= '$to_date' ";
66 $sql .= " AND tran_date < '$to_date' ";
69 $result = db_query($sql,"No general ledger accounts were returned");
71 $row = db_fetch_row($result);
75 //----------------------------------------------------------------------------------------------------
77 function display_trial_balance()
79 global $table_style, $path_to_root;
81 div_start('balance_tbl');
82 start_table($table_style);
84 <td rowspan=2 class='tableheader'>" . _("Account") . "</td>
85 <td rowspan=2 class='tableheader'>" . _("Account Name") . "</td>
86 <td colspan=2 class='tableheader'>" . _("Brought Forward") . "</td>
87 <td colspan=2 class='tableheader'>" . _("This Period") . "</td>
88 <td colspan=2 class='tableheader'>" . _("Balance") . "</td>
90 <td class='tableheader'>" . _("Debit") . "</td>
91 <td class='tableheader'>" . _("Credit") . "</td>
92 <td class='tableheader'>" . _("Debit") . "</td>
93 <td class='tableheader'>" . _("Credit") . "</td>
94 <td class='tableheader'>" . _("Debit") . "</td>
95 <td class='tableheader'>" . _("Credit") . "</td>
102 $totprev = $totcurr = 0.0;
103 $accounts = get_gl_accounts();
105 while ($account = db_fetch($accounts))
107 if (is_account_balancesheet($account["account_code"]))
111 $begin = begin_fiscalyear();
112 if (date1_greater_date2($begin, $_POST['TransFromDate']))
113 $begin = $_POST['TransFromDate'];
114 $begin = add_days($begin, -1);
116 $prev_balance = get_balance($account["account_code"], $begin, $_POST['TransFromDate'], false, false);
118 $curr_balance = get_balance($account["account_code"], $_POST['TransFromDate'], $_POST['TransToDate']);
119 if (check_value("NoZero") && !$prev_balance && !$curr_balance)
121 $totprev += $prev_balance;
122 $totcurr += $curr_balance;
123 alt_table_row_color($k);
125 $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?" . SID . "TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "'>" . $account["account_code"] . "</a>";
128 label_cell($account["account_name"]);
130 display_debit_or_credit_cells($prev_balance);
131 display_debit_or_credit_cells($curr_balance);
132 display_debit_or_credit_cells($prev_balance + $curr_balance);
135 start_row("class='inquirybg'");
136 label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=2");
137 display_debit_or_credit_cells($totprev);
138 display_debit_or_credit_cells($totcurr);
139 display_debit_or_credit_cells($totprev + $totcurr);
146 //----------------------------------------------------------------------------------------------------
148 gl_inquiry_controls();
150 display_trial_balance();
152 //----------------------------------------------------------------------------------------------------