9694b7a3b33298251ecbea7b7fe40c5835434d32
[fa-stable.git] / reporting / rep501.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:       Dimension Summary
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_dimension_summary();
30
31 function getTransactions($from, $to)
32 {
33         $sql = "SELECT *
34                 FROM
35                         ".TB_PREF."dimensions
36                 WHERE reference >= '$from'
37                 AND reference <= '$to'
38                 ORDER BY
39                         reference";
40
41     return db_query($sql,"No transactions were returned");
42 }
43
44 function getYTD($dim)
45 {
46         $date = Today();
47         $date = begin_fiscalyear($date);
48         date2sql($date);
49         
50         $sql = "SELECT SUM(amount) AS Balance
51                 FROM
52                         ".TB_PREF."gl_trans
53                 WHERE (dimension_id = '$dim' OR dimension2_id = '$dim')
54                 AND tran_date >= '$date'";
55
56     $TransResult = db_query($sql,"No transactions were returned");
57         if (db_num_rows($TransResult) == 1)
58         {
59                 $DemandRow = db_fetch_row($TransResult);
60                 $balance = $DemandRow[0];
61         }
62         else
63                 $balance = 0.0;
64
65     return $balance;
66 }
67
68 //----------------------------------------------------------------------------------------------------
69
70 function print_dimension_summary()
71 {
72     global $path_to_root;
73
74     $fromdim = $_POST['PARAM_0'];
75     $todim = $_POST['PARAM_1'];
76     $showbal = $_POST['PARAM_2'];
77     $comments = $_POST['PARAM_3'];
78         $destination = $_POST['PARAM_4'];
79         if ($destination)
80         {
81                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
82                 $filename = "DimensionSummary.xml";
83         }       
84         else
85         {
86                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
87                 $filename = "DimensionSummary.pdf";
88         }
89
90         $cols = array(0, 50, 210, 250, 320, 395, 465,   515);
91
92         $headers = array(_('Reference'), _('Name'), _('Type'), _('Date'), _('Due Date'), _('Closed'), _('YTD'));
93
94         $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'right');
95
96     $params =   array(  0 => $comments,
97                                     1 => array('text' => _('Dimension'), 'from' => $fromdim, 'to' => $todim));
98
99     $rep = new FrontReport(_('Dimension Summary'), $filename, user_pagesize());
100
101     $rep->Font();
102     $rep->Info($params, $cols, $headers, $aligns);
103     $rep->Header();
104
105         $res = getTransactions($fromdim, $todim);
106         while ($trans=db_fetch($res))
107         {
108                 $rep->TextCol(0, 1, $trans['reference']);
109                 $rep->TextCol(1, 2, $trans['name']);
110                 $rep->TextCol(2, 3, $trans['type_']);
111                 $rep->DateCol(3, 4, $trans['date_'], true);
112                 $rep->DateCol(4, 5, $trans['due_date'], true);
113                 if ($trans['closed'])
114                         $str = _('Yes');
115                 else
116                         $str = _('No');
117                 $rep->TextCol(5, 6, $str);
118                 if ($showbal)
119                 {
120                         $balance = getYTD($trans['id']);
121                         $rep->AmountCol(6, 7, $balance, 0);
122                 }       
123                 $rep->NewLine(1, 2);
124         }
125         $rep->Line($rep->row);
126     $rep->End();
127 }
128
129 ?>