Eliminated non-static method calls and other bulk fixes to fix php5 warnings
[fa-stable.git] / reporting / rep704.php
1 <?php
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 ***********************************************************************/
12 $page_security = 'SA_GLREP';
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       GL Accounts Transactions
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
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");
25
26 //----------------------------------------------------------------------------------------------------
27
28 print_GL_transactions();
29
30 //----------------------------------------------------------------------------------------------------
31
32 function print_GL_transactions()
33 {
34         global $path_to_root, $systypes_array;
35
36         $dim = get_company_pref('use_dimension');
37         $dimension = $dimension2 = 0;
38
39         $from = $_POST['PARAM_0'];
40         $to = $_POST['PARAM_1'];
41         $fromacc = $_POST['PARAM_2'];
42         $toacc = $_POST['PARAM_3'];
43         if ($dim == 2)
44         {
45                 $dimension = $_POST['PARAM_4'];
46                 $dimension2 = $_POST['PARAM_5'];
47                 $comments = $_POST['PARAM_6'];
48                 $destination = $_POST['PARAM_7'];
49         }
50         else if ($dim == 1)
51         {
52                 $dimension = $_POST['PARAM_4'];
53                 $comments = $_POST['PARAM_5'];
54                 $destination = $_POST['PARAM_6'];
55         }
56         else
57         {
58                 $comments = $_POST['PARAM_4'];
59                 $destination = $_POST['PARAM_5'];
60         }
61         if ($destination)
62                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
63         else
64                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
65
66         $rep = new FrontReport(_('GL Account Transactions'), "GLAccountTransactions", user_pagesize());
67         $dec = user_price_dec();
68
69         $cols = array(0, 70, 90, 140, 210, 280, 340, 400, 450, 510, 570);
70         //------------0--1---2---3----4----5----6----7----8----9----10-------
71         //-----------------------dim1-dim2-----------------------------------
72         //-----------------------dim1----------------------------------------
73         //-------------------------------------------------------------------
74         $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
75
76         if ($dim == 2)
77                 $headers = array(_('Type'),     _('#'), _('Date'), _('Dimension')." 1", _('Dimension')." 2",
78                         _('Person/Item'), _('Debit'),   _('Credit'), _('Balance'));
79         elseif ($dim == 1)
80                 $headers = array(_('Type'),     _('#'), _('Date'), _('Dimension'), "", _('Person/Item'),
81                         _('Debit'),     _('Credit'), _('Balance'));
82         else
83                 $headers = array(_('Type'),     _('#'), _('Date'), "", "", _('Person/Item'),
84                         _('Debit'),     _('Credit'), _('Balance'));
85
86         if ($dim == 2)
87         {
88         $params =   array(      0 => $comments,
89                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
90                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc),
91                         3 => array('text' => _('Dimension')." 1", 'from' => get_dimension_string($dimension),
92                             'to' => ''),
93                         4 => array('text' => _('Dimension')." 2", 'from' => get_dimension_string($dimension2),
94                             'to' => ''));
95     }
96     else if ($dim == 1)
97     {
98         $params =   array(      0 => $comments,
99                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
100                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc),
101                         3 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension),
102                             'to' => ''));
103     }
104     else
105     {
106         $params =   array(      0 => $comments,
107                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
108                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc));
109     }
110
111         $rep->Font();
112         $rep->Info($params, $cols, $headers, $aligns);
113         $rep->Header();
114
115         $accounts = get_gl_accounts($fromacc, $toacc);
116
117         while ($account=db_fetch($accounts))
118         {
119                 if (is_account_balancesheet($account["account_code"]))
120                         $begin = "";
121                 else
122                 {
123                         $begin = begin_fiscalyear();
124                         if (date1_greater_date2($begin, $from))
125                                 $begin = $from;
126                         $begin = add_days($begin, -1);
127                 }
128                 $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
129
130                 $trans = get_gl_transactions($from, $to, -1, $account['account_code'], $dimension, $dimension2);
131                 $rows = db_num_rows($trans);
132                 if ($prev_balance == 0.0 && $rows == 0)
133                         continue;
134                 $rep->Font('bold');
135                 $rep->TextCol(0, 3,     $account['account_code'] . " " . $account['account_name']);
136                 $rep->TextCol(3, 5, _('Opening Balance'));
137                 if ($prev_balance > 0.0)
138                         $rep->AmountCol(6, 7, abs($prev_balance), $dec);
139                 else
140                         $rep->AmountCol(7, 8, abs($prev_balance), $dec);
141                 $rep->Font();
142                 $total = $prev_balance;
143                 $rep->NewLine(2);
144                 if ($rows > 0)
145                 {
146                         while ($myrow=db_fetch($trans))
147                         {
148                                 $total += $myrow['amount'];
149
150                                 $rep->TextCol(0, 1, $systypes_array[$myrow["type"]]);
151                                 $rep->TextCol(1, 2,     $myrow['type_no']);
152                                 $rep->DateCol(2, 3,     $myrow["tran_date"], true);
153                                 if ($dim >= 1)
154                                         $rep->TextCol(3, 4,     get_dimension_string($myrow['dimension_id']));
155                                 if ($dim > 1)
156                                         $rep->TextCol(4, 5,     get_dimension_string($myrow['dimension2_id']));
157                                 $rep->TextCol(5, 6,     payment_person_name($myrow["person_type_id"],$myrow["person_id"], false));
158                                 if ($myrow['amount'] > 0.0)
159                                         $rep->AmountCol(6, 7, abs($myrow['amount']), $dec);
160                                 else
161                                         $rep->AmountCol(7, 8, abs($myrow['amount']), $dec);
162                                 $rep->TextCol(8, 9,     number_format2($total, $dec));
163                                 $rep->NewLine();
164                                 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
165                                 {
166                                         $rep->Line($rep->row - 2);
167                                         $rep->Header();
168                                 }
169                         }
170                         $rep->NewLine();
171                 }
172                 $rep->Font('bold');
173                 $rep->TextCol(3, 5,     _("Ending Balance"));
174                 if ($total > 0.0)
175                         $rep->AmountCol(6, 7, abs($total), $dec);
176                 else
177                         $rep->AmountCol(7, 8, abs($total), $dec);
178                 $rep->Font();
179                 $rep->Line($rep->row - $rep->lineHeight + 4);
180                 $rep->NewLine(2, 1);
181         }
182         $rep->End();
183 }
184
185 ?>