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 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 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 insert($resID, $totalCost, $totalMileage, $fuel) { $SQL = 'INSERT INTO Billings (_idReservations, TotalCost, TotalMileage, FuelCost) VALUES (:id, :cost, :mileage, :fuel)'; $statement = new Statement($this->connection); $statement->setInt("id", $resID)->setStr("cost", $totalCost); $statement->setInt("mileage", $totalMileage)->setStr("fuel", $fuel); return $statement->insert($SQL); }
public function complete($params) { $log = $params['log']; $mechanic = Session::get('id'); $SQL = 'UPDATE Maintenance SET _ReturnedBy = :mechanic, DateReturned = CURRENT_TIMESTAMP WHERE MaintenanceLogNumber = :log'; $statement = new Statement(new Connection()); $statement->setInt('log', $log); $statement->setInt('mechanic', $mechanic); $complete = $statement->update($SQL); if (!is_a($complete, "PDOException")) { header('Location:/mechanic'); } else { $data = ['error' => $complete->errorInfo[2], 'return' => "/maintenance/log/{$log}"]; $html = $this->view->render('Error', $data); $this->response->setContent($html); } }
public function removePart($params) { extract($params); $SQL = "DELETE FROM PartsUsed WHERE _idPartsInventory = :part"; $statement = new Statement(new Connection()); $statement->setInt('part', $id); $statement->delete($SQL); header("Location: /maintenance/log/{$log}/update/{$item}"); }