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/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
24 if (user_use_date_picker())
25 $js = get_js_date_picker();
27 page(_($help_context = "Balance Sheet Drilldown"), false, false, "", $js);
29 //----------------------------------------------------------------------------------------------------
34 $Ajax->activate('balance_tbl');
37 if (isset($_GET["TransFromDate"]))
38 $_POST["TransFromDate"] = $_GET["TransFromDate"];
39 if (isset($_GET["TransToDate"]))
40 $_POST["TransToDate"] = $_GET["TransToDate"];
41 if (isset($_GET["Dimension"]))
42 $_POST["Dimension"] = $_GET["Dimension"];
43 if (isset($_GET["Dimension2"]))
44 $_POST["Dimension2"] = $_GET["Dimension2"];
45 if (isset($_GET["AccGrp"]))
46 $_POST["AccGrp"] = $_GET["AccGrp"];
48 //----------------------------------------------------------------------------------------------------
50 function display_type ($type, $typename, $from, $to, $convert, $dimension, $dimension2, $drilldown)
52 global $path_to_root, $levelptr, $k;
57 //Get Accounts directly under this group/type
58 $result = get_gl_accounts(null, null, $type);
60 while ($account=db_fetch($result))
62 $net_balance = get_gl_trans_from_to("", $to, $account["account_code"], $dimension, $dimension2);
66 if ($drilldown && $levelptr == 0)
68 $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?TransFromDate="
69 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
70 . "&account=" . $account['account_code'] . "'>" . $account['account_code']
71 ." ". $account['account_name'] ."</a>";
73 start_row("class='stockmankobg'");
75 amount_cell(($net_balance) * $convert);
79 $acctstotal += $net_balance;
84 //Get Account groups/types under this group/type
85 $result = get_account_types(false, false, $type);
86 while ($accounttype=db_fetch($result))
88 $typestotal += display_type($accounttype["id"], $accounttype["name"], $from, $to,
89 $convert, $dimension, $dimension2, $drilldown);
92 //Display Type Summary if total is != 0
93 if (($acctstotal + $typestotal) != 0)
95 if ($drilldown && $type == $_POST["AccGrp"])
97 start_row("class='inquirybg' style='font-weight:bold'");
98 label_cell(_('Total') . " " . $typename);
99 amount_cell(($acctstotal + $typestotal) * $convert);
102 //START Patch#1 : Display only direct child types
103 $acctype1 = get_account_type($type);
104 $parent1 = $acctype1["parent"];
105 if ($drilldown && $parent1 == $_POST["AccGrp"])
108 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
109 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
110 . "&AccGrp=" . $type ."'>" . $type . " " . $typename ."</a>";
112 alt_table_row_color($k);
114 amount_cell(($acctstotal + $typestotal) * $convert);
118 return ($acctstotal + $typestotal);
121 function inquiry_controls()
123 $dim = get_company_pref('use_dimension');
124 start_table(TABLESTYLE_NOBORDER);
125 date_cells(_("As at:"), 'TransToDate');
127 dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
129 dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
130 submit_cells('Show',_("Show"),'','', 'default');
133 hidden('TransFromDate');
137 function display_balance_sheet()
139 global $path_to_root;
141 $from = begin_fiscalyear();
142 $to = $_POST['TransToDate'];
144 if (!isset($_POST['Dimension']))
145 $_POST['Dimension'] = 0;
146 if (!isset($_POST['Dimension2']))
147 $_POST['Dimension2'] = 0;
148 $dimension = $_POST['Dimension'];
149 $dimension2 = $_POST['Dimension2'];
150 $lconvert = $econvert = 1;
151 if (isset($_POST["AccGrp"]) && (strlen($_POST['AccGrp']) > 0))
152 $drilldown = 1; // Deeper Level
154 $drilldown = 0; // Root level
156 div_start('balance_tbl');
158 start_table(TABLESTYLE, "width='30%'");
160 if (!$drilldown) //Root Level
164 $calculateclose = 0.0;
167 $classresult = get_account_classes(false, 1);
169 while ($class = db_fetch($classresult))
172 $convert = get_class_type_convert($class["ctype"]);
173 $ctype = $class["ctype"];
176 table_section_title($class["class_name"]);
178 //Get Account groups/types under this group/type
179 $typeresult = get_account_types(false, $class['cid'], -1);
182 while ($accounttype=db_fetch($typeresult))
184 $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to,
185 $convert, $dimension, $dimension2, $drilldown);
187 if ($TypeTotal != 0 )
189 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
190 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
191 . "&AccGrp=" . $accounttype['id'] ."'>" . $accounttype['id']." ".$accounttype['name'] ."</a>";
192 alt_table_row_color($k);
194 amount_cell($TypeTotal * $convert);
197 $classclose += $TypeTotal;
200 //Print Class Summary
201 start_row("class='inquirybg' style='font-weight:bold'");
202 label_cell(_('Total') . " " . $class["class_name"]);
203 amount_cell($classclose * $convert);
206 if ($ctype == CL_EQUITY)
208 $equityclose += $classclose;
209 $econvert = $convert;
211 if ($ctype == CL_LIABILITIES)
213 $lclose += $classclose;
214 $lconvert = $convert;
217 $calculateclose += $classclose;
221 $calculateclose *= -1;
222 //Final Report Summary
223 $url = "<a href='$path_to_root/gl/inquiry/profit_loss.php?TransFromDate="
224 . $from."&TransToDate=".$to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
225 ."&Compare=0'>"._('Calculated Return')."</a>";
227 start_row("class='inquirybg' style='font-weight:bold'");
229 amount_cell($calculateclose);
232 start_row("class='inquirybg' style='font-weight:bold'");
233 label_cell(_('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
234 amount_cell($lclose * $lconvert + $equityclose * $econvert + $calculateclose);
239 //Level Pointer : Global variable defined in order to control display of root
243 $accounttype = get_account_type($_POST["AccGrp"]);
244 $classid = $accounttype["class_id"];
245 $class = get_account_class($classid);
246 $convert = get_class_type_convert($class["ctype"]);
249 table_section_title($_POST["AccGrp"]. " " . get_account_type_name($_POST["AccGrp"]));
251 $classclose = display_type($accounttype["id"], $accounttype["name"], $from, $to,
252 $convert, $dimension, $dimension2, $drilldown);
255 end_table(1); // outer table
259 //----------------------------------------------------------------------------------------------------
265 display_balance_sheet();