appointment-seeder-overall-completed

et#27
Mahesh Sharma 2 years ago
parent 45d0b8f609
commit 98fb64971a
  1. 10
      app/Http/Controllers/Admin/AppointmentController.php
  2. 7
      app/Http/Controllers/AppointmentController.php
  3. 34
      database/seeders/AppointmentTableSeeder.php
  4. 6
      resources/views/admin/appointment/edit.blade.php
  5. 21
      resources/views/appointment.blade.php

@ -23,7 +23,7 @@ class AppointmentController extends Controller
$key = \request('status'); $key = \request('status');
$appointments = $appointments->where('status',$key); $appointments = $appointments->where('status',$key);
} }
$appointments = $appointments->paginate(config('custom.per_page')); $appointments = $appointments->paginate(20);
return view($this->view.'index',compact('appointments')); return view($this->view.'index',compact('appointments'));
} }
@ -36,8 +36,8 @@ class AppointmentController extends Controller
{ {
$request->validate([ $request->validate([
'date' => 'required|date', 'date' => 'required|date',
'start_time' => 'required|date_format:H:i', 'start_time' => 'required|date_format:H:i A',
'end_time' => 'required|date_format:H:i', 'end_time' => 'required|date_format:H:i A',
// 'location' => 'required|max:255', // 'location' => 'required|max:255',
// 'description' => 'required', // 'description' => 'required',
]); ]);
@ -67,8 +67,8 @@ class AppointmentController extends Controller
{ {
$request->validate([ $request->validate([
'date' => 'required|date', 'date' => 'required|date',
'start_time' => 'required|date_format:H:i', 'start_time' => 'required|date_format:H:i A',
'end_time' => 'required|date_format:H:i', 'end_time' => 'required|date_format:H:i A',
// 'location' => 'required|max:255', // 'location' => 'required|max:255',
// 'description' => 'required', // 'description' => 'required',
]); ]);

@ -37,10 +37,9 @@ class AppointmentController extends Controller
$currentTime = Carbon::now(); $currentTime = Carbon::now();
$appointments = []; $appointments = [];
foreach ($appointments_all as $appointment) { foreach ($appointments_all as $appointment) {
$start_time = date("H:i", strtotime($appointment->start_time));
$appointmentDate = Carbon::createFromFormat('Y-m-d H:i:s', $appointment->date.' '.$appointment->start_time); $appointmentDate = Carbon::createFromFormat('Y-m-d H:i', $appointment->date.' '.$start_time);
if ($appointmentDate->gt($currentTime)) {
if ($appointmentDate->gt($currentTime) || $appointmentDate > $currentTime) {
array_push($appointments, $appointment); array_push($appointments, $appointment);
} }
} }

@ -20,23 +20,25 @@ class AppointmentTableSeeder extends Seeder
public function run() public function run()
{ {
$startTime = Carbon::parse("9:00 AM");
$startTime = Carbon::parse("09:00:00"); $endTime = Carbon::parse("5:00 PM");
$endTime = Carbon::parse("17:00:00"); foreach(config('custom.service_type') as $key => $value){
for ($i = 0; $i < 7; $i++) {
for ($i = 0; $i < 7; $i++) { $date = Carbon::now()->addDays($i);
$date = Carbon::now()->addDays($i);
for ($j = 0; $j <= ((($endTime->diffInMinutes($startTime)) / 30)-1); $j++) {
for ($j = 0; $j <= (($endTime->diffInMinutes($startTime)) / 30); $j++) { $currentTime = $startTime->copy()->addMinutes(30 * $j);
$currentTime = $startTime->copy()->addMinutes(30 * $j); $currentEndTime = $startTime->copy()->addMinutes(30 * $j + 30);
$currentEndTime = $startTime->copy()->addMinutes(30 * $j + 30);
DB::table('appointments')->insert([
DB::table('appointments')->insert([ 'date' => $date,
'date' => $date, 'start_time' => $currentTime->format("H:i A"),
'start_time' => $currentTime->format("H:i:s"), 'end_time' => $currentEndTime->format("H:i A"),
'end_time' => $currentEndTime->format("H:i:s"), 'service_type' => $key
]); ]);
}
} }
} }
} }
} }

@ -42,19 +42,19 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label> Date <span style="color: red";> * </span> </label> <label> Date <span style="color: red";> * </span> </label>
<input type="date" class="form-control" id="inputPassword3" name="date" value="{{$appointment->date}}" required> <input type="date" class="form-control" id="inputPassword3" name="date" value="{{$appointment->date}}" required/>
</div> </div>
</div> </div>
<div class="col-md-6" > <div class="col-md-6" >
<div class="form-group" > <div class="form-group" >
<label>Start Time <span style="color: red";> * </span></label> <label>Start Time <span style="color: red";> * </span></label>
<input type="time" name="start_time" class="form-control" required value = "{{$appointment->start_time}}"/> <input type="text" name="start_time" class="form-control" value = "{{$appointment->start_time}}" required/>
</div> </div>
</div> </div>
<div class="col-md-6" > <div class="col-md-6" >
<div class="form-group" > <div class="form-group" >
<label>End Time <span style="color: red";> * </span></label> <label>End Time <span style="color: red";> * </span></label>
<input type="time" name="end_time" class="form-control" required value = "{{$appointment->end_time}}"/> <input type="text" name="end_time" class="form-control" value = "{{$appointment->end_time}}" required/>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">

@ -184,21 +184,24 @@
for (var i = 0; i < appointments.length; i++) { for (var i = 0; i < appointments.length; i++) {
var appointment = appointments[i]; var appointment = appointments[i];
var isAmStart = appointment.start_time < '12:00:00'; // var isAmStart = appointment.start_time < '12:00:00';
var isAmEnd = appointment.end_time < '12:00:00'; // var isAmEnd = appointment.end_time < '12:00:00';
timeSlots += '<button type="button" class="time-slot" data-toggle="modal" data-target="#appointmentModal" data-appointment-id="' + appointment.id + '">' + appointment.start_time +' '+ (isAmEnd ? 'AM' : 'PM')+ ' - ' + appointment.end_time +' ' + (isAmEnd ? 'AM' : 'PM') + '</button>'; var isAmStart = '';
var isAmEnd = '';
timeSlots += '<button type="button" class="time-slot" data-toggle="modal" data-target="#appointmentModal" data-appointment-id="' + appointment.id + '" data-start-time="'+appointment.start_time+'" + data-end-time="'+appointment.end_time+'" >' + appointment.start_time +' - ' + appointment.end_time +'</button>';
} }
$('#'+id+'-available-dates').html(timeSlots); $('#'+id+'-available-dates').html(timeSlots);
$('.time-slot').click(function (e) { $('.time-slot').click(function (e) {
e.preventDefault(); e.preventDefault();
var appointmentId = $(this).data("appointment-id"); var appointmentId = $(this).data("appointment-id");
var startTime = $(this).data("start-time");
var endTime = $(this).data("end-time");
$('#appointment-form input[name="appointment_id"]').val(appointmentId); $('#appointment-form input[name="appointment_id"]').val(appointmentId);
$('#booking_date').html(formated_date); $('#booking_date').html(formated_date);
$('#start_time').html('&nbsp;<b>('+appointment.start_time+'</b>'); $('#start_time').html('&nbsp;<b>('+startTime+'</b>');
$('#end_time').html('<b>'+appointment.end_time+')</b>'); $('#end_time').html('<b>'+endTime+')</b>');
$("#modal").modal("show"); $("#modal").modal("show");
}); });
@ -218,12 +221,12 @@
data: $("form").serialize(), data: $("form").serialize(),
success: function(response) { success: function(response) {
$("#modal").modal("hide"); $("#modal").modal("hide");
var isAmStart = response.appointment.start_time < '12:00:00'; // var isAmStart = response.appointment.start_time < '12:00:00';
var isAmEnd = response.appointment.end_time < '12:00:00'; // var isAmEnd = response.appointment.end_time < '12:00:00';
Swal.fire({ Swal.fire({
title: 'Booked!!', title: 'Booked!!',
text: 'Appointment Successfully Booked for '+response.appointment_detail['name']+' at '+response.formated_date +'('+response.appointment['start_time']+' '+(isAmStart ? 'AM' : 'PM')+ ' - ' + response.appointment['end_time']+' '+ (isAmEnd ? 'AM' : 'PM') +')', text: 'Appointment Successfully Booked for '+response.appointment_detail['name']+' at '+response.formated_date +'('+response.appointment['start_time']+' - ' + response.appointment['end_time']+' )',
icon: 'success' icon: 'success'
}).then(function(){ }).then(function(){
location.reload(); location.reload();

Loading…
Cancel
Save