Example #1
0
/**
* Function to approve an incident, this adds a transaction and confirms the 'bill' is correct.
* @author Paul Heaney
* @param incidentid ID of the incident to approve
*/
function approve_incident_transaction($transactionid)
{
    global $dbLinks, $sit, $CONFIG, $strUnits;
    $rtnvalue = TRUE;
    // Check transaction exists, and is awaiting approval and is an incident
    $sql = "SELECT l.linkcolref, t.serviceid FROM `{$GLOBALS['dbLinks']}` AS l, `{$GLOBALS['dbTransactions']}` AS t ";
    $sql .= "WHERE t.transactionid = l.origcolref AND t.transactionstatus = " . BILLING_AWAITINGAPPROVAL . " AND l.linktype = 6 AND t.transactionid = {$transactionid}";
    $result = mysql_query($sql);
    if (mysql_error()) {
        trigger_error("Error identify incident transaction. " . mysql_error(), E_USER_WARNING);
    }
    if (mysql_num_rows($result) > 0) {
        list($incidentid, $serviceid) = mysql_fetch_row($result);
        $bills = get_incident_billable_breakdown_array($incidentid);
        $multipliers = get_all_available_multipliers();
        $totalunits = 0;
        $totalbillableunits = 0;
        $totalrefunds = 0;
        foreach ($bills as $bill) {
            foreach ($multipliers as $m) {
                $a[$m] += $bill[$m]['count'];
            }
        }
        foreach ($multipliers as $m) {
            $s .= sprintf($GLOBALS['strXUnitsAtX'], $a[$m], $m);
            $totalbillableunits += $m * $a[$m];
            $totalunits += $a[$m];
        }
        $unitrate = get_unit_rate(incident_maintid($incidentid));
        $totalrefunds += $bills['refunds'];
        $cost = ($totalbillableunits += $totalrefunds) * $unitrate * -1;
        $desc = trim("Incident {$incidentid}: {$totalbillableunits}: {$strUnits} @ {$CONFIG['currency_symbol']}{$unitrate}. {$s}");
        //FIXME i18n
        $rtn = update_contract_balance(incident_maintid($incidentid), $desc, $cost, $serviceid, $transactionid, $totalunits, $totalbillableunits, $totalrefunds);
        if ($rtn == FALSE) {
            $rtnvalue = FALSE;
        }
    } else {
        $rtnvalue = FALSE;
    }
    return $rtnvalue;
}
 $description = "[b]{$strAmount}[/b]: {$amount} {$strMinutes}\n\n{$description}";
 $amount *= 60;
 // to seconds
 $sqlInsert = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp, duration) VALUES ";
 $sqlInsert .= "('{$incidentid}', '{$sit[2]}', 'editing', '{$obj->owner}', '{$obj->status}', '{$description}', '{$now}', '{$amount}')";
 $resultInsert = mysql_query($sqlInsert);
 if (mysql_error()) {
     trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR);
 }
 if (mysql_affected_rows() > 0) {
     $success = TRUE;
 } else {
     $success = FALSE;
 }
 if ($success) {
     $bills = get_incident_billable_breakdown_array($incidentid);
     $multipliers = get_all_available_multipliers();
     $totalunits = 0;
     $totalbillableunits = 0;
     $totalrefunds = 0;
     foreach ($bills as $bill) {
         foreach ($multipliers as $m) {
             $a[$m] += $bill[$m]['count'];
         }
     }
     foreach ($multipliers as $m) {
         $s .= sprintf($GLOBALS['strXUnitsAtX'], $a[$m], $m);
         $totalunits += $a[$m];
         $totalbillableunits += $m * $a[$m];
     }
     $unitrate = get_unit_rate(incident_maintid($incidentid));