Merged changes from main trunk up to 2.2.3
[fa-stable.git] / reporting / rep701.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:       Chart of GL Accounts
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_Chart_of_Accounts();
29
30 //----------------------------------------------------------------------------------------------------
31
32 function print_Chart_of_Accounts()
33 {
34         global $path_to_root;
35
36         $showbalance = $_POST['PARAM_0'];
37         $comments = $_POST['PARAM_1'];
38         $destination = $_POST['PARAM_2'];
39         if ($destination)
40                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
41         else
42                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
43
44         $dec = 0;
45
46         $cols = array(0, 50, 300, 425, 500);
47
48         $headers = array(_('Account'), _('Account Name'), _('Account Code'), _('Balance'));
49         
50         $aligns = array('left', 'left', 'left', 'right');
51         
52         $params = array(0 => $comments);
53
54         $rep = new FrontReport(_('Chart of Accounts'), "ChartOfAccounts", user_pagesize());
55         
56         $rep->Font();
57         $rep->Info($params, $cols, $headers, $aligns);
58         $rep->Header();
59
60         $classname = '';
61         $group = '';
62
63         $accounts = get_gl_accounts_all();
64
65         while ($account=db_fetch($accounts))
66         {
67                 if ($account['AccountTypeName'] != $group)
68                 {
69                         if ($classname != '')
70                                 $rep->row -= 4;
71                         if ($account['AccountClassName'] != $classname)
72                         {
73                                 $rep->Font('bold');
74                                 //$rep->TextCol(0, 4, $account['AccountClassName']);
75                                 $rep->TextCol(0, 1, $account['ClassID']);
76                                 $rep->TextCol(1, 4, $account['AccountClassName']);
77                                 $rep->Font();
78                                 //$rep->row -= ($rep->lineHeight + 4);
79                                 $rep->NewLine();
80                         }
81                         $group = $account['AccountTypeName'];
82                         //$rep->TextCol(0, 4, $account['AccountTypeName']);
83                         $rep->TextCol(0, 1, $account['AccountType']);
84                         $rep->TextCol(1, 4, $account['AccountTypeName']);
85                         //$rep->Line($rep->row - 4);
86                         //$rep->row -= ($rep->lineHeight + 4);
87                         $rep->NewLine();
88                 }
89                 $classname = $account['AccountClassName'];
90                 
91                 if ($account['account_code'] != null)
92                 {
93                         if ($showbalance == 1)
94                         {
95                                 $begin = begin_fiscalyear();
96                                 if (is_account_balancesheet($account["account_code"]))
97                                         $begin = "";
98                                 $balance = get_gl_trans_from_to($begin, ToDay(), $account["account_code"], 0);
99                         }
100                         $rep->TextCol(0, 1,     $account['account_code']);
101                         $rep->TextCol(1, 2,     $account['account_name']);
102                         $rep->TextCol(2, 3,     $account['account_code2']);
103                         if ($showbalance == 1)  
104                                 $rep->AmountCol(3, 4, $balance, $dec);
105
106                         $rep->NewLine();
107                         if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
108                         {
109                                 $rep->Line($rep->row - 2);
110                                 $rep->Header();
111                         }
112                 }       
113         }
114         $rep->Line($rep->row);
115         $rep->End();
116 }
117
118 ?>