/** * HTML table showing a summary of current contract service periods * @author Ivan Lucas * @param int $contractid. Contract ID of the contract to show service for * @param bool $billing. Show billing info when TRUE, hide it when FALSE * @returns string. HTML table */ function contract_service_table($contractid, $billing) { global $CONFIG, $dbService; $sql = "SELECT * FROM `{$dbService}` WHERE contractid = {$contractid} ORDER BY enddate DESC"; $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } if (mysql_num_rows($result) > 0) { $shade = ''; $html = "\n<table align='center'>"; $html .= "<tr>"; if ($billing) { $html .= "<th></th>"; } $html .= "<th>{$GLOBALS['strStartDate']}</th><th>{$GLOBALS['strEndDate']}</th>"; if ($billing) { $html .= "<th>{$GLOBALS['strAvailableBalance']}</th>"; } $html .= "<th>{$GLOBALS['strOperation']}</th>"; $html .= "</tr>\n"; while ($service = mysql_fetch_object($result)) { $service->startdate = mysql2date($service->startdate . '09:00'); $service->enddate = mysql2date($service->enddate . '17:00'); $service->lastbilled = mysql2date($service->lastbilled); $html .= "<tr class='{$shade}'>"; if ($billing) { $balance = get_service_balance($service->serviceid); $awaitingapproval = service_transaction_total($service->serviceid, BILLING_AWAITINGAPPROVAL) * -1; $reserved = service_transaction_total($service->serviceid, BILLING_RESERVED) * -1; $span = "<strong>{$GLOBALS['strServiceID']}:</strong> {$service->serviceid}<br />"; if (!empty($service->title)) { $span .= "<strong>{$GLOBALS['strTitle']}</strong>: {$service->title}<br />"; } if (!empty($service->notes)) { $span .= "<strong>{$GLOBALS['strNotes']}</strong>: {$service->notes}<br />"; } if (!empty($service->cust_ref)) { $span .= "<strong>{$GLOBALS['strCustomerReference']}</strong>: {$service->cust_ref}"; if ($service->cust_ref_date != "1970-01-01") { $span .= " - <strong>{$GLOBALS['strCustomerReferenceDate']}</strong>: {$service->cust_ref_date}"; } $span .= "<br />"; } if ($service->creditamount != 0) { $span .= "<strong>{$GLOBALS['strCreditAmount']}</strong>: {$CONFIG['currency_symbol']}" . number_format($service->creditamount, 2) . "<br />"; } if ($service->unitrate != 0) { $span .= "<strong>{$GLOBALS['strUnitRate']}</strong>: {$CONFIG['currency_symbol']}{$service->unitrate}<br />"; } if ($balance != $service->balance) { $span .= "<strong>{$GLOBALS['strBalance']}</strong>: {$CONFIG['currency_symbol']}" . number_format($service->balance, 2) . "<br />"; if ($awaitingapproval != FALSE) { $span .= "<strong>{$GLOBALS['strAwaitingApproval']}</strong>: {$CONFIG['currency_symbol']}" . number_format($awaitingapproval, 2) . "<br />"; } if ($reserved != FALSE) { $span .= "<strong>{$GLOBALS['strReserved']}</strong>: {$CONFIG['currency_symbol']}" . number_format($reserved, 2) . "<br />"; } $span .= "<strong>{$GLOBALS['strAvailableBalance']}</strong>: {$CONFIG['currency_symbol']}" . number_format($balance, 2) . "<br />"; } if ($service->lastbilled > 0) { $span .= "<strong>{$GLOBALS['strLastBilled']}</strong>: " . ldate($CONFIG['dateformat_date'], $service->lastbilled) . "<br />"; } if ($service->foc == 'yes') { $span .= "<strong>{$GLOBALS['strFreeOfCharge']}</strong>"; } $html .= "<td><a href='transactions.php?serviceid={$service->serviceid}' class='info'>" . icon('billing', 16); if (!empty($span)) { $html .= "<span>{$span}</span>"; } $html .= "</a></td>"; $html .= "<td><a href='transactions.php?serviceid={$service->serviceid}' class='info'>" . ldate($CONFIG['dateformat_date'], $service->startdate); if (!empty($span)) { $html .= "<span>{$span}</span>"; } $html .= "</a></td>"; } else { $html .= "<td>" . ldate($CONFIG['dateformat_date'], $service->startdate); $html .= "</td>"; } $html .= "<td>"; $html .= ldate($CONFIG['dateformat_date'], $service->enddate) . "</td>"; if ($billing) { $html .= "<td>{$CONFIG['currency_symbol']}" . number_format($balance, 2) . "</td>"; } $html .= "<td><a href='contract_edit_service.php?mode=editservice&serviceid={$service->serviceid}&contractid={$contractid}'>{$GLOBALS['strEditService']}</a>"; if ($billing) { $html .= " | <a href='contract_edit_service.php?mode=showform&sourceservice={$service->serviceid}&contractid={$contractid}'>{$GLOBALS['strEditBalance']}</a>"; } $html .= "</td></tr>\n"; } $html .= "</table>\n"; if ($shade == 'shade1') { $shade = 'shade2'; } else { $shade = 'shade1'; } } return $html; }
$shade = 'shade1'; while ($obj = mysql_fetch_object($result)) { if ($obj->foc == 'yes' and !empty($focaszero)) { $obj->creditamount = 0; $obj->balance = 0; } if (!empty($expiredaszero) and strtotime($obj->enddate) < $now) { $obj->balance = 0; $unitsat1times = 0; $actual = 0; } $totalcredit += $obj->creditamount; $totalbalance += $obj->balance; $awaitingapproval = service_transaction_total($obj->serviceid, BILLING_AWAITINGAPPROVAL) * -1; $totalawaitingapproval += $awaitingapproval; $reserved = service_transaction_total($obj->serviceid, BILLING_RESERVED) * -1; $totalreserved += $reserved; $actual = $obj->balance - $awaitingapproval - $reserved; $totalactual += $actual; if ($obj->unitrate != 0) { $unitsat1times = round($actual / $obj->unitrate, 2); } else { $unitsat1times = 0; } $remainingunits += $unitsat1times; if ($display == 'html') { if ($obj->site != $lastsite or $obj->product != $lastproduct) { if ($shade == 'shade1') { $shade = 'shade2'; } else { $shade = 'shade1';