Example #1
0
     if (!$result) {
         $addition_errors = 1;
         $addition_errors_string .= user_alert($strAdditionFail, E_USER_WARNING);
     }
     // Add service
     $sql = "INSERT INTO `{$dbService}` (contractid, startdate, enddate, creditamount, unitrate, incidentrate, foc) ";
     $sql .= "VALUES ('{$maintid}', '{$startdate}', '{$enddate}', '{$amount}', '{$unitrate}', '{$incidentrate}', '{$foc}')";
     mysql_query($sql);
     if (mysql_error()) {
         trigger_error(mysql_error(), E_USER_ERROR);
     }
     if (mysql_affected_rows() < 1) {
         trigger_error("Insert failed", E_USER_ERROR);
     }
     $serviceid = mysql_insert_id();
     update_contract_balance($maintid, $strNewContract, $amount, $serviceid);
     if ($addition_errors == 1) {
         // show addition error message
         include APPLICATION_INCPATH . 'htmlheader.inc.php';
         echo $addition_errors_string;
         include APPLICATION_INCPATH . 'htmlfooter.inc.php';
     } else {
         // show success message
         trigger('TRIGGER_NEW_CONTRACT', array('contractid' => $maintid, 'userid' => $sit[2]));
         html_redirect("contract_details.php?id={$maintid}");
     }
     clear_form_data('add_contract');
 } else {
     // show error message if errors
     include APPLICATION_INCPATH . 'htmlheader.inc.php';
     html_redirect("contract_add.php", FALSE);
            header("Location: {$CONFIG['application_webpath']}noaccess.php?id=79");
            exit;
        } else {
            $status = update_contract_balance($contractid, $reason, $amount, $sourceservice);
            if ($status) {
                html_redirect("{$CONFIG['application_webpath']}contract_details.php?id={$contractid}", TRUE, $strSuccessfullyUpdated);
            } else {
                html_redirect("{$CONFIG['application_webpath']}contract_details.php?id={$contractid}", FALSE, $strUpdateFailed);
            }
        }
        break;
    case 'transfer':
        if (user_permission($sit[2], 79) == FALSE) {
            header("Location: {$CONFIG['application_webpath']}noaccess.php?id=79");
            exit;
        } else {
            $status = update_contract_balance($contractid, $reason, $amount * -1, $sourceservice);
            if ($status) {
                $status = update_contract_balance($contractid, $reason, $amount, $destinationservice);
                if ($status) {
                    html_redirect("{$CONFIG['application_webpath']}contract_details.php?id={$contractid}", TRUE);
                } else {
                    html_redirect("{$CONFIG['application_webpath']}contract_details.php?id={$contractid}", FALSE);
                }
                exit;
            }
            html_redirect('main.php', FALSE, $strFailed);
            exit;
        }
        break;
}
Example #3
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;
}
// Approve billable incidents
require 'core.php';
require_once APPLICATION_LIBPATH . 'functions.inc.php';
include_once APPLICATION_LIBPATH . 'billing.inc.php';
// This page requires authentication
require_once APPLICATION_LIBPATH . 'auth.inc.php';
$transactiond = cleanvar($_REQUEST['transactionid']);
$title = $strBilling;
include APPLICATION_INCPATH . 'htmlheader.inc.php';
$sql = "SELECT * FROM `{$GLOBALS['dbTransactions']}` WHERE transactionid = {$transactiond}";
$result = mysql_query($sql);
if (mysql_error()) {
    trigger_error("Error getting transaction " . mysql_error());
}
if (mysql_num_rows($result) > 0) {
    $obj = mysql_fetch_object($result);
    if ($obj->transactionstatus == BILLING_AWAITINGAPPROVAL) {
        // function update_contract_balance($contractid, $description, $amount, $serviceid='', $transactionid='', $totalunits=0, $totalbillableunits=0, $totalrefunds=0)
        $r = update_contract_balance('', '', $obj->amount, $obj->serviceid, $obj->transactionid);
        if ($r) {
            html_redirect("billable_incidents.php", TRUE, "{$strTransactionApproved}");
        } else {
            html_redirect("billable_incidents.php", FALSE, "{$strFailedtoApproveTransactID} {$transactiond}");
        }
    } else {
        html_redirect("billable_incidents.php", FALSE, "{$strTransactionXnotAwaitingApproval}", $transactiond);
    }
} else {
    html_redirect("billable_incidents.php", FALSE, "{$strNoTransactionsFoundWithID} {$transactiond}");
}
include APPLICATION_INCPATH . 'htmlfooter.inc.php';
     $sql = "INSERT INTO `{$dbService}` (contractid, startdate, enddate, creditamount, unitrate, incidentrate, cust_ref, cust_ref_date, title, notes, foc) ";
     $sql .= "VALUES ('{$contractid}', '{$startdate}', '{$enddate}', '{$amount}', '{$unitrate}', '{$incidentrate}', '{$cust_ref}', '{$cust_ref_date}', '{$title}', '{$notes}', '{$foc}')";
 } else {
     $sql = "INSERT INTO `{$dbService}` (contractid, startdate, enddate, title, notes) ";
     $sql .= "VALUES ('{$contractid}', '{$startdate}', '{$enddate}', '{$title}', '{$notes}')";
 }
 mysql_query($sql);
 if (mysql_error()) {
     trigger_error(mysql_error(), E_USER_ERROR);
 }
 if (mysql_affected_rows() < 1) {
     trigger_error("Insert failed", E_USER_ERROR);
 }
 $serviceid = mysql_insert_id();
 if ($amount != 0) {
     update_contract_balance($contractid, "New service", $amount, $serviceid);
 }
 $sql = "SELECT expirydate FROM `{$dbMaintenance}` WHERE id = {$contractid}";
 $result = mysql_query($sql);
 if (mysql_error()) {
     trigger_error(mysql_error(), E_USER_WARNING);
 }
 if (mysql_num_rows($result) > 0) {
     $obj = mysql_fetch_object($result);
     if ($obj->expirydate < strtotime($enddate)) {
         $update = "UPDATE `{$dbMaintenance}` ";
         $update .= "SET expirydate = '" . strtotime($enddate) . "' ";
         $update .= "WHERE id = {$contractid}";
         mysql_query($update);
         if (mysql_error()) {
             trigger_error(mysql_error(), E_USER_ERROR);