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 //START Patch#1 : Display only direct child types
101 $acctype1 = get_account_type($type);
102 $parent1 = $acctype1["parent"];
103 if ($drilldown && $parent1 == $_POST["AccGrp"])
105 //elseif ($drilldown && $type != $_POST["AccGrp"])
107 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
108 . $from . "&TransToDate=" . $to
109 . "&AccGrp=" . $type ."'>" . $typename ."</a>";
111 alt_table_row_color($k);
113 amount_cell(($acctstotal + $typestotal) * $convert);
117 return ($acctstotal + $typestotal);
120 function inquiry_controls()
122 start_table(TABLESTYLE_NOBORDER);
123 date_cells(_("As at:"), 'TransToDate');
124 submit_cells('Show',_("Show"),'','', 'default');
127 hidden('TransFromDate');
131 function display_balance_sheet()
133 global $path_to_root;
135 $from = begin_fiscalyear();
136 $to = $_POST['TransToDate'];
138 $dim = get_company_pref('use_dimension');
139 $dimension = $dimension2 = 0;
140 $lconvert = $econvert = 1;
141 if (isset($_POST["AccGrp"]) && (strlen($_POST['AccGrp']) > 0))
142 $drilldown = 1; // Deeper Level
144 $drilldown = 0; // Root level
146 div_start('balance_tbl');
148 start_table(TABLESTYLE, "width=30%");
150 if (!$drilldown) //Root Level
154 $calculateclose = 0.0;
159 $classresult = get_account_classes(false, 1);
161 while ($class = db_fetch($classresult))
164 $convert = get_class_type_convert($class["ctype"]);
165 $ctype = $class["ctype"];
166 $classname = $class["class_name"];
169 table_section_title($class["class_name"]);
171 //Get Account groups/types under this group/type
172 $typeresult = get_account_types(false, $class['cid'], -1);
174 while ($accounttype=db_fetch($typeresult))
176 $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to,
177 $convert, $drilldown, $path_to_root);
179 if ($TypeTotal != 0 )
181 $url = "<a href='$path_to_root/gl/inquiry/balance_sheet.php?TransFromDate="
182 . $from . "&TransToDate=" . $to . "&AccGrp=" . $accounttype['id'] ."'>" . $accounttype['name'] ."</a>";
183 alt_table_row_color($k);
185 amount_cell($TypeTotal * $convert);
188 $classclose += $TypeTotal;
191 //Print Class Summary
192 start_row("class='inquirybg' style='font-weight:bold'");
193 label_cell(_('Total') . " " . $class["class_name"]);
194 amount_cell($classclose * $convert);
197 if ($ctype == CL_EQUITY)
199 $equityclose += $classclose;
200 $econvert = $convert;
202 if ($ctype == CL_LIABILITIES)
204 $lclose += $classclose;
205 $lconvert = $convert;
208 $calculateclose += $classclose;
212 $calculateclose *= -1;
213 //Final Report Summary
214 $url = "<a href='$path_to_root/gl/inquiry/profit_loss.php?TransFromDate="
215 . $from."&TransToDate=".$to
216 ."&Compare=0'>"._('Calculated Return')."</a>";
218 start_row("class='inquirybg' style='font-weight:bold'");
220 amount_cell($calculateclose);
223 start_row("class='inquirybg' style='font-weight:bold'");
224 label_cell(_('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
225 amount_cell($lclose * $lconvert + $equityclose * $econvert + $calculateclose);
230 //Level Pointer : Global variable defined in order to control display of root
234 $accounttype = get_account_type($_POST["AccGrp"]);
235 $classid = $accounttype["class_id"];
236 $class = get_account_class($classid);
237 $convert = get_class_type_convert($class["ctype"]);
240 table_section_title(get_account_type_name($_POST["AccGrp"]));
242 $classclose = display_type($accounttype["id"], $accounttype["name"], $from, $to,
243 $convert, $drilldown, $path_to_root);
246 end_table(1); // outer table
250 //----------------------------------------------------------------------------------------------------
256 display_balance_sheet();