2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_GLANALYTIC';
13 $path_to_root="../..";
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/ui.inc");
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
20 include_once($path_to_root . "/includes/data_checks.inc");
22 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 $js = get_js_date_picker();
28 page(_($help_context = "Trial Balance"), false, false, "", $js);
31 $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
\r
32 $cls_pdeb = $cls_pcre = $cls_cdeb = $cls_ccre = $cls_tdeb = $cls_tcre = $cls_pbal = $cls_cbal = $cls_tbal = 0;
\r
33 $grp_pdeb = $grp_pcre = $grp_cdeb = $grp_ccre = $grp_tdeb = $grp_tcre = $grp_pbal = $grp_cbal = $grp_tbal = 0;
\r
35 //----------------------------------------------------------------------------------------------------
40 $Ajax->activate('balance_tbl');
44 function gl_inquiry_controls()
46 $dim = get_company_pref('use_dimension');
49 start_table(TABLESTYLE_NOBORDER);
51 date_cells(_("From:"), 'TransFromDate', '', null, -30);
52 date_cells(_("To:"), 'TransToDate');
54 dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
56 dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
57 check_cells(_("No zero values"), 'NoZero', null);
58 check_cells(_("Only balances"), 'Balance', null);
60 submit_cells('Show',_("Show"),'','', 'default');
65 //----------------------------------------------------------------------------------------------------
67 function display_trial_balance($type, $typename)
\r
71 global $k, $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
\r
72 $printtitle = 0; //Flag for printing type name
\r
76 //$accounts = get_gl_accounts();
\r
77 //Get Accounts directly under this group/type
\r
78 $accounts = get_gl_accounts(null, null, $type);
\r
80 $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
81 $begin = begin_fiscalyear();
82 if (date1_greater_date2($begin, $_POST['TransFromDate']))
83 $begin = $_POST['TransFromDate'];
84 $begin = add_days($begin, -1);
86 while ($account = db_fetch($accounts))
88 //Print Type Title if it has atleast one non-zero account
\r
91 start_row("class='inquirybg' style='font-weight:bold'");
\r
92 label_cell("Group - ".$type ." - ".$typename, "colspan=8");
\r
97 $prev = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransFromDate'], false, false);
98 $curr = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
99 $tot = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransToDate'], false, true);
100 if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
102 alt_table_row_color($k);
104 $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "&Dimension=" . $_POST["Dimension"] . "&Dimension2=" . $_POST["Dimension2"] . "'>" . $account["account_code"] . "</a>";
107 label_cell($account["account_name"]);
108 if (check_value('Balance'))
110 display_debit_or_credit_cells($prev['balance']);
111 display_debit_or_credit_cells($curr['balance']);
112 display_debit_or_credit_cells($tot['balance']);
117 amount_cell($prev['debit']);
118 amount_cell($prev['credit']);
119 amount_cell($curr['debit']);
120 amount_cell($curr['credit']);
121 amount_cell($tot['debit']);
122 amount_cell($tot['credit']);
123 $pdeb += $prev['debit'];
124 $pcre += $prev['credit'];
125 $cdeb += $curr['debit'];
126 $ccre += $curr['credit'];
127 $tdeb += $tot['debit'];
128 $tcre += $tot['credit'];
130 $pbal += $prev['balance'];
131 $cbal += $curr['balance'];
132 $tbal += $tot['balance'];
136 //Get Account groups/types under this group/type
\r
137 $result = get_account_types(false, false, $type);
\r
138 while ($accounttype=db_fetch($result))
\r
140 //Print Type Title if has sub types and not previously printed
\r
143 start_row("class='inquirybg' style='font-weight:bold'");
\r
144 label_cell("Group - ".$type ." - ".$typename, "colspan=8");
\r
148 display_trial_balance($accounttype["id"], $accounttype["name"].' ('.$typename.')');
\r
152 //----------------------------------------------------------------------------------------------------
\r
154 gl_inquiry_controls();
\r
156 if (isset($_POST['TransFromDate']))
\r
158 $row = get_current_fiscalyear();
\r
159 if (date1_greater_date2($_POST['TransFromDate'], sql2date($row['end'])))
\r
161 display_error(_("The from date cannot be bigger than the fiscal year end."));
\r
162 set_focus('TransFromDate');
\r
166 div_start('balance_tbl');
\r
167 if (!isset($_POST['Dimension']))
\r
168 $_POST['Dimension'] = 0;
\r
169 if (!isset($_POST['Dimension2']))
\r
170 $_POST['Dimension2'] = 0;
\r
171 start_table(TABLESTYLE);
\r
172 $tableheader = "<tr>
\r
173 <td rowspan=2 class='tableheader'>" . _("Account") . "</td>
\r
174 <td rowspan=2 class='tableheader'>" . _("Account Name") . "</td>
\r
175 <td colspan=2 class='tableheader'>" . _("Brought Forward") . "</td>
\r
176 <td colspan=2 class='tableheader'>" . _("This Period") . "</td>
\r
177 <td colspan=2 class='tableheader'>" . _("Balance") . "</td>
\r
179 <td class='tableheader'>" . _("Debit") . "</td>
\r
180 <td class='tableheader'>" . _("Credit") . "</td>
\r
181 <td class='tableheader'>" . _("Debit") . "</td>
\r
182 <td class='tableheader'>" . _("Credit") . "</td>
\r
183 <td class='tableheader'>" . _("Debit") . "</td>
\r
184 <td class='tableheader'>" . _("Credit") . "</td>
\r
189 //display_trial_balance();
\r
191 $classresult = get_account_classes(false);
\r
192 while ($class = db_fetch($classresult))
\r
194 start_row("class='inquirybg' style='font-weight:bold'");
\r
195 label_cell("Class - ".$class['cid'] ." - ".$class['class_name'], "colspan=8");
\r
198 //Get Account groups/types under this group/type with no parents
\r
199 $typeresult = get_account_types(false, $class['cid'], -1);
\r
200 while ($accounttype=db_fetch($typeresult))
\r
202 display_trial_balance($accounttype["id"], $accounttype["name"]);
\r
206 //$prev = get_balance(null, $begin, $_POST['TransFromDate'], false, false);
207 //$curr = get_balance(null, $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
208 //$tot = get_balance(null, $begin, $_POST['TransToDate'], false, true);
209 if (!check_value('Balance'))
211 start_row("class='inquirybg' style='font-weight:bold'");
212 label_cell(_("Total") ." - ".$_POST['TransToDate'], "colspan=2");
221 start_row("class='inquirybg' style='font-weight:bold'");
222 label_cell(_("Ending Balance") ." - ".$_POST['TransToDate'], "colspan=2");
223 display_debit_or_credit_cells($pbal);
224 display_debit_or_credit_cells($cbal);
225 display_debit_or_credit_cells($tbal);
229 if (($pbal = round2($pbal, user_price_dec())) != 0)
230 //display_warning(_("The Opening Balance is not in balance, probably due to a non closed Previous Fiscalyear."));
\r
233 //----------------------------------------------------------------------------------------------------