Пример #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $liquidacion = Liquidacion::findOrFail($id);
     $taxis = Taxi::lists('matricula', 'id');
     $choferes = Chofer::lists('apellido', 'id');
     return view('liquidaciones.edit', compact('liquidacion'))->with(['taxis' => $taxis, 'choferes' => $choferes]);
 }
Пример #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $taxi = Taxi::findOrFail($id);
     $taxi->fill($request->all());
     $taxi->save();
     return \Redirect::route('taxis.index');
 }
Пример #3
0
 /**
  * Display's the selected Taxi Details
  *
  * @param  int  $taxi_id
  *
  * @return mixed Taxi Details Info
  */
 public function show($taxi_id)
 {
     $taxi = Taxi::find($taxi_id);
     if (is_null($taxi)) {
         return redirect('/')->with('message', 'Taxi not found');
     }
     return view('taxi.home', compact('taxi') + $this->data);
 }
Пример #4
0
 public function listadoChofer(Request $request)
 {
     $taxi_id = $request->taxi_id;
     $chofer_id = $request->chofer_id;
     $fecha_desde = $request->fecha_desde;
     $fecha_hasta = $request->fecha_hasta;
     $chofer = Chofer::where('id', $chofer_id)->first();
     $taxi = Taxi::where('id', $taxi_id)->first();
     $liquidaciones = Liquidacion::matricula($taxi->id)->choferid($chofer->id)->fechaDesde($fecha_desde)->fechaHasta($fecha_hasta)->orderBy('fecha', 'ASC')->get();
     $view = view('liquidaciones.pdf_index', compact('liquidaciones', 'chofer', 'taxi', 'fecha_desde', 'fecha_hasta'))->render();
     $pdf = \PDF::loadView('liquidaciones.pdf_index', compact('liquidaciones', 'chofer', 'taxi', 'fecha_desde', 'fecha_hasta'));
     return $pdf->stream();
 }
Пример #5
0
 /**
  * Post: Create a new Taxi Complaint Report
  *
  * @param object $request Data from Report Taxi Form
  *
  * @return json Taxi ID
  */
 public function report(Request $request)
 {
     $user = Auth::user();
     $rules = ['plate_number' => 'required', 'name' => 'required', 'incident_date' => 'required', 'violations' => 'required'];
     // if not authenticated, add additional rules - for user account
     if (is_null($user)) {
         $rules += ['email' => 'required|email', 'full_name' => 'required', 'contact_number' => 'required', 'reg_password' => 'required|confirmed'];
     }
     // iterate on each pictures and add a valid rule
     $txp = count($request->taxi_pictures) - 1;
     foreach (range(0, $txp) as $index) {
         $rules['taxi_pictures.' . $index] = 'image';
     }
     $this->validate($request, $rules);
     $data = Taxi::store($request, $user);
     // db transaction (search) yielded to many results
     // redirect to search page using the plate_number as keyword
     if (!empty($data) && is_array($data) && isset($data['plate_number'])) {
         // return redirect('search/' . $data['plate_number']);
         return response()->json(['data' => ['plate_number' => $data['plate_number']], 200]);
     }
     // user is not logged-in, try auto login the current reporter
     if (is_null($user)) {
         Auth::attempt(['email' => $request->email, 'password' => $request->password]);
     }
     if (!empty($data) && is_array($data) && isset($data['taxi_id'])) {
         return response()->json(['data' => ['taxi_id' => $data['taxi_id']], 200]);
     } else {
         return response()->json(['message' => 'Failed add new report', 500]);
     }
 }
Пример #6
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $gastos = Gasto::paginate();
     $taxis = Taxi::orderBy('matricula', 'ASC')->get();
     return view('gastos.create', compact('gastos', 'taxis'));
 }
Пример #7
0
 /**
  * Store Taxi and Report information to the database
  * If $user param is null, this will register the based on the form info.
  * If the reported taxi already exist on the database use it then create a report
  * If it doesn't exist yet, register this a new taxi then create a report
  *
  * @param object $request Request object from the form
  * @param object $user User object
  *
  * @return array Taxi information
  */
 public static function store($request, $user)
 {
     $data = DB::transaction(function () use($request, $user) {
         // register the new user
         if (is_null($user)) {
             $user = new User();
             $user->name = $request->full_name;
             $user->email = $request->email;
             $user->password = bcrypt($request->password);
             $user->contact_number = $request->contact_number;
             $user->save();
         }
         $user_id = $user ? $user->id : 1;
         // user's id or admin
         $plate_number = self::sanitize($request->plate_number);
         // 1. find if it exist, if not create one
         // 2. if search result yielded more than 1 do a taxi search
         $taxi_search = self::search($plate_number);
         // use the existing taxi,
         if (count($taxi_search) === 1) {
             // todo: should we also update with the new data?
             $taxi = $taxi_search->first();
             $taxi->description = $request->description;
             $taxi->save();
         } else {
             if (count($taxi_search) === 0) {
                 $taxi = new Taxi();
                 $taxi->plate_number = $plate_number;
                 $taxi->name = $request->name;
                 $taxi->description = $request->description;
                 $taxi->save();
             } else {
                 return ['plate_number' => $plate_number];
             }
         }
         if (!empty($request->incident_time)) {
             $incident_time = date('H:i:s', strtotime($request->incident_time));
         } else {
             $incident_time = null;
         }
         $taxi_complaint = new TaxiComplaint();
         $taxi_complaint->taxi_id = $taxi->id;
         $taxi_complaint->incident_date = $request->incident_date;
         $taxi_complaint->incident_time = $incident_time;
         $taxi_complaint->incident_location = $request->incident_location;
         $taxi_complaint->notes = $request->notes;
         $taxi_complaint->drivers_name = $request->drivers_name;
         $taxi_complaint->created_by = $user_id;
         $taxi_complaint->save();
         foreach ($request->violations as $violation_id) {
             $taxi_violation = new TaxiViolation();
             $taxi_violation->taxi_complaint_id = $taxi_complaint->id;
             $taxi_violation->violation_id = $violation_id;
             $taxi_violation->save();
         }
         $path_prefix = 'images/uploads/' . $user_id;
         // this is the directory where to save the uploaded images
         $user_dir = public_path($path_prefix);
         if (!empty($request->taxi_pictures) && is_array($request->taxi_pictures)) {
             foreach ($request->taxi_pictures as $picture) {
                 if (!is_null($picture) && $picture->isValid()) {
                     //prepare the filename and url
                     $fname = str_random(40);
                     $ext = strtolower($picture->getClientOriginalExtension());
                     $filename = $fname . '.' . $ext;
                     $file_uri = $path_prefix . '/' . $filename;
                     // move the uploaded file to it's location
                     $picture->move($user_dir, $filename);
                     // save the url and new filename to db
                     $taxi_picture = new TaxiPicture();
                     $taxi_picture->taxi_id = $taxi->id;
                     // added taxi_complaint_id so that we could
                     // track taxi physical changes
                     $taxi_picture->taxi_complaint_id = $taxi_complaint->id;
                     $taxi_picture->path = $file_uri;
                     $taxi_picture->created_by = $user_id;
                     $taxi_picture->save();
                 }
             }
         }
         return ['taxi_id' => $taxi->id];
     });
     // end db::transaction
     return $data;
 }