public function add_check()
 {
     $validator = Validator::make(Input::all(), PastTime::$rules);
     if (!$validator->fails()) {
         $time = new PastTime();
         $date_past_explode = explode('/', Input::get('date_past'));
         $time->date_past = $date_past_explode[2] . '-' . $date_past_explode[1] . '-' . $date_past_explode[0];
         $dateTime_start = new DateTime($time->date_past);
         $time->time_start = $dateTime_start->format('Y-m-d') . ' ' . Input::get('time_start') . ':00';
         if (Input::get('time_end')) {
             if (Input::get('time_end') <= Input::get('time_start')) {
                 $dateTime_start->modify('+1 day');
             }
             $time->time_end = $dateTime_start->format('Y-m-d') . ' ' . Input::get('time_end') . ':00';
         }
         if (Auth::user()->isSuperAdmin()) {
             $time->user_id = Input::get('user_id');
             $time->invoice_id = Input::get('invoice_id');
             $time->is_free = Input::get('is_free', false);
         } else {
             $time->user_id = Auth::user()->id;
             $time->is_free = false;
         }
         $time->ressource_id = Input::get('ressource_id');
         $time->comment = Input::get('comment');
         if ($time->save()) {
             return Redirect::route('pasttime_list', $time->id)->with('mSuccess', 'Le temps passé a bien été ajouté');
         } else {
             return Redirect::route('pasttime_add')->with('mError', 'Impossible de créer ce temps passé')->withInput();
         }
     } else {
         return Redirect::route('pasttime_add')->with('mError', 'Il y a des erreurs')->withErrors($validator->messages())->withInput();
     }
 }
 public function logTimeAjax($id)
 {
     $booking_item = BookingItem::find($id);
     if (!$booking_item) {
         return Response::json(array('status' => 'KO', 'message' => 'La réservation est inconnue'));
     }
     $time = new PastTime();
     $time->user_id = $booking_item->booking->user_id;
     $time->ressource_id = $booking_item->ressource_id;
     $time->date_past = date('Y-m-d', strtotime($booking_item->start_at));
     $time->time_start = $booking_item->start_at;
     $time->time_end = date('Y-m-d H:i:s', strtotime($booking_item->start_at) + $booking_item->duration * 60);
     $existing = PastTime::query()->where('user_id', $time->user_id)->where('ressource_id', $time->ressource_id)->where('date_past', $time->date_past)->where('time_start', $time->time_start)->where('time_end', $time->time_end)->count() > 0;
     if ($existing) {
         return Response::json(array('status' => 'KO', 'message' => sprintf('Un enregistrement similaire à %s est déjà présent', $booking_item->booking->title)));
     }
     $time->save();
     return Response::json(array('status' => 'OK', 'message' => sprintf('La réunion %s a été comptabilisée', $booking_item->booking->title), 'event' => $booking_item->toJsonEvent()));
 }