DONE: add notification for gadaian and pendahuluan
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Vault;
|
|||||||
use Auth0\SDK\API\Management\Users;
|
use Auth0\SDK\API\Management\Users;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Services\StaffNotificationClient;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
class TunaiController extends Controller
|
class TunaiController extends Controller
|
||||||
{
|
{
|
||||||
@@ -476,10 +477,54 @@ class TunaiController extends Controller
|
|||||||
$audit->updated_at = $current;
|
$audit->updated_at = $current;
|
||||||
$audit->save();
|
$audit->save();
|
||||||
|
|
||||||
|
$this->notifyKhazanahAliranTunai($kodcaw, $request, $reqteller);
|
||||||
|
|
||||||
return response()->json($reqteller,200);
|
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)
|
public function getTunaiSemalam($kodcaw)
|
||||||
{
|
{
|
||||||
$current = new Carbon();
|
$current = new Carbon();
|
||||||
|
|||||||
@@ -1978,40 +1978,80 @@ class PembiayaanOnlineService
|
|||||||
return BatchPembiayaanOnline::on($mysql)->where('id', $batchId)->first();
|
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()
|
public function suggestSlot()
|
||||||
{
|
{
|
||||||
$now = Carbon::now();
|
$now = Carbon::now();
|
||||||
$mins = ((int) $now->format('G')) * 60 + (int) $now->format('i');
|
$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 [
|
return [
|
||||||
'slot' => 'BATCH1',
|
'slot' => $batch1['slot'],
|
||||||
'cutoff' => '11:00',
|
'cutoff' => $batch1['cutoff'],
|
||||||
'proses' => '12:30',
|
'proses' => $batch1['proses'],
|
||||||
'lewat' => false,
|
'lewat' => false,
|
||||||
|
'baki_minit' => $cutoff1 - $mins,
|
||||||
'nota' => 'Dalam waktu Batch 1',
|
'nota' => 'Dalam waktu Batch 1',
|
||||||
|
'jadual' => $jadual,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mins < 15 * 60) {
|
if ($mins < $cutoff2) {
|
||||||
return [
|
return [
|
||||||
'slot' => 'BATCH2',
|
'slot' => $batch2['slot'],
|
||||||
'cutoff' => '15:00',
|
'cutoff' => $batch2['cutoff'],
|
||||||
'proses' => '16:30',
|
'proses' => $batch2['proses'],
|
||||||
'lewat' => false,
|
'lewat' => false,
|
||||||
|
'baki_minit' => $cutoff2 - $mins,
|
||||||
'nota' => 'Dalam waktu Batch 2',
|
'nota' => 'Dalam waktu Batch 2',
|
||||||
|
'jadual' => $jadual,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'slot' => 'BATCH2',
|
'slot' => $batch2['slot'],
|
||||||
'cutoff' => '15:00',
|
'cutoff' => $batch2['cutoff'],
|
||||||
'proses' => '16:30 (hari berikutnya jika sudah lewat)',
|
'proses' => $batch2['proses'] . ' (hari berikutnya jika sudah lewat)',
|
||||||
'lewat' => true,
|
'lewat' => true,
|
||||||
|
'baki_minit' => 0,
|
||||||
'nota' => 'Selepas cutoff Batch 2 — masih boleh hantar; Operasi mungkin proses esok',
|
'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.
|
* One batch per branch / day / slot (B1-001 or B2-001). Later submits append.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user