added event and call

This commit is contained in:
hafifierahman
2025-03-02 09:01:18 +08:00
committed by Hafifie PKB
parent 6f52b6256f
commit d79c367d48
5 changed files with 169 additions and 3 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class AutoSerahan implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $pengesahan;
public $cawangan;
public $kodlaluan;
public $id;
public function __construct($pengesahan,$id,$cawangan,$kodlaluan)
{
$this->pengesahan = $pengesahan;
$this->id = $id;
$this->cawangan = $cawangan;
$this->kodlaluan = $kodlaluan;
}
public function broadcastOn()
{
return ['autoserahan-notice'];
}
public function broadcastAs()
{
return 'autoserahan-event';
}
}
@@ -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);
}
}
}