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;
33 //----------------------------------------------------------------------------------------------------
38 $Ajax->activate('balance_tbl');
42 function gl_inquiry_controls()
44 $dim = get_company_pref('use_dimension');
47 start_table(TABLESTYLE_NOBORDER);
49 date_cells(_("From:"), 'TransFromDate', '', null, -30);
50 date_cells(_("To:"), 'TransToDate');
52 dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
54 dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
55 check_cells(_("No zero values"), 'NoZero', null);
56 check_cells(_("Only balances"), 'Balance', null);
58 submit_cells('Show',_("Show"),'','', 'default');
63 //----------------------------------------------------------------------------------------------------
65 function display_trial_balance($type, $typename)
69 global $k, $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
70 $printtitle = 0; //Flag for printing type name
74 //Get Accounts directly under this group/type
75 $accounts = get_gl_accounts(null, null, $type);
77 $begin = get_fiscalyear_begin_for_date($_POST['TransFromDate']);
78 if (date1_greater_date2($begin, $_POST['TransFromDate']))
79 $begin = $_POST['TransFromDate'];
80 $begin = add_days($begin, -1);
82 while ($account = db_fetch($accounts))
84 //Print Type Title if it has atleast one non-zero account
87 start_row("class='inquirybg' style='font-weight:bold'");
88 label_cell(_("Group")." - ".$type ." - ".$typename, "colspan=8");
93 $prev = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransFromDate'], false, false);
94 $curr = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
95 $tot = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransToDate'], false, true);
96 if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
98 alt_table_row_color($k);
100 $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>";
103 label_cell($account["account_name"]);
104 if (check_value('Balance'))
106 display_debit_or_credit_cells($prev['balance']);
107 display_debit_or_credit_cells($curr['balance']);
108 display_debit_or_credit_cells($tot['balance']);
113 amount_cell($prev['debit']);
114 amount_cell($prev['credit']);
115 amount_cell($curr['debit']);
116 amount_cell($curr['credit']);
117 amount_cell($tot['debit']);
118 amount_cell($tot['credit']);
119 $pdeb += $prev['debit'];
120 $pcre += $prev['credit'];
121 $cdeb += $curr['debit'];
122 $ccre += $curr['credit'];
123 $tdeb += $tot['debit'];
124 $tcre += $tot['credit'];
126 $pbal += $prev['balance'];
127 $cbal += $curr['balance'];
128 $tbal += $tot['balance'];
132 //Get Account groups/types under this group/type
133 $result = get_account_types(false, false, $type);
134 while ($accounttype=db_fetch($result))
136 //Print Type Title if has sub types and not previously printed
139 start_row("class='inquirybg' style='font-weight:bold'");
140 label_cell(_("Group")." - ".$type ." - ".$typename, "colspan=8");
145 display_trial_balance($accounttype["id"], $accounttype["name"].' ('.$typename.')');
149 //----------------------------------------------------------------------------------------------------
151 gl_inquiry_controls();
153 if (isset($_POST['TransFromDate']))
155 $row = get_current_fiscalyear();
156 if (date1_greater_date2($_POST['TransFromDate'], sql2date($row['end'])))
158 display_error(_("The from date cannot be bigger than the fiscal year end."));
159 set_focus('TransFromDate');
163 div_start('balance_tbl');
164 if (!isset($_POST['Dimension']))
165 $_POST['Dimension'] = 0;
166 if (!isset($_POST['Dimension2']))
167 $_POST['Dimension2'] = 0;
168 start_table(TABLESTYLE);
170 <td rowspan=2 class='tableheader'>" . _("Account") . "</td>
171 <td rowspan=2 class='tableheader'>" . _("Account Name") . "</td>
172 <td colspan=2 class='tableheader'>" . _("Brought Forward") . "</td>
173 <td colspan=2 class='tableheader'>" . _("This Period") . "</td>
174 <td colspan=2 class='tableheader'>" . _("Balance") . "</td>
176 <td class='tableheader'>" . _("Debit") . "</td>
177 <td class='tableheader'>" . _("Credit") . "</td>
178 <td class='tableheader'>" . _("Debit") . "</td>
179 <td class='tableheader'>" . _("Credit") . "</td>
180 <td class='tableheader'>" . _("Debit") . "</td>
181 <td class='tableheader'>" . _("Credit") . "</td>
186 //display_trial_balance();
188 $classresult = get_account_classes(false);
189 while ($class = db_fetch($classresult))
191 start_row("class='inquirybg' style='font-weight:bold'");
192 label_cell(_("Class")." - ".$class['cid'] ." - ".$class['class_name'], "colspan=8");
195 //Get Account groups/types under this group/type with no parents
196 $typeresult = get_account_types(false, $class['cid'], -1);
197 while ($accounttype=db_fetch($typeresult))
199 display_trial_balance($accounttype["id"], $accounttype["name"]);
203 //$prev = get_balance(null, $begin, $_POST['TransFromDate'], false, false);
204 //$curr = get_balance(null, $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
205 //$tot = get_balance(null, $begin, $_POST['TransToDate'], false, true);
206 if (!check_value('Balance'))
208 start_row("class='inquirybg' style='font-weight:bold'");
209 label_cell(_("Total") ." - ".$_POST['TransToDate'], "colspan=2");
218 start_row("class='inquirybg' style='font-weight:bold'");
219 label_cell(_("Ending Balance") ." - ".$_POST['TransToDate'], "colspan=2");
220 display_debit_or_credit_cells($pbal);
221 display_debit_or_credit_cells($cbal);
222 display_debit_or_credit_cells($tbal);
226 if (($pbal = round2($pbal, user_price_dec())) != 0 && $_POST['Dimension'] == 0 && $_POST['Dimension2'] == 0)
227 display_warning(_("The Opening Balance is not in balance, probably due to a non closed Previous Fiscalyear."));
230 //----------------------------------------------------------------------------------------------------