Changed license type to GPLv3 in top of files
[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     include_once($path_to_root . "/reporting/includes/pdf_report.inc");
75
76     $fromdim = $_POST['PARAM_0'];
77     $todim = $_POST['PARAM_1'];
78     $showbal = $_POST['PARAM_2'];
79     $comments = $_POST['PARAM_3'];
80     
81
82         $cols = array(0, 50, 210, 250, 320, 395, 465,   515);
83
84         $headers = array(_('Reference'), _('Name'), _('Type'), _('Date'), _('Due Date'), _('Closed'), _('YTD'));
85
86         $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'right');
87
88     $params =   array(  0 => $comments,
89                                     1 => array('text' => _('Dimension'), 'from' => $fromdim, 'to' => $todim));
90
91     $rep = new FrontReport(_('Dimension Summary'), "DimensionSummary.pdf", user_pagesize());
92
93     $rep->Font();
94     $rep->Info($params, $cols, $headers, $aligns);
95     $rep->Header();
96
97         $res = getTransactions($fromdim, $todim);
98         while ($trans=db_fetch($res))
99         {
100                 $rep->TextCol(0, 1, $trans['reference']);
101                 $rep->TextCol(1, 2, $trans['name']);
102                 $rep->TextCol(2, 3, $trans['type_']);
103                 $rep->TextCol(3, 4, $trans['date_']);
104                 $rep->TextCol(4, 5, $trans['due_date']);
105                 if ($trans['closed'])
106                         $str = _('Yes');
107                 else
108                         $str = _('No');
109                 $rep->TextCol(5, 6, $str);
110                 if ($showbal)
111                 {
112                         $balance = getYTD($trans['id']);
113                         $rep->TextCol(6, 7, number_format2($balance, 0));
114                 }       
115                 $rep->NewLine(1, 2);
116         }
117         $rep->Line($rep->row);
118     $rep->End();
119 }
120
121 ?>