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