From 6f1dfed9ee701b4f59e1952bc305b1d89b077112 Mon Sep 17 00:00:00 2001 From: ISMAIL MASSERAN Date: Mon, 21 Sep 2026 14:30:20 +0800 Subject: [PATCH] DONE: add notification for gadaian and pendahuluan --- app/Http/Controllers/TunaiController.php | 45 ++++++++++++++ .../PembiayaanOnlineService.php | 62 +++++++++++++++---- 2 files changed, 96 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/TunaiController.php b/app/Http/Controllers/TunaiController.php index 12d0fba..05e55b9 100644 --- a/app/Http/Controllers/TunaiController.php +++ b/app/Http/Controllers/TunaiController.php @@ -13,6 +13,7 @@ use App\Vault; use Auth0\SDK\API\Management\Users; use Illuminate\Http\Request; use Carbon\Carbon; +use App\Services\StaffNotificationClient; use Illuminate\Support\Facades\Log; class TunaiController extends Controller { @@ -476,10 +477,54 @@ class TunaiController extends Controller $audit->updated_at = $current; $audit->save(); + $this->notifyKhazanahAliranTunai($kodcaw, $request, $reqteller); return response()->json($reqteller,200); } + /** + * Inbox for PC/PPC at the branch. Failures must not block the request. + * + * @param string $kodcaw + * @param \Illuminate\Http\Request $request + * @param \App\RequestTeller $reqteller + * @return void + */ + protected function notifyKhazanahAliranTunai($kodcaw, Request $request, $reqteller) + { + try { + $cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first(); + $namaCaw = $kodcaw; + if ($cawangan) { + $nama = trim((string) $cawangan->nama_cawangan); + if ($nama !== '') { + $namaCaw = $nama; + } + } + + $modal = (float) $request->modal; + $serahan = (float) $request->serahan; + + app(StaffNotificationClient::class)->notify([ + 'type' => 'aliran_tunai.pending_khazanah', + 'cawangan' => $kodcaw, + 'audience' => ['role' => 'pc'], + 'data' => [ + 'request_no' => isset($reqteller->no) ? $reqteller->no : null, + 'kodlaluan' => $request->kodlaluan, + 'modal' => $modal, + 'serahan' => $serahan, + 'cawangan_nama' => $namaCaw, + ], + ]); + } catch (\Throwable $e) { + Log::warning('Aliran tunai khazanah notification failed: '.$e->getMessage(), [ + 'kodcaw' => $kodcaw, + 'kodlaluan' => $request->kodlaluan, + ]); + } + } + public function getTunaiSemalam($kodcaw) { $current = new Carbon(); diff --git a/app/Services/PembiayaanOnline/PembiayaanOnlineService.php b/app/Services/PembiayaanOnline/PembiayaanOnlineService.php index c760288..a33e519 100644 --- a/app/Services/PembiayaanOnline/PembiayaanOnlineService.php +++ b/app/Services/PembiayaanOnline/PembiayaanOnlineService.php @@ -1978,40 +1978,80 @@ class PembiayaanOnlineService return BatchPembiayaanOnline::on($mysql)->where('id', $batchId)->first(); } + public function slotJadual() + { + return [ + [ + 'slot' => 'BATCH1', + 'label' => 'Batch 1', + 'mula' => '00:00', + 'cutoff' => '11:00', + 'proses' => '12:30', + ], + [ + 'slot' => 'BATCH2', + 'label' => 'Batch 2', + 'mula' => '11:00', + 'cutoff' => '15:00', + 'proses' => '16:30', + ], + ]; + } + public function suggestSlot() { $now = Carbon::now(); $mins = ((int) $now->format('G')) * 60 + (int) $now->format('i'); + $jadual = $this->slotJadual(); + $batch1 = $jadual[0]; + $batch2 = $jadual[1]; + $cutoff1 = $this->hmToMinutes($batch1['cutoff']); + $cutoff2 = $this->hmToMinutes($batch2['cutoff']); - if ($mins < 11 * 60) { + if ($mins < $cutoff1) { return [ - 'slot' => 'BATCH1', - 'cutoff' => '11:00', - 'proses' => '12:30', + 'slot' => $batch1['slot'], + 'cutoff' => $batch1['cutoff'], + 'proses' => $batch1['proses'], 'lewat' => false, + 'baki_minit' => $cutoff1 - $mins, 'nota' => 'Dalam waktu Batch 1', + 'jadual' => $jadual, ]; } - if ($mins < 15 * 60) { + if ($mins < $cutoff2) { return [ - 'slot' => 'BATCH2', - 'cutoff' => '15:00', - 'proses' => '16:30', + 'slot' => $batch2['slot'], + 'cutoff' => $batch2['cutoff'], + 'proses' => $batch2['proses'], 'lewat' => false, + 'baki_minit' => $cutoff2 - $mins, 'nota' => 'Dalam waktu Batch 2', + 'jadual' => $jadual, ]; } return [ - 'slot' => 'BATCH2', - 'cutoff' => '15:00', - 'proses' => '16:30 (hari berikutnya jika sudah lewat)', + 'slot' => $batch2['slot'], + 'cutoff' => $batch2['cutoff'], + 'proses' => $batch2['proses'] . ' (hari berikutnya jika sudah lewat)', 'lewat' => true, + 'baki_minit' => 0, 'nota' => 'Selepas cutoff Batch 2 — masih boleh hantar; Operasi mungkin proses esok', + 'jadual' => $jadual, ]; } + protected function hmToMinutes($hm) + { + $parts = explode(':', (string) $hm); + $h = isset($parts[0]) ? (int) $parts[0] : 0; + $m = isset($parts[1]) ? (int) $parts[1] : 0; + + return ($h * 60) + $m; + } + /** * One batch per branch / day / slot (B1-001 or B2-001). Later submits append. *