Advertisement
Guest User

Untitled

a guest
Jul 8th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Service;
  7. use App\Employee;
  8. use App\Booking;
  9.  
  10. class ConfirmationController extends Controller
  11. {
  12.     public function __construct()
  13.     {
  14.         $this->middleware('auth');
  15.     }
  16.  
  17.     public function index(Request $request)
  18.     {
  19.             $user = $request->user()->id;
  20.         $services = Service::where('id',$request->service)->get();
  21.         $employees = Employee::where('id',$request->employee)->get();
  22.         $date = $request->date;
  23.         $start = $request->start;
  24.         $duration = $request->duration;
  25.         $end = $start + $duration;
  26.         $category = Service::where('id', $request->service)->first('id_category');
  27.  
  28.        
  29.         // Antes de redireccionar a la vista confirmacion se valida si el usuario ya tiene alguna cita para esa misma fecha y hora o que se cruce con la cita que va a programar
  30.         $bookingsOfUser = Booking::where('date', date('Y-m-d', $date))->where('id_user', $user)->get();  
  31.  
  32.             foreach ($bookingsOfUser as $bookinguser) {            
  33.  
  34.                 if ($start == $bookinguser->start) {
  35.                   return 'Fallo 1';
  36.                 }
  37.  
  38.                 if ($start > $bookinguser->start && $start < $bookinguser->end) {
  39.                   return 'Fallo 2';
  40.                 }
  41.  
  42.                 if ($start < $bookinguser->start && $end > $bookinguser->start) {
  43.                   return 'Fallo 3';
  44.                 }
  45.  
  46.                 if ($start < $bookinguser->end && $end > $bookinguser->end) {
  47.                   return 'Fallo 4';
  48.                 }              
  49.             }
  50.  
  51.         setlocale(LC_TIME, 'es_CO.utf8'); // Se establece locale en español
  52.  
  53.         $data = [
  54.           'services' => $services,
  55.           'employees' => $employees,
  56.           'date' => $date,
  57.           'start' => $start,
  58.         ];
  59.  
  60.         return view('confirmation')->with($data);
  61.  
  62.     } //end function index
  63.  
  64.   } //end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement