DONE: auto add ic photo for existing customer
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user