-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathreports.php
97 lines (73 loc) · 2.68 KB
/
reports.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
Copyright (C) 2010 Craig A Rodway.
This file is part of Print Master.
Print Master is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Print Master is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Print Master. If not, see <http://www.gnu.org/licenses/>.
*/
// Include initialisation file
include_once('inc/core.php');
// Get action from query string
$action = fRequest::getValid('action', array('list'));
$printer_id = fCRUD::getSearchValue('printer_id');
$date_from = fCRUD::getSearchValue('date_from');
$date_to = fCRUD::getSearchValue('date_to');
/**
* Default action - show report of consumable installation
*/
if ($action == 'list') {
// Set the users to be sortable by name or email, defaulting to name
$sort = fCRUD::getSortColumn(array(
'events.date', 'models.name', 'printers.name', 'consumables.name', 'events.cost'
));
// Set the sorting to default to ascending
$dir = fCRUD::getSortDirection('desc');
// Redirect the user if one of the values was loaded from the session
fCRUD::redirectWithLoadedValues();
// Determine search parameters
$sql_where = '';
if ($printer_id)
{
$printer = new Printer($printer_id);
$sql_where .= ' AND events.printer_id = ' . $db->escape('integer', $printer_id);
}
if ($date_from)
{
$sql_where .= ' AND DATE(events.date) >= ' . $db->escape('date', $date_from);
}
if ($date_to)
{
$sql_where .= ' AND DATE(events.date) <= ' . $db->escape('date', $date_to);
}
// Get recordset object from tables
$sql = "SELECT
CAST(CONCAT(manufacturers.name, ' ', models.name) AS CHAR) AS model,
printers.name AS printer_name,
printers.ipaddress,
consumables.name AS consumable_name,
consumables.col_c, consumables.col_y, consumables.col_m, consumables.col_k,
consumables.chargeback,
events.*
FROM events
LEFT JOIN consumables ON events.consumable_id = consumables.id
LEFT JOIN printers ON events.printer_id = printers.id
LEFT JOIN models ON printers.model_id = models.id
LEFT JOIN manufacturers ON models.manufacturer_id = manufacturers.id
WHERE 1 = 1
$sql_where
ORDER BY $sort $dir";
$events = $db->query($sql)->asObjects();
// Get list of printers for dropdown box
$printers = Printer::getSimple($db);
// Include page to show table
include 'views/reports/index.php';
}
?>