public function display() { $connection = new Connection(); $statement = new Statement($connection); //get mechanic view $SQL = "SELECT * FROM MechanicView WHERE idMINIEmployee = :id"; $statement->setInt('id', Session::get('id')); $mechanic = $statement->select($SQL)->first(); // get vehicles with issues that have not yet been added to maintenance. $SQL = 'SELECT * FROM VehicleReportedIssues'; $statement = new Statement($connection); $issues = $statement->select($SQL)->all(); // get vehicles in under maintenance. $SQL = 'SELECT * FROM Maintenance m INNER JOIN VehicleView v ON m._idVehicle = v.idVehicle WHERE _ReturnedBy IS NULL'; $statement = new Statement($connection); $maintenance = $statement->select($SQL)->all(); // display completed maintenance. $SQL = 'SELECT * FROM Maintenance m INNER JOIN VehicleView v ON m._idVehicle = v.idVehicle WHERE _ReturnedBy IS NOT NULL ORDER BY DateReturned DESC'; $statement = new Statement($connection); $completed = $statement->select($SQL)->all(); $data = ['mechanic' => $mechanic, 'issues' => $issues, 'maintenance' => $maintenance, 'completed' => $completed]; $html = $this->view->render('MechanicHome', $data); $this->response->setContent($html); }
public function generatePartsInventory() { // get part types $SQL = "SELECT * FROM PartType"; $statement = new Statement($this->connection); $data = $statement->select($SQL)->all(); $mechanic = 11; $loc = "0000000000"; foreach ($data as $d) { $part = $d['idPartType']; for ($i = 0; $i < 15; $i++) { $insert = 'INSERT INTO PartsInventory (_idPartType, _MechanicIn, DateIn, Location) VALUES (:type, :mechanic, CURRENT_TIMESTAMP, :loc)'; $statement = new Statement($this->connection); $statement->setInt("type", $part); $statement->setInt("mechanic", $mechanic); $statement->setStr("loc", $loc); $statement->insert($insert); } } $SQL = "SELECT * FROM PartsInventory"; $statement = new Statement($this->connection); $data = $statement->select($SQL)->all(); var_dump($data); }
public function checkout($params) { $issue = $params['issue']; $description = $this->request->getParameter('description'); $connection = new Connection(); // get the vehicle form the issue number $SQL = "SELECT idVehicle FROM VehicleReportedIssues WHERE idReportedIssues = :issue"; $statement = new Statement($connection); $statement->setInt('issue', $issue); $vehicle = $statement->select($SQL)->first()['idVehicle']; // insert the vehicle to maintenance $SQL = 'INSERT INTO Maintenance (_idVehicle, BriefDescription, MaintenanceEntryDate) VALUES (:vehicle, :description, CURRENT_TIMESTAMP)'; $statement = new Statement($connection); $statement->setInt('vehicle', $vehicle); $statement->setInt('description', $description); $log = $statement->insert($SQL); // update the reported issues table $SQL = 'UPDATE ReportedIssues SET _MaintenanceLogNumber = :log WHERE idReportedIssues = :issue'; $statement = new Statement($connection); $statement->setInt('log', $log); $statement->setInt('issue', $issue); $statement->update($SQL); header('Location:/mechanic'); }
public function display($params) { $log = $params['log']; $SQL = 'SELECT * FROM Maintenance l INNER JOIN VehicleView v ON v.idVehicle = l._idVehicle WHERE l.MaintenanceLogNumber = :log'; $statement = new Statement(new Connection()); $statement->setInt('log', $log); $details = $statement->select($SQL)->first(); $SQL = 'SELECT * FROM MaintenanceItem i WHERE i._MaintenanceLogNumber = :log AND i._CompletedBy IS NULL'; $statement = new Statement(new Connection()); $statement->setInt('log', $log); $open = $statement->select($SQL)->all(); $this->addParts($open); $SQL = 'SELECT * FROM MaintenanceItem i INNER JOIN MechanicView m ON i._CompletedBy = m.idMINIEmployee WHERE i._MaintenanceLogNumber = :log AND i._CompletedBy IS NOT NULL'; $statement = new Statement(new Connection()); $statement->setInt('log', $log); $completed = $statement->select($SQL)->all(); // get parts used $this->addParts($completed); $data = ['details' => $details, 'open' => $open, 'completed' => $completed, 'log' => $log]; $html = $this->view->render('MaintenanceDetail', $data); $this->response->setContent($html); }
public function display($params) { $log = $params['log']; $description = ''; $parts = []; $item = 0; $action = "/maintenance/log/{$log}/additem"; // if the form is required for update if (array_key_exists('item', $params)) { // get the description $item = $params['item']; $SQL = "SELECT ItemDescription FROM MaintenanceItem WHERE idMaintenanceItem = :item"; $statement = new Statement(new Connection()); $statement->setInt('item', $item); $description = $statement->select($SQL)->first()['ItemDescription']; // get the parts used $parts = (new PartsGateway())->partsUsedForItem($item); $action = "/maintenance/log/{$log}/update/{$item}"; } // select part categories $SQL = "SELECT DISTINCT idPartCategory, PartCategoryName FROM PartCategory"; $statement = new Statement(new Connection()); $partCategories = $statement->select($SQL)->all(); // select count of parts in stock $cid = 0; $SQL = "SELECT InStock, idPartType, PartName FROM PartsStockView WHERE idPartCategory = :cid"; $statement = new Statement(new Connection()); $statement->setInt('cid', $cid); $statement->prepare($SQL); $statement->bindParams(); // add the stock parts to categories $length = count($partCategories); for ($i = 0; $i < $length; $i++) { $statement->setInt('cid', (int) $partCategories[$i]['idPartCategory']); $statement->bindParams(); $partCategories[$i]['parts'] = $statement->execute()->all(); } $data = ['partCategories' => $partCategories, 'log' => $log, 'description' => $description, 'item' => $item, 'partsUsed' => $parts, 'action' => $action]; $html = $this->view->render('MaintenanceDetailItem', $data); $this->response->setContent($html); }