Stable merged into unstable again (due to failure on binary file during previous...
[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 function display_type ($type, $typename, &$dec, &$rep, $showbalance, $level)
29 {
30         $printtitle = 0; //Flag for printing type name  
31
32         //Get Accounts directly under this group/type
33         $result = get_gl_accounts(null, null, $type);   
34         while ($account=db_fetch($result))
35         {
36                 //Print Type Title if it has atleast one non-zero account       
37                 if (!$printtitle)
38                 {
39                         $prefix = '';
40                         for ($sp=1; $sp<=$level; $sp++)
41                         {
42                                 $prefix .= '         ';
43                         }
44                         $printtitle = 1;
45                         $rep->row -= 4;
46                         $rep->TextCol(0, 1, $type);
47                         $rep->TextCol(1, 4, $prefix.$typename);
48                         $rep->row -= 4;
49                         $rep->Line($rep->row);
50                         $rep->NewLine();                
51                 }                       
52                 if ($showbalance == 1)
53                 {
54                         $begin = begin_fiscalyear();
55                         if (is_account_balancesheet($account["account_code"]))
56                                 $begin = "";
57                         $balance = get_gl_trans_from_to($begin, ToDay(), $account["account_code"], 0);
58                 }
59                 $rep->TextCol(0, 1,     $account['account_code']);
60                 $rep->TextCol(1, 2,     $prefix.$account['account_name']);
61                 $rep->TextCol(2, 3,     $account['account_code2']);
62                 if ($showbalance == 1)  
63                         $rep->AmountCol(3, 4, $balance, $dec);
64                 $rep->NewLine();
65         }
66
67         //Get Account groups/types under this group/type
68         $result = get_account_types(false, false, $type);
69         while ($accounttype=db_fetch($result))
70         {
71                 //Print Type Title if has sub types and not previously printed
72                 if (!$printtitle)
73                 {
74                         $printtitle = 1;
75                         $rep->row -= 4;
76                         $rep->TextCol(0, 1, $type);
77                         $rep->TextCol(1, 4, $typename);
78                         $rep->row -= 4;
79                         $rep->Line($rep->row);
80                         $rep->NewLine();                
81                 }
82                 $nextlevel = $level + 1;
83                 display_type($accounttype["id"], $accounttype["name"].' ('.$typename.')', $dec, $rep, $showbalance, $nextlevel);
84         }
85 }
86
87 //----------------------------------------------------------------------------------------------------
88
89 print_Chart_of_Accounts();
90
91 //----------------------------------------------------------------------------------------------------
92
93 function print_Chart_of_Accounts()
94 {
95         global $path_to_root;
96
97         $showbalance = $_POST['PARAM_0'];
98         $comments = $_POST['PARAM_1'];
99         $destination = $_POST['PARAM_2'];
100         if ($destination)
101                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
102         else
103                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
104
105         $dec = 0;
106
107         $cols = array(0, 50, 300, 425, 500);
108
109         $headers = array(_('Account'), _('Account Name'), _('Account Code'), _('Balance'));
110         
111         $aligns = array('left', 'left', 'left', 'right');
112         
113         $params = array(0 => $comments);
114
115         $rep = new FrontReport(_('Chart of Accounts'), "ChartOfAccounts", user_pagesize());
116         
117         $rep->Font();
118         $rep->Info($params, $cols, $headers, $aligns);
119         $rep->NewPage();
120
121         $classresult = get_account_classes(false);
122         while ($class = db_fetch($classresult))
123         {
124                 $rep->Font('bold');
125                 $rep->TextCol(0, 1, $class['cid']);
126                 $rep->TextCol(1, 4, $class['class_name']);
127                 $rep->Font();
128                 $rep->NewLine();
129
130                 //Get Account groups/types under this group/type with no parents
131                 $typeresult = get_account_types(false, $class['cid'], -1);
132                 while ($accounttype=db_fetch($typeresult))
133                 {
134                         display_type($accounttype["id"], $accounttype["name"], $dec, $rep, $showbalance, 0);
135                 }
136                 $rep->NewLine();
137         }
138         $rep->Line($rep->row + 10);
139         $rep->End();
140 }
141
142 ?>