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");
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, $path_to_root)
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, $path_to_root);
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"])
107 //elseif ($drilldown && $type != $_POST["AccGrp"])
109 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
110 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
111 . "&AccGrp=" . $type ."'>" . $type . " " . $typename ."</a>";
113 alt_table_row_color($k);
115 amount_cell(($acctstotal + $typestotal) * $convert);
119 return ($acctstotal + $typestotal);
122 function inquiry_controls()
124 $dim = get_company_pref('use_dimension');
125 start_table(TABLESTYLE_NOBORDER);
126 date_cells(_("As at:"), 'TransToDate');
128 dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
130 dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
131 submit_cells('Show',_("Show"),'','', 'default');
134 hidden('TransFromDate');
138 function display_balance_sheet()
140 global $path_to_root;
142 $from = begin_fiscalyear();
143 $to = $_POST['TransToDate'];
145 if (!isset($_POST['Dimension']))
146 $_POST['Dimension'] = 0;
147 if (!isset($_POST['Dimension2']))
148 $_POST['Dimension2'] = 0;
149 $dimension = $_POST['Dimension'];
150 $dimension2 = $_POST['Dimension2'];
151 $lconvert = $econvert = 1;
152 if (isset($_POST["AccGrp"]) && (strlen($_POST['AccGrp']) > 0))
153 $drilldown = 1; // Deeper Level
155 $drilldown = 0; // Root level
157 div_start('balance_tbl');
159 start_table(TABLESTYLE, "width='30%'");
161 if (!$drilldown) //Root Level
165 $calculateclose = 0.0;
170 $classresult = get_account_classes(false, 1);
172 while ($class = db_fetch($classresult))
175 $convert = get_class_type_convert($class["ctype"]);
176 $ctype = $class["ctype"];
177 $classname = $class["class_name"];
180 table_section_title($class["class_name"]);
182 //Get Account groups/types under this group/type
183 $typeresult = get_account_types(false, $class['cid'], -1);
185 while ($accounttype=db_fetch($typeresult))
187 $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to,
188 $convert, $dimension, $dimension2, $drilldown, $path_to_root);
190 if ($TypeTotal != 0 )
192 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
193 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
194 . "&AccGrp=" . $accounttype['id'] ."'>" . $accounttype['id']." ".$accounttype['name'] ."</a>";
195 alt_table_row_color($k);
197 amount_cell($TypeTotal * $convert);
200 $classclose += $TypeTotal;
203 //Print Class Summary
204 start_row("class='inquirybg' style='font-weight:bold'");
205 label_cell(_('Total') . " " . $class["class_name"]);
206 amount_cell($classclose * $convert);
209 if ($ctype == CL_EQUITY)
211 $equityclose += $classclose;
212 $econvert = $convert;
214 if ($ctype == CL_LIABILITIES)
216 $lclose += $classclose;
217 $lconvert = $convert;
220 $calculateclose += $classclose;
224 $calculateclose *= -1;
225 //Final Report Summary
226 $url = "<a href='$path_to_root/gl/inquiry/profit_loss.php?TransFromDate="
227 . $from."&TransToDate=".$to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
228 ."&Compare=0'>"._('Calculated Return')."</a>";
230 start_row("class='inquirybg' style='font-weight:bold'");
232 amount_cell($calculateclose);
235 start_row("class='inquirybg' style='font-weight:bold'");
236 label_cell(_('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
237 amount_cell($lclose * $lconvert + $equityclose * $econvert + $calculateclose);
242 //Level Pointer : Global variable defined in order to control display of root
246 $accounttype = get_account_type($_POST["AccGrp"]);
247 $classid = $accounttype["class_id"];
248 $class = get_account_class($classid);
249 $convert = get_class_type_convert($class["ctype"]);
252 table_section_title($_POST["AccGrp"]. " " . get_account_type_name($_POST["AccGrp"]));
254 $classclose = display_type($accounttype["id"], $accounttype["name"], $from, $to,
255 $convert, $dimension, $dimension2, $drilldown, $path_to_root);
258 end_table(1); // outer table
262 //----------------------------------------------------------------------------------------------------
268 display_balance_sheet();