Moving 2.0 development version to main trunk.
[fa-stable.git] / reporting / rep706.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       Balance Sheet
9 // ----------------------------------------------------------------
10 $path_to_root="../";
11
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");
16
17 //----------------------------------------------------------------------------------------------------
18
19 // trial_inquiry_controls();
20 print_balance_sheet();
21
22
23 //----------------------------------------------------------------------------------------------------
24
25 function print_balance_sheet()
26 {
27         global $comp_path, $path_to_root;
28
29         include_once($path_to_root . "reporting/includes/pdf_report.inc");
30         $dim = get_company_pref('use_dimension');
31         $dimension = $dimension2 = 0;
32
33         $from = $_POST['PARAM_0'];
34         $to = $_POST['PARAM_1'];
35         if ($dim == 2)
36         {
37                 $dimension = $_POST['PARAM_2'];
38                 $dimension2 = $_POST['PARAM_3'];
39                 $graphics = $_POST['PARAM_4'];
40                 $comments = $_POST['PARAM_5'];
41         }
42         else if ($dim == 1)
43         {
44                 $dimension = $_POST['PARAM_2'];
45                 $graphics = $_POST['PARAM_3'];
46                 $comments = $_POST['PARAM_4'];
47         }
48         else
49         {
50                 $graphics = $_POST['PARAM_2'];
51                 $comments = $_POST['PARAM_3'];
52         }
53         if ($graphics)
54         {
55                 include_once($path_to_root . "reporting/includes/class.graphic.inc");
56                 $pg = new graph();
57         }
58         $dec = 0;
59
60         $cols = array(0, 50, 200, 350, 425,     500);
61         //------------0--1---2----3----4----5--
62
63         $headers = array(_('Account'), _('Account Name'), _('Open Balance'), _('Period'),
64                 _('Close Balance'));
65
66         $aligns = array('left', 'left', 'right', 'right', 'right');
67
68     if ($dim == 2)
69     {
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' => ''));
76     }
77     else if ($dim == 1)
78     {
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' => ''));
83     }
84     else
85     {
86         $params =   array(      0 => $comments,
87                                     1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
88     }
89
90         $rep = new FrontReport(_('Balance Sheet'), "BalanceSheet.pdf", user_pagesize());
91
92         $rep->Font();
93         $rep->Info($params, $cols, $headers, $aligns);
94         $rep->Header();
95
96         $classname = '';
97         $group = '';
98         $totalopen = 0.0;
99         $totalperiod = 0.0;
100         $totalclose = 0.0;
101         $classopen = 0.0;
102         $classperiod = 0.0;
103         $classclose = 0.0;
104         $assetsopen = 0.0;
105         $assetsperiod = 0.0;
106         $assetsclose = 0.0;
107         $closeclass = false;
108
109         $accounts = get_gl_accounts_all(1);
110
111         while ($account=db_fetch($accounts))
112         {
113                 $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
114
115                 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
116
117                 if (!$prev_balance && !$curr_balance)
118                         continue;
119
120                 if ($account['AccountClassName'] != $classname)
121                 {
122                         if ($classname != '')
123                         {
124                                 $closeclass = true;
125                         }
126                 }
127
128                 if ($account['AccountTypeName'] != $group)
129                 {
130                         if ($group != '')
131                         {
132                                 $rep->Line($rep->row + 6);
133                                 $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));
138                                 if ($graphics)
139                                 {
140                                         $pg->x[] = $group;
141                                         $pg->y[] = abs($totalclose);
142                                 }
143                                 $totalopen = $totalperiod = $totalclose = 0.0;
144                                 $rep->row -= ($rep->lineHeight + 4);
145                                 if ($closeclass)
146                                 {
147                                         $rep->Line($rep->row + 6);
148                                         $rep->row -= 6;
149                                         $rep->Font('bold');
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));
154                                         $rep->Font();
155                                         $assetsopen += $classopen;
156                                         $assetsperiod += $classperiod;
157                                         $assetsclose += $classclose;
158                                         $classopen = $classperiod = $classclose = 0.0;
159                                         $rep->NewLine(3);
160                                         $closeclass = false;
161                                 }
162                         }
163                         if ($account['AccountClassName'] != $classname)
164                         {
165                                 $rep->Font('bold');
166                                 $rep->TextCol(0, 5, $account['AccountClassName']);
167                                 $rep->Font();
168                                 $rep->row -= ($rep->lineHeight + 4);
169                         }
170                         $group = $account['AccountTypeName'];
171                         $rep->TextCol(0, 5, $account['AccountTypeName']);
172                         $rep->Line($rep->row - 4);
173                         $rep->row -= ($rep->lineHeight + 4);
174                 }
175                 $classname = $account['AccountClassName'];
176
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']);
185
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));
189
190                 $rep->NewLine();
191
192                 if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
193                 {
194                         $rep->Line($rep->row - 2);
195                         $rep->Header();
196                 }
197         }
198         if ($account['AccountClassName'] != $classname)
199         {
200                 if ($classname != '')
201                 {
202                         $closeclass = true;
203                 }
204         }
205         if ($account['AccountTypeName'] != $group)
206         {
207                 if ($group != '')
208                 {
209                         $rep->Line($rep->row + 6);
210                         $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));
215                         if ($graphics)
216                         {
217                                 $pg->x[] = $group;
218                                 $pg->y[] = abs($totalclose);
219                         }
220                         $rep->row -= ($rep->lineHeight + 4);
221                         if ($closeclass)
222                         {
223                                 $rep->Line($rep->row + 6);
224                                 $calculateopen = -$assetsopen - $classopen;
225                                 $calculateperiod = -$assetsperiod - $classperiod;
226                                 $calculateclose = -$assetsclose  - $classclose;
227                                 $rep->row -= 6;
228
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));
233                                 if ($graphics)
234                                 {
235                                         $pg->x[] = _('Calculated Return');
236                                         $pg->y[] = abs($calculateclose);
237                                 }
238                                 $rep->row -= ($rep->lineHeight + 4);
239
240                                 $rep->Font('bold');
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));
245                                 $rep->Font();
246                                 $rep->NewLine();
247                         }
248                 }
249         }
250         $rep->Line($rep->row);
251         if ($graphics)
252         {
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;
268                 $rep->NewLine(2);
269                 if ($rep->row - $h < $rep->bottomMargin)
270                         $rep->Header();
271                 $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
272         }
273         $rep->End();
274 }
275
276 ?>