Explore/ismail (#9)
Build Docker Image / build-backend (push) Successful in 19s

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: #9
This commit was merged in pull request #9.
This commit is contained in:
2026-09-06 10:22:39 +08:00
parent 51860cea37
commit 41a9cf6d20
36 changed files with 3800 additions and 124 deletions
+135 -59
View File
@@ -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();