From 03228cae2fc46d7cf36fd0cfeb9733da6c0edf9c Mon Sep 17 00:00:00 2001 From: ISMAIL MASSERAN Date: Wed, 9 Sep 2026 10:27:59 +0800 Subject: [PATCH] DONE: auto add ic photo for existing customer --- app/Http/Controllers/CustomerController.php | 33 +++++++++++++++++++++ routes/web.php | 1 + 2 files changed, 34 insertions(+) diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 0b250dd..bc45c47 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -1127,6 +1127,39 @@ public function AdminsearchCustomerBySAG(Request $request) return response()->json(['message' => 'Customer PDPA updated successfully.'], 200); } + /** + * Store MyKad photo for an existing customer only when gambar_mykad is empty. + */ + public function storeMykadPhotoIfMissing($ic, Request $request) + { + $customer = Customer::on('mysql7') + ->where('kplama', '=', $ic) + ->orWhere('kpbaru', '=', $ic) + ->first(); + + if (!$customer) { + return response()->json(['error' => 'Customer not found.', 'stored' => false], 404); + } + + if (!empty($customer->gambar_mykad)) { + return response()->json([ + 'message' => 'MyKad photo already stored.', + 'gambar_mykad' => $customer->gambar_mykad, + 'stored' => false, + ], 200); + } + + $this->attachMykadPhoto($customer, $request); + + return response()->json([ + 'message' => !empty($customer->gambar_mykad) + ? 'MyKad photo stored.' + : 'No photo provided or store failed.', + 'gambar_mykad' => $customer->gambar_mykad, + 'stored' => !empty($customer->gambar_mykad), + ], 200); + } + /** * Save MyKad photo into arrahn_files and link it on customer.gambar_mykad. */ diff --git a/routes/web.php b/routes/web.php index 464075c..a08e973 100644 --- a/routes/web.php +++ b/routes/web.php @@ -54,6 +54,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('customers/{ic}/gadai/{status}',['uses'=>'CustomerController@showOneCustomerGadai']); $router->get('customers/{ic}/gadai/{status}/{kodcaw}',['uses'=>'CustomerController@showOneCustomerGadaiByCawangan']); $router->post('customers/create/{kodcaw}',['uses'=>'CustomerController@createCustomer']); + $router->post('customers/{ic}/mykad-photo', ['uses' => 'CustomerController@storeMykadPhotoIfMissing']); $router->delete('customers/{kodcaw}/{nokp}', ['uses' => 'CustomerController@delete']); $router->put('customers/update/{nokp}', ['uses' => 'CustomerController@customerUpdate']); $router->put('customers/update/kaunter/{nokp}/{kodcaw}', ['uses' => 'CustomerController@customerUpdateKaunter']);