diff --git a/app/Events/AutoSerahan.php b/app/Events/AutoSerahan.php new file mode 100644 index 0000000..a618636 --- /dev/null +++ b/app/Events/AutoSerahan.php @@ -0,0 +1,36 @@ +pengesahan = $pengesahan; + $this->id = $id; + $this->cawangan = $cawangan; + $this->kodlaluan = $kodlaluan; + } + + public function broadcastOn() + { + return ['autoserahan-notice']; + } + + public function broadcastAs() + { + return 'autoserahan-event'; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/KhazanahController.php b/app/Http/Controllers/KhazanahController.php index 8cba09c..5bc8be0 100644 --- a/app/Http/Controllers/KhazanahController.php +++ b/app/Http/Controllers/KhazanahController.php @@ -4286,4 +4286,76 @@ class KhazanahController extends Controller $val = preg_replace('/\.(?=.*\.)/', '', $val); return floatval($val); } + + + public function AutoSerahan(Request $request) + { + // Step 1: Call API v3 First + $call_approval_v3 = Http::withOptions(['verify' => config('app.api_verify')]) + ->post(config('api.url_koop') . '/api/autoserahan/create', [ + 'kodcaw' => $request->arraysend['kodcaw'], + 'teller' => $request->arraysend['teller'], + 'amaun' => $request->arraysend['amaun'], + 'txtring1' => $request->arraysend['ambilanring1'], + 'txtring5' => $request->arraysend['ambilanring5'], + 'txtring10' => $request->arraysend['ambilanring10'], + 'txtring20' => $request->arraysend['ambilanring20'], + 'txtring50' => $request->arraysend['ambilanring50'], + 'txtring100' => $request->arraysend['ambilanring100'], + 'txtsen1' => $request->arraysend['ambilansen1'], + 'txtsen5' => $request->arraysend['ambilansen5'], + 'txtsen10' => $request->arraysend['ambilansen10'], + 'txtsen20' => $request->arraysend['ambilansen20'], + 'txtsen50' => $request->arraysend['ambilansen50'], + 'jenis' => 'pendahuluan', + 'version' => 'v3', + ])->json(); + + // Check if API v3 was successful before proceeding + if (!isset($call_approval_v3['id']) || $call_approval_v3['status'] !== 'success') { + return response()->json([ + 'status' => 'failed', + 'message' => 'API v3 failed. Cannot proceed to API v2.', + 'error' => $call_approval_v3 + ], 400); + } + + // Step 2: Call API v2 using response from API v3 + $call_approval_v2 = Http::withOptions(['verify' => config('app.api_verify')]) + ->post(config('api.url_pkb') . '/api/autoserahan/create', [ + 'id' => $call_approval_v3['id'], // Use ID from API v3 response + 'kodcaw' => $request->arraysend['kodcaw'], + 'teller' => $request->arraysend['teller'], + 'amaun' => $request->arraysend['amaun'], + 'txtring1' => $request->arraysend['ambilanring1'], + 'txtring5' => $request->arraysend['ambilanring5'], + 'txtring10' => $request->arraysend['ambilanring10'], + 'txtring20' => $request->arraysend['ambilanring20'], + 'txtring50' => $request->arraysend['ambilanring50'], + 'txtring100' => $request->arraysend['ambilanring100'], + 'txtsen1' => $request->arraysend['ambilansen1'], + 'txtsen5' => $request->arraysend['ambilansen5'], + 'txtsen10' => $request->arraysend['ambilansen10'], + 'txtsen20' => $request->arraysend['ambilansen20'], + 'txtsen50' => $request->arraysend['ambilansen50'], + 'jenis' => 'serahan', + 'version' => 'v2', + ])->json(); + + // Step 3: Check if both API v3 and API v2 were successful + if ($call_approval_v2['status'] === 'success' && $call_approval_v3['status'] === 'success') { + return response()->json([ + 'status' => 'success', + 'message' => 'Approval process completed successfully', + 'id' => $call_approval_v3['id'], + ]); + } else { + return response()->json([ + 'status' => 'failed', + 'message' => 'One of the approvals failed', + ], 400); + } + } + + } diff --git a/config/api.php b/config/api.php index e8ea7a3..7b7aa37 100644 --- a/config/api.php +++ b/config/api.php @@ -1,4 +1,6 @@ env('API_URL') + 'url' => env('API_URL'), + 'url_koop' => env('API_URL_KOOP','http://localhost:8000'), + 'url_pkb' => env('API_URL_PKB','http://localhost:8000'), ]; \ No newline at end of file diff --git a/resources/views/khazanah/pendahuluanserahanmain.blade.php b/resources/views/khazanah/pendahuluanserahanmain.blade.php index cbcb895..c579a82 100644 --- a/resources/views/khazanah/pendahuluanserahanmain.blade.php +++ b/resources/views/khazanah/pendahuluanserahanmain.blade.php @@ -393,6 +393,7 @@ }); return false; } + let SwalPengesahan = ''; if(jenisserahan == 'biasa') { @@ -406,7 +407,7 @@ } }); }else{ - Swal.fire({ + let SwalPengesahan = Swal.fire({ title: 'Tunggu Pengesahan Daripada Operasi.', icon: 'info', width: 600, @@ -448,7 +449,6 @@ } function sendRequest(arraysend,jenisserahan){ - if(jenisserahan == 'biasa'){ $.ajax({ method: 'post', @@ -503,6 +503,60 @@ error: function (jqXHR, textStatus, errorThrown) { console.log(textStatus, errorThrown); } + }); + }else{ + let approvalid = ''; + $.ajax({ + method: 'post', + url: '{{ route("khazanah.autoserahan") }}', + data: { + "_token": "{{ csrf_token() }}", + 'arraysend': arraysend + }, + success:function(e){ + approvalid = e.id; + Swal.update({ + text: 'Menunggu Pengesahan Daripada Operasi!', + }); + } + }); + + var pusher = new Pusher("{{ env('PUSHER_APP_KEY') }}", { + cluster: 'ap1', + encrypted: true + }); + + var channel = pusher.subscribe('autoserahan-notice'); + channel.bind('autoserahan-event', function(data) { + console.log(data); + if(data.pengesahan === 'Lulus' && data.id == approvalid && data.cawangan == kodcaw && data.kodlaluan == teller) + { + Swal.fire({ + icon: 'success', + title: 'Auto Serahan Berjaya', + text: 'Operasi berjaya meluluskan Auto Serahan!' + }).then(function(){ + location.reload(); + }); + }else if(data.pengesahan == 'Batal' && data.id == approvalid && data.cawangan == kodcaw && data.kodlaluan == teller){ + Swal.fire({ + icon: 'error', + title: 'Auto Serahan Dibatalkan', + text: 'Operasi membatalkan Auto Serahan!' + }).then(function(){ + location.reload(); + }); + }else{ + Swal.fire({ + icon: 'error', + title: 'Auto Serahan Mengalami Ralat', + text: 'Auto Serahan tidak berjaya!' + }).then(function(){ + location.reload(); + }); + } + + }); } diff --git a/routes/web.php b/routes/web.php index d31216d..e6719ef 100644 --- a/routes/web.php +++ b/routes/web.php @@ -161,6 +161,8 @@ Route::post('/permohonan/simpan',['as'=>'permohonan.simpan','uses' => 'KhazanahC Route::get('/permohonan/status/{mohonid}',['as'=>'permohonan.status','uses' => 'KhazanahController@StatusPermohonan'])->middleware('auth','khazanah'); Route::post('/permohonan/cit',['as'=>'permohonan.cit','uses' => 'KhazanahController@CITPermohonan'])->middleware('auth','khazanah'); Route::post('/permohonan/download',['as'=>'permohonan.download','uses' => 'KhazanahController@DownloadFiles'])->middleware('auth','khazanah'); +Route::post('/khazanah/autoserahan',['as'=>'khazanah.autoserahan','uses'=>'KhazanahController@AutoSerahan'])->middleware('auth','khazanah'); + Route::post('/kakitangan/harian',['as'=>'kakitangan.harian','uses'=>'KakitanganController@kakitanganHarian'])->middleware('auth','khazanah'); Route::get('/lelong',['as'=>'lelong','uses'=>'LelongController@lelong']);