/
hire_history_report.php
executable file
·93 lines (80 loc) · 2.47 KB
/
hire_history_report.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
<?php
require ("../settings.php");
$OUTPUT = display();
require ("../template.php");
function display()
{
extract($_REQUEST);
$fields = array();
$fields["from_year"] = date("Y");
$fields["from_month"] = date("m");
$fields["from_day"] = "01";
$fields["to_year"] = date("Y");
$fields["to_month"] = date("m");
$fields["to_day"] = date("d");
extract($fields, EXTR_SKIP);
$from_date = "$from_year-$from_month-$from_day";
$to_date = "$to_year-$to_month-$to_day";
$sql = "SELECT assets_hired.invnum, surname, des, assets_hired.invid,
extract('epoch' FROM hired_time) AS e_hired,
extract('epoch' FROM return_time) AS e_return
FROM hire.assets_hired
LEFT JOIN hire.notes_reprint
ON assets_hired.invid=notes_reprint.invid
LEFT JOIN cubit.customers
ON assets_hired.cust_id=customers.cusnum
LEFT JOIN cubit.assets
ON assets_hired.asset_id=assets.id
WHERE hired_time BETWEEN '$from_date 0:00:00' AND '$to_date 23:59:59' OR
return_time BETWEEN '$from_date 0:00:00' AND '$to_date 23:59:59'
ORDER BY invnum DESC";
$history_rslt = db_exec($sql) or errDie("Unable to retrieve history.");
$history_out = "";
while ($history_data = pg_fetch_array($history_rslt)) {
if ($history_data["e_return"]) {
$return = date("d-m-Y", $history_data["e_return"]);
} else {
$return = "Still on Hire";
}
$history_out .= "
<tr class='".bg_class()."'>
<td>H".getHirenum($history_data["invid"], 1)."</td>
<td>$history_data[surname]</td>
<td>$history_data[des]</td>
<td>".date("d-m-Y", $history_data["e_hired"])."</td>
<td>$return</td>
</tr>";
}
if (empty($history_out)) {
$history_out = "
<tr class='".bg_class()."'>
<td colspan='5'><li>No results found</li></td>
</tr>";
}
$OUTPUT = "<center>
<h3>Hire History Report</h3>
<form method='post' action='".SELF."'>
<table ".TMPL_tblDflts.">
<tr><th colspan='4'>Date Range</th></tr>
<tr class='".bg_class()."'>
<td>".mkDateSelect("from", $from_year, $from_month, $from_day)."</td>
<td> <b>To</b> </td>
<td>".mkDateSelect("to", $to_year, $to_month, $to_day)."</td>
<td>
<input type='submit' value='Select' style='font-weight: bold' />
</td>
</tr>
</table>
</form>
<table ".TMPL_tblDflts.">
<tr>
<th>Hire No</th>
<th>Company / Name</th>
<th>Product</th>
<th>Date Hired</th>
<th>Date Returned</th>
</tr>
$history_out
</table>";
return $OUTPUT;
}