2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-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 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
39 $dim = get_company_pref('use_dimension');
40 $dimension = $dimension2 = 0;
42 $from = $_POST['PARAM_0'];
43 $to = $_POST['PARAM_1'];
46 $dimension = $_POST['PARAM_2'];
47 $dimension2 = $_POST['PARAM_3'];
48 $graphics = $_POST['PARAM_4'];
49 $comments = $_POST['PARAM_5'];
53 $dimension = $_POST['PARAM_2'];
54 $graphics = $_POST['PARAM_3'];
55 $comments = $_POST['PARAM_4'];
59 $graphics = $_POST['PARAM_2'];
60 $comments = $_POST['PARAM_3'];
64 include_once($path_to_root . "/reporting/includes/class.graphic.inc");
69 $cols = array(0, 50, 200, 350, 425, 500);
70 //------------0--1---2----3----4----5--
72 $headers = array(_('Account'), _('Account Name'), _('Open Balance'), _('Period'),
75 $aligns = array('left', 'left', 'right', 'right', 'right');
79 $params = array( 0 => $comments,
80 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
81 2 => array('text' => _('Dimension')." 1",
82 'from' => get_dimension_string($dimension), 'to' => ''),
83 3 => array('text' => _('Dimension')." 2",
84 'from' => get_dimension_string($dimension2), 'to' => ''));
88 $params = array( 0 => $comments,
89 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
90 2 => array('text' => _('Dimension'),
91 'from' => get_dimension_string($dimension), 'to' => ''));
95 $params = array( 0 => $comments,
96 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
99 $rep = new FrontReport(_('Balance Sheet'), "BalanceSheet.pdf", user_pagesize());
102 $rep->Info($params, $cols, $headers, $aligns);
118 $accounts = get_gl_accounts_all(1);
120 while ($account=db_fetch($accounts))
122 $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
124 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
126 if (!$prev_balance && !$curr_balance)
129 if ($account['AccountClassName'] != $classname)
131 if ($classname != '')
137 if ($account['AccountTypeName'] != $group)
141 $rep->Line($rep->row + 6);
143 $rep->TextCol(0, 2, _('Total') . " " . $group);
144 $rep->TextCol(2, 3, number_format2($totalopen, $dec));
145 $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
146 $rep->TextCol(4, 5, number_format2($totalclose, $dec));
150 $pg->y[] = abs($totalclose);
152 $totalopen = $totalperiod = $totalclose = 0.0;
153 $rep->row -= ($rep->lineHeight + 4);
156 $rep->Line($rep->row + 6);
159 $rep->TextCol(0, 2, _('Total') . " " . $classname);
160 $rep->TextCol(2, 3, number_format2($classopen, $dec));
161 $rep->TextCol(3, 4, number_format2($classperiod, $dec));
162 $rep->TextCol(4, 5, number_format2($classclose, $dec));
164 $assetsopen += $classopen;
165 $assetsperiod += $classperiod;
166 $assetsclose += $classclose;
167 $classopen = $classperiod = $classclose = 0.0;
172 if ($account['AccountClassName'] != $classname)
175 $rep->TextCol(0, 5, $account['AccountClassName']);
177 $rep->row -= ($rep->lineHeight + 4);
179 $group = $account['AccountTypeName'];
180 $rep->TextCol(0, 5, $account['AccountTypeName']);
181 $rep->Line($rep->row - 4);
182 $rep->row -= ($rep->lineHeight + 4);
184 $classname = $account['AccountClassName'];
186 $totalopen += $prev_balance;
187 $totalperiod += $curr_balance;
188 $totalclose = $totalopen + $totalperiod;
189 $classopen += $prev_balance;
190 $classperiod += $curr_balance;
191 $classclose = $classopen + $classperiod;
192 $rep->TextCol(0, 1, $account['account_code']);
193 $rep->TextCol(1, 2, $account['account_name']);
195 $rep->TextCol(2, 3, number_format2($prev_balance, $dec));
196 $rep->TextCol(3, 4, number_format2($curr_balance, $dec));
197 $rep->TextCol(4, 5, number_format2($curr_balance + $prev_balance, $dec));
201 if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
203 $rep->Line($rep->row - 2);
207 if ($account['AccountClassName'] != $classname)
209 if ($classname != '')
214 if ($account['AccountTypeName'] != $group)
218 $rep->Line($rep->row + 6);
220 $rep->TextCol(0, 2, _('Total') . " " . $group);
221 $rep->TextCol(2, 3, number_format2($totalopen, $dec));
222 $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
223 $rep->TextCol(4, 5, number_format2($totalclose, $dec));
227 $pg->y[] = abs($totalclose);
229 $rep->row -= ($rep->lineHeight + 4);
232 $rep->Line($rep->row + 6);
233 $calculateopen = -$assetsopen - $classopen;
234 $calculateperiod = -$assetsperiod - $classperiod;
235 $calculateclose = -$assetsclose - $classclose;
238 $rep->TextCol(0, 2, _('Calculated Return'));
239 $rep->TextCol(2, 3, number_format2($calculateopen, $dec));
240 $rep->TextCol(3, 4, number_format2($calculateperiod, $dec));
241 $rep->TextCol(4, 5, number_format2($calculateclose, $dec));
244 $pg->x[] = _('Calculated Return');
245 $pg->y[] = abs($calculateclose);
247 $rep->row -= ($rep->lineHeight + 4);
250 $rep->TextCol(0, 2, _('Total') . " " . $classname);
251 $rep->TextCol(2, 3, number_format2(-$assetsopen, $dec));
252 $rep->TextCol(3, 4, number_format2(-$assetsperiod, $dec));
253 $rep->TextCol(4, 5, number_format2(-$assetsclose, $dec));
259 $rep->Line($rep->row);
262 global $decseps, $graph_skin;
263 $pg->title = $rep->title;
264 $pg->axis_x = _("Group");
265 $pg->axis_y = _("Amount");
266 $pg->graphic_1 = $to;
267 $pg->type = $graphics;
268 $pg->skin = $graph_skin;
269 $pg->built_in = false;
270 $pg->fontfile = $path_to_root . "/reporting/fonts/Vera.ttf";
271 $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
272 $filename = $comp_path.'/'.user_company()."/pdf_files/test.png";
273 $pg->display($filename, true);
274 $w = $pg->width / 1.5;
275 $h = $pg->height / 1.5;
276 $x = ($rep->pageWidth - $w) / 2;
278 if ($rep->row - $h < $rep->bottomMargin)
280 $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);