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 @@ +
+
+
+ Scan IC / Passport * +
+
+ + Wajib. JPG, PNG atau PDF (maks 4MB). +
+ Preview scan IC + +
+
+
+
diff --git a/resources/views/customers/partials/ic_scan_register_script.blade.php b/resources/views/customers/partials/ic_scan_register_script.blade.php new file mode 100644 index 00000000..2a2ea408 --- /dev/null +++ b/resources/views/customers/partials/ic_scan_register_script.blade.php @@ -0,0 +1,80 @@ + diff --git a/resources/views/customers/partials/ic_scan_upload.blade.php b/resources/views/customers/partials/ic_scan_upload.blade.php new file mode 100644 index 00000000..7034648f --- /dev/null +++ b/resources/views/customers/partials/ic_scan_upload.blade.php @@ -0,0 +1,204 @@ +@php + $hasScanIc = !empty($customer_info['has_scan_ic']); + $scanIcMime = strtolower((string) ($customer_info['scan_ic_mime'] ?? '')); + $scanIcIsPdf = strpos($scanIcMime, 'pdf') !== false; + $scanIcNoic = !empty($customer_info['kpbaru']) ? $customer_info['kpbaru'] : ($customer_info['kplama'] ?? ''); + $scanIcPreviewUrl = $hasScanIc + ? route('customer.showIcScan', ['icno' => $scanIcNoic, 't' => $customer_info['scan_ic'] ?? time()]) + : ''; +@endphp + + + +
+
+
+ Scan Dokumen IC / Passport * +
+ Wajib dimuat naik sebelum daftar pembiayaan. Format JPG, PNG atau PDF (maks 4MB). +
+
+ @if ($hasScanIc) + Telah dimuat naik + @else + Belum dimuat naik + @endif +
+
+
+ + + +
+
+
+ @if ($hasScanIc && $scanIcIsPdf) + Lihat fail PDF + Preview scan IC + @else + Lihat fail PDF + Preview scan IC + @endif +
{{ $customer_info['scan_ic_filename'] ?? '' }}
+
+
+ + diff --git a/resources/views/customers/v1/index.blade.php b/resources/views/customers/v1/index.blade.php index 54eca7af..1c639356 100644 --- a/resources/views/customers/v1/index.blade.php +++ b/resources/views/customers/v1/index.blade.php @@ -21,6 +21,9 @@
+ @if(session()->has('error')) +
{{ session('error') }}
+ @endif
masukkan nombor kad pengenalan
@@ -84,7 +87,7 @@
- + @include('customers.partials.ic_scan_register_field', ['scanFieldId' => 'scan_ic_manual'])
+@include('customers.partials.ic_scan_register_script')