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 $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
63 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
64 if (!$prev_balance && !$curr_balance)
67 if ($drilldown && $levelptr == 0)
69 $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?TransFromDate="
70 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
71 . "&account=" . $account['account_code'] . "'>" . $account['account_code']
72 ." ". $account['account_name'] ."</a>";
74 start_row("class='stockmankobg'");
76 amount_cell(($curr_balance + $prev_balance) * $convert);
80 $acctstotal += $curr_balance + $prev_balance;
85 //Get Account groups/types under this group/type
86 $result = get_account_types(false, false, $type);
87 while ($accounttype=db_fetch($result))
89 $typestotal += display_type($accounttype["id"], $accounttype["name"], $from, $to,
90 $convert, $dimension, $dimension2, $drilldown, $path_to_root);
93 //Display Type Summary if total is != 0
94 if (($acctstotal + $typestotal) != 0)
96 if ($drilldown && $type == $_POST["AccGrp"])
98 start_row("class='inquirybg' style='font-weight:bold'");
99 label_cell(_('Total') . " " . $typename);
100 amount_cell(($acctstotal + $typestotal) * $convert);
103 //START Patch#1 : Display only direct child types
104 $acctype1 = get_account_type($type);
105 $parent1 = $acctype1["parent"];
106 if ($drilldown && $parent1 == $_POST["AccGrp"])
108 //elseif ($drilldown && $type != $_POST["AccGrp"])
110 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
111 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
112 . "&AccGrp=" . $type ."'>" . $type . " " . $typename ."</a>";
114 alt_table_row_color($k);
116 amount_cell(($acctstotal + $typestotal) * $convert);
120 return ($acctstotal + $typestotal);
123 function inquiry_controls()
125 $dim = get_company_pref('use_dimension');
126 start_table(TABLESTYLE_NOBORDER);
127 date_cells(_("As at:"), 'TransToDate');
129 dimensions_list_cells(_("Dimension")." 1:", 'Dimension', null, true, " ", false, 1);
131 dimensions_list_cells(_("Dimension")." 2:", 'Dimension2', null, true, " ", false, 2);
132 submit_cells('Show',_("Show"),'','', 'default');
135 hidden('TransFromDate');
139 function display_balance_sheet()
141 global $path_to_root;
143 $from = begin_fiscalyear();
144 $to = $_POST['TransToDate'];
146 if (!isset($_POST['Dimension']))
147 $_POST['Dimension'] = 0;
148 if (!isset($_POST['Dimension2']))
149 $_POST['Dimension2'] = 0;
150 $dimension = $_POST['Dimension'];
151 $dimension2 = $_POST['Dimension2'];
152 $lconvert = $econvert = 1;
153 if (isset($_POST["AccGrp"]) && (strlen($_POST['AccGrp']) > 0))
154 $drilldown = 1; // Deeper Level
156 $drilldown = 0; // Root level
158 div_start('balance_tbl');
160 start_table(TABLESTYLE, "width=30%");
162 if (!$drilldown) //Root Level
166 $calculateclose = 0.0;
171 $classresult = get_account_classes(false, 1);
173 while ($class = db_fetch($classresult))
176 $convert = get_class_type_convert($class["ctype"]);
177 $ctype = $class["ctype"];
178 $classname = $class["class_name"];
181 table_section_title($class["class_name"]);
183 //Get Account groups/types under this group/type
184 $typeresult = get_account_types(false, $class['cid'], -1);
186 while ($accounttype=db_fetch($typeresult))
188 $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to,
189 $convert, $dimension, $dimension2, $drilldown, $path_to_root);
191 if ($TypeTotal != 0 )
193 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
194 . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
195 . "&AccGrp=" . $accounttype['id'] ."'>" . $accounttype['id']." ".$accounttype['name'] ."</a>";
196 alt_table_row_color($k);
198 amount_cell($TypeTotal * $convert);
201 $classclose += $TypeTotal;
204 //Print Class Summary
205 start_row("class='inquirybg' style='font-weight:bold'");
206 label_cell(_('Total') . " " . $class["class_name"]);
207 amount_cell($classclose * $convert);
210 if ($ctype == CL_EQUITY)
212 $equityclose += $classclose;
213 $econvert = $convert;
215 if ($ctype == CL_LIABILITIES)
217 $lclose += $classclose;
218 $lconvert = $convert;
221 $calculateclose += $classclose;
225 $calculateclose *= -1;
226 //Final Report Summary
227 $url = "<a href='$path_to_root/gl/inquiry/profit_loss.php?TransFromDate="
228 . $from."&TransToDate=".$to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2
229 ."&Compare=0'>"._('Calculated Return')."</a>";
231 start_row("class='inquirybg' style='font-weight:bold'");
233 amount_cell($calculateclose);
236 start_row("class='inquirybg' style='font-weight:bold'");
237 label_cell(_('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
238 amount_cell($lclose * $lconvert + $equityclose * $econvert + $calculateclose);
243 //Level Pointer : Global variable defined in order to control display of root
247 $accounttype = get_account_type($_POST["AccGrp"]);
248 $classid = $accounttype["class_id"];
249 $class = get_account_class($classid);
250 $convert = get_class_type_convert($class["ctype"]);
253 table_section_title($_POST["AccGrp"]. " " . get_account_type_name($_POST["AccGrp"]));
255 $classclose = display_type($accounttype["id"], $accounttype["name"], $from, $to,
256 $convert, $dimension, $dimension2, $drilldown, $path_to_root);
259 end_table(1); // outer table
263 //----------------------------------------------------------------------------------------------------
269 display_balance_sheet();