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 ***********************************************************************/
13 // ----------------------------------------------------------------
17 // Title: Balance Sheet
18 // ----------------------------------------------------------------
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 //----------------------------------------------------------------------------------------------------
28 // trial_inquiry_controls();
29 print_balance_sheet();
32 //----------------------------------------------------------------------------------------------------
34 function print_balance_sheet()
36 global $comp_path, $path_to_root;
38 $dim = get_company_pref('use_dimension');
39 $dimension = $dimension2 = 0;
41 $from = $_POST['PARAM_0'];
42 $to = $_POST['PARAM_1'];
45 $dimension = $_POST['PARAM_2'];
46 $dimension2 = $_POST['PARAM_3'];
47 $graphics = $_POST['PARAM_4'];
48 $comments = $_POST['PARAM_5'];
49 $destination = $_POST['PARAM_6'];
53 $dimension = $_POST['PARAM_2'];
54 $graphics = $_POST['PARAM_3'];
55 $comments = $_POST['PARAM_4'];
56 $destination = $_POST['PARAM_5'];
60 $graphics = $_POST['PARAM_2'];
61 $comments = $_POST['PARAM_3'];
62 $destination = $_POST['PARAM_4'];
66 include_once($path_to_root . "/reporting/includes/excel_report.inc");
67 $filename = "BalanceSheet.xml";
71 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
72 $filename = "BalanceSheet.pdf";
76 include_once($path_to_root . "/reporting/includes/class.graphic.inc");
81 $cols = array(0, 50, 200, 350, 425, 500);
82 //------------0--1---2----3----4----5--
84 $headers = array(_('Account'), _('Account Name'), _('Open Balance'), _('Period'),
87 $aligns = array('left', 'left', 'right', 'right', 'right');
91 $params = array( 0 => $comments,
92 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
93 2 => array('text' => _('Dimension')." 1",
94 'from' => get_dimension_string($dimension), 'to' => ''),
95 3 => array('text' => _('Dimension')." 2",
96 'from' => get_dimension_string($dimension2), 'to' => ''));
100 $params = array( 0 => $comments,
101 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
102 2 => array('text' => _('Dimension'),
103 'from' => get_dimension_string($dimension), 'to' => ''));
107 $params = array( 0 => $comments,
108 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
110 //display_error("Error!");
112 $rep = new FrontReport(_('Balance Sheet'), $filename, user_pagesize());
114 $rep->Info($params, $cols, $headers, $aligns);
130 $accounts = get_gl_accounts_all(1);
132 while ($account=db_fetch($accounts))
134 $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
136 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
138 if (!$prev_balance && !$curr_balance)
141 if ($account['AccountClassName'] != $classname)
143 if ($classname != '')
149 if ($account['AccountTypeName'] != $group)
154 $rep->Line($rep->row);
156 $rep->TextCol(0, 2, _('Total') . " " . $group);
157 $rep->AmountCol(2, 3, $totalopen, $dec);
158 $rep->AmountCol(3, 4, $totalperiod, $dec);
159 $rep->AmountCol(4, 5, $totalclose, $dec);
163 $pg->y[] = abs($totalclose);
165 $totalopen = $totalperiod = $totalclose = 0.0;
170 $rep->Line($rep->row);
173 $rep->TextCol(0, 2, _('Total') . " " . $classname);
174 $rep->AmountCol(2, 3, $classopen, $dec);
175 $rep->AmountCol(3, 4, $classperiod, $dec);
176 $rep->AmountCol(4, 5, $classclose, $dec);
178 $assetsopen += $classopen;
179 $assetsperiod += $classperiod;
180 $assetsclose += $classclose;
181 $classopen = $classperiod = $classclose = 0.0;
186 if ($account['AccountClassName'] != $classname)
189 $rep->TextCol(0, 5, $account['AccountClassName']);
193 $group = $account['AccountTypeName'];
195 $rep->TextCol(0, 5, $account['AccountTypeName']);
197 $rep->Line($rep->row);
200 $classname = $account['AccountClassName'];
202 $totalopen += $prev_balance;
203 $totalperiod += $curr_balance;
204 $totalclose = $totalopen + $totalperiod;
205 $classopen += $prev_balance;
206 $classperiod += $curr_balance;
207 $classclose = $classopen + $classperiod;
208 $rep->TextCol(0, 1, $account['account_code']);
209 $rep->TextCol(1, 2, $account['account_name']);
211 $rep->AmountCol(2, 3, $prev_balance, $dec);
212 $rep->AmountCol(3, 4, $curr_balance, $dec);
213 $rep->AmountCol(4, 5, $curr_balance + $prev_balance, $dec);
217 if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
219 $rep->Line($rep->row - 2);
223 if ($account['AccountClassName'] != $classname)
225 if ($classname != '')
230 if ($account['AccountTypeName'] != $group)
235 $rep->Line($rep->row);
237 $rep->TextCol(0, 2, _('Total') . " " . $group);
238 $rep->AmountCol(2, 3, $totalopen, $dec);
239 $rep->AmountCol(3, 4, $totalperiod, $dec);
240 $rep->AmountCol(4, 5, $totalclose, $dec);
244 $pg->y[] = abs($totalclose);
249 $calculateopen = -$assetsopen - $classopen;
250 $calculateperiod = -$assetsperiod - $classperiod;
251 $calculateclose = -$assetsclose - $classclose;
253 $rep->Line($rep->row);
255 $rep->TextCol(0, 2, _('Calculated Return'));
256 $rep->AmountCol(2, 3, $calculateopen, $dec);
257 $rep->AmountCol(3, 4, $calculateperiod, $dec);
258 $rep->AmountCol(4, 5, $calculateclose, $dec);
261 $pg->x[] = _('Calculated Return');
262 $pg->y[] = abs($calculateclose);
266 $rep->TextCol(0, 2, _('Total') . " " . $classname);
267 $rep->AmountCol(2, 3, -$assetsopen, $dec);
268 $rep->AmountCol(3, 4, -$assetsperiod, $dec);
269 $rep->AmountCol(4, 5, -$assetsclose, $dec);
275 $rep->Line($rep->row);
278 global $decseps, $graph_skin;
279 $pg->title = $rep->title;
280 $pg->axis_x = _("Group");
281 $pg->axis_y = _("Amount");
282 $pg->graphic_1 = $to;
283 $pg->type = $graphics;
284 $pg->skin = $graph_skin;
285 $pg->built_in = false;
286 $pg->fontfile = $path_to_root . "/reporting/fonts/Vera.ttf";
287 $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
288 $filename = $comp_path.'/'.user_company()."/pdf_files/test.png";
289 $pg->display($filename, true);
290 $w = $pg->width / 1.5;
291 $h = $pg->height / 1.5;
292 $x = ($rep->pageWidth - $w) / 2;
294 if ($rep->row - $h < $rep->bottomMargin)
296 $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);