Ejemplo n.º 1
0
/**
    * @author Ivan Lucas
    * @param int $contractid. Contract ID of the contract to show a balance for
    * @return int. Number of available units according to the service balances and unit rates
    * @todo Check this is correct
**/
function contract_unit_balance($contractid, $includenonapproved = FALSE, $includereserved = TRUE, $showonlycurrentlyvalid = TRUE)
{
    global $now, $dbService;
    $unitbalance = 0;
    $sql = "SELECT * FROM `{$dbService}` WHERE contractid = {$contractid} ";
    if ($showonlycurrentlyvalid) {
        $sql .= "AND UNIX_TIMESTAMP(startdate) <= {$now} ";
        $sql .= "AND UNIX_TIMESTAMP(enddate) >= {$now}  ";
    }
    $sql .= "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) {
        while ($service = mysql_fetch_object($result)) {
            $multiplier = get_billable_multiplier(strtolower(date('D', $now)), date('G', $now));
            $unitamount = $service->unitrate * $multiplier;
            if ($unitamount > 0 and $service->balance != 0) {
                $unitbalance += round($service->balance / $unitamount);
            }
        }
    }
    if ($includenonapproved) {
        $awaiting = contract_transaction_total($contractid, BILLING_AWAITINGAPPROVAL);
        if ($awaiting != 0) {
            $unitbalance += round($awaiting / $unitamount);
        }
    }
    if ($includereserved) {
        $reserved = contract_transaction_total($contractid, BILLING_RESERVED);
        if ($reserved != 0) {
            $unitbalance += round($reserved / $unitamount);
        }
    }
    return $unitbalance;
}
Ejemplo n.º 2
0
/**
 * Return the html of contract detatils
 * @author Kieran Hogg
 * @param int $maintid - ID of the contract
 * @param string $mode. 'internal' or 'external'
 * @return array of supported contracts, NULL if none
 * @todo FIXME not quite generic enough for a function ?
 */
function contract_details($id, $mode = 'internal')
{
    global $CONFIG, $iconset, $dbMaintenance, $dbSites, $dbResellers, $dbLicenceTypes, $now;
    $sql = "SELECT m.*, m.notes AS maintnotes, s.name AS sitename, ";
    $sql .= "r.name AS resellername, lt.name AS licensetypename ";
    $sql .= "FROM `{$dbMaintenance}` AS m, `{$dbSites}` AS s, ";
    $sql .= "`{$dbResellers}` AS r, `{$dbLicenceTypes}` AS lt ";
    $sql .= "WHERE s.id = m.site ";
    $sql .= "AND m.id='{$id}' ";
    $sql .= "AND m.reseller = r.id ";
    $sql .= "AND (m.licence_type IS NULL OR m.licence_type = lt.id) ";
    if ($mode == 'external') {
        $sql .= "AND m.site = '{$_SESSION['siteid']}'";
    }
    $maintresult = mysql_query($sql);
    if (mysql_error()) {
        trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING);
    }
    $maint = mysql_fetch_object($maintresult);
    $html = "<table align='center' class='vertical'>";
    $html .= "<tr><th>{$GLOBALS['strContract']} {$GLOBALS['strID']}:</th>";
    $html .= "<td><h3>" . icon('contract', 32) . " ";
    $html .= "{$maint->id}</h3></td></tr>";
    $html .= "<tr><th>{$GLOBALS['strStatus']}:</th><td>";
    if ($maint->term == 'yes') {
        $html .= "<strong>{$GLOBALS['strTerminated']}</strong>";
    } else {
        $html .= $GLOBALS['strActive'];
    }
    if ($maint->expirydate < $now and $maint->expirydate != '-1') {
        $html .= "<span class='expired'>, {$GLOBALS['strExpired']}</span>";
    }
    $html .= "</td></tr>\n";
    $html .= "<tr><th>{$GLOBALS['strSite']}:</th>";
    if ($mode == 'internal') {
        $html .= "<td><a href=\"site_details.php?id=" . $maint->site . "\">" . $maint->sitename . "</a></td></tr>";
    } else {
        $html .= "<td><a href=\"sitedetails.php\">" . $maint->sitename . "</a></td></tr>";
    }
    $html .= "<tr><th>{$GLOBALS['strAdminContact']}:</th>";
    if ($mode == 'internal') {
        $html .= "<td><a href=\"contact_details.php?id=";
        $html .= "{$maint->admincontact}\">";
        $html .= contact_realname($maint->admincontact) . "</a></td></tr>";
    } else {
        $html .= "<td><a href='contactdetails.php?id={$maint->admincontact}'>";
        $html .= contact_realname($maint->admincontact) . "</a></td></tr>";
    }
    $html .= "<tr><th>{$GLOBALS['strReseller']}:</th><td>";
    if (empty($maint->resellername)) {
        $html .= $GLOBALS['strNoReseller'];
    } else {
        $html .= $maint->resellername;
    }
    $html .= "</td></tr>";
    $html .= "<tr><th>{$GLOBALS['strProduct']}:</th><td>" . product_name($maint->product) . "</td></tr>";
    $html .= "<tr><th>{$GLOBALS['strIncidents']}:</th>";
    $html .= "<td>";
    $incidents_remaining = $maint->incident_quantity - $maint->incidents_used;
    if ($maint->incident_quantity == 0) {
        $quantity = $GLOBALS['strUnlimited'];
    } else {
        $quantity = $maint->incident_quantity;
    }
    $html .= sprintf($GLOBALS['strUsedNofN'], $maint->incidents_used, $quantity);
    if ($maint->incidents_used >= $maint->incident_quantity and $maint->incident_quantity != 0) {
        $html .= " ({$GLOBALS['strZeroRemaining']})";
    }
    $html .= "</td></tr>";
    if ($maint->licence_quantity != '0') {
        $html .= "<tr><th>{$GLOBALS['strLicense']}:</th>";
        $html .= "<td>{$maint->licence_quantity} {$maint->licensetypename}</td></tr>\n";
    }
    $html .= "<tr><th>{$GLOBALS['strServiceLevel']}:</th><td>" . servicelevel_name($maint->servicelevelid) . "</td></tr>";
    $html .= "<tr><th>{$GLOBALS['strExpiryDate']}:</th><td>";
    if ($maint->expirydate == '-1') {
        $html .= "{$GLOBALS['strUnlimited']}";
    } else {
        $html .= ldate($CONFIG['dateformat_date'], $maint->expirydate);
    }
    $html .= "</td></tr>";
    if ($mode == 'internal') {
        $timed = db_read_column('timed', $GLOBALS['dbServiceLevels'], $maint->servicelevelid);
        if ($timed == 'yes') {
            $timed = TRUE;
        } else {
            $timed = FALSE;
        }
        $html .= "<tr><th>{$GLOBALS['strService']}</th><td>";
        $html .= contract_service_table($id, $timed);
        $html .= "</td></tr>\n";
        if ($timed) {
            $html .= "<tr><th>{$GLOBALS['strBalance']}</th><td>{$CONFIG['currency_symbol']}" . number_format(get_contract_balance($id, TRUE, TRUE), 2);
            $multiplier = get_billable_multiplier(strtolower(date('D', $now)), date('G', $now));
            $html .= " (&cong;" . contract_unit_balance($id, TRUE, TRUE) . " units)";
            $html .= "</td></tr>";
        }
    }
    if ($maint->maintnotes != '' and $mode == 'internal') {
        $html .= "<tr><th>{$GLOBALS['strNotes']}:</th><td>{$maint->maintnotes}</td></tr>";
    }
    $html .= "</table>";
    if ($mode == 'internal') {
        $html .= "<p align='center'>";
        $html .= "<a href=\"contract_edit.php?action=edit&amp;maintid={$id}\">{$GLOBALS['strEditContract']}</a> | ";
        $html .= "<a href='contract_add_service.php?contractid={$id}'>{$GLOBALS['strAddService']}</a></p>";
    }
    $html .= "<h3>{$GLOBALS['strContacts']}</h3>";
    if (mysql_num_rows($maintresult) > 0) {
        if ($maint->allcontactssupported == 'yes') {
            $html .= "<p class='info'>{$GLOBALS['strAllSiteContactsSupported']}</p>";
        } else {
            $allowedcontacts = $maint->supportedcontacts;
            $supportedcontacts = supported_contacts($id);
            $numberofcontacts = 0;
            $numberofcontacts = sizeof($supportedcontacts);
            if ($allowedcontacts == 0) {
                $allowedcontacts = $GLOBALS['strUnlimited'];
            }
            $html .= "<table align='center'>";
            $supportcount = 1;
            if ($numberofcontacts > 0) {
                foreach ($supportedcontacts as $contact) {
                    $html .= "<tr><th>{$GLOBALS['strContact']} #{$supportcount}:</th>";
                    $html .= "<td>" . icon('contact', 16) . " ";
                    if ($mode == 'internal') {
                        $html .= "<a href=\"contact_details.php?";
                    } else {
                        $html .= "<a href=\"contactdetails.php?";
                    }
                    $html .= "id={$contact}\">" . contact_realname($contact) . "</a>, ";
                    $html .= contact_site($contact) . "</td>";
                    if ($mode == 'internal') {
                        $html .= "<td><a href=\"contract_delete_contact.php?contactid=" . $contact . "&amp;maintid={$id}&amp;context=maintenance\">{$GLOBALS['strRemove']}</a></td></tr>\n";
                    } else {
                        $html .= "<td><a href=\"{$_SERVER['PHP_SELF']}?id={$id}&amp;contactid=" . $contact . "&amp;action=remove\">{$GLOBALS['strRemove']}</a></td></tr>\n";
                    }
                    $supportcount++;
                }
                $html .= "</table>";
            } else {
                $html .= "<p class='info'>{$GLOBALS['strNoRecords']}<p>";
            }
        }
        if ($maint->allcontactssupported != 'yes') {
            $html .= "<p align='center'>";
            $html .= sprintf($GLOBALS['strUsedNofN'], "<strong>" . $numberofcontacts . "</strong>", "<strong>" . $allowedcontacts . "</strong>");
            $html .= "</p>";
            if ($numberofcontacts < $allowedcontacts or $allowedcontacts == 0 and $mode == 'internal') {
                $html .= "<p align='center'><a href='contract_add_contact.php?maintid={$id}&amp;siteid={$maint->site}&amp;context=maintenance'>";
                $html .= "{$GLOBALS['strAddContact']}</a></p>";
            } else {
                $html .= "<h3>{$GLOBALS['strAddContact']}</h3>";
                $html .= "<form action='{$_SERVER['PHP_SELF']}?id={$id}&amp;action=";
                $html .= "add' method='post' >";
                $html .= "<p align='center'>{$GLOBLAS['strAddNewSupportedContact']} ";
                $html .= contact_site_drop_down('contactid', 'contactid', maintenance_siteid($id), supported_contacts($id));
                $html .= help_link('NewSupportedContact');
                $html .= " <input type='submit' value='{$GLOBALS['strAdd']}' /></p></form>";
            }
            if ($mode == 'external') {
                $html .= "<p align='center'><a href='addcontact.php'>";
                $html .= "{$GLOBALS['strAddNewSiteContact']}</a></p>";
            }
        }
        $html .= "<br />";
        $html .= "<h3>{$GLOBALS['strSkillsSupportedUnderContract']}:</h3>";
        // supported software
        $sql = "SELECT * FROM `{$GLOBALS[dbSoftwareProducts]}` AS sp, `{$GLOBALS[dbSoftware]}` AS s ";
        $sql .= "WHERE sp.softwareid = s.id AND productid='{$maint->product}' ";
        $result = mysql_query($sql);
        if (mysql_error()) {
            trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING);
        }
        if (mysql_num_rows($result) > 0) {
            $html .= "<table align='center'>";
            while ($software = mysql_fetch_object($result)) {
                $software->lifetime_end = mysql2date($software->lifetime_end);
                $html .= "<tr><td> " . icon('skill', 16) . " ";
                if ($software->lifetime_end > 0 and $software->lifetime_end < $now) {
                    $html .= "<span class='deleted'>";
                }
                $html .= $software->name;
                if ($software->lifetime_end > 0 and $software->lifetime_end < $now) {
                    $html .= "</span>";
                }
                $html .= "</td></tr>\n";
            }
            $html .= "</table>\n";
        } else {
            $html .= "<p align='center'>{$GLOBALS['strNone']} / {$GLOBALS['strUnknown']}<p>";
        }
    } else {
        $html = "<p align='center'>{$GLOBALS['strNothingToDisplay']}</p>";
    }
    return $html;
}