Preparation for report destination PDF/Printer and Excel (and Open Office Calc)
[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 = 2;
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 // trial_inquiry_controls();
29 print_Chart_of_Accounts();
30
31 //----------------------------------------------------------------------------------------------------
32
33 function print_Chart_of_Accounts()
34 {
35         global $path_to_root;
36
37         $showbalance = $_POST['PARAM_0'];
38         $comments = $_POST['PARAM_1'];
39         $destination = $_POST['PARAM_2'];
40         if (isset($destination) && $destination)
41         {
42                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
43                 $filename = "ChartOfAccounts.xml";
44         }       
45         else
46         {
47                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
48                 $filename = "ChartOfAccounts.pdf";
49         }
50         $dec = 0;
51
52         $cols = array(0, 50, 300, 425, 500);
53
54         $headers = array(_('Account'), _('Account Name'), _('Account Code'), _('Balance'));
55         
56         $aligns = array('left', 'left', 'left', 'right');
57         
58         $params = array(0 => $comments);
59
60         $rep = new FrontReport(_('Chart of Accounts'), $filename, user_pagesize());
61         
62         $rep->Font();
63         $rep->Info($params, $cols, $headers, $aligns);
64         $rep->Header();
65
66         $classname = '';
67         $group = '';
68
69         $accounts = get_gl_accounts_all();
70
71         while ($account=db_fetch($accounts))
72         {
73                 if ($showbalance == 1)
74                 {
75                         $begin = begin_fiscalyear();
76                         if (is_account_balancesheet($account["account_code"]))
77                                 $begin = "";
78                         $balance = get_gl_trans_from_to($begin, ToDay(), $account["account_code"], 0);
79                 }
80                 if ($account['AccountTypeName'] != $group)
81                 {
82                         if ($classname != '')
83                                 $rep->row -= 4;
84                         if ($account['AccountClassName'] != $classname)
85                         {
86                                 $rep->Font('bold');
87                                 $rep->TextCol(0, 4, $account['AccountClassName']);
88                                 $rep->Font();
89                                 //$rep->row -= ($rep->lineHeight + 4);
90                                 $rep->NewLine();
91                         }
92                         $group = $account['AccountTypeName'];
93                         $rep->TextCol(0, 4, $account['AccountTypeName']);
94                         //$rep->Line($rep->row - 4);
95                         //$rep->row -= ($rep->lineHeight + 4);
96                         $rep->NewLine();
97                 }
98                 $classname = $account['AccountClassName'];
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         $rep->Line($rep->row);
114         $rep->End();
115 }
116
117 ?>