Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="card">
- <div class="card-header bg-info">
- Set Appointment Details
- </div>
- <div class="card-body" style="overflow: scroll;height: 605px;">
- @if($bookingRequest->appointment)
- {!! Form::model($bookingRequest->appointment, ['url' => route('therapist.book.appointment', $bookingRequest)]) !!}
- @else
- {!! Form::open(['url' => route('therapist.book.appointment', $bookingRequest)]) !!}
- @endif
- <table class="table dyanmic" id="dynamic">
- <thead>
- <th>
- Session
- </th>
- </thead>
- <tbody>
- <tr>
- <td>
- <div class="form-row data">
- <div class="col-6">
- {!! Form::inputGroup('date', 'Starting', 'start_date[]') !!}
- </div>
- <div class="col-6">
- {!! Form::inputGroup('date', 'Until', 'end_date[]') !!}
- </div>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- <div class="form-row data">
- <div class="col-6">
- {!! Form::inputGroup('time', ' ', 'start_date_time[]') !!}
- </div>
- <div class="col-6">
- {!! Form::inputGroup('time', ' ', 'end_date_time[]') !!}
- </div>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- {!! Form::inputGroup('text', 'Other Services Applied', 'other_services[]') !!}
- {!! Form::inputGroup('number', 'Fee', 'other_services_fee[]') !!}
- </td>
- </tr>
- </tbody>
- <tfoot>
- <td>
- <div class="form-row form-group data">
- <div class="col-8">
- <button class="btn btn-sm btn-danger remove-line" id="remove-line"><i class="fa fa-times"></i></button>
- <button type="button" class="btn btn-sm btn-outline-primary add-line" id="add-line">
- <i class="fa fa-plus"></i> Add new session</button>
- </div>
- </div>
- </td>
- </tfoot>
- </table>
- <button type="submit" class="btn btn-success" name="submit" id="submit">Submit</button>
- {!! Form::close() !!}
- </div>
- </div>
- @endif
- </div>
- <script type="text/javascript">
- $(document).ready(function(){
- var postURL = "<?php echo url('/therapist-calendar')?>";
- var table = $(this).closest('table.dynamic');
- var i = 1;
- $('#add-line').click(function (){
- i++;
- $('#dynamic').append(
- '<tr id="row'+i+'" class="dynamic-added">'+
- '<th>Add another session</th>'+
- '</tr>'+
- ''+
- '<tr id="row'+i+'" class="dynamic-added">'+
- '<td><div class="form-row data"><div class="col-6">{!! Form::inputGroup("date", "Starting", "start_date[]") !!}</div>' +
- '<div class="col-6">{!! Form::inputGroup("date", "Until", "end_date[]") !!}</div></div></td>'+
- '</tr>' +
- ''+
- '<tr id="row'+i+'" class="dynamic-added">'+
- '<td><div class="form-row data"><div class="col-6">{!! Form::inputGroup("time", "Start Time", "start_date_time[]") !!}</div>' +
- '<div class="col-6">{!! Form::inputGroup("time", "End Time", "end_date_time[]") !!}</div></div></td>'+
- '</tr>' +
- ''+
- '<tr id="row'+i+'" class="dynamic-added">'+
- '<td>{!! Form::inputGroup("text", "Other Services Applied", "other_services[]") !!}' +
- '{!! Form::inputGroup("number", "Fee", "other_services_fee[]") !!}</td>'+
- '</tr>'
- );
- });
- $(document).on('click', '.remove-line', function (){
- var button_id = $(this).attr("id");
- $('#row'+button_id+'').remove();
- });
- $.ajaxSetup({
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- }
- });
- $('submit').click(function(){
- $.ajax({
- URL: postURL,
- method: "POST",
- data: $('#add_name').serialize(),
- type: 'json',
- });
- });
- });
- </script>
- public function saveAppointment(Request $request, BookingRequest $bookingRequest)
- {
- $validator = Validator::make($request->all(), [
- 'start_date' => 'required|date|after:yesterday',
- 'end_date' => 'required|date|after_or_equal:start_date',
- 'start_date_time' => 'required|date_format:H:i',
- 'end_date_time' => 'required|date_format:H:i',
- 'other_services' => 'sometimes|nullable|string',
- 'other_services_fee' => 'sometimes|nullable|numeric',
- ]);
- $bookingRequest->load('appointment');
- Auth::user()->load([
- 'therapist.appointments[]'
- ]);
- $validator->after(function ($v) use ($request, $bookingRequest) {
- if ($v->errors()) {
- $startDateTime[] = Carbon::parse("{$request->start_date} {$request->start_date_time}");
- $endDateTime[] = Carbon::parse("{$request->end_date} {$request->end_date_time}");
- /** @NOTE: lte => Less than or equal */
- if ($endDateTime->lte($startDateTime)) {
- $v->errors()->add('end_date_time', 'This should be after start date and time');
- return;
- }
- $conflicts = data_get(Auth::user(), 'therapist.approvedAppointments')
- ->filter(function ($existingAppointment) use ($startDateTime, $bookingRequest) {
- // ignore the same appointments
- if(optional($bookingRequest->appointment)->id === $existingAppointment->id){
- return false;
- }
- return $startDateTime->between($existingAppointment->start_timestamp, $existingAppointment->end_timestamp);
- });
- if($conflicts->isNotEmpty()){
- $v->errors()->add('start_date', 'Conflict');
- $v->errors()->add('end_date', 'Conflict');
- $v->errors()->add('end_date_time', 'Conflict');
- $v->errors()->add('start_date_time', 'Conflict');
- }
- }
- });
- $input = $validator->validate();
- $appointment = array_merge(
- $input,
- $bookingRequest->only(['client_id', 'therapist_id']),
- ['name' => '-', 'address' => '-']
- );
- DB::transaction(function () use ($bookingRequest, $appointment) {
- if ($bookingRequest->appointment()->exists()) {
- $bookingRequest->appointment()->update($appointment);
- } else {
- $bookingRequest->approve();
- $bookingRequest->appointment()->create($appointment);
- }
- });
- return redirect()->back()->with('message', 'Booking successful');
- }
- $request = $request->all();
- $input = array();
- foreach($request['start_date'] as $key => $startDate){
- foreach($request['start_date_time'] as $key => $startDateTime){
- $input[$key]['start_date'] = $startDate;
- $input[$key]['start_date_time'] = $startDateTime;
- $dateTimeDuration = Carbon::parse("{$startDate} {$startDateTime}");
- }
- }
- $validator = Validator::make($request->all(), [
- 'start_date' => 'required|array|date|after:yesterday', //OR
- "start_date.*" => => 'required|date|after:yesterday'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement