diff --git a/app/Http/Controllers/CustomersController.php b/app/Http/Controllers/CustomersController.php index 2913fdbc..f0c23fd4 100644 --- a/app/Http/Controllers/CustomersController.php +++ b/app/Http/Controllers/CustomersController.php @@ -312,6 +312,61 @@ class CustomersController extends Controller return response()->json($response->json() ?? ['stored' => false], $response->status()); } + /** + * Upload scanned IC / passport document for the current customer. + */ + public function storeIcScan(Request $request) + { + $icno = preg_replace('/[^0-9A-Za-z]/', '', (string) ($request->input('icno') ?: Session::get('noic'))); + if ($icno === '') { + return response()->json(['error' => 'No. IC diperlukan.', 'stored' => false], 422); + } + + list($scanPayload, $scanError) = $this->scanIcPayloadFromRequest($request); + if ($scanError) { + return response()->json(['error' => $scanError, 'stored' => false], 422); + } + + $response = Http::withOptions(['verify' => config('app.api_verify')]) + ->post(config('api.url') . '/api/customers/' . $icno . '/ic-scan', $scanPayload); + + return response()->json($response->json() ?? ['stored' => false], $response->status()); + } + + public function showIcScan(Request $request) + { + $icno = preg_replace('/[^0-9A-Za-z]/', '', (string) ($request->query('icno') ?: Session::get('noic'))); + if ($icno === '') { + abort(404); + } + + $response = Http::withOptions(['verify' => config('app.api_verify')]) + ->get(config('api.url') . '/api/customers/' . $icno . '/ic-scan'); + + $payload = $response->json(); + $file = is_array($payload) ? ($payload['file'] ?? null) : null; + if (!$response->successful() || !$file || empty($file['data'])) { + abort(404); + } + + $raw = $file['data']; + if (strpos($raw, 'base64,') !== false) { + $raw = substr($raw, strpos($raw, 'base64,') + 7); + } + $binary = base64_decode($raw, true); + if ($binary === false) { + $binary = base64_decode($file['data']); + } + + $type = $file['type'] ?? 'application/octet-stream'; + $filename = $file['filename'] ?? 'scan-ic'; + + return response($binary, 200, [ + 'Content-Type' => $type, + 'Content-Disposition' => 'inline; filename="' . $filename . '"', + ]); + } + /** * Show the form for creating a new resource. * @@ -330,6 +385,11 @@ class CustomersController extends Controller */ public function store(Request $request) { + list($scanPayload, $scanError) = $this->scanIcPayloadFromRequest($request); + if ($scanError) { + return redirect()->back()->with('error', $scanError)->withInput(); + } + if ($request->idtype == 'nokp') { $nokpbaru = $request->noic; $nokplama = ''; @@ -415,6 +475,10 @@ class CustomersController extends Controller $customer_payload['photo_mime'] = $request->input('photo_mime') ?: 'image/jpeg'; } + $customer_payload['file_base64'] = $scanPayload['file_base64']; + $customer_payload['file_mime'] = $scanPayload['file_mime']; + $customer_payload['filename'] = $scanPayload['filename']; + $customer_info = Http::withOptions(['verify' => config('app.api_verify')])->post(config('api.url') . '/api/customers/create/' . $auth_user['cawangan'], $customer_payload); Session::put('customer_info', $customer_info); @@ -692,6 +756,34 @@ class CustomersController extends Controller ]); } + private function scanIcPayloadFromRequest(Request $request) + { + if (!$request->hasFile('scan_ic')) { + return [null, 'Sila muat naik scan dokumen IC / Passport.']; + } + + $file = $request->file('scan_ic'); + if (!$file->isValid()) { + return [null, 'Fail scan IC tidak sah.']; + } + + if ($file->getSize() > 4 * 1024 * 1024) { + return [null, 'Saiz fail scan IC maksimum 4MB.']; + } + + $mime = strtolower((string) ($file->getMimeType() ?: '')); + $allowed = ['image/jpeg', 'image/jpg', 'image/png', 'application/pdf']; + if (!in_array($mime, $allowed, true)) { + return [null, 'Format fail scan IC mestilah JPG, PNG atau PDF.']; + } + + return [[ + 'file_base64' => base64_encode(file_get_contents($file->getRealPath())), + 'file_mime' => $mime, + 'filename' => $file->getClientOriginalName(), + ], null]; + } + private function printBlank($value) { if ($value === null) { diff --git a/app/Http/Controllers/GadaianController.php b/app/Http/Controllers/GadaianController.php index 128855f2..cc372162 100644 --- a/app/Http/Controllers/GadaianController.php +++ b/app/Http/Controllers/GadaianController.php @@ -164,6 +164,9 @@ class GadaianController extends Controller $noic = $request->noic; $customers_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/' . $noic)->json(); $customer_info = $customers_info; + if (!is_array($customer_info) || empty($customer_info['has_scan_ic'])) { + return redirect()->route('customer_info')->with('error', 'Sila muat naik scan dokumen IC sebelum daftar pembiayaan.'); + } $limit_pinjaman_semasa = 0; $auth_user = Auth::user(); if ($request->session()->get('page_reload') == null) { diff --git a/resources/views/customers/partials/ic_scan_register_field.blade.php b/resources/views/customers/partials/ic_scan_register_field.blade.php new file mode 100644 index 00000000..212139b5 --- /dev/null +++ b/resources/views/customers/partials/ic_scan_register_field.blade.php @@ -0,0 +1,19 @@ +