PHP 7.4 Bugs in some reports.
[fa-stable.git] / reporting / rep710.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_GLANALYTIC';
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       Audit Trail
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 include_once($path_to_root . "/includes/ui/ui_view.inc");
26
27 //----------------------------------------------------------------------------------------------------
28
29 print_audit_trail();
30
31 function getTransactions($from, $to, $type, $user)
32 {
33         $fromdate = date2sql($from) . " 00:00:00";
34         $todate = date2sql($to). " 23:59.59";
35
36         $sql = "SELECT a.*, 
37                 SUM(IF(ISNULL(g.amount), NULL, IF(g.amount > 0, g.amount, 0))) AS amount,
38                 u.user_id,
39                 UNIX_TIMESTAMP(a.stamp) as unix_stamp
40                 FROM ".TB_PREF."audit_trail AS a JOIN ".TB_PREF."users AS u
41                 LEFT JOIN ".TB_PREF."gl_trans AS g ON (g.type_no=a.trans_no
42                         AND g.type=a.type)
43                 WHERE a.user = u.id ";
44         if ($type != -1)
45                 $sql .= "AND a.type=$type ";
46         if ($user != -1)        
47                 $sql .= "AND a.user='$user' ";
48         $sql .= "AND a.stamp >= '$fromdate'
49                         AND a.stamp <= '$todate'
50                 GROUP BY a.trans_no,a.gl_seq,a.stamp    
51                 ORDER BY a.stamp,a.gl_seq";
52     return db_query($sql,"No transactions were returned");
53 }
54 //----------------------------------------------------------------------------------------------------
55
56 function print_audit_trail()
57 {
58     global $path_to_root, $systypes_array;
59
60     $from = $_POST['PARAM_0'];
61     $to = $_POST['PARAM_1'];
62     $systype = $_POST['PARAM_2'];
63     $user = $_POST['PARAM_3'];
64     $comments = $_POST['PARAM_4'];
65         $orientation = $_POST['PARAM_5'];
66         $destination = $_POST['PARAM_6'];
67         if ($destination)
68                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
69         else
70                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
71
72         $orientation = ($orientation ? 'L' : 'P');
73     $dec = user_price_dec();
74
75     $cols = array(0, 60, 120, 180, 240, 340, 400, 460, 520);
76
77     $headers = array(_('Date'), _('Time'), _('User'), _('Trans Date'),
78         _('Type'), _('#'), _('Action'), _('Amount'));
79
80     $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'left', 'right');
81
82         $usr = get_user($user);
83         $user_id = isset($usr['user_id']) ? $usr['user_id'] : "";
84     $params =   array(  0 => $comments,
85                                     1 => array('text' => _('Period'), 'from' => $from,'to' => $to),
86                         2 => array('text' => _('Type'), 'from' => ($systype != -1 ? $systypes_array[$systype] : _('All')), 'to' => ''),
87                         3 => array('text' => _('User'), 'from' => ($user != -1 ? $user_id : _('All')), 'to' => ''));
88
89     $rep = new FrontReport(_('Audit Trail'), "AuditTrail", user_pagesize(), 9, $orientation);
90     if ($orientation == 'L')
91         recalculate_cols($cols);
92
93     $rep->Font();
94     $rep->Info($params, $cols, $headers, $aligns);
95     $rep->NewPage();
96
97     $trans = getTransactions($from, $to, $systype, $user);
98
99         $tot_amount = 0;
100     while ($myrow=db_fetch($trans))
101     {
102         $rep->TextCol(0, 1, sql2date(date("Y-m-d", $myrow['unix_stamp'])));
103         if (user_date_format() == 0)
104                 $rep->TextCol(1, 2, date("h:i:s a", $myrow['unix_stamp']));
105         else    
106                 $rep->TextCol(1, 2, date("H:i:s", $myrow['unix_stamp']));
107         $rep->TextCol(2, 3, $myrow['user_id']);
108         $rep->TextCol(3, 4, sql2date($myrow['gl_date']));
109         $rep->TextCol(4, 5, $systypes_array[$myrow['type']]);
110         $rep->TextCol(5, 6, $myrow['trans_no']);
111         if ($myrow['gl_seq'] == null)
112                 $action = _('Changed');
113         else
114                 $action = _('Closed');
115         $rep->TextCol(6, 7, $action);
116         if ($myrow['amount'] != null) {
117                 $rep->AmountCol(7, 8, $myrow['amount'], $dec);
118                         if ($systype != -1)
119                                 $tot_amount += $myrow['amount'];
120                 }
121         $rep->NewLine(1, 2);
122     }
123     $rep->Line($rep->row  + 4);
124         if ($systype != -1) {
125         $rep->NewLine(1, 2);
126         $rep->TextCol(6, 7, _('Total'));
127                 $rep->AmountCol(7, 8, $tot_amount, $dec);
128         }
129     $rep->End();
130 }
131