/** Table::create($data, $options) * @param $data array array data to be inserted into the database * @param $options array array options to be passed to sqlCreate * @return true|array data on success false otherwise * @example $users = new Users(); $users->create(array('name'=>'sdf'), array('record'=>true)); */ public function create(array $data, array $options = array()) { foreach ($data as $key => $val) { if (!in_array($key, $this->_cols)) { unset($data[$key]); } } $opts = (array) array(); $opts['table'] = $this->_name; $opts['fields'] = $data; $data = sqlCreate($opts); if (array_key_exists("record", $options) && $options['record']) { $data = sqlPull(array('table' => $this->_name, 'where' => $this->_primary . '=' . $data, 'onerow' => true)); } return $data; }
function createEquipFaultNote($referid, $config) { $data["note"] = $config; $data["date"] = date("U"); $data["userid"] = $_SESSION["userid"]; $data["faultid"] = $referid; $noteid = sqlCreate(array("table" => "equip_notes", "fields" => $data)); return $noteid; }
/** refuel($test = FALSE) * get open and missing refuel data * @param BOOL $test is this a request for test platform? * @return TRUE on success. FALSE otherwise */ public function refuel($test = FALSE) { $fleets = $this->_incomefleets; $data = (array) array(); foreach ($fleets as $val) { $data[$val['maxid']]['fleet_id'] = $val['maxid']; if (array_key_exists('fleets', $val)) { $sql = (string) 'SELECT SUM(`fleet_count`) AS `fleet_count`, SUM(`missing_count`) AS `missing_count`, SUM(`open_count`) AS `open_count`, SUM(`total_open_count`) AS `total_open_count` '; $sql .= 'FROM `refuels` '; $fleetsToLoop = (array) array(); foreach ($val['fleets'] as $ook) { $fleetsToLoop[] = $ook[0]; } $sql .= 'WHERE `fleet_id` IN(' . implode($fleetsToLoop, ',') . ')'; $row = sqlQuery($sql); if ($row === FALSE) { continue; } $data[$val['maxid']]['fleet_count'] = $row[0]['fleet_count']; $data[$val['maxid']]['missing_count'] = $row[0]['missing_count']; $data[$val['maxid']]['open_count'] = $row[0]['open_count']; $data[$val['maxid']]['total_open_count'] = $row[0]['total_open_count']; } else { //: Get fleet count $trucks = $this->_apiurl . "report=145&responseFormat=csv&Fleet=" . $val['maxid'] . "&Start%20Date=" . date("Y-m-d") . "&Stop%20Date=" . date("Y-m-d", strtotime("+1 day")); if ($test === TRUE) { $trucks = preg_replace('/https\\:\\/\\/login\\.max\\.bwtsgroup\\.com/', 'http://max.mobilize.biz', $trucks); } $fileParser = new FileParser($trucks); $fileParser->setCurlFile("trucks." . $val['maxid'] . ".csv"); $trucks = $fileParser->parseFile(); if ($trucks === FALSE) { print "<pre style='font-family:verdana;font-size:13'>"; print_r($fileParser->getErrors()); print "</pre>"; return FALSE; } if (is_array($trucks) === FALSE) { return FALSE; } $data[$val['maxid']]['fleet_count'] = count($trucks); //: End $refuels = $this->_apiurl . "report=175&responseFormat=csv&Fleet=" . $val['maxid'] . "&Start%20Date=" . date("Y-m-d", strtotime('-30 days')) . "&Stop%20Date=" . date("Y-m-01", strtotime("+1 month")); if ($test === TRUE) { $refuels = preg_replace('/https\\:\\/\\/login\\.max\\.bwtsgroup\\.com/', 'http://max.mobilize.biz', $refuels); } print $refuels . PHP_EOL; $fileParser = new FileParser($refuels); $fileParser->setCurlFile("missingrefuels" . $val['maxid'] . ".csv"); $missingrefuels = $fileParser->parseFile(); if ($missingrefuels === FALSE) { print "<pre style='font-family:verdana;font-size:13'>"; print_r($fileParser->getErrors()); print "</pre>"; return FALSE; } if (is_array($missingrefuels) === FALSE) { return FALSE; } // print_r($missingrefuels); $i = (int) 0; //: Missing Refuels foreach ($missingrefuels as $key => $value) { //: Checks if ($val['maxid'] == 73) { print_r($value); } if ($value['Odometer'] === '(none)' || $value['Odometer'] === '') { continue; } if (substr($value['Variance'], 0, 1) !== '-') { continue; } //: End if ($value['Variance'] * -1 >= $val['kms_limit']) { $i++; } } $data[$val['maxid']]['missing_count'] = $i; //: End //: Open Refuels $refuels = $this->_apiurl . "report=174&responseFormat=csv&Fleet=" . $val['maxid'] . "&Start%20Date=" . date("Y-m-d", strtotime('-30 days')) . "&Stop%20Date=" . date("Y-m-01", strtotime("+1 month")); if ($test === TRUE) { $refuels = preg_replace('/https\\:\\/\\/login\\.max\\.bwtsgroup\\.com/', 'http://max.mobilize.biz', $refuels); } print $refuels . PHP_EOL; $fileParser = new FileParser($refuels); $fileParser->setCurlFile("openrefuels" . $val['maxid'] . ".csv"); $openrefuels = $fileParser->parseFile(); if ($openrefuels === FALSE) { print "<pre style='font-family:verdana;font-size:13'>"; print_r($fileParser->getErrors()); print "</pre>"; return FALSE; } if (is_array($openrefuels) === FALSE) { return FALSE; } // print_r($openrefuels); $cnt = (int) 0; foreach ($openrefuels as $key => $value) { //: Convert the refuel time difference into seconds $refuel_time = (int) 0; $split = preg_split('/\\s/', $value['Duration Open (Refuel Time)']); if (array_key_exists(0, $split)) { if (substr($split[0], -1, 1) === 'd') { //: Days $refuel_time += 24 * 60 * 60 * (int) $split[0]; } else { //: Hours $refuel_time += 60 * 60 * (int) $split[0]; } } if (array_key_exists(1, $split)) { //: Hours $refuel_time += 60 * 60 * (int) $split[0]; } // print('refuel time: '.$refuel_time.PHP_EOL); if ($refuel_time >= $val['open_time']) { $cnt++; } //: End } $data[$val['maxid']]['total_open_count'] = count($openrefuels); $data[$val['maxid']]['open_count'] = $cnt; //: End } } foreach ($data as $key => $val) { $record = sqlPull(array("table" => "refuels", "where" => "fleet_id=" . $key, "customkey" => "fleet_id")); if (array_key_exists($key, $record) && $record[$key]) { sqlCommit(array("table" => "refuels", "where" => "fleet_id=" . $key, "fields" => $val)); } else { sqlCreate(array("table" => "refuels", "fields" => $val)); } print '|'; } }
} $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA); foreach ($t24Budget as $fleet => $data) { foreach ($data as $day) { // print_r($day); $sql = (string) "SELECT * FROM `fleet_scores` WHERE `fleetid`=" . $day["fleetid"] . " AND `date`=" . $day["date"]; //print($sql);exit; if ($result = $mysqli->query($sql)) { $record = (array) array(); while ($obj = $result->fetch_array()) { foreach ($obj as $key => $val) { if (is_int($key) === TRUE) { unset($obj[$key]); } } $record = $obj; } /* free result set */ $result->close(); } // print_r($record); if (isset($record) && $record) { //: Update sqlCommit(array("table" => "fleet_scores", "where" => "id=" . $record["id"], "fields" => $day)); } else { sqlCreate(array("table" => "fleet_scores", "fields" => $day)); } } } } //: End
public function saveFleetDay($fleetscore) { // Create or commit records to database { $record = sqlPull(array("table" => "fleet_scores", "where" => "date=" . $this->_date, "customkey" => "fleetid")); $check = (array) array("income", "contrib", "kms", "budget", "budgetcontrib", "budkms"); foreach ($fleetscore as $fleetkey => $fleetval) { if ($record[$fleetkey]) { if ($this->confirmFleetScoreData($record[$fleetkey], $fleetval) === FALSE) { continue; } //sqlDelete(array("table"=>"fleet_scores", "where"=>"fleetid=".$fleetkey." AND day=".$this->_day)); //sqlCreate(array("table"=>"fleet_scores", "fields"=>$fleetval)); sqlCommit(array("table" => "fleet_scores", "where" => "fleetid=" . $fleetkey . " AND date=" . $this->_date, "fields" => $fleetval)); } else { sqlCreate(array("table" => "fleet_scores", "fields" => $fleetval)); } } // } }