Kaynağa Gözat

fixed confirming appointment

Josh 4 yıl önce
ebeveyn
işleme
7f7dc779df

+ 45 - 0
app/Http/Controllers/GuestController.php

@@ -13,6 +13,7 @@ use App\Models\Section;
 use App\Models\SectionTemplate;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\File;
+use Illuminate\Support\Facades\Http;
 use Illuminate\Support\Facades\Response;
 
 class GuestController extends Controller
@@ -63,4 +64,48 @@ class GuestController extends Controller
        return view('app.guest.appointment-confirmation', compact('appointment'));
     }
 
+    public function processAppointmentConfirmation(Request $request){
+        $appointmentUid = $request->get('appointment_uid');
+        $appointment = Appointment::where('uid', $appointmentUid)->first();
+        abort_if(!count($appointment->confirmationRequests), 404, 'No confirmation requests on this appointment.');
+        abort_if(!$appointment, 404, 'Invalid url');
+        abort_if($appointment->status == 'CANCELLED', 404, 'Appointment has been cancelled');
+        abort_if($appointment->status == 'COMPLETED', 404, 'Appointment has been completed'); 
+        abort_if($appointment->status == 'ABANDONED', 404, 'Appointment has been abandoned');
+
+        $decision = $request->get('decision');
+        $memo = $request->get('memo');
+        $response = null;
+        $data = [
+            'uid' => $appointment->uid,
+            'memo' => $memo
+        ];
+
+        $url = '/appointment/confirmationDecisionAccept';
+        if($decision == 'REJECT'){
+            $url = '/appointment/confirmationDecisionReject';
+        }
+
+        $response = $this->calljava($request, $url, $data);
+
+        if($response['success']){
+            return redirect()->back()->with('success', true);
+        }
+        return redirect()->back()->with('error', true);
+    }
+
+    // TODO move to utility
+    private function callJava($request, $endPoint, $data)
+    {
+        $url =  config('stag.backendUrl') . $endPoint;
+        
+        $response = Http::asForm()
+            ->withHeaders([
+                'secret' => 'superman'
+            ])
+            ->post($url, $data)
+            ->json();
+        return $response;
+    }
+
 }

+ 14 - 5
resources/views/app/guest/appointment-confirmation.blade.php

@@ -5,7 +5,16 @@
         <div class="col-md-12">
             <h1>Appointment Confirmation</h1>
             <div>
-                <form action="">
+                @if(session('success'))
+                    <div class="alert alert-info">Submitted successfully</div>
+                @endif
+                @if(session('error'))
+                    <div class="alert alert-danger">Error while submitting the data. Please contact the administrator</div>
+                @endif
+                <form action="{{route('process-appointment_confirmation')}}" method="POST">
+                    @csrf
+                    <input type="hidden" name="appointment_uid" value="{{$appointment->uid}}">
+
                     <div class="form-group">
                         <p>Hi {{$appointment->client->name_first}} {{$appointment->client->name_last}}!</p>
                     </div>
@@ -16,12 +25,12 @@
 
                     <div class="form-group">
                         <div class="check">
-                            <input type="checkbox" name="accept" id="" class="check-input">
-                            <label for="" class="check-label">Accept</label>
+                            <input type="radio" name="decision" value="ACCEPT" id="appointment_confirmation_accept" class="check-input">
+                            <label for="appointment_confirmation_accept" class="check-label">Accept</label>
                         </div>
                         <div class="check">
-                            <input type="checkbox" name="reject" id="" class="check-input">
-                            <label for="" class="check-label">Reject</label>
+                            <input type="radio" name="decision" value="REJECT" id="appointment_confirmation_reject" class="check-input">
+                            <label for="appointment_confirmation_reject" class="check-label">Reject</label>
                         </div>
                     </div>
 

+ 1 - 1
resources/views/app/log-in-as.blade.php

@@ -25,7 +25,7 @@
                     <td>{{$pro->cell_number}}</td>
                     <td>{{$pro->email}}</td>
                     <td>
-                        <form action="{{route('process-log-in-as')}}" method="POST">
+                        <form action="{{route('process-log-in-as')}}" method="POST"  target="_top">
                             @csrf
                             <input type="hidden" name="proUid" value="{{$pro->uid}}">
                             <button class="btn btn-primary">Login</button>

+ 1 - 1
resources/views/layouts/template.blade.php

@@ -106,7 +106,7 @@
             @if($pro->pro_type == 'ADMIN')
             <div class="ml-1 d-inline-block text-secondary">|</div>
             <div class="d-flex align-items-center">
-                <a href="{{route('log-in-as')}}" class="small text-white ml-1">Log In As</a>
+                <a href="{{route('log-in-as')}}"  native target="_top"  class="small text-white ml-1">Log In As</a>
             </div>
             @endif
 

+ 1 - 0
routes/web.php

@@ -42,6 +42,7 @@ Route::post('/set_security_questions', 'HomeController@postSetSecurityQuestions'
 Route::get("/guest/section/{accessToken}", 'GuestController@section')->name('guest_section_access');
 Route::get("/guest/handout/{handoutClientUid}", 'GuestController@handout')->name('guest_handout_access');
 Route::get("/appointment-confirmation/{appointmentUid}", 'GuestController@appointmentConfirmation')->name('appointment_confirmation');
+Route::post("/process-appointment-confirmation", 'GuestController@processAppointmentConfirmation')->name('process-appointment_confirmation');
 
 Route::middleware('pro.auth')->group(function () {