*** empty log message ***
[fa-stable.git] / reporting / rep501.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       Bill Of Material
9 // ----------------------------------------------------------------
10 $path_to_root="../";
11
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
16
17 //----------------------------------------------------------------------------------------------------
18
19 // trial_inquiry_controls();
20 print_dimension_summary();
21
22 function getTransactions($from, $to)
23 {
24         $sql = "SELECT *
25                 FROM
26                         ".TB_PREF."dimensions
27                 WHERE reference >= '$from'
28                 AND reference <= '$to'
29                 ORDER BY
30                         reference";
31
32     return db_query($sql,"No transactions were returned");
33 }
34
35 function getYTD($dim)
36 {
37         $date = Today();
38         $date = begin_fiscalyear($date);
39         date2sql($date);
40         
41         $sql = "SELECT SUM(amount) AS Balance
42                 FROM
43                         ".TB_PREF."gl_trans
44                 WHERE (dimension_id = '$dim' OR dimension2_id = '$dim')
45                 AND tran_date >= '$date'";
46
47     $TransResult = db_query($sql,"No transactions were returned");
48         if (db_num_rows($TransResult) == 1)
49         {
50                 $DemandRow = db_fetch_row($TransResult);
51                 $balance = $DemandRow[0];
52         }
53         else
54                 $balance = 0.0;
55
56     return $balance;
57 }
58
59 //----------------------------------------------------------------------------------------------------
60
61 function print_dimension_summary()
62 {
63     global $path_to_root;
64
65     include_once($path_to_root . "reporting/includes/pdf_report.inc");
66
67     $fromdim = $_POST['PARAM_0'];
68     $todim = $_POST['PARAM_1'];
69     $showbal = $_POST['PARAM_2'];
70     $comments = $_POST['PARAM_3'];
71     
72
73         $cols = array(0, 50, 210, 250, 320, 395, 465,   515);
74
75         $headers = array(_('Reference'), _('Name'), _('Type'), _('Date'), _('Due Date'), _('Closed'), _('YTD'));
76
77         $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'right');
78
79     $params =   array(  0 => $comments,
80                                     1 => array('text' => _('Dimension'), 'from' => $fromdim, 'to' => $todim));
81
82     $rep = new FrontReport(_('Dimension Summary'), "DimensionSummary.pdf", user_pagesize());
83
84     $rep->Font();
85     $rep->Info($params, $cols, $headers, $aligns);
86     $rep->Header();
87
88         $res = getTransactions($fromdim, $todim);
89         while ($trans=db_fetch($res))
90         {
91                 $rep->TextCol(0, 1, $trans['reference']);
92                 $rep->TextCol(1, 2, $trans['name']);
93                 $rep->TextCol(2, 3, $trans['type_']);
94                 $rep->TextCol(3, 4, $trans['date_']);
95                 $rep->TextCol(4, 5, $trans['due_date']);
96                 if ($trans['closed'])
97                         $str = _('Yes');
98                 else
99                         $str = _('No');
100                 $rep->TextCol(5, 6, $str);
101                 if ($showbal)
102                 {
103                         $balance = getYTD($trans['id']);
104                         $rep->TextCol(6, 7, number_format2($balance, 0));
105                 }       
106                 $rep->NewLine(1, 2);
107         }
108         $rep->Line($rep->row);
109     $rep->End();
110 }
111
112 ?>