4 // ----------------------------------------------------------------
8 // Title: Balance Sheet
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
20 print_balance_sheet();
23 //----------------------------------------------------------------------------------------------------
25 function print_balance_sheet()
29 include_once($path_to_root . "reporting/includes/pdf_report.inc");
30 $dim = get_company_pref('use_dimension');
31 $dimension = $dimension2 = 0;
33 $from = $_POST['PARAM_0'];
34 $to = $_POST['PARAM_1'];
37 $dimension = $_POST['PARAM_2'];
38 $dimension2 = $_POST['PARAM_3'];
39 $graphics = $_POST['PARAM_4'];
40 $comments = $_POST['PARAM_5'];
44 $dimension = $_POST['PARAM_2'];
45 $graphics = $_POST['PARAM_3'];
46 $comments = $_POST['PARAM_4'];
50 $graphics = $_POST['PARAM_2'];
51 $comments = $_POST['PARAM_3'];
55 include_once($path_to_root . "reporting/includes/class.graphic.inc");
60 $cols = array(0, 50, 200, 350, 425, 500);
61 //------------0--1---2----3----4----5--
63 $headers = array(_('Account'), _('Account Name'), _('Open Balance'), _('Period'),
66 $aligns = array('left', 'left', 'right', 'right', 'right');
70 $params = array( 0 => $comments,
71 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
72 2 => array('text' => _('Dimension')." 1",
73 'from' => get_dimension_string($dimension), 'to' => ''),
74 3 => array('text' => _('Dimension')." 2",
75 'from' => get_dimension_string($dimension2), 'to' => ''));
79 $params = array( 0 => $comments,
80 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
81 2 => array('text' => _('Dimension'),
82 'from' => get_dimension_string($dimension), 'to' => ''));
86 $params = array( 0 => $comments,
87 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
90 $rep = new FrontReport(_('Balance Sheet'), "BalanceSheet.pdf", user_pagesize());
93 $rep->Info($params, $cols, $headers, $aligns);
108 $accounts = get_gl_accounts_all(1);
110 while ($account=db_fetch($accounts))
112 $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
114 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
116 if (!$prev_balance && !$curr_balance)
119 if ($account['AccountClassName'] != $classname)
121 if ($classname != '')
127 if ($account['AccountTypeName'] != $group)
131 $rep->Line($rep->row + 6);
133 $rep->TextCol(0, 2, _('Total') . " " . $group);
134 $rep->TextCol(2, 3, number_format2($totalopen, $dec));
135 $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
136 $rep->TextCol(4, 5, number_format2($totalclose, $dec));
140 $pg->y[] = abs($totalclose);
142 $totalopen = $totalperiod = $totalclose = 0.0;
143 $rep->row -= ($rep->lineHeight + 4);
146 $rep->Line($rep->row + 6);
149 $rep->TextCol(0, 2, _('Total') . " " . $classname);
150 $rep->TextCol(2, 3, number_format2($classopen, $dec));
151 $rep->TextCol(3, 4, number_format2($classperiod, $dec));
152 $rep->TextCol(4, 5, number_format2($classclose, $dec));
154 $assetsopen += $classopen;
155 $assetsperiod += $classperiod;
156 $assetsclose += $classclose;
157 $classopen = $classperiod = $classclose = 0.0;
162 if ($account['AccountClassName'] != $classname)
165 $rep->TextCol(0, 5, $account['AccountClassName']);
167 $rep->row -= ($rep->lineHeight + 4);
169 $group = $account['AccountTypeName'];
170 $rep->TextCol(0, 5, $account['AccountTypeName']);
171 $rep->Line($rep->row - 4);
172 $rep->row -= ($rep->lineHeight + 4);
174 $classname = $account['AccountClassName'];
176 $totalopen += $prev_balance;
177 $totalperiod += $curr_balance;
178 $totalclose = $totalopen + $totalperiod;
179 $classopen += $prev_balance;
180 $classperiod += $curr_balance;
181 $classclose = $classopen + $classperiod;
182 $rep->TextCol(0, 1, $account['account_code']);
183 $rep->TextCol(1, 2, $account['account_name']);
185 $rep->TextCol(2, 3, number_format2($prev_balance, $dec));
186 $rep->TextCol(3, 4, number_format2($curr_balance, $dec));
187 $rep->TextCol(4, 5, number_format2($curr_balance + $prev_balance, $dec));
191 if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
193 $rep->Line($rep->row - 2);
197 if ($account['AccountClassName'] != $classname)
199 if ($classname != '')
204 if ($account['AccountTypeName'] != $group)
208 $rep->Line($rep->row + 6);
210 $rep->TextCol(0, 2, _('Total') . " " . $group);
211 $rep->TextCol(2, 3, number_format2($totalopen, $dec));
212 $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
213 $rep->TextCol(4, 5, number_format2($totalclose, $dec));
217 $pg->y[] = abs($totalclose);
219 $rep->row -= ($rep->lineHeight + 4);
222 $rep->Line($rep->row + 6);
223 $calculateopen = -$assetsopen - $classopen;
224 $calculateperiod = -$assetsperiod - $classperiod;
225 $calculateclose = -$assetsclose - $classclose;
228 $rep->TextCol(0, 2, _('Calculated Return'));
229 $rep->TextCol(2, 3, number_format2($calculateopen, $dec));
230 $rep->TextCol(3, 4, number_format2($calculateperiod, $dec));
231 $rep->TextCol(4, 5, number_format2($calculateclose, $dec));
234 $pg->x[] = _('Calculated Return');
235 $pg->y[] = abs($calculateclose);
237 $rep->row -= ($rep->lineHeight + 4);
240 $rep->TextCol(0, 2, _('Total') . " " . $classname);
241 $rep->TextCol(2, 3, number_format2(-$assetsopen, $dec));
242 $rep->TextCol(3, 4, number_format2(-$assetsperiod, $dec));
243 $rep->TextCol(4, 5, number_format2(-$assetsclose, $dec));
249 $rep->Line($rep->row);
252 global $decseps, $graph_skin;
253 $pg->title = $rep->title;
254 $pg->axis_x = _("Group");
255 $pg->axis_y = _("Amount");
256 $pg->graphic_1 = $to;
257 $pg->type = $graphics;
258 $pg->skin = $graph_skin;
259 $pg->built_in = false;
260 $pg->fontfile = $path_to_root . "reporting/fonts/Vera.ttf";
261 $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
262 $filename = $path_to_root . "reporting/pdf_files/test.png";
263 $pg->display($filename, true);
264 $w = $pg->width / 1.5;
265 $h = $pg->height / 1.5;
266 $x = ($rep->pageWidth - $w) / 2;
268 if ($rep->row - $h < $rep->bottomMargin)
270 $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);