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