DONE: auto add ic photo for existing customer

This commit is contained in:
ISMAIL MASSERAN
2026-09-09 10:27:59 +08:00
parent 22279af86c
commit 03228cae2f
2 changed files with 34 additions and 0 deletions
@@ -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.
*/