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