DONE: auto add ic photo for existing customer
This commit is contained in:
Vendored
+55
-1
@@ -234,15 +234,69 @@ async function handleMyKadReader() {
|
||||
}
|
||||
}
|
||||
|
||||
function customerNeedsMykadPhoto(customer) {
|
||||
if (!customer || typeof customer !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !customer.gambar_mykad && !customer.photo_base64;
|
||||
}
|
||||
|
||||
async function storeMykadPhotoForExistingCustomerIfMissing(customer, readerData) {
|
||||
if (!customerNeedsMykadPhoto(customer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!readerData || !readerData.has_photo || !readerData.photo_base64) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof store_mykad_photo_endpoint === 'undefined' || !store_mykad_photo_endpoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
const csrfToken = document.querySelector('input[name="_token"]');
|
||||
const nric = getMyKadNumberWithoutHyphens(
|
||||
customer.kpbaru || customer.kplama || readerData.nric || ''
|
||||
);
|
||||
|
||||
if (!nric) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await fetch(store_mykad_photo_endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'X-CSRF-TOKEN': csrfToken ? csrfToken.value : '',
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
icno: nric,
|
||||
photo_base64: readerData.photo_base64,
|
||||
photo_mime: readerData.photo_mime || 'image/jpeg',
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
// Do not block customer search if photo backfill fails.
|
||||
console.warn('Failed to store MyKad photo for existing customer', error);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMyKadData(data) {
|
||||
return checkIfMyKadExists(data.nric)
|
||||
.then(response => {
|
||||
.then(async response => {
|
||||
let isResponseArray = Array.isArray(response);
|
||||
let resolved_response = isResponseArray ? response.pop() : response;
|
||||
|
||||
if (!resolved_response || resolved_response === 'no-data') {
|
||||
populateDaftarPelangganModal(data);
|
||||
} else {
|
||||
await storeMykadPhotoForExistingCustomerIfMissing(resolved_response, data);
|
||||
|
||||
let input_search_noic = document.querySelector("form[name='frmsearch'] input[name='noic']");
|
||||
let form_search_noic = document.querySelector("form[name='frmsearch']");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user