-
Notifications
You must be signed in to change notification settings - Fork 0
/
asset_service_hist.php
executable file
·146 lines (122 loc) · 3.62 KB
/
asset_service_hist.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
require ("settings.php");
error_reporting(E_ALL);
$OUTPUT = display();
require ("template.php");
function display()
{
extract ($_REQUEST);
$fields = array();
$fields["frm_year"] = date("Y") - 1;
$fields["frm_month"] = date("m");
$fields["frm_day"] = date("d");
$fields["to_year"] = date("Y");
$fields["to_month"] = date("m");
$fields["to_day"] = date("d");
$fields["group_id"] = 0;
$fields["search"] = "";
extract ($fields, EXTR_SKIP);
$frm_date = "$frm_year-$frm_month-$frm_day";
$to_date = "$to_year-$to_month-$to_day";
// Create the groups dropdown
$sql = "SELECT * FROM cubit.assetgrp";
$group_rslt = db_exec($sql) or errDie("Unable to retrieve asset group.");
$group_sel = "<select name='group_id' style='width: 100%'>";
$group_sel.= "<option value='0'>All</option>";
while ($group_data = pg_fetch_array($group_rslt)) {
if ($group_data["grpid"] == $group_id) {
$sel = "selected";
} else {
$sel = "";
}
$group_sel .= "
<option value='$group_data[grpid]' $sel>
$group_data[grpname]
</option>";
}
// Retrieve the service history -------------------------------------------
$sql = "
SELECT * FROM cubit.asset_svdates
WHERE (svdate BETWEEN '$frm_date' AND '$to_date') ORDER BY svdate DESC";
$service_rslt = db_exec($sql) or errDie("Unable to retrieve service dates.");
$service_out = "";
while ($service_data = pg_fetch_array($service_rslt)) {
// Should we search by groups
if ($group_id) {
$group_sql = "AND grpid='$group_id'";
} else {
$group_sql = "";
}
// Retrieve the asset information
$sql = "
SELECT * FROM cubit.assets
WHERE id='$service_data[asset_id]' $group_sql AND (
des ILIKE '$search%' OR serial ILIKE '$search%' OR
serial2 ILIKE '$search%')";
$asset_rslt = db_exec($sql) or errDie("Unable to retrieve asset data.");
if (!pg_num_rows($asset_rslt)) {
continue;
}
$asset_data = pg_fetch_array($asset_rslt);
// Retrieve the asset group
$sql = "SELECT * FROM cubit.assetgrp WHERE grpid='$asset_data[grpid]'";
$group_rslt = db_exec($sql) or errDie("Unable to retrieve asset group.");
$group_data = pg_fetch_array($group_rslt);
$service_out .= "<tr class='".bg_class()."'>
<td>$service_data[svdate]</td>
<td>$group_data[grpname]</td>
<td>$asset_data[des]</td>
<td>$asset_data[serial]</td>
<td>$asset_data[serial2]</td>
</tr>";
}
if (empty($service_out)) {
$service_out = "<tr class='".bg_class()."'>
<td colspan='5'>No results found.</td>
</tr>";
}
$OUTPUT = "<center>
<h3>Assets Service History</h3>
<form method='post' action='".SELF."'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='4'>Date Range</th>
</tr>
<tr class='".bg_class()."'>
<td><b> From </b></td>
<td>".mkDateSelect("frm", $frm_year, $frm_month, $frm_day)."</td>
<td><b> To </b></td>
<td>".mkDateSelect("to", $to_year, $to_month, $to_day)."</td>
</tr>
<tr>
<th colspan='2'>Search</th>
<th colspan='2'>Group</th>
</tr>
<tr class='".bg_class()."'>
<td colspan='2'>
<input type='text' name='search' value='$search'
style='width:100%' />
</td>
<td colspan='2'>$group_sel</td>
</tr>
<tr class='".bg_class()."'>
<td colspan='4' align='center'>
<input type='submit' value='Search »' />
</td>
</tr>
</table>
</form>
<p></p>
<table ".TMPL_tblDflts.">
<tr>
<th>Service Date</th>
<th>Group</th>
<th>Description</th>
<th>Serial No</th>
<th>2nd Serial No</th>
</tr>
$service_out
</table>
</center>";
return $OUTPUT;
}