Example #1
0
function exportFleetScoreUpdates()
{
    require_once BASE . 'basefunctions/baseapis/PHPExcel/php-excel.class.php';
    $manager = new TableManager("fleet_scores");
    $data = __sanitizeData($_GET);
    $where = (string) "1=1";
    if (isset($data["fleet"]) && $data["fleet"]) {
        $where .= $manager->quoteString(" AND `fleetid`=?", (int) $data["fleet"]);
    }
    if (isset($data["start"]) && $data["start"]) {
        $where .= $manager->quoteString(" AND `date`>=?", (int) unixDate($data["start"]));
    }
    if (isset($data["end"]) && $data["end"]) {
        $where .= $manager->quoteString(" AND `date`<=?", (int) unixDate($data["end"]));
    }
    $manager->setWhere($where);
    $manager->setOrderBy(array("column" => "date"));
    $records = $manager->selectMultiple();
    $rows = returnFleetTruckCount();
    $xlsdata = (array) array();
    $fleetdayobj = new fleetDayHandler();
    $tempfleetlist = $fleetdayobj->getIncomeFleets();
    $fleetlist = array();
    foreach ($tempfleetlist as $tempkey => $tempval) {
        $fleetlist[$tempval["id"]] = $tempval;
    }
    unset($tempfleetlist);
    unset($fleetdayobj);
    $row = (array) array("Date", "Fleet", "Income budget", "Income", "Contribution budget", "Contribution", "Truck count", "Kms", "Ave. Kms per truck", "Budget Ave. Kms per truck");
    $xlsdata[] = $row;
    foreach ($records as $val) {
        $row = (array) array(date("Y-m-d", $val["date"]), $fleetlist[$val["fleetid"]]["name"], $val["budget"], $val["income"], $val["budgetcontrib"], $val["contrib"], $rows[$val["fleetid"]]["count"], $val["kms"], round($val["kms"] / (isset($rows[$val["fleetid"]]) && isset($rows[$val["fleetid"]]["count"]) ? $rows[$val["fleetid"]]["count"] : 1), 2), round($val["budkms"] / (isset($rows[$val["fleetid"]]) && isset($rows[$val["fleetid"]]["count"]) ? $rows[$val["fleetid"]]["count"] : 1), 2));
        $xlsdata[] = $row;
    }
    $xls = new Excel_XML('UTF-8', TRUE);
    $xls->addArray($xlsdata);
    $xls->generateXML('fleet_score_data');
}
Example #2
0
/** ocdData.php
 * @package ocdData
 * @author Feighen Oosterbroek <*****@*****.**>
 * @copyright 2013 onwards Barloworld Transport Solutions
 * @license GNU GPL
 * @link http://www.gnu.org/licenses/gpl.html
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
function ocdData()
{
    //: Preparation
    $times = substr_count($_SERVER['PHP_SELF'], "/");
    $rootaccess = "";
    $i = 1;
    while ($i < $times) {
        $rootaccess .= "../";
        $i++;
    }
    defined('BASE') || define("BASE", $rootaccess);
    include_once BASE . "/basefunctions/localdefines.php";
    include_once BASE . "/basefunctions/dbcontrols.php";
    include_once BASE . "/basefunctions/baseapis/manapi.php";
    include_once BASE . "Maxine/api/maxineapi.php";
    require_once BASE . "basefunctions/baseapis/fleetDayHandler.php";
    $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link));
    $fleetdayobj = new fleetDayHandler();
    $fleetlist = (array) array();
    $tmp = $fleetdayobj->getIncomeFleets();
    foreach ($tmp as $key => $val) {
        $sorted[$val['maxid']] = $val["name"];
    }
    asort($sorted, SORT_STRING);
    foreach ($sorted as $key => $val) {
        $fleetlist[$key] = $sorted[$key];
    }
    unset($sorted);
    unset($tmp);
    $sql = (string) 'SELECT `r`.`fleet_id`, `missing_count`, `open_count`, `total_open_count`, `count`, `litres` FROM `refuels` AS `r` INNER JOIN `unauthorized_refuels` AS `u` ON `r`.`fleet_id`=`u`.`fleet_id`';
    if (isset($_POST) && isset($_POST['conf']) && $_POST['conf']) {
        if (isset($_POST['conf']['fleetid']) && $_POST['conf']['fleetid']) {
            $data = __sanitizeData(array(0 => $_POST['conf']['fleetid']));
            $sql .= ' WHERE `r`.`fleet_id`=' . $data[0];
        }
    }
    $fleetid = (int) (isset($_POST['conf']) && $_POST['conf'] && (isset($_POST['conf']['fleetid']) && $_POST['conf']['fleetid']) ? $_POST['conf']['fleetid'] : 0);
    $records = sqlQuery($sql);
    $data = (array) array();
    foreach ($records as $val) {
        $data[$val['fleet_id']] = $val;
    }
    unset($records);
    //: End
    print '<!DOCTYPE html>';
    print '<head>';
    print '<meta charset="utf-8">';
    print '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">';
    print '<title>Dashboards - Barloworld Transport</title>';
    print '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />';
    print '<link href="favicon.ico" rel="shortcut icon" />';
    print '<link rel="stylesheet" href="' . BASE . 'basefunctions/scripts/bootstrap.min.css">';
    print '<link href="' . BASE . 'basefunctions/scripts/font-awesome.min.css" rel="stylesheet">';
    print '<link rel="stylesheet" href="' . BASE . 'Maxine/displaycase/content/site/css/fonts.css">';
    print '<link rel="stylesheet" href="' . BASE . 'Maxine/displaycase/content/site/css/main.css">';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/modernizr-2.6.2.min.js"></script>';
    print '<script src="' . BASE . 'basefunctions/scripts/jquery.min.js"></script>';
    print '<script src="' . BASE . 'basefunctions/scripts/jquery.ui.touch-punch.min.js"></script>';
    print '<!--[if lt IE 9]>';
    print '<script src="' . BASE . 'basefunctions/scripts/html5shiv.min.js"></script>';
    print '<script src="' . BASE . 'basefunctions/scripts/respond.js"></script>';
    print '<![endif]-->';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jcircle.js"></script>';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.js"></script>';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.time.js"></script>';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.tooltip.js"></script>';
    print '</head>' . PHP_EOL;
    print '<body>';
    print '<div id="root"></div>';
    print '<div id="page" style="overflow-y:auto;">';
    print '<header>';
    print '<div class="controlsWrapper">';
    print '<a href="#" class="menu"></a>';
    print '</div><!-- controlsWrapper -->';
    print '</header>';
    print '<nav>';
    print '<ul>';
    print '<li><a href="/?personal">Dashboard</a></li>';
    print '<li><a href="/?mydashdetails">Dashboard Builder</a></li>';
    print '<li><a href="/?importfleetday">Import Day</a></li>';
    print '<li><a href="/?checkfleetscoreupdates">Fleet Scores</a></li>';
    print '<li><a href="/?ocddata">OCD Data</a></li>';
    print '<li><a href="/?logout">Logout</a></li>';
    print '</ul>';
    print '</nav>';
    //: Page Content
    print '<div id="blackouts">';
    //: Form
    print '<div class="fleetWrapper" style="height:10%;">';
    print '<form method="POST">';
    print '<table><tbody><tr>';
    print '<td>';
    //: Col 1
    print '<label for="conf[fleetid]">Fleet:</label>';
    print '<select id="conf[fleetid]" name="conf[fleetid]" value="' . $fleetid . '">';
    print '<option value="0" ' . ($fleetid == 0 ? "selected" : "") . '>All</option>';
    foreach ($fleetlist as $fleetkey => $fleetval) {
        if (!$fleetval) {
            continue;
        }
        print '<option value="' . $fleetkey . '"' . ($fleetid == $fleetkey ? ' selected="selected"' : '') . '>' . $fleetval . '</option>';
    }
    print '</select>';
    print '</td>';
    print '<td>';
    //: Col 2
    print '<input type="Submit" value="Search" />';
    print '</td>';
    print '</tr></tbody></table>';
    print '</form>';
    print '</div>';
    print '<div class="fleetWrapper" style="height:90%;">';
    print '<table style="margin-bottom:20px;">';
    if ($data) {
        $cols = (array) array('fleet_id' => 'Fleet', 'missing_count' => 'Missing count', 'total_open_count' => 'Total open', 'open_count' => 'Open above fleet limit', 'count' => 'Unauthorized count', 'litres' => 'Litres');
        print '<thead><tr>';
        foreach ($cols as $key => $val) {
            print '<td>' . $val . '</td>';
        }
        print '</tr></thead>';
        print '<tbody>';
        foreach ($fleetlist as $key => $val) {
            //: Skip rows that do not have an active fleet
            if (array_key_exists($key, $data) === FALSE) {
                continue;
            }
            $row = $data[$key];
            print '<tr>';
            foreach ($cols as $key1 => $val1) {
                print '<td>';
                print $key1 == 'fleet_id' ? $val : $row[$key1];
                print '</td>';
            }
            print '</tr>';
        }
        print '</tbody>';
    } else {
        print '<tbody><tr><td>No results to show</td></tr></tbody>';
    }
    print '</table>';
    print '</div>';
    //: End
    print '</div>';
    //: End
    //: End Page
    print '<script>window.jQuery || document.write("<script src=\\"' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery-1.9.1.min.js\\"><\\/script>")</script>';
    print '<script src="' . BASE . 'basefunctions/scripts/jquery.color.min.js"></script>';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/plugins.js"></script>';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/styling.js"></script>';
    print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/main.js"></script>';
    print '<script type="text/javascript" language="javascript" src="' . BASE . '/basefunctions/scripts/manline.js"></script>';
    print '</body>' . PHP_EOL;
    print '</html>';
}