Esempio n. 1
0
 public static function appointmentAgenda($doctor, $bussines)
 {
     #obtener variables
     $dayLetter = Helpers::getDateString(date('Y-m-d'), 'day');
     $agenda_id = Business::find($bussines)->agenda_id;
     $dating_duration = Agenda::find($agenda_id)->dating_duration;
     $custom_day = CustomDay::where('day', $date)->where('agenda_id', $agenda_id)->first();
     if (is_null($custom_day)) {
         #No existe en CustomDay la fecha
         $configday = Configday::where('agenda_id', $agenda_id)->where('day', $dayLetter)->first();
         if ($configday) {
             #Existe la agenda en la agenda
             $is_day_off_configday = $configday->is_day_off;
             $starttime_am = $configday->starttime_am;
             $starttime_am = $date . ' ' . $starttime_am;
             $endtime_am = $configday->endtime_am;
             $endtime_am = $date . ' ' . $endtime_am;
             $lunch_start = $configday->lunch_start;
             $lunch_end = $configday->lunch_end;
             $starttime_pm = $configday->starttime_pm;
             $starttime_pm = $date . ' ' . $starttime_pm;
             $endtime_pm = $configday->endtime_pm;
             $endtime_pm = $date . ' ' . $endtime_pm;
             if ($is_day_off_configday) {
                 #Cuando is_day_off = 1 	=> que ese dia NO se trabaja
                 return "0";
             } else {
                 /*	
                 	Cuando is_day_off = 0	=> que ese dia se trabaja
                 	Luego buscaremos la fecha en la tabla Appointment(Citas)
                 	quisiera que en la citas actuales puedas ver citas posteriores(futuras)
                 	fechas año-mes-dia					
                 */
                 $appointments = Appointment::where('day', $date)->get();
                 $hours = Helpers::getHours($starttime_am, $endtime_am, $starttime_pm, $endtime_pm, $dating_duration);
                 $hours_back = $hours;
                 foreach ($hours as $h => $j) {
                     $star_h = $j['start'];
                     $appointment = Appointment::where('day', $date)->get();
                     foreach ($appointment as $key) {
                         $start_key = Carbon::parse($key->start_date)->toTimeString();
                         if ($start_key == $star_h) {
                             unset($hours_back[$h]);
                         }
                     }
                 }
                 return $hours_back;
             }
         } else {
             return "0";
         }
     } else {
         #Si existe en CustomDay la fecha
         $is_day_off = $custom_day->is_day_off;
         $starttime_am = $custom_day->starttime_am;
         $starttime_am = $date . ' ' . $starttime_am;
         $endtime_am = $custom_day->endtime_am;
         $endtime_am = $date . ' ' . $endtime_am;
         $lunch_start = $custom_day->lunch_start;
         $lunch_end = $custom_day->lunch_end;
         $starttime_pm = $custom_day->starttime_pm;
         $starttime_pm = $date . ' ' . $starttime_pm;
         $endtime_pm = $custom_day->endtime_pm;
         $endtime_pm = $date . ' ' . $endtime_pm;
         #Verificar si esa fecha is_day_off = 1
         if ($is_day_off) {
             return "0";
         } else {
             $appointments = Appointment::where('day', $date)->get();
             $hours = Helpers::getHours($starttime_am, $endtime_am, $starttime_pm, $endtime_pm, $dating_duration);
             $hours_back = $hours;
             foreach ($hours as $h => $j) {
                 $star_h = $j['start'];
                 $appointment = Appointment::where('day', $date)->get();
                 foreach ($appointment as $key) {
                     $start_key = Carbon::parse($key->start_date)->toTimeString();
                     if ($start_key == $star_h) {
                         unset($hours_back[$h]);
                     }
                 }
             }
             return Response::json($hours_back);
         }
     }
 }