public static function appointmentTimesHH($date, $doctor, $bussines) { #obtener variables $in_start = date('Y-m-d', Input::get('start')); $date = $in_start; $dayLetter = Helpers::getDateString($date, '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)) { $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; $l1 = $date . 'T' . '00:00:00'; $l2 = $date . 'T' . '00:00:00'; $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_start = $date . ' ' . $lunch_start; $lunch_end = $configday->lunch_end; $lunch_end = $date . ' ' . $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 $a = array(array('title' => 'Dia No Disponible', 'start' => $l1, 'end' => $l2, 'color' => 'gray', 'editable' => false, 'allDay' => true)); return Response::json($a); } 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::getHoursHH($starttime_am, $endtime_am, $lunch_start, $lunch_end, $starttime_pm, $endtime_pm, $dating_duration); $hours_back = $hours; foreach ($hours as $h => $j) { $star_h = $j['start']; /* Validar que soo muestre la citas pendiente */ $states = array('confirmed', 'delayed', 'pending', 'in-progress', 'served', 'old'); $appointment = Appointment::where('day', $date)->whereIn('state', $states)->get(); foreach ($appointment as $key) { $start_key = Carbon::parse($key->start_date)->toTimeString(); $h_key = Carbon::parse($star_h)->toTimeString(); $user = Patient::find($key->patient_id)->user_id; $name_user = User::find($user)->getFullName(); if ($start_key == $h_key) { #dd($hours_back[$h]); #unset($hours_back[$h]); $hours_back[$h]['title'] = $name_user . " - " . $key->reason; if ($key->state == 'confirmed') { $hours_back[$h]['title'] = $name_user . " - " . $key->reason; $hours_back[$h]['color'] = '#00D900'; $hours_back[$h]['id'] = $key->id; } else { if ($key->state == 'delayed') { $hours_back[$h]['color'] = '#FF9900'; $hours_back[$h]['title'] = $name_user . " - " . $key->reason; $hours_back[$h]['id'] = $key->id; } else { if ($key->state == 'pending') { $hours_back[$h]['color'] = '#E40B0B'; $hours_back[$h]['title'] = $name_user . " - " . $key->reason; $hours_back[$h]['id'] = $key->id; } else { if ($key->state == 'in-progress') { $hours_back[$h]['color'] = '#FFFF00'; $hours_back[$h]['title'] = $name_user . " - " . $key->reason; $hours_back[$h]['id'] = $key->id; } else { if ($key->state == 'old') { $hours_back[$h]['color'] = '#000000'; $hours_back[$h]['title'] = $name_user . " - " . $key->reason; } else { if ($key->state == 'served') { $hours_back[$h]['color'] = '#4A86E8'; $hours_back[$h]['title'] = $name_user . " - " . $key->reason; } else { $hours_back[$h]['color'] = '#D9D9D9'; } } } } } } } } } return Response::json($hours_back); } } else { $a = array(array('title' => 'Dia No Disponible', 'start' => $l1, 'end' => $l2, 'color' => 'gray', 'editable' => false, 'allDay' => true)); return Response::json($a); } } 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 = $configday->lunch_start; $l1 = $date . 'T' . $lunch_start; $lunch_start = $date . ' ' . $lunch_start; $lunch_end = $configday->lunch_end; $l2 = $date . 'T' . $lunch_end; $lunch_end = $date . ' ' . $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) { $a = array('title' => 'Dia No Disponible', 'start' => $l1, 'end' => $l2, 'color' => 'gray', 'background' => 'gray'); return Response::json($a); } else { $states = array('confirmed', 'delayed', 'pending', 'in-progress', 'served', 'old'); $appointment = Appointment::where('day', $date)->whereIn('state', $states)->get(); #$hours = Helpers::getHours($starttime_am,$endtime_am,$starttime_pm,$endtime_pm,'45'); $hours = Helpers::getHoursHH($starttime_am, $endtime_am, $lunch_start, $lunch_end, $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); } } }