Improved float compare in certain files (AR/AP ledger)
[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 . "/admin/db/fiscalyears_db.inc");
23 include_once($path_to_root . "/includes/date_functions.inc");
24 include_once($path_to_root . "/includes/data_checks.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
26
27 //----------------------------------------------------------------------------------------------------
28
29 print_GL_transactions();
30
31 //----------------------------------------------------------------------------------------------------
32
33 function print_GL_transactions()
34 {
35         global $path_to_root, $systypes_array;
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 ($destination)
63                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
64         else
65                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
66
67         $rep = new FrontReport(_('GL Account Transactions'), "GLAccountTransactions", user_pagesize());
68         $dec = user_price_dec();
69
70   //$cols = array(0, 80, 100, 150, 210, 280, 340, 400, 450, 510, 570);
71         $cols = array(0, 65, 105, 125, 175, 230, 290, 345, 405, 465, 525);
72         //------------0--1---2---3----4----5----6----7----8----9----10-------
73         //-----------------------dim1-dim2-----------------------------------
74         //-----------------------dim1----------------------------------------
75         //-------------------------------------------------------------------
76         $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
77
78         if ($dim == 2)
79                 $headers = array(_('Type'),     _('Ref'), _('#'),       _('Date'), _('Dimension')." 1", _('Dimension')." 2",
80                         _('Person/Item'), _('Debit'),   _('Credit'), _('Balance'));
81         elseif ($dim == 1)
82                 $headers = array(_('Type'),     _('Ref'), _('#'),       _('Date'), _('Dimension'), "", _('Person/Item'),
83                         _('Debit'),     _('Credit'), _('Balance'));
84         else
85                 $headers = array(_('Type'),     _('Ref'), _('#'),       _('Date'), "", "", _('Person/Item'),
86                         _('Debit'),     _('Credit'), _('Balance'));
87
88         if ($dim == 2)
89         {
90         $params =   array(      0 => $comments,
91                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
92                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc),
93                         3 => array('text' => _('Dimension')." 1", 'from' => get_dimension_string($dimension),
94                             'to' => ''),
95                         4 => array('text' => _('Dimension')." 2", 'from' => get_dimension_string($dimension2),
96                             'to' => ''));
97     }
98     else if ($dim == 1)
99     {
100         $params =   array(      0 => $comments,
101                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
102                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc),
103                         3 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension),
104                             'to' => ''));
105     }
106     else
107     {
108         $params =   array(      0 => $comments,
109                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
110                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc));
111     }
112
113         $rep->Font();
114         $rep->Info($params, $cols, $headers, $aligns);
115         $rep->NewPage();
116
117         $accounts = get_gl_accounts($fromacc, $toacc);
118
119         while ($account=db_fetch($accounts))
120         {
121                 if (is_account_balancesheet($account["account_code"]))
122                         $begin = "";
123                 else
124                 {
125                         $begin = get_fiscalyear_begin_for_date($from);
126                         if (date1_greater_date2($begin, $from))
127                                 $begin = $from;
128                         $begin = add_days($begin, -1);
129                 }
130                 $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
131
132                 $trans = get_gl_transactions($from, $to, -1, $account['account_code'], $dimension, $dimension2);
133                 $rows = db_num_rows($trans);
134                 if ($prev_balance == 0.0 && $rows == 0)
135                         continue;
136                 $rep->Font('bold');
137                 $rep->TextCol(0, 4,     $account['account_code'] . " " . $account['account_name'], -2);
138                 $rep->TextCol(4, 6, _('Opening Balance'));
139                 if ($prev_balance > 0.0)
140                         $rep->AmountCol(7, 8, abs($prev_balance), $dec);
141                 else
142                         $rep->AmountCol(8, 9, abs($prev_balance), $dec);
143                 $rep->Font();
144                 $total = $prev_balance;
145                 $rep->NewLine(2);
146                 if ($rows > 0)
147                 {
148                         while ($myrow=db_fetch($trans))
149                         {
150                                 $total += $myrow['amount'];
151
152                                 $rep->TextCol(0, 1, $systypes_array[$myrow["type"]], -2);
153                                 $reference = get_reference($myrow["type"], $myrow["type_no"]);
154                                 $rep->TextCol(1, 2, $reference);
155                                 $rep->TextCol(2, 3,     $myrow['type_no'], -2);
156                                 $rep->DateCol(3, 4,     $myrow["tran_date"], true);
157                                 if ($dim >= 1)
158                                         $rep->TextCol(4, 5,     get_dimension_string($myrow['dimension_id']));
159                                 if ($dim > 1)
160                                         $rep->TextCol(5, 6,     get_dimension_string($myrow['dimension2_id']));
161                                 $txt = payment_person_name($myrow["person_type_id"],$myrow["person_id"], false);
162                                 $memo = $myrow['memo_'];
163                                 if ($txt != "")
164                                 {
165                                         if ($memo != "")
166                                                 $txt = $txt."/".$memo;
167                                 }
168                                 else
169                                         $txt = $memo;
170                                 $rep->TextCol(6, 7,     $txt, -2);
171                                 if ($myrow['amount'] > 0.0)
172                                         $rep->AmountCol(7, 8, abs($myrow['amount']), $dec);
173                                 else
174                                         $rep->AmountCol(8, 9, abs($myrow['amount']), $dec);
175                                 $rep->TextCol(9, 10, number_format2($total, $dec));
176                                 $rep->NewLine();
177                                 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
178                                 {
179                                         $rep->Line($rep->row - 2);
180                                         $rep->NewPage();
181                                 }
182                         }
183                         $rep->NewLine();
184                 }
185                 $rep->Font('bold');
186                 $rep->TextCol(4, 6,     _("Ending Balance"));
187                 if ($total > 0.0)
188                         $rep->AmountCol(7, 8, abs($total), $dec);
189                 else
190                         $rep->AmountCol(8, 9, abs($total), $dec);
191                 $rep->Font();
192                 $rep->Line($rep->row - $rep->lineHeight + 4);
193                 $rep->NewLine(2, 1);
194         }
195         $rep->End();
196 }
197
198 ?>