/** * @param array $existingVehicleInspection * @param \Madkom\RegistryApplication\Domain\CarManagement\VehicleInspection\VehicleInspection $newVehicleInspection * * @return bool */ public function checkForDuplicates(array $existingVehicleInspection, VehicleInspection $newVehicleInspection) { /** @var VehicleInspection $vehicleInspection */ foreach ($existingVehicleInspection as $vehicleInspection) { if ($newVehicleInspection->getLastInspection() === $vehicleInspection->getLastInspection() || $newVehicleInspection->getId() === $vehicleInspection->getId()) { return true; } } return false; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), Vehicle::$rules, Vehicle::$messages); if ($validator->passes()) { $vehicle = new Vehicle(); $vehicle->chasis = Input::get('chasis'); $vehicle->enginecc = Input::get('enginecc'); $vehicle->engineno = Input::get('engineno'); $vehicle->yor = Input::get('yor'); $vehicle->destination = Input::get('destination'); $vehicle->make = Input::get('make'); $vehicle->model = Input::get('model'); $vehicle->location_id = Input::get('location_id'); $vehicle->vec = ''; $vehicle->inspection_date = Input::get('inspection_date'); $vehicle->charge = Location::find(Input::get('location_id'))->location_charge; $vehicle->user_id = Auth::id(); $vehicle->save(); $file = Input::file('vec'); $extension = $file->getClientOriginalExtension(); $fileName = "VEC" . $vehicle->id . '.' . $extension; $vehicle->vec = $fileName; $vehicle->save(); $file->move('uploads', $fileName); //Upload the file to public/uploads // CREATE NEW VEHICLE INSPECTION RECORD $insp = new VehicleInspection(); $insp->vehicle_id = $vehicle->id; $insp->save(); //CREATE NEW VEHICLE ROADWORTHINESS RECORD $insp_details = new InspectorDetails(); $insp_details->vehicle_id = $vehicle->id; $insp_details->save(); //Event::fire('vehicle.create', [$vehicle]); return Redirect::to('vehicles')->with('success', 'Vehicle Added Successfully'); } else { return Redirect::to('vehicles/create')->withErrors($validator)->withInput(); } }
/** * @param \Madkom\RegistryApplication\Domain\CarManagement\VehicleInspection\VehicleInspection $newVehicleInspection * * @return bool */ public function checkDates(VehicleInspection $newVehicleInspection) { $interval = $newVehicleInspection->getUpcomingInspection()->diff($newVehicleInspection->getLastInspection()); $interval = $interval->format('%R%a'); return (int) $interval >= 0 ?: false; }