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