private function getEndingContracts()
 {
     $endingContracts = array();
     $c = new oqc_ExternalContract();
     $contracts = $c->get_full_list('', 'already_notified=0 and enddate >= NOW()');
     $nowTimestamp = time();
     if (!empty($contracts)) {
         foreach ($contracts as $contract) {
             $enddate = date_parse($contract->enddate);
             // make sure that foreach contract the notification is sent only once && if this contract ends in the warning interval
             if (!$contract->already_notified && $nowTimestamp >= mktime(0, 0, 0, $enddate['month'] - $contract->warn_in_months, $enddate['day'], $enddate['year'])) {
                 $endingContracts[] = $contract;
             }
         }
     }
     return $endingContracts;
 }
<?php

header("Content-type: application/json");
$fileExists = false;
if (array_key_exists('n', $_REQUEST)) {
    $name = $_REQUEST['n'];
    if (array_key_exists('id', $_REQUEST)) {
        $id = $_REQUEST['id'];
        if (!defined('sugarEntry')) {
            define('sugarEntry', true);
        }
        chdir("..");
        require_once 'include/entryPoint.php';
        require_once 'modules/oqc_ExternalContract/oqc_ExternalContract.php';
        $e = new oqc_ExternalContract();
        if ($e->retrieve($id)) {
            $normalizedName = trim($e->{$name});
            if (empty($normalizedName)) {
                // if no file location has been set for this field we reply true
                // because returning false would generate a warning in all cases (with or without a file set).
                // thus, returning true in this case results in nothing being displayed.
                $fileExists = true;
            } else {
                require_once 'include/oqc/common/Configuration.php';
                $conf = Configuration::getInstance();
                $rootDir = $conf->get('storageDirectory');
                // note that we must not use the normalized name at this point because the filename could actually contain leading or trailing spaces.
                $fileExists = file_exists($rootDir . $e->{$name});
            }
        }
    }
<?php

if (!defined('sugarEntry')) {
    define('sugarEntry', true);
}
chdir('..');
require_once 'include/entryPoint.php';
require_once 'modules/oqc_ExternalContract/oqc_ExternalContract.php';
$externalContract = new oqc_ExternalContract();
if ($externalContract->retrieve($_REQUEST['id'])) {
    $json = getJSONobj();
    $costs = $externalContract->getCostsArray();
    $spendForCategory = array();
    foreach ($costs as $cost) {
        $spendForCategory[$cost['category']] += floatval($cost['price']);
    }
    $chartData = array();
    foreach ($spendForCategory as $category => $price) {
        $chartData[] = array('category' => $category, 'price' => $price);
    }
    $encoded = $json->encode($chartData);
    echo $encoded;
} else {
    echo "No External Contract with id='" + $_REQUEST['id'] + "' found.";
}
<?php

if (!defined('sugarEntry')) {
    define('sugarEntry', true);
}
chdir('..');
require_once 'include/entryPoint.php';
require_once 'modules/oqc_ExternalContract/oqc_ExternalContract.php';
require_once 'modules/oqc_ExternalContractCosts/oqc_ExternalContractCosts.php';
$expenses = array();
$e = new oqc_ExternalContract();
$result = $e->get_list('', 'deleted=0');
$externalContracts = $result['list'];
foreach ($externalContracts as $externalContract) {
    $costIds = explode(' ', $externalContract->costs);
    $c = new oqc_ExternalContractCosts();
    foreach ($costIds as $id) {
        if ($c->retrieve($id)) {
            if (!array_key_exists($c->year, $expenses)) {
                $expenses[$c->year] = array();
            }
            $expenses[$c->year][$c->category] += $c->price;
        }
    }
}
$chartData = array();
foreach ($expenses as $year => $categories) {
    $chartData[] = array_merge(array('year' => $year), $categories);
}
$json = getJSONobj();
$encoded = $json->encode($chartData);
 public static function getBiggestExternalContract()
 {
     $externalContract = new oqc_ExternalContract();
     $list = $externalContract->get_full_list("finalcosts desc", "deleted=0");
     return $list[0];
 }