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"); $fields["perc_search"] = "100"; $fields["export"] = 0; extract($fields, EXTR_SKIP); $from_date = dateFmt($from_year, $from_month, $from_day); $to_date = dateFmt($to_year, $to_month, $to_day); $sql = "SELECT id, serial, des, grpname\r\n\t\t\tFROM cubit.assets\r\n\t\t\t\tLEFT JOIN cubit.assetgrp ON assets.grpid=assetgrp.grpid\r\n\t\t\tORDER BY serial ASC"; $asset_rslt = db_exec($sql) or errDie("Unable to retrieve assets."); $asset_out = ""; while ($asset_data = pg_fetch_array($asset_rslt)) { $percentage = utilisationPerc($asset_data["id"], $from_date, $to_date); if (!is_numeric($perc_search) || $percentage > $perc_search) { continue; } $asset_out .= "<tr class='" . bg_class() . "'>\r\n\t\t\t<td>{$asset_data['grpname']}</td>\r\n\t\t\t<td>" . getSerial($asset_data["id"]) . "</td>\r\n\t\t\t<td>{$asset_data['des']}</td>\r\n\t\t\t<td align='center'>\r\n\t\t\t\t<b>" . utilisationDays($asset_data["id"], $from_date, $to_date) . "</b>\r\n\t\t\t</td>\r\n\t\t\t<td align='center' >\r\n\t\t\t\t<b>{$percentage}%</b>\r\n\t\t\t</td>\r\n\t\t\t<td width='2%' bgcolor='" . ext_progressColor($percentage) . "'> </td>\r\n\t\t</tr>"; } if (empty($asset_out)) { $asset_out = "<tr class='" . bg_class() . "'>\r\n\t\t\t<td colspan='6'><li>No results found</li></td>\r\n\t\t</tr>"; } $OUTPUT = "<center>\r\n\t<h3>Hire Utilisation Report</h3>\r\n\t<form method='post' action='" . SELF . "'>\r\n\t<table " . TMPL_tblDflts . ">\r\n\t\t<tr>\r\n\t\t\t<th colspan='3'>Date Range</th>\r\n\t\t</tr>\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td>" . mkDateSelect("from", $from_year, $from_month, $from_day) . "</td>\r\n\t\t\t<td> <b> To </b> </td>\r\n\t\t\t<td>" . mkDateSelect("to", $to_year, $to_month, $to_day) . "</td>\r\n\t\t</tr>\r\n\t\t<tr>\r\n\t\t\t<th colspan='3'>Utilisation Percentage Filter (Less Than or Equal)</th>\r\n\t\t</tr>\r\n\t\t<tr class='" . bg_class() . "'>\r\n\t\t\t<td colspan='3' align='center'>\r\n\t\t\t\t<input type='text' name='perc_search' value='{$perc_search}'\r\n\t\t\t\tsize='2' style='text-align: center' />%\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t<tr>\r\n\t\t\t<td colspan='3' align='center'>\r\n\t\t\t\t<input type='submit' value='Apply to Report'\r\n\t\t\t\tstyle='font-weight: bold; font-size: 1.1em' />\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t</table>\r\n\t</form>"; $OUTPUT .= $xls_out = "\r\n\t<h3>Hire Utilisation Report For {$from_date} to {$to_date}</h3>\r\n\t<table " . TMPL_tblDflts . " width='70%'>\r\n\t\t<tr>\r\n\t\t\t<th>Group</th>\r\n\t\t\t<th>Serial</th>\r\n\t\t\t<th>Description</th>\r\n\t\t\t<th>Days Hired</th>\r\n\t\t\t<th>Utilisation Percentage</th>\r\n\t\t\t<th width='2%'> </th>\r\n\t\t</tr>\r\n\t\t{$asset_out}\r\n\t</table>"; $OUTPUT .= "\r\n\t<form method='post' action='" . SELF . "'>\r\n\t\t<input type='hidden' name='export' value='1' />\r\n\t\t<input type='submit' value='Export to Spreadsheet' />\r\n\t</form>\r\n\t</center>"; if ($export) { $xls_out = clean_html($xls_out); require_lib("xls"); StreamXLS("hire_utilisation", $xls_out); } return $OUTPUT; }
function utilisationPerc($asset_id, $from_date, $to_date) { $DAYS = 60 * 60 * 24; $from_time = getDTEpoch("{$from_date} 0:00:00"); $to_time = getDTEpoch("{$to_date} 23:59:59"); $total_days = ($to_time - $from_time) / $DAYS; $hired_days = utilisationDays($asset_id, $from_date, $to_date); $percentage = $hired_days / $total_days * 100; return sprint($percentage); }