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()
27 global $comp_path, $path_to_root;
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);
109 $accounts = get_gl_accounts_all(1);
111 while ($account=db_fetch($accounts))
113 $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
115 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
117 if (!$prev_balance && !$curr_balance)
120 if ($account['AccountClassName'] != $classname)
122 if ($classname != '')
128 if ($account['AccountTypeName'] != $group)
132 $rep->Line($rep->row + 6);
134 $rep->TextCol(0, 2, _('Total') . " " . $group);
135 $rep->TextCol(2, 3, number_format2($totalopen, $dec));
136 $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
137 $rep->TextCol(4, 5, number_format2($totalclose, $dec));
141 $pg->y[] = abs($totalclose);
143 $totalopen = $totalperiod = $totalclose = 0.0;
144 $rep->row -= ($rep->lineHeight + 4);
147 $rep->Line($rep->row + 6);
150 $rep->TextCol(0, 2, _('Total') . " " . $classname);
151 $rep->TextCol(2, 3, number_format2($classopen, $dec));
152 $rep->TextCol(3, 4, number_format2($classperiod, $dec));
153 $rep->TextCol(4, 5, number_format2($classclose, $dec));
155 $assetsopen += $classopen;
156 $assetsperiod += $classperiod;
157 $assetsclose += $classclose;
158 $classopen = $classperiod = $classclose = 0.0;
163 if ($account['AccountClassName'] != $classname)
166 $rep->TextCol(0, 5, $account['AccountClassName']);
168 $rep->row -= ($rep->lineHeight + 4);
170 $group = $account['AccountTypeName'];
171 $rep->TextCol(0, 5, $account['AccountTypeName']);
172 $rep->Line($rep->row - 4);
173 $rep->row -= ($rep->lineHeight + 4);
175 $classname = $account['AccountClassName'];
177 $totalopen += $prev_balance;
178 $totalperiod += $curr_balance;
179 $totalclose = $totalopen + $totalperiod;
180 $classopen += $prev_balance;
181 $classperiod += $curr_balance;
182 $classclose = $classopen + $classperiod;
183 $rep->TextCol(0, 1, $account['account_code']);
184 $rep->TextCol(1, 2, $account['account_name']);
186 $rep->TextCol(2, 3, number_format2($prev_balance, $dec));
187 $rep->TextCol(3, 4, number_format2($curr_balance, $dec));
188 $rep->TextCol(4, 5, number_format2($curr_balance + $prev_balance, $dec));
192 if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
194 $rep->Line($rep->row - 2);
198 if ($account['AccountClassName'] != $classname)
200 if ($classname != '')
205 if ($account['AccountTypeName'] != $group)
209 $rep->Line($rep->row + 6);
211 $rep->TextCol(0, 2, _('Total') . " " . $group);
212 $rep->TextCol(2, 3, number_format2($totalopen, $dec));
213 $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
214 $rep->TextCol(4, 5, number_format2($totalclose, $dec));
218 $pg->y[] = abs($totalclose);
220 $rep->row -= ($rep->lineHeight + 4);
223 $rep->Line($rep->row + 6);
224 $calculateopen = -$assetsopen - $classopen;
225 $calculateperiod = -$assetsperiod - $classperiod;
226 $calculateclose = -$assetsclose - $classclose;
229 $rep->TextCol(0, 2, _('Calculated Return'));
230 $rep->TextCol(2, 3, number_format2($calculateopen, $dec));
231 $rep->TextCol(3, 4, number_format2($calculateperiod, $dec));
232 $rep->TextCol(4, 5, number_format2($calculateclose, $dec));
235 $pg->x[] = _('Calculated Return');
236 $pg->y[] = abs($calculateclose);
238 $rep->row -= ($rep->lineHeight + 4);
241 $rep->TextCol(0, 2, _('Total') . " " . $classname);
242 $rep->TextCol(2, 3, number_format2(-$assetsopen, $dec));
243 $rep->TextCol(3, 4, number_format2(-$assetsperiod, $dec));
244 $rep->TextCol(4, 5, number_format2(-$assetsclose, $dec));
250 $rep->Line($rep->row);
253 global $decseps, $graph_skin;
254 $pg->title = $rep->title;
255 $pg->axis_x = _("Group");
256 $pg->axis_y = _("Amount");
257 $pg->graphic_1 = $to;
258 $pg->type = $graphics;
259 $pg->skin = $graph_skin;
260 $pg->built_in = false;
261 $pg->fontfile = $path_to_root . "reporting/fonts/Vera.ttf";
262 $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
263 $filename = $comp_path.'/'.user_company()."/pdf_files/test.png";
264 $pg->display($filename, true);
265 $w = $pg->width / 1.5;
266 $h = $pg->height / 1.5;
267 $x = ($rep->pageWidth - $w) / 2;
269 if ($rep->row - $h < $rep->bottomMargin)
271 $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);