From 6f4507dc08a9d282e7a3ca52f9e46f2ce844a333 Mon Sep 17 00:00:00 2001 From: ISMAIL MASSERAN Date: Thu, 3 Sep 2026 11:29:20 +0800 Subject: [PATCH] DONE: store mykad image in database --- app/Http/Controllers/CustomersController.php | 11 +++++-- public/js/mykad-reader-customer.js | 32 ++++++++++++++++++++ resources/views/customers/v1/index.blade.php | 10 ++++-- resources/views/customers/v1/info.blade.php | 12 ++++++++ resources/views/customers/v2/index.blade.php | 10 ++++-- resources/views/customers/v2/info.blade.php | 12 ++++++++ 6 files changed, 79 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/CustomersController.php b/app/Http/Controllers/CustomersController.php index 40fee0c9..91351741 100644 --- a/app/Http/Controllers/CustomersController.php +++ b/app/Http/Controllers/CustomersController.php @@ -358,7 +358,7 @@ class CustomersController extends Controller ])->json(); } - $customer_info = Http::withOptions(['verify' => config('app.api_verify')])->post(config('api.url') . '/api/customers/create/' . $auth_user['cawangan'], [ + $customer_payload = [ 'kodcaw' => $auth_user['cawangan'], 'nopelanggan' => $no_pelanggan, 'nokpbaru' => $nokpbaru, @@ -385,7 +385,14 @@ class CustomersController extends Controller 'nota_pekerjaan' => $request->nota_pekerjaan, 'notaarcc' => $request->notaarcc, 'tujuangadai' => $request->tujuan_gadai, - ]); + ]; + + if ($request->filled('photo_base64')) { + $customer_payload['photo_base64'] = $request->input('photo_base64'); + $customer_payload['photo_mime'] = $request->input('photo_mime') ?: 'image/jpeg'; + } + + $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); Session::put('noic', $request->noic); diff --git a/public/js/mykad-reader-customer.js b/public/js/mykad-reader-customer.js index e15ccbcb..f07a8560 100644 --- a/public/js/mykad-reader-customer.js +++ b/public/js/mykad-reader-customer.js @@ -338,10 +338,12 @@ let populateDaftarPelangganModal = (data) => { photo.src = 'data:' + mime + ';base64,' + data.photo_base64; photo_container.classList.remove('d-none'); photo_container.classList.add('d-flex'); + setMykadPhotoFields(data.photo_base64, mime); } else { photo.src = original_photo_loader; photo_container.classList.add('d-none'); photo_container.classList.remove('d-flex'); + setMykadPhotoFields('', ''); } disablePointerEventsOnClickableInputs(); @@ -360,8 +362,38 @@ let hideMykadPhoto = () => { photo_container.classList.add('d-none'); photo_container.classList.remove('d-flex'); } + + setMykadPhotoFields('', ''); }; +function setMykadPhotoFields(base64, mime) { + let form = document.querySelector("#daftar_pelanggan_mykad_reader form") + || document.getElementById("form-mykad-reader"); + let photoInput = (form && form.querySelector("input[name='photo_base64']")) + || document.getElementById("photo_base64"); + let mimeInput = (form && form.querySelector("input[name='photo_mime']")) + || document.getElementById("photo_mime"); + + if (photoInput) { + photoInput.value = base64 || ''; + } + + if (mimeInput) { + mimeInput.value = mime || ''; + } +} + +function copyMykadPhotoFromImage() { + let photo = document.querySelector("#daftar_pelanggan_mykad_reader #photo-mykad"); + if (!photo || !photo.src || photo.src.indexOf("base64,") === -1) { + return; + } + + let parts = photo.src.split("base64,"); + let mimeMatch = photo.src.match(/^data:([^;]+);/); + setMykadPhotoFields(parts[1] || "", mimeMatch ? mimeMatch[1] : "image/jpeg"); +} + if (button_read_mykad) { button_read_mykad.addEventListener("click", handleMyKadReader); } diff --git a/resources/views/customers/v1/index.blade.php b/resources/views/customers/v1/index.blade.php index c0b5f64a..a2fc5dae 100644 --- a/resources/views/customers/v1/index.blade.php +++ b/resources/views/customers/v1/index.blade.php @@ -210,15 +210,17 @@