Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local> Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local> Co-authored-by: afrina <afrina@koppkb.com> Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BatchPembiayaanOnline extends Model
|
||||
{
|
||||
protected $table = 'batch_pembiayaan_online';
|
||||
|
||||
protected $fillable = [
|
||||
'batch_no',
|
||||
'kodcaw',
|
||||
'tarikh',
|
||||
'slot',
|
||||
'bilangan',
|
||||
'jumlah_keseluruhan',
|
||||
'status',
|
||||
'pc_submitted_by',
|
||||
'submitted_at',
|
||||
];
|
||||
}
|
||||
@@ -11,6 +11,17 @@ class Cawangan extends Model
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Display name from master table (`details_caw`).
|
||||
* Keep this as the single mapping so callers do not guess nama/namacaw.
|
||||
*/
|
||||
public function getNamaCawanganAttribute()
|
||||
{
|
||||
$nama = trim((string) ($this->attributes['details_caw'] ?? ''));
|
||||
|
||||
return $nama !== '' ? $nama : (string) ($this->attributes['kodcaw'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
||||
+2
-1
@@ -62,7 +62,8 @@ class Customer extends Model
|
||||
'telefon2',
|
||||
'nota_pekerjaan',
|
||||
'tagpelanggan',
|
||||
'tag_anggota'
|
||||
'tag_anggota',
|
||||
'gambar_mykad'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ class Gadai extends Model
|
||||
'nilaimarhun',
|
||||
'berat',
|
||||
'pinjaman',
|
||||
'cara_terima',
|
||||
'telahbayar',
|
||||
'upahtelahbyr',
|
||||
'cajtelahbyr',
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Audit;
|
||||
use App\Marhun;
|
||||
use App\BankMaster;
|
||||
use App\ARFiles;
|
||||
use App\Customer;
|
||||
use App\Gadai;
|
||||
use App\Lelong;
|
||||
@@ -64,7 +65,7 @@ class CustomerController extends Controller
|
||||
->orWhere('kpbaru','=',$ic)
|
||||
->first();
|
||||
|
||||
return response()->json($customer);
|
||||
return response()->json($this->withMykadPhoto($customer));
|
||||
}
|
||||
|
||||
public function showOneCustomerByICAdmin(Request $request){
|
||||
@@ -74,7 +75,7 @@ class CustomerController extends Controller
|
||||
->orWhere('kpbaru','=',$request->ic)
|
||||
->first();
|
||||
|
||||
return response()->json($customer);
|
||||
return response()->json($this->withMykadPhoto($customer));
|
||||
}
|
||||
|
||||
public function showOneCustomerByICMobile($ic){
|
||||
@@ -368,6 +369,8 @@ class CustomerController extends Controller
|
||||
'tujuangadai'=>$request->tujuangadai
|
||||
]);
|
||||
|
||||
$this->attachMykadPhoto($customer, $request);
|
||||
|
||||
$audit = new Audit();
|
||||
$audit->users = $request->teller;
|
||||
$audit->actions = "Daftar Pelanggan Baru";
|
||||
@@ -377,7 +380,7 @@ class CustomerController extends Controller
|
||||
$audit->updated_at = $current;
|
||||
$audit->save();
|
||||
|
||||
return response()->json($customer, 201);
|
||||
return response()->json($this->withMykadPhoto($customer), 201);
|
||||
}
|
||||
|
||||
public function customerUpdate($nokp,Request $request){
|
||||
@@ -403,58 +406,31 @@ class CustomerController extends Controller
|
||||
}
|
||||
|
||||
public function assignAnggota($noic, Request $request)
|
||||
{
|
||||
// Semak sama ada pelanggan wujud
|
||||
$customer = Customer::on('mysql7')
|
||||
->where('kpbaru', $noic)
|
||||
->orWhere('kplama', $noic)
|
||||
->first();
|
||||
{
|
||||
// Semak sama ada pelanggan wujud
|
||||
$customer = Customer::on('mysql7')
|
||||
->where('kpbaru', $noic)
|
||||
->orWhere('kplama', $noic)
|
||||
->first();
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pelanggan tidak dijumpai.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Kemaskini tag_anggota
|
||||
$customer->tag_anggota = 1;
|
||||
$customer->save();
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pelanggan tidak dijumpai.'
|
||||
], 404);
|
||||
'success' => true,
|
||||
'message' => 'Tag anggota berjaya dikemaskini.',
|
||||
'data' => $customer
|
||||
], 200);
|
||||
}
|
||||
|
||||
// Kemaskini tag_anggota
|
||||
$customer->tag_anggota = 1;
|
||||
$customer->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tag anggota berjaya dikemaskini.',
|
||||
'data' => $customer
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function assignAnggota($noic, Request $request)
|
||||
{
|
||||
// Semak sama ada pelanggan wujud
|
||||
$customer = Customer::on('mysql7')
|
||||
->where('kpbaru', $noic)
|
||||
->orWhere('kplama', $noic)
|
||||
->first();
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pelanggan tidak dijumpai.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Kemaskini tag_anggota
|
||||
$customer->tag_anggota = 1;
|
||||
$customer->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tag anggota berjaya dikemaskini.',
|
||||
'data' => $customer
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function customerUpdateKaunter($nokp,$kodcaw, Request $request){
|
||||
$current = Carbon::now();
|
||||
|
||||
@@ -889,14 +865,6 @@ class CustomerController extends Controller
|
||||
}
|
||||
|
||||
|
||||
public function anggotaKoperasi(Request $request){
|
||||
|
||||
$anggota = Anggota::where('noic',$request->noic)->first();
|
||||
|
||||
return response()->json($anggota);
|
||||
}
|
||||
|
||||
|
||||
public function showCustomerByEachCawangan($ic)
|
||||
{
|
||||
$cawangan_all = Cawangan::on('mysql7')->get();
|
||||
@@ -1159,6 +1127,114 @@ public function AdminsearchCustomerBySAG(Request $request)
|
||||
return response()->json(['message' => 'Customer PDPA updated successfully.'], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save MyKad photo into arrahn_files and link it on customer.gambar_mykad.
|
||||
*/
|
||||
protected function attachMykadPhoto($customer, Request $request)
|
||||
{
|
||||
if (!$customer) {
|
||||
return;
|
||||
}
|
||||
|
||||
$raw = $this->photoBase64FromRequest($request);
|
||||
if ($raw === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$fileId = $this->storeMykadPhoto($raw, $request->input('photo_mime', $request->json('photo_mime')), $customer);
|
||||
if (!$fileId) {
|
||||
return;
|
||||
}
|
||||
|
||||
Customer::on('mysql7')
|
||||
->where('kpbaru', $customer->kpbaru)
|
||||
->where('kplama', $customer->kplama)
|
||||
->update(['gambar_mykad' => $fileId]);
|
||||
|
||||
$customer->gambar_mykad = $fileId;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Failed to attach MyKad photo: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function photoBase64FromRequest(Request $request)
|
||||
{
|
||||
$raw = $request->input('photo_base64');
|
||||
if ($raw === null || $raw === '') {
|
||||
$raw = $request->json('photo_base64');
|
||||
}
|
||||
|
||||
return is_string($raw) ? $raw : '';
|
||||
}
|
||||
|
||||
protected function storeMykadPhoto($raw, $mime, $customer)
|
||||
{
|
||||
$commaPos = strpos($raw, ',');
|
||||
if ($commaPos !== false) {
|
||||
$raw = substr($raw, $commaPos + 1);
|
||||
}
|
||||
$raw = preg_replace('/\s+/', '', $raw);
|
||||
|
||||
if ($raw === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$decoded = base64_decode($raw, true);
|
||||
if ($decoded === false) {
|
||||
$decoded = base64_decode($raw);
|
||||
}
|
||||
if ($decoded === false || $decoded === '') {
|
||||
Log::warning('MyKad photo skipped: invalid base64');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (strlen($raw) > 400000) {
|
||||
Log::warning('MyKad photo skipped: payload too large');
|
||||
return null;
|
||||
}
|
||||
|
||||
$mime = strtolower((string) ($mime ?: 'image/jpeg'));
|
||||
if (!in_array($mime, ['image/jpeg', 'image/jpg', 'image/png'], true)) {
|
||||
$mime = 'image/jpeg';
|
||||
}
|
||||
|
||||
$nric = preg_replace('/[^0-9A-Za-z]/', '', (string) ($customer->kpbaru ?: ''));
|
||||
$ext = $mime === 'image/png' ? 'png' : 'jpg';
|
||||
|
||||
$file = new ARFiles();
|
||||
$file->data = $raw;
|
||||
$file->filename = ($nric !== '' ? $nric : 'mykad') . '.' . $ext;
|
||||
$file->type = $mime;
|
||||
$file->tarikhmasa = Carbon::now()->toDateTimeString();
|
||||
$file->save();
|
||||
|
||||
return $file->id;
|
||||
}
|
||||
|
||||
protected function withMykadPhoto($customer)
|
||||
{
|
||||
if (!$customer) {
|
||||
return $customer;
|
||||
}
|
||||
|
||||
$payload = $customer->toArray();
|
||||
$payload['photo_base64'] = null;
|
||||
$payload['photo_mime'] = null;
|
||||
|
||||
if (empty($customer->gambar_mykad)) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
$file = ARFiles::on('mysql7')->where('id', $customer->gambar_mykad)->first();
|
||||
if ($file && $file->data) {
|
||||
$payload['photo_base64'] = $file->data;
|
||||
$payload['photo_mime'] = $file->type ?: 'image/jpeg';
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
// public function createNotaArcc($kodcaw, Request $request)
|
||||
// {
|
||||
// $current = Carbon::now();
|
||||
|
||||
@@ -145,15 +145,18 @@ class KomuditiController extends Controller
|
||||
$komuditi_current = KomuditiPurchase::on('mysql7')->where('date_purchase','=',$current->toDateString())->orderBy('created_at','desc')->first();
|
||||
|
||||
$unit_current = $komuditi_current['unit_komuditi'];
|
||||
|
||||
$update_unit = $unit_current - $request->unit_komuditi;
|
||||
|
||||
$unit_current = round((float) $komuditi_current['unit_komuditi'], 2);
|
||||
$unit_komuditi = round((float) $request->unit_komuditi, 2);
|
||||
$update_unit = round($unit_current - $unit_komuditi, 2);
|
||||
|
||||
$update_komuditi = KomuditiPurchase::on('mysql7')->where('id','=',$komuditi_current['id'])->update([
|
||||
'unit_komuditi' => $update_unit
|
||||
]);
|
||||
|
||||
$komuditi_transaksi = KomuditiTransaksi::on('mysql7')->create([
|
||||
'unit_komuditi' => $request->unit_komuditi,
|
||||
'unit_komuditi' => $unit_komuditi,
|
||||
'nosijil'=>$komuditi_current['no_sijil'],
|
||||
'norujukan' => $request->norujukan,
|
||||
'kodcaw' => $request->kodcaw ,
|
||||
|
||||
@@ -605,7 +605,7 @@ class LelongController extends Controller
|
||||
|
||||
if($cawangan['tagarrahnbid'] == 1){
|
||||
if(env('APP_ENV') != 'production'){
|
||||
$link = 'http://niklah.arrahn.com.my/api/portalApi';
|
||||
$link = 'https://adminbid-kopkb.erahn.com.my/api/portalApi';
|
||||
}else{
|
||||
$link = 'https://adminbid-kopkb.erahn.com.my/api/portalApi';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\PembiayaanOnline\ModalOnlineService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModalOnlineController extends Controller
|
||||
{
|
||||
protected $service;
|
||||
|
||||
public function __construct(ModalOnlineService $service = null)
|
||||
{
|
||||
$this->service = $service ?: new ModalOnlineService();
|
||||
}
|
||||
|
||||
protected function respond(array $result)
|
||||
{
|
||||
return response()->json($result['payload'], $result['status']);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/modal-online/{kodcaw}
|
||||
* Read-only: does not create today's row.
|
||||
*/
|
||||
public function get($kodcaw)
|
||||
{
|
||||
return $this->respond($this->service->get($kodcaw));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Alias of get() — no longer auto-creates RM100k.
|
||||
*/
|
||||
public function getOrCreate($kodcaw)
|
||||
{
|
||||
return $this->get($kodcaw);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/modal-online/{kodcaw}/reserve
|
||||
*/
|
||||
public function reserve($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->reserve($kodcaw, $request->input('amaun', 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/initiate/modal-online?zone=all|{zone}
|
||||
*/
|
||||
public function initiate(Request $request)
|
||||
{
|
||||
return $this->respond($this->service->initiate($request->input('zone', 'all')));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/modal-online/{kodcaw}/topup/request
|
||||
* PC mohon had (hari pertama) atau tambah modal. Body: amaun, dimohon_oleh, nota?
|
||||
*/
|
||||
public function requestTopUp($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->requestTopUp(
|
||||
$kodcaw,
|
||||
$request->input('amaun', 0),
|
||||
$request->input('dimohon_oleh', ''),
|
||||
$request->input('nota')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/modal-online/{kodcaw}/topup/requests?status=&tarikh=
|
||||
*/
|
||||
public function listTopUpByCawangan($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->listTopUpRequests(
|
||||
$kodcaw,
|
||||
$request->input('status'),
|
||||
$request->input('tarikh')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/modal-online/operasi/topup/requests?status=PENDING&tarikh=
|
||||
*/
|
||||
public function listTopUpOperasi(Request $request)
|
||||
{
|
||||
$status = $request->input('status', 'PENDING');
|
||||
if ($status === 'all' || $status === '') {
|
||||
$status = null;
|
||||
}
|
||||
|
||||
return $this->respond($this->service->listTopUpRequests(
|
||||
null,
|
||||
$status,
|
||||
$request->input('tarikh')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/modal-online/operasi/topup/{id}/approve
|
||||
* Body: diluluskan_oleh, nota?, amaun? (optional override)
|
||||
*/
|
||||
public function approveTopUp($id, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->approveTopUp(
|
||||
$id,
|
||||
$request->input('diluluskan_oleh', ''),
|
||||
$request->input('nota'),
|
||||
null,
|
||||
$request->input('amaun')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/modal-online/operasi/topup/{id}/reject
|
||||
* Body: diluluskan_oleh, nota?
|
||||
*/
|
||||
public function rejectTopUp($id, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->rejectTopUp(
|
||||
$id,
|
||||
$request->input('diluluskan_oleh', ''),
|
||||
$request->input('nota')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/modal-online/{kodcaw}/close
|
||||
* Body: ditutup_oleh
|
||||
*/
|
||||
public function close($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->close(
|
||||
$kodcaw,
|
||||
$request->input('ditutup_oleh', '')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/modal-online/operasi/eod?zone=all&tarikh=
|
||||
*/
|
||||
public function listToday(Request $request)
|
||||
{
|
||||
return $this->respond($this->service->listToday(
|
||||
$request->input('zone', 'all'),
|
||||
$request->input('tarikh')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/modal-online/operasi/eod/close-all
|
||||
* Body: ditutup_oleh, zone?
|
||||
*/
|
||||
public function closeAll(Request $request)
|
||||
{
|
||||
return $this->respond($this->service->closeAll(
|
||||
$request->input('ditutup_oleh', ''),
|
||||
$request->input('zone', 'all')
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\PembiayaanOnline\PembiayaanOnlineService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PembiayaanOnlineController extends Controller
|
||||
{
|
||||
protected $service;
|
||||
|
||||
public function __construct(PembiayaanOnlineService $service = null)
|
||||
{
|
||||
$this->service = $service ?: new PembiayaanOnlineService();
|
||||
}
|
||||
|
||||
protected function respond(array $result)
|
||||
{
|
||||
return response()->json($result['payload'], $result['status']);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/{kodcaw}
|
||||
*/
|
||||
public function store($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->store($kodcaw, $request->all()));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/{kodcaw}/by-norujukan/{norujukan}
|
||||
*/
|
||||
public function show($kodcaw, $norujukan)
|
||||
{
|
||||
return $this->respond($this->service->show($kodcaw, $norujukan));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/{kodcaw}/queue
|
||||
*/
|
||||
public function queue($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->queue($kodcaw, $request->input('status')));
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /api/pembiayaan-online/{kodcaw}/lines/{id}
|
||||
*/
|
||||
public function updateLine($kodcaw, $id, Request $request)
|
||||
{
|
||||
// Prefer only present keys so "has" semantics match previous controller.
|
||||
$input = [];
|
||||
foreach ([
|
||||
'kodbank', 'noakaun', 'nama_bank', 'nama_akaun', 'nota',
|
||||
'bukti_akaun_file_id', 'borang_file_id', 'update_customer_bank',
|
||||
] as $key) {
|
||||
if ($request->has($key)) {
|
||||
$input[$key] = $request->input($key);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->respond($this->service->updateLine($kodcaw, $id, $input));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/{kodcaw}/batches
|
||||
*/
|
||||
public function listBatches($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->listBatches(
|
||||
$kodcaw,
|
||||
$request->input('tarikh'),
|
||||
$request->input('status')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/{kodcaw}/batches/{batchId}
|
||||
*/
|
||||
public function showBatch($kodcaw, $batchId)
|
||||
{
|
||||
return $this->respond($this->service->showBatch($kodcaw, $batchId));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/{kodcaw}/batches/submit
|
||||
*/
|
||||
public function submitBatch($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->submitBatch(
|
||||
$kodcaw,
|
||||
$request->input('ids', []),
|
||||
$request->input('pc_submitted_by', ''),
|
||||
$request->input('slot')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/operasi/batches
|
||||
*/
|
||||
public function operasiListBatches(Request $request)
|
||||
{
|
||||
return $this->respond($this->service->operasiListBatches(
|
||||
$request->input('status', 'SUBMITTED'),
|
||||
$request->input('tarikh')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/operasi/{kodcaw}/batches/{batchId}
|
||||
*/
|
||||
public function operasiShowBatch($kodcaw, $batchId)
|
||||
{
|
||||
return $this->showBatch($kodcaw, $batchId);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/operasi/{kodcaw}/lines/{id}/approve
|
||||
*/
|
||||
public function operasiApproveLine($kodcaw, $id, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->operasiApproveLine(
|
||||
$kodcaw,
|
||||
$id,
|
||||
$request->input('ops_by', '')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/operasi/{kodcaw}/lines/{id}/reject
|
||||
*/
|
||||
public function operasiRejectLine($kodcaw, $id, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->operasiRejectLine(
|
||||
$kodcaw,
|
||||
$id,
|
||||
$request->input('ops_by', ''),
|
||||
$request->input('reject_reason', '')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/operasi/{kodcaw}/batches/{batchId}/approve
|
||||
*/
|
||||
public function operasiApproveBatch($kodcaw, $batchId, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->operasiApproveBatch(
|
||||
$kodcaw,
|
||||
$batchId,
|
||||
$request->input('ops_by', '')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/operasi/{kodcaw}/lines/{id}/paid
|
||||
* Body: ops_by, no_rujukan_bayaran, tarikh_bayaran?,
|
||||
* bukti_data + bukti_filename + bukti_type OR bukti_file_id
|
||||
*/
|
||||
public function operasiMarkPaid($kodcaw, $id, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->operasiMarkPaid($kodcaw, $id, $request->all()));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/operasi/{kodcaw}/batches/{batchId}/paid
|
||||
*/
|
||||
public function operasiMarkPaidBatch($kodcaw, $batchId, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->operasiMarkPaidBatch($kodcaw, $batchId, $request->all()));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/{kodcaw}/lines/{id}/bukti
|
||||
*/
|
||||
public function getBukti($kodcaw, $id)
|
||||
{
|
||||
return $this->respond($this->service->getBukti($kodcaw, $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/pembiayaan-online/{kodcaw}/paid?blast_sent=0
|
||||
*/
|
||||
public function paidQueue($kodcaw, Request $request)
|
||||
{
|
||||
return $this->respond($this->service->paidQueue(
|
||||
$kodcaw,
|
||||
$request->input('blast_sent')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/pembiayaan-online/{kodcaw}/paid/blast
|
||||
* Body: ids[] (or ids), blast_by?
|
||||
*/
|
||||
public function markBlastSent($kodcaw, Request $request)
|
||||
{
|
||||
$ids = $request->input('ids', $request->input('id'));
|
||||
return $this->respond($this->service->markBlastSent(
|
||||
$kodcaw,
|
||||
$ids,
|
||||
$request->input('blast_by')
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -400,12 +400,14 @@ class VaultController extends Controller
|
||||
}
|
||||
|
||||
|
||||
$bakiakhirVault = $vault ? $vault['bakiakhir'] : 0;
|
||||
|
||||
if($total != 0)
|
||||
{
|
||||
$totalbakiakhirtunai = $vault['bakiakhir'] + $total;
|
||||
$totalbakiakhirtunai = $bakiakhirVault + $total;
|
||||
}else
|
||||
{
|
||||
$totalbakiakhirtunai = $vault['bakiakhir'];
|
||||
$totalbakiakhirtunai = $bakiakhirVault;
|
||||
}
|
||||
|
||||
return response()->json($totalbakiakhirtunai);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ModalOnline extends Model
|
||||
{
|
||||
protected $table = 'modal_online';
|
||||
|
||||
protected $fillable = [
|
||||
'tarikh',
|
||||
'kodcaw',
|
||||
'had',
|
||||
'digunakan',
|
||||
'baki',
|
||||
'tambah',
|
||||
'kurang',
|
||||
'ditutup',
|
||||
'ditutup_oleh',
|
||||
'ditutup_at',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PembiayaanOnline extends Model
|
||||
{
|
||||
protected $table = 'pembiayaan_online';
|
||||
|
||||
protected $fillable = [
|
||||
'norujukan',
|
||||
'nokp',
|
||||
'nopelanggan',
|
||||
'nama_pelanggan',
|
||||
'kodcaw',
|
||||
'pinjaman',
|
||||
'kodbank',
|
||||
'nama_bank',
|
||||
'noakaun',
|
||||
'nama_akaun',
|
||||
'bukti_akaun_file_id',
|
||||
'borang_file_id',
|
||||
'status',
|
||||
'reject_reason',
|
||||
'rejected_by',
|
||||
'rejected_at',
|
||||
'batch_id',
|
||||
'bukti_file_id',
|
||||
'no_rujukan_bayaran',
|
||||
'tarikh_bayaran',
|
||||
'paid_at',
|
||||
'created_by',
|
||||
'pc_submitted_by',
|
||||
'ops_by',
|
||||
'nota',
|
||||
'blast_sent',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RequestModalOnline extends Model
|
||||
{
|
||||
protected $table = 'request_modal_online';
|
||||
protected $connection = 'mysql7';
|
||||
|
||||
protected $fillable = [
|
||||
'kodcaw',
|
||||
'tarikh',
|
||||
'amaun',
|
||||
'dimohon_oleh',
|
||||
'status',
|
||||
'diluluskan_oleh',
|
||||
'nota',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,858 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\PembiayaanOnline;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\ModalOnline;
|
||||
use App\RequestModalOnline;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ModalOnlineService
|
||||
{
|
||||
/**
|
||||
* @return array{ok:bool,status:int,payload:mixed,mysql?:string}
|
||||
*/
|
||||
public function resolveMysql($kodcaw)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 404,
|
||||
'payload' => ['message' => 'Cawangan tidak dijumpai'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => null,
|
||||
'mysql' => $cawangan['mysql'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function todayDate()
|
||||
{
|
||||
return Carbon::now()->toDateString();
|
||||
}
|
||||
|
||||
protected function findPending($kodcaw)
|
||||
{
|
||||
return RequestModalOnline::on('mysql7')
|
||||
->where('kodcaw', $kodcaw)
|
||||
->where('status', 'PENDING')
|
||||
->first();
|
||||
}
|
||||
|
||||
protected function pendingPayload($pending)
|
||||
{
|
||||
return $pending ? $pending->toArray() : null;
|
||||
}
|
||||
|
||||
protected function missingSnapshot($kodcaw, $tarikh, $pending = null)
|
||||
{
|
||||
return [
|
||||
'tarikh' => $tarikh,
|
||||
'kodcaw' => $kodcaw,
|
||||
'had' => 0.00,
|
||||
'digunakan' => 0.00,
|
||||
'baki' => 0.00,
|
||||
'tambah' => 0.00,
|
||||
'kurang' => 0.00,
|
||||
'ditutup' => 0,
|
||||
'missing' => true,
|
||||
'pending_request' => $this->pendingPayload($pending),
|
||||
];
|
||||
}
|
||||
|
||||
protected function recalcBaki($modal)
|
||||
{
|
||||
$modal->baki = round(
|
||||
(float) $modal->had + (float) $modal->tambah - (float) $modal->kurang - (float) $modal->digunakan,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get today's modal_online row. Does not create — PC must request had from Operasi.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function get($kodcaw)
|
||||
{
|
||||
$resolved = $this->resolveMysql($kodcaw);
|
||||
if (!$resolved['ok']) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
$mysql = $resolved['mysql'];
|
||||
$tarikh = $this->todayDate();
|
||||
$pending = $this->findPending($kodcaw);
|
||||
|
||||
$modal = ModalOnline::on($mysql)
|
||||
->where('kodcaw', $kodcaw)
|
||||
->where('tarikh', $tarikh)
|
||||
->first();
|
||||
|
||||
if (!$modal) {
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => $this->missingSnapshot($kodcaw, $tarikh, $pending),
|
||||
];
|
||||
}
|
||||
|
||||
$payload = $modal->toArray();
|
||||
$payload['missing'] = false;
|
||||
$payload['pending_request'] = $this->pendingPayload($pending);
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => $payload,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use get(). Kept so existing callers do not auto-seed RM100k.
|
||||
*/
|
||||
public function getOrCreate($kodcaw)
|
||||
{
|
||||
return $this->get($kodcaw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve amount inside an existing branch DB connection (caller may wrap in transaction).
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function reserveAmountOnConnection($mysql, $kodcaw, $amaun, $tarikh = null)
|
||||
{
|
||||
$amaun = round((float) $amaun, 2);
|
||||
if ($amaun <= 0) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'Amaun tidak sah'],
|
||||
];
|
||||
}
|
||||
|
||||
$tarikh = $tarikh ?: Carbon::now()->toDateString();
|
||||
|
||||
$modal = ModalOnline::on($mysql)
|
||||
->where('kodcaw', $kodcaw)
|
||||
->where('tarikh', $tarikh)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
if (!$modal) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => [
|
||||
'message' => 'Modal online belum diwujudkan. Sila mohon had daripada Operasi terlebih dahulu.',
|
||||
'missing' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if ((int) ($modal->ditutup ?? 0) === 1) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => [
|
||||
'message' => 'Modal online hari ini sudah ditutup (EOD)',
|
||||
'modal_online' => $modal,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if ((float) $modal->baki < $amaun) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => [
|
||||
'message' => 'Baki modal online tidak mencukupi',
|
||||
'baki' => (float) $modal->baki,
|
||||
'amaun' => $amaun,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$modal->digunakan = round((float) $modal->digunakan + $amaun, 2);
|
||||
$modal->baki = round(
|
||||
(float) $modal->had + (float) $modal->tambah - (float) $modal->kurang - (float) $modal->digunakan,
|
||||
2
|
||||
);
|
||||
$modal->save();
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => $modal,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve amount from today's online float (transactional).
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function reserve($kodcaw, $amaun)
|
||||
{
|
||||
$resolved = $this->resolveMysql($kodcaw);
|
||||
if (!$resolved['ok']) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
$mysql = $resolved['mysql'];
|
||||
$amaun = round((float) $amaun, 2);
|
||||
|
||||
if ($amaun <= 0) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'Amaun tidak sah'],
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
return DB::connection($mysql)->transaction(function () use ($mysql, $kodcaw, $amaun) {
|
||||
return $this->reserveAmountOnConnection($mysql, $kodcaw, $amaun);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('ModalOnline reserve failed: ' . $e->getMessage());
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 500,
|
||||
'payload' => ['message' => 'Gagal reserve modal online'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Had is no longer auto-seeded. Returns how many branches already have a row today.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function initiate($zone = 'all')
|
||||
{
|
||||
$current = $this->todayDate();
|
||||
|
||||
if ($zone == 'all') {
|
||||
$cawanganAll = Cawangan::on('mysql7')->get();
|
||||
} else {
|
||||
$cawanganAll = Cawangan::on('mysql7')->where('zone', $zone)->get();
|
||||
}
|
||||
|
||||
$existing = 0;
|
||||
$missing = 0;
|
||||
|
||||
foreach ($cawanganAll as $cawangan) {
|
||||
try {
|
||||
$exists = ModalOnline::on($cawangan['mysql'])
|
||||
->where('kodcaw', $cawangan['kodcaw'])
|
||||
->where('tarikh', $current)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
$existing++;
|
||||
} else {
|
||||
$missing++;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('initiate modal_online skip ' . $cawangan['kodcaw'] . ': ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => [
|
||||
'tarikh' => $current,
|
||||
'created' => 0,
|
||||
'existing' => $existing,
|
||||
'missing' => $missing,
|
||||
'message' => 'Modal online tidak di-initiate automatik. PC perlu mohon had daripada Operasi.',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* PC request opening had (or extra top-up) from Operasi.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function requestTopUp($kodcaw, $amaun, $dimohonOleh, $nota = null)
|
||||
{
|
||||
$resolved = $this->resolveMysql($kodcaw);
|
||||
if (!$resolved['ok']) {
|
||||
return $resolved;
|
||||
}
|
||||
$mysql = $resolved['mysql'];
|
||||
|
||||
$amaun = round((float) $amaun, 2);
|
||||
$dimohonOleh = trim((string) $dimohonOleh);
|
||||
|
||||
if ($amaun <= 0) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'Amaun tidak sah'],
|
||||
];
|
||||
}
|
||||
if ($dimohonOleh === '') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'dimohon_oleh diperlukan'],
|
||||
];
|
||||
}
|
||||
|
||||
$tarikh = $this->todayDate();
|
||||
$pending = $this->findPending($kodcaw);
|
||||
|
||||
if ($pending) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 409,
|
||||
'payload' => [
|
||||
'message' => 'Masih ada permohonan modal online PENDING untuk cawangan ini',
|
||||
'request' => $pending,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$modal = ModalOnline::on($mysql)
|
||||
->where('kodcaw', $kodcaw)
|
||||
->where('tarikh', $tarikh)
|
||||
->first();
|
||||
|
||||
if ($modal && (int) ($modal->ditutup ?? 0) === 1) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => [
|
||||
'message' => 'Modal online hari ini sudah ditutup (EOD). Tidak boleh mohon.',
|
||||
'modal_online' => $modal,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$jenis = $modal ? 'TOPUP' : 'HAD';
|
||||
|
||||
$request = RequestModalOnline::on('mysql7')->create([
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => $tarikh,
|
||||
'amaun' => $amaun,
|
||||
'dimohon_oleh' => $dimohonOleh,
|
||||
'status' => 'PENDING',
|
||||
'nota' => $nota,
|
||||
]);
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 201,
|
||||
'payload' => [
|
||||
'request' => $request,
|
||||
'jenis' => $jenis,
|
||||
'modal_online' => $modal ?: $this->missingSnapshot($kodcaw, $tarikh, $request),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* List top-up requests.
|
||||
* For PC: pass kodcaw. For Operasi: omit kodcaw (all branches).
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function listTopUpRequests($kodcaw = null, $status = null, $tarikh = null)
|
||||
{
|
||||
$query = RequestModalOnline::on('mysql7')->newQuery();
|
||||
|
||||
if ($kodcaw) {
|
||||
$query->where('kodcaw', $kodcaw);
|
||||
}
|
||||
if ($status) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
if ($tarikh) {
|
||||
$query->where('tarikh', $tarikh);
|
||||
}
|
||||
|
||||
$rows = $query->orderBy('id', 'desc')->get();
|
||||
|
||||
$cawMap = [];
|
||||
if (!$kodcaw) {
|
||||
foreach (Cawangan::on('mysql7')->get() as $caw) {
|
||||
$cawMap[$caw->kodcaw] = $caw->nama_cawangan;
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($rows as $row) {
|
||||
$item = $row->toArray();
|
||||
if (!$kodcaw) {
|
||||
$item['cawangan_nama'] = $cawMap[$row->kodcaw] ?? null;
|
||||
}
|
||||
$data[] = $item;
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => [
|
||||
'bilangan' => count($data),
|
||||
'data' => $data,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Operasi approve: first request of the day sets had; later requests add tambah.
|
||||
* Optional $amaunOverride lets operasi lulus a different amount than dimohon.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function approveTopUp($requestId, $diluluskanOleh, $nota = null, $expectedKodcaw = null, $amaunOverride = null)
|
||||
{
|
||||
$diluluskanOleh = trim((string) $diluluskanOleh);
|
||||
if ($diluluskanOleh === '') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'diluluskan_oleh diperlukan'],
|
||||
];
|
||||
}
|
||||
|
||||
$req = RequestModalOnline::on('mysql7')->where('id', $requestId)->first();
|
||||
if (!$req) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 404,
|
||||
'payload' => ['message' => 'Permohonan tidak dijumpai'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($expectedKodcaw && $req->kodcaw !== $expectedKodcaw) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 404,
|
||||
'payload' => ['message' => 'Permohonan tidak dijumpai'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($req->status !== 'PENDING') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => [
|
||||
'message' => 'Hanya permohonan PENDING boleh diluluskan',
|
||||
'status' => $req->status,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$kodcaw = $req->kodcaw;
|
||||
$resolved = $this->resolveMysql($kodcaw);
|
||||
if (!$resolved['ok']) {
|
||||
return $resolved;
|
||||
}
|
||||
$mysql = $resolved['mysql'];
|
||||
$amaunDimohon = round((float) $req->amaun, 2);
|
||||
$amaun = $amaunDimohon;
|
||||
if ($amaunOverride !== null && $amaunOverride !== '') {
|
||||
$amaun = round((float) $amaunOverride, 2);
|
||||
if ($amaun <= 0) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'Amaun diluluskan tidak sah'],
|
||||
];
|
||||
}
|
||||
}
|
||||
$tarikh = $this->todayDate();
|
||||
|
||||
try {
|
||||
$applied = DB::connection($mysql)->transaction(function () use ($mysql, $kodcaw, $tarikh, $amaun) {
|
||||
$modal = ModalOnline::on($mysql)
|
||||
->where('kodcaw', $kodcaw)
|
||||
->where('tarikh', $tarikh)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
$jenis = 'TOPUP';
|
||||
|
||||
if (!$modal) {
|
||||
$modal = ModalOnline::on($mysql)->create([
|
||||
'tarikh' => $tarikh,
|
||||
'kodcaw' => $kodcaw,
|
||||
'had' => $amaun,
|
||||
'digunakan' => 0.00,
|
||||
'baki' => $amaun,
|
||||
'tambah' => 0.00,
|
||||
'kurang' => 0.00,
|
||||
'ditutup' => 0,
|
||||
]);
|
||||
$modal = ModalOnline::on($mysql)
|
||||
->where('id', $modal->id)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
$jenis = 'HAD';
|
||||
} else {
|
||||
if ((int) ($modal->ditutup ?? 0) === 1) {
|
||||
throw new \RuntimeException('MODAL_ONLINE_CLOSED');
|
||||
}
|
||||
|
||||
$modal->tambah = round((float) $modal->tambah + $amaun, 2);
|
||||
$this->recalcBaki($modal);
|
||||
$modal->save();
|
||||
}
|
||||
|
||||
return ['modal' => $modal, 'jenis' => $jenis];
|
||||
});
|
||||
|
||||
$modal = $applied['modal'];
|
||||
$jenis = $applied['jenis'];
|
||||
|
||||
$req->status = 'APPROVED';
|
||||
$req->diluluskan_oleh = $diluluskanOleh;
|
||||
$req->amaun = $amaun;
|
||||
|
||||
$notes = [];
|
||||
if (abs($amaun - $amaunDimohon) >= 0.01) {
|
||||
$notes[] = 'Amaun dimohon RM ' . number_format($amaunDimohon, 2)
|
||||
. ', diluluskan RM ' . number_format($amaun, 2);
|
||||
}
|
||||
if ($nota !== null && trim((string) $nota) !== '') {
|
||||
$notes[] = trim((string) $nota);
|
||||
}
|
||||
if ($notes) {
|
||||
$existing = trim((string) $req->nota);
|
||||
$req->nota = $existing === ''
|
||||
? implode(' | ', $notes)
|
||||
: $existing . ' | ' . implode(' | ', $notes);
|
||||
}
|
||||
$req->save();
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => [
|
||||
'request' => $req->fresh(),
|
||||
'jenis' => $jenis,
|
||||
'modal_online' => $modal,
|
||||
],
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
if ($e->getMessage() === 'MODAL_ONLINE_CLOSED') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'Modal online hari ini sudah ditutup (EOD). Tidak boleh lulus permohonan.'],
|
||||
];
|
||||
}
|
||||
Log::error('approveTopUp failed: ' . $e->getMessage());
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 500,
|
||||
'payload' => ['message' => 'Gagal lulus permohonan modal online'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operasi reject top-up request.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function rejectTopUp($requestId, $diluluskanOleh, $nota = null, $expectedKodcaw = null)
|
||||
{
|
||||
$diluluskanOleh = trim((string) $diluluskanOleh);
|
||||
if ($diluluskanOleh === '') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'diluluskan_oleh diperlukan'],
|
||||
];
|
||||
}
|
||||
|
||||
$req = RequestModalOnline::on('mysql7')->where('id', $requestId)->first();
|
||||
if (!$req) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 404,
|
||||
'payload' => ['message' => 'Permohonan tidak dijumpai'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($expectedKodcaw && $req->kodcaw !== $expectedKodcaw) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 404,
|
||||
'payload' => ['message' => 'Permohonan tidak dijumpai'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($req->status !== 'PENDING') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => [
|
||||
'message' => 'Hanya permohonan PENDING boleh ditolak',
|
||||
'status' => $req->status,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$req->status = 'REJECTED';
|
||||
$req->diluluskan_oleh = $diluluskanOleh;
|
||||
if ($nota !== null && trim((string) $nota) !== '') {
|
||||
$req->nota = trim(
|
||||
trim((string) $req->nota) === ''
|
||||
? (string) $nota
|
||||
: $req->nota . ' | ' . $nota
|
||||
);
|
||||
}
|
||||
$req->save();
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => ['request' => $req],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* EOD close for one branch: return unused baki via kurang, mark ditutup.
|
||||
* Also auto-rejects PENDING top-up requests for the branch.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function close($kodcaw, $ditutupOleh)
|
||||
{
|
||||
$resolved = $this->resolveMysql($kodcaw);
|
||||
if (!$resolved['ok']) {
|
||||
return $resolved;
|
||||
}
|
||||
$mysql = $resolved['mysql'];
|
||||
|
||||
$ditutupOleh = trim((string) $ditutupOleh);
|
||||
if ($ditutupOleh === '') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'ditutup_oleh diperlukan'],
|
||||
];
|
||||
}
|
||||
|
||||
$tarikh = Carbon::now()->toDateString();
|
||||
$now = Carbon::now();
|
||||
|
||||
try {
|
||||
$result = DB::connection($mysql)->transaction(function () use ($mysql, $kodcaw, $tarikh, $ditutupOleh, $now) {
|
||||
$modal = ModalOnline::on($mysql)
|
||||
->where('kodcaw', $kodcaw)
|
||||
->where('tarikh', $tarikh)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
if (!$modal) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 404,
|
||||
'payload' => [
|
||||
'message' => 'Tiada modal online hari ini untuk ditutup. Teller belum mohon / PC belum lulus had.',
|
||||
'missing' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if ((int) ($modal->ditutup ?? 0) === 1) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 409,
|
||||
'payload' => [
|
||||
'message' => 'Modal online sudah ditutup untuk hari ini',
|
||||
'modal_online' => $modal,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$unused = round((float) $modal->baki, 2);
|
||||
$modal->kurang = round((float) $modal->kurang + $unused, 2);
|
||||
$modal->baki = round(
|
||||
(float) $modal->had + (float) $modal->tambah - (float) $modal->kurang - (float) $modal->digunakan,
|
||||
2
|
||||
);
|
||||
$modal->ditutup = 1;
|
||||
$modal->ditutup_oleh = $ditutupOleh;
|
||||
$modal->ditutup_at = $now;
|
||||
$modal->save();
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => [
|
||||
'modal_online' => $modal,
|
||||
'dikembalikan' => $unused,
|
||||
],
|
||||
];
|
||||
});
|
||||
|
||||
if (!$result['ok']) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$pendingRejected = RequestModalOnline::on('mysql7')
|
||||
->where('kodcaw', $kodcaw)
|
||||
->where('status', 'PENDING')
|
||||
->get();
|
||||
|
||||
foreach ($pendingRejected as $req) {
|
||||
$req->status = 'REJECTED';
|
||||
$req->diluluskan_oleh = $ditutupOleh;
|
||||
$tag = 'Auto reject: EOD close';
|
||||
$req->nota = trim((string) $req->nota) === ''
|
||||
? $tag
|
||||
: trim($req->nota) . ' | ' . $tag;
|
||||
$req->save();
|
||||
}
|
||||
|
||||
$result['payload']['pending_topup_ditolak'] = $pendingRejected->count();
|
||||
return $result;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('modal online close failed: ' . $e->getMessage());
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 500,
|
||||
'payload' => ['message' => 'Gagal tutup modal online'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operasi: list today's modal_online across branches.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function listToday($zone = 'all', $tarikh = null)
|
||||
{
|
||||
$tarikh = $tarikh ?: Carbon::now()->toDateString();
|
||||
|
||||
if ($zone == 'all') {
|
||||
$cawanganAll = Cawangan::on('mysql7')->get();
|
||||
} else {
|
||||
$cawanganAll = Cawangan::on('mysql7')->where('zone', $zone)->get();
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
foreach ($cawanganAll as $cawangan) {
|
||||
try {
|
||||
$modal = ModalOnline::on($cawangan['mysql'])
|
||||
->where('kodcaw', $cawangan['kodcaw'])
|
||||
->where('tarikh', $tarikh)
|
||||
->first();
|
||||
|
||||
$row = $modal ? $modal->toArray() : [
|
||||
'tarikh' => $tarikh,
|
||||
'kodcaw' => $cawangan['kodcaw'],
|
||||
'had' => 0,
|
||||
'digunakan' => 0,
|
||||
'baki' => 0,
|
||||
'tambah' => 0,
|
||||
'kurang' => 0,
|
||||
'ditutup' => 0,
|
||||
'missing' => true,
|
||||
];
|
||||
$row['cawangan_nama'] = $cawangan->nama_cawangan;
|
||||
$row['missing'] = empty($modal);
|
||||
$rows[] = $row;
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('listToday modal_online skip ' . $cawangan['kodcaw'] . ': ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
usort($rows, function ($a, $b) {
|
||||
return strcmp((string) ($a['kodcaw'] ?? ''), (string) ($b['kodcaw'] ?? ''));
|
||||
});
|
||||
|
||||
$open = 0;
|
||||
$closed = 0;
|
||||
$missing = 0;
|
||||
foreach ($rows as $row) {
|
||||
if (!empty($row['missing'])) {
|
||||
$missing++;
|
||||
} elseif ((int) ($row['ditutup'] ?? 0) === 1) {
|
||||
$closed++;
|
||||
} else {
|
||||
$open++;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => [
|
||||
'tarikh' => $tarikh,
|
||||
'bilangan' => count($rows),
|
||||
'open' => $open,
|
||||
'closed' => $closed,
|
||||
'missing' => $missing,
|
||||
'data' => $rows,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Operasi bulk EOD close for open branches today.
|
||||
*
|
||||
* @return array{ok:bool,status:int,payload:mixed}
|
||||
*/
|
||||
public function closeAll($ditutupOleh, $zone = 'all')
|
||||
{
|
||||
$ditutupOleh = trim((string) $ditutupOleh);
|
||||
if ($ditutupOleh === '') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'status' => 422,
|
||||
'payload' => ['message' => 'ditutup_oleh diperlukan'],
|
||||
];
|
||||
}
|
||||
|
||||
$list = $this->listToday($zone);
|
||||
$closed = 0;
|
||||
$skipped = 0;
|
||||
$failed = [];
|
||||
|
||||
foreach ($list['payload']['data'] as $row) {
|
||||
if (!empty($row['missing']) || (int) ($row['ditutup'] ?? 0) === 1) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
$res = $this->close($row['kodcaw'], $ditutupOleh);
|
||||
if ($res['ok']) {
|
||||
$closed++;
|
||||
} else {
|
||||
$failed[] = [
|
||||
'kodcaw' => $row['kodcaw'],
|
||||
'message' => $res['payload']['message'] ?? 'gagal',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'status' => 200,
|
||||
'payload' => [
|
||||
'closed' => $closed,
|
||||
'skipped' => $skipped,
|
||||
'failed' => $failed,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -398,7 +398,7 @@ class OnePercentService
|
||||
$t_gadai = Carbon::parse($gadai->t_gadai);
|
||||
$t_bayaran = Carbon::parse($trans->tarikh_bayaran);
|
||||
|
||||
if ($t_gadai->month === $t_bayaran->month && $t_gadai->year === $t_bayaran->year) {
|
||||
if (($t_gadai->month == $t_bayaran->month) && ($t_gadai->year == $t_bayaran->year)) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
|
||||
+36
-34
@@ -58,31 +58,34 @@ class GadaiV2
|
||||
}
|
||||
}
|
||||
|
||||
private function getKadarUpahAnggota($nokp,$total_nilai_marhun = 0,$groupid = 2) : Float{
|
||||
//Log::info('DEBUG NOKP:' . $nokp);
|
||||
if($nokp){
|
||||
$customer = Customer::on('mysql7')
|
||||
->select('tag_anggota')
|
||||
->where(function($q) use ($nokp) {
|
||||
$q->where('kpbaru', $nokp)
|
||||
->orWhere('kplama', $nokp);
|
||||
})
|
||||
->first();
|
||||
$customer = $customer ? $customer->toArray() : [];
|
||||
if(isset($customer) && $customer['tag_anggota'] == 1){
|
||||
return 0.16;
|
||||
}else{
|
||||
return KadarUpah::where('min', '<=', $total_nilai_marhun)
|
||||
->where('max', '>=', $total_nilai_marhun)
|
||||
->where('group_id', $groupid)
|
||||
->value('kadarujrah');
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
|
||||
private function getKadarUpahAnggota($nokp, $total_nilai_marhun = 0, $groupid = 2): ?float
|
||||
{
|
||||
if (!$nokp) {
|
||||
return null; // tiada nokp = tak boleh tentukan kadar
|
||||
}
|
||||
|
||||
$customer = Customer::on('mysql7')
|
||||
->select('tag_anggota')
|
||||
->where(function ($q) use ($nokp) {
|
||||
$q->where('kpbaru', $nokp)
|
||||
->orWhere('kplama', $nokp);
|
||||
})
|
||||
->first();
|
||||
|
||||
$customer = $customer ? $customer->toArray() : [];
|
||||
|
||||
if (isset($customer['tag_anggota']) && $customer['tag_anggota'] == 1) {
|
||||
return 0.00; // ahli — kadar 0.00 memang sah
|
||||
}
|
||||
|
||||
$kadar = KadarUpah::where('min', '<=', $total_nilai_marhun)
|
||||
->where('max', '>=', $total_nilai_marhun)
|
||||
->where('group_id', $groupid)
|
||||
->value('kadarujrah');
|
||||
|
||||
return is_null($kadar) ? null : (float) $kadar; // tak jumpa row = null (block)
|
||||
}
|
||||
|
||||
public function createMarhun($norujukan,HttpRequest $request){
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
@@ -108,19 +111,18 @@ class GadaiV2
|
||||
$total_nilai_marhun = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->sum('n_marhun');
|
||||
$total_berat = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->sum('berat');
|
||||
|
||||
$kadar_raw = $this->getKadarUpahAnggota($request->nokp, $total_nilai_marhun, $cawangan['group_id']);
|
||||
$kadar_raw = $this->getKadarUpahAnggota($request->nokp, $total_nilai_marhun, $cawangan['group_id']);
|
||||
|
||||
if (empty($kadar_raw) || $kadar_raw == 0) {
|
||||
|
||||
Log::error('[BLOCKED] Kadar upah kosong / 0', [
|
||||
'nokp' => $request->nokp,
|
||||
'total_nilai_marhun' => $total_nilai_marhun,
|
||||
'group_id' => $cawangan['group_id'],
|
||||
]);
|
||||
|
||||
throw new \Exception("Kadar upah kosong / 0, transaksi dibatalkan!");
|
||||
}
|
||||
if (is_null($kadar_raw)) {
|
||||
Log::error('[BLOCKED] Kadar upah tidak dijumpai', [
|
||||
'nokp' => $request->nokp,
|
||||
'total_nilai_marhun' => $total_nilai_marhun,
|
||||
'group_id' => $cawangan['group_id'],
|
||||
]);
|
||||
throw new \Exception("Kadar upah tidak dijumpai, transaksi dibatalkan!");
|
||||
}
|
||||
|
||||
// $kadar_raw = 0.00 (ahli) akan lepas ke sini dan diteruskan
|
||||
|
||||
// query kadar upah lama
|
||||
// $kadar_raw = KadarUpah::where('min','<=',$total_nilai_marhun)->where('max','>=',$total_nilai_marhun)->first();
|
||||
|
||||
Reference in New Issue
Block a user