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["AccGrp"]))
42 $_POST["AccGrp"] = $_GET["AccGrp"];
44 //----------------------------------------------------------------------------------------------------
46 function display_type ($type, $typename, $from, $to, $convert, $drilldown, $path_to_root)
50 $dimension = $dimension2 = 0;
54 //Get Accounts directly under this group/type
55 $result = get_gl_accounts(null, null, $type);
57 while ($account=db_fetch($result))
59 $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
60 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
61 if (!$prev_balance && !$curr_balance)
64 if ($drilldown && $levelptr == 0)
66 $url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?TransFromDate="
67 . $from . "&TransToDate=" . $to
68 . "&account=" . $account['account_code'] . "'>" . $account['account_code']
69 ." ". $account['account_name'] ."</a>";
71 start_row("class='stockmankobg'");
73 amount_cell(($curr_balance + $prev_balance) * $convert);
77 $acctstotal += $curr_balance + $prev_balance;
82 //Get Account groups/types under this group/type
83 $result = get_account_types(false, false, $type);
84 while ($accounttype=db_fetch($result))
86 $typestotal += display_type($accounttype["id"], $accounttype["name"], $from, $to,
87 $convert, $drilldown, $path_to_root);
90 //Display Type Summary if total is != 0
91 if (($acctstotal + $typestotal) != 0)
93 if ($drilldown && $type == $_POST["AccGrp"])
95 start_row("class='inquirybg' style='font-weight:bold'");
96 label_cell(_('Total') . " " . $typename);
97 amount_cell(($acctstotal + $typestotal) * $convert);
100 elseif ($drilldown && $type != $_POST["AccGrp"])
102 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
103 . $from . "&TransToDate=" . $to
104 . "&AccGrp=" . $type ."'>" . $typename ."</a>";
106 alt_table_row_color($k);
108 amount_cell(($acctstotal + $typestotal) * $convert);
112 return ($acctstotal + $typestotal);
115 function inquiry_controls()
117 start_table("class='tablestyle_noborder'");
118 date_cells(_("As at:"), 'TransToDate');
119 submit_cells('Show',_("Show"),'','', 'default');
122 hidden('TransFromDate');
126 function display_balance_sheet()
128 global $comp_path, $path_to_root, $table_style;
130 $from = begin_fiscalyear();
131 $to = $_POST['TransToDate'];
133 $dim = get_company_pref('use_dimension');
134 $dimension = $dimension2 = 0;
135 $lconvert = $econvert = 1;
136 if (isset($_POST["AccGrp"]) && (strlen($_POST['AccGrp']) > 0))
137 $drilldown = 1; // Deeper Level
139 $drilldown = 0; // Root level
141 div_start('balance_tbl');
143 start_table("width=30% $table_style");
145 if (!$drilldown) //Root Level
149 $calculateclose = 0.0;
154 $classresult = get_account_classes(false, 1);
156 while ($class = db_fetch($classresult))
159 $convert = get_class_type_convert($class["ctype"]);
160 $ctype = $class["ctype"];
161 $classname = $class["class_name"];
164 table_section_title($class["class_name"]);
166 //Get Account groups/types under this group/type
167 $typeresult = get_account_types(false, $class['cid'], -1);
169 while ($accounttype=db_fetch($typeresult))
171 $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to,
172 $convert, $drilldown, $path_to_root);
174 if ($TypeTotal != 0 )
176 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
177 . $from . "&TransToDate=" . $to . "&AccGrp=" . $accounttype['id'] ."'>" . $accounttype['name'] ."</a>";
178 alt_table_row_color($k);
180 amount_cell($TypeTotal * $convert);
183 $classclose += $TypeTotal;
186 //Print Class Summary
187 start_row("class='inquirybg' style='font-weight:bold'");
188 label_cell(_('Total') . " " . $class["class_name"]);
189 amount_cell($classclose * $convert);
192 if ($ctype == CL_EQUITY)
194 $equityclose += $classclose;
195 $econvert = $convert;
197 if ($ctype == CL_LIABILITIES)
199 $lclose += $classclose;
200 $lconvert = $convert;
203 $calculateclose += $classclose;
207 $calculateclose *= -1;
208 //Final Report Summary
209 $url = "<a href='$path_to_root/gl/inquiry/profit_loss.php?TransFromDate="
210 . $from."&TransToDate=".$to
211 ."&Compare=0'>"._('Calculated Return')."</a>";
213 start_row("class='inquirybg' style='font-weight:bold'");
215 amount_cell($calculateclose);
218 start_row("class='inquirybg' style='font-weight:bold'");
219 label_cell(_('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
220 amount_cell($lclose * $lconvert + $equityclose * $econvert + $calculateclose);
225 //Level Pointer : Global variable defined in order to control display of root
229 $accounttype = get_account_type($_POST["AccGrp"]);
230 $classid = $accounttype["class_id"];
231 $class = get_account_class($classid);
232 $convert = get_class_type_convert($class["ctype"]);
235 table_section_title(get_account_type_name($_POST["AccGrp"]));
237 $classclose = display_type($accounttype["id"], $accounttype["name"], $from, $to,
238 $convert, $drilldown, $path_to_root);
241 end_table(1); // outer table
245 //----------------------------------------------------------------------------------------------------
251 display_balance_sheet();