$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)); $totalrefunds = $bills['refunds']; // $numberofunits += $bills['refunds']; $cost = ($totalbillableunits + $totalrefunds) * $unitrate * -1; $desc = trim("{$numberofunits} {$strUnits} @ {$CONFIG['currency_symbol']}{$unitrate} {$strForIncident} {$incidentid}. {$s}"); $transactionid = get_incident_transactionid($incidentid); if ($transactionid != FALSE) { $r = update_transaction($transactionid, $cost, $desc, BILLING_AWAITINGAPPROVAL); if ($r) { html_redirect('billable_incidents.php', TRUE, $strUpdateSuccessful); } else { html_redirect('billable_incidents.php', FALSE, $strUpdateFailed); } } else { html_redirect('billable_incidents.php', FALSE, $strUpdateFailed); }
/** * 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; }
trigger_error("MySQL Query Error " . mysql_error(), E_USER_ERROR); } if (!$result) { $addition_errors = 1; $addition_errors_string .= "<p class='error'>Update of incident failed</p>\n"; } if ($addition_errors == 0) { // dump details to incident update if ($oldtitle != $title) { $header .= "Title: {$oldtitle} -> <b>{$title}</b>\n"; } if ($oldcontact != $contact) { $contactname = contact_realname($contact); $contactsite = contact_site($contact); $header .= "Contact: " . contact_realname($oldcontact) . " -> <b>{$contactname}</b>\n"; $maintsiteid = maintenance_siteid(incident_maintid($id)); if ($maintsiteid > 0 and contact_siteid($contact) != $maintsiteid) { $maintcontactsite = site_name($maintsiteid); $header .= "Assigned to <b>{$contactname} of {$contactsite}</b> on behalf of {$maintcontactsite} (The contract holder)\n"; } } if ($oldexternalid != $externalid) { $header .= "External ID: "; if ($oldexternalid != '') { $header .= $oldexternalid; } else { $header .= "None"; } $header .= " -> <b>"; if ($externalid != '') { $header .= $externalid;