diff --git a/.env.example b/.env.example index 76f0423..7dbef1a 100644 --- a/.env.example +++ b/.env.example @@ -44,3 +44,6 @@ AWS_BUCKET= MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +MYKAD_READER_PORT=8085 +MYKAD_READER_ENABLED_CAWANGAN='' # IF NO CAWANGAN STATED, ALL CAWANGAN IS ENABLED diff --git a/app/Http/Controllers/CustomersController.php b/app/Http/Controllers/CustomersController.php index 5f7e35a..10b5c78 100644 --- a/app/Http/Controllers/CustomersController.php +++ b/app/Http/Controllers/CustomersController.php @@ -47,12 +47,8 @@ class CustomersController extends Controller $auth_user = Auth::user(); $api_url = config('api.url'); $cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json(); + $customer_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/'. Session::get('noic'))->json(); - // if($customers_info){ - // $customer_info = $customers_info[0]; - // }else{ - // $customer_info = $customers_info; - // } $komoditi = Komoditi::first(); $min_komoditi = $komoditi['min_komoditi']; @@ -115,7 +111,7 @@ class CustomersController extends Controller if(sizeof($customers_info) > 0) return $customers_info; else - return "no-data"; + return response(["no-data"], 200); } /** @@ -204,7 +200,9 @@ class CustomersController extends Controller 'tujuangadai'=>$request->tujuan_gadai, ]); - Session::put('customer_info',$customer_info); + Session::put('customer_info', $customer_info); + Session::put('noic', $request->noic); + event(new PelangganNotify('lulus',$auth_user['cawangan'])); return redirect()->route('customer_info')->with( ['customer_info' => $customer_info] ); } diff --git a/app/User.php b/app/User.php index c7c24fc..33e4953 100644 --- a/app/User.php +++ b/app/User.php @@ -3,6 +3,7 @@ namespace App; use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; @@ -37,4 +38,9 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + + public function cawangan_kerja(): HasOne + { + return $this->hasOne(Cawangan::class, 'kodcaw', 'cawangan'); + } } diff --git a/config/mykad-reader.php b/config/mykad-reader.php new file mode 100644 index 0000000..e1dc6da --- /dev/null +++ b/config/mykad-reader.php @@ -0,0 +1,9 @@ + 'http://localhost:' . $x . '/?MYKADJSON'; + +return[ + 'endpoint' => env('MYKAD_READER_ENDPOINT', $getReaderEndpoint(env('MYKAD_READER_PORT', $default_port))), + 'enabled_cawangan' => array_map(fn ($cawangan) => trim($cawangan), explode(',', env('MYKAD_READER_ENABLED_CAWANGAN'))) ?? [], +]; diff --git a/public/css/loader.css b/public/css/loader.css new file mode 100644 index 0000000..e266e71 --- /dev/null +++ b/public/css/loader.css @@ -0,0 +1,121 @@ +/* Absolute Center Spinner */ +.loading { + position: fixed; + z-index: 999; + height: 2em; + width: 2em; + overflow: show; + margin: auto; + top: 0; + left: 0; + bottom: 0; + right: 0; + } + + /* Transparent Overlay */ + .loading:before { + content: ''; + display: block; + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: radial-gradient(rgba(20, 20, 20,.8), rgba(0, 0, 0, .8)); + + background: -webkit-radial-gradient(rgba(20, 20, 20,.8), rgba(0, 0, 0,.8)); + } + + /* :not(:required) hides these rules from IE9 and below */ + .loading:not(:required) { + /* hide "loading..." text */ + font: 0/0 a; + color: transparent; + text-shadow: none; + background-color: transparent; + border: 0; + } + + .loading:not(:required):after { + content: ''; + display: block; + font-size: 10px; + width: 1em; + height: 1em; + margin-top: -0.5em; + -webkit-animation: spinner 150ms infinite linear; + -moz-animation: spinner 150ms infinite linear; + -ms-animation: spinner 150ms infinite linear; + -o-animation: spinner 150ms infinite linear; + animation: spinner 150ms infinite linear; + border-radius: 0.5em; + -webkit-box-shadow: rgba(255,255,255, 0.75) 1.5em 0 0 0, rgba(255,255,255, 0.75) 1.1em 1.1em 0 0, rgba(255,255,255, 0.75) 0 1.5em 0 0, rgba(255,255,255, 0.75) -1.1em 1.1em 0 0, rgba(255,255,255, 0.75) -1.5em 0 0 0, rgba(255,255,255, 0.75) -1.1em -1.1em 0 0, rgba(255,255,255, 0.75) 0 -1.5em 0 0, rgba(255,255,255, 0.75) 1.1em -1.1em 0 0; + box-shadow: rgba(255,255,255, 0.75) 1.5em 0 0 0, rgba(255,255,255, 0.75) 1.1em 1.1em 0 0, rgba(255,255,255, 0.75) 0 1.5em 0 0, rgba(255,255,255, 0.75) -1.1em 1.1em 0 0, rgba(255,255,255, 0.75) -1.5em 0 0 0, rgba(255,255,255, 0.75) -1.1em -1.1em 0 0, rgba(255,255,255, 0.75) 0 -1.5em 0 0, rgba(255,255,255, 0.75) 1.1em -1.1em 0 0; + } + + /* Animation */ + + @-webkit-keyframes spinner { + 0% { + -webkit-transform: rotate(0deg); + -moz-transform: rotate(0deg); + -ms-transform: rotate(0deg); + -o-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -webkit-transform: rotate(360deg); + -moz-transform: rotate(360deg); + -ms-transform: rotate(360deg); + -o-transform: rotate(360deg); + transform: rotate(360deg); + } + } + @-moz-keyframes spinner { + 0% { + -webkit-transform: rotate(0deg); + -moz-transform: rotate(0deg); + -ms-transform: rotate(0deg); + -o-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -webkit-transform: rotate(360deg); + -moz-transform: rotate(360deg); + -ms-transform: rotate(360deg); + -o-transform: rotate(360deg); + transform: rotate(360deg); + } + } + @-o-keyframes spinner { + 0% { + -webkit-transform: rotate(0deg); + -moz-transform: rotate(0deg); + -ms-transform: rotate(0deg); + -o-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -webkit-transform: rotate(360deg); + -moz-transform: rotate(360deg); + -ms-transform: rotate(360deg); + -o-transform: rotate(360deg); + transform: rotate(360deg); + } + } + @keyframes spinner { + 0% { + -webkit-transform: rotate(0deg); + -moz-transform: rotate(0deg); + -ms-transform: rotate(0deg); + -o-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -webkit-transform: rotate(360deg); + -moz-transform: rotate(360deg); + -ms-transform: rotate(360deg); + -o-transform: rotate(360deg); + transform: rotate(360deg); + } + } \ No newline at end of file diff --git a/public/img/6mb.gif b/public/img/6mb.gif new file mode 100644 index 0000000..91897fb Binary files /dev/null and b/public/img/6mb.gif differ diff --git a/public/img/pikachu-running.gif b/public/img/pikachu-running.gif new file mode 100644 index 0000000..c9f27f6 Binary files /dev/null and b/public/img/pikachu-running.gif differ diff --git a/public/img/spinner-loader.gif b/public/img/spinner-loader.gif new file mode 100644 index 0000000..081b6f4 Binary files /dev/null and b/public/img/spinner-loader.gif differ diff --git a/public/js/iris-mykad-websocket-client-api.js b/public/js/iris-mykad-websocket-client-api.js new file mode 100644 index 0000000..6101f3d --- /dev/null +++ b/public/js/iris-mykad-websocket-client-api.js @@ -0,0 +1,258 @@ +WebSocketManager = { + url:"", + init: function(url) { + WebSocketManager.url = url; + }, + open: function(callback, slot) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"OPEN","Slot":"'+ slot +'"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + wsocket.close(); + callback(obj); + }; + + }, + listReader: function(callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"LIST_READER"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode); + }; + + }, + close: function(callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"CLOSE"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + wsocket.close(); + callback(obj); + }; + }, + verifyFPTemplate: function(callback, ThumbCode, Bas64FPLeft, Bas64FPRight) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"VERIFY_FP_TEMPLATE","ThumbCode":"'+ ThumbCode +'","Bas64FPLeft":"'+ Bas64FPLeft +'","Bas64FPRight":"'+ Bas64FPRight +'"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + wsocket.close(); + callback(obj.RespCode, obj.RespMessage); + }; + + }, + readMyKad: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"READ_MYKAD"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + readAllText: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"READ_ALL_TEXT"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + readPhoto: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"READ_PHOTO"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + readBio: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"READ_BIO"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + readMyKid: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"READ_MYKID"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + FPBioEnrol: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_ENROL"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + //var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(obj); + }; + }, + getThumbImage: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"GET_MYKAD_THUMB_IMAGE"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + getThumbBin1: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"GET_THUMB_BIN1"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + getThumbBin2: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"GET_THUMB_BIN2"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + FPBioEnrolBin1: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_ENROL_BIN1"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + //var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(obj); + }; + }, + FPBioEnrolBin2: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_ENROL_BIN2"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + //var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(obj); + }; + }, + FPBioVerify: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_VERIFY"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + FPBioVerifyBin: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_VERIFY_BIN"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + FPBioVerifyLeft: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_VERIFY_LEFT"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + FPBioVerifyBinLeft: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_VERIFY_BIN_LEFT"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + FPBioVerifyRight: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_VERIFY_RIGHT"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + }, + FPBioVerifyBinRight: function (callback) { + wsocket = new WebSocket(WebSocketManager.url); + wsocket.onopen = function () { + wsocket.send('{"Cmd":"FP_BIO_VERIFY_BIN_RIGHT"}'); + }; + wsocket.onmessage = function (evt) { + var obj = JSON.parse(evt.data); + var data = JSON.parse(obj.RespMessage); + wsocket.close(); + callback(data, obj.RespCode, obj.RespSW12AndApiName); + }; + } +} diff --git a/public/js/mykad-reader-customer.js b/public/js/mykad-reader-customer.js new file mode 100644 index 0000000..caca8e5 --- /dev/null +++ b/public/js/mykad-reader-customer.js @@ -0,0 +1,293 @@ + +let button_read_mykad = document.getElementById("button_read_mykad"); +let button_close_modal = document.querySelector("#daftar_pelanggan_mykad_reader button.btn.btn-danger"); +let original_photo_loader = document.querySelector("#photo-mykad").src; + + let showLoader = () => { + let pageLoader = document.getElementById('page_loader'); + pageLoader.removeAttribute('class'); + pageLoader.classList.add('loading'); + }; + + let hideLoader = () => { + let pageLoader = document.getElementById('page_loader'); + pageLoader.removeAttribute('class'); + }; + + function handleMyKadReader() + { + showLoader(); + WebSocketManager.init("wss://localhost:5963/mykadwebsocket"); + WebSocketManager.listReader(callbackDoneGetListCardReader); + } + + function callbackDoneGetListCardReader(data, respcode) + { + console.log('done get list card reader'); + + if(respcode === -1){ + console.log({'location': 'callbackDoneGetListCardReader', 'data' : data} ); + } + + let isDevicesConnected = Object.keys(data).length > 0; + + if(! isDevicesConnected){ + hideLoader(); + + Swal.fire({ icon: 'error', title: 'Pembaca MyKad tidak dapat dikesan, sila periksa sambungan', }); + + return; + } + + let slots = data.toString().split(','); + WebSocketManager.open(doneOpenReaderConnection, slots[0]); + } + + function doneOpenReaderConnection() + { + WebSocketManager.readAllText(callBackAfterReadMykad); + } + + function handleMyKadReaderError(sw12AndApiName) + { + hideLoader(); + + let error_handler_dictionary = { + '0x80100069' : 'Tiada MyKad dikesan, sila masukkan Mykad untuk dibaca', + '0x80100066' : 'MyKad mungkin dimasukkan terbalik, sila masukkan dengan betul', + 'default' : sw12AndApiName, + }; + + let error_data = sw12AndApiName.split(" "); + + let error_code = error_data.filter(x => x.startsWith('0x')).splice(-1) + + let error_message = error_handler_dictionary['default']; + + let hasDefinedError = error_handler_dictionary.hasOwnProperty(error_code); + + if(hasDefinedError){ + error_message = error_handler_dictionary[error_code]; + } + + Swal.fire({ icon: 'error', title: error_message, }); + } + + function callBackAfterReadMykad(data, respcode, sw12AndApiName) + { + if(respcode !== 0){ + handleMyKadReaderError(sw12AndApiName); + return + } + + checkIfMyKadExists(data.IDNum) + .then(response => { + let isResponseArray = Array.isArray(response); + resolved_response = isResponseArray ? response.pop() : response; + + if (resolved_response === 'no-data') { + populateDaftarPelangganModal(data, handleReadPhoto); + } else { + let input_search_noic = document.getElementById("noic"); + let form_search_noic = document.querySelector("form[name='frmsearch']"); + + let getMyKadNumberWithoutHypens = myKadNumber => myKadNumber.replace(/-/g, ''); + input_search_noic.value = getMyKadNumberWithoutHypens(data.IDNum); + form_search_noic.submit(); + } + }) + .catch(error => { + Swal.fire({ + icon: 'error', + title: error, + }); + }); + + hideLoader(); + } + + function checkIfMyKadExists(myKadNumber) { + let myKadNumberWithoutHyphens = myKadNumber.replace(/-/g, ''); + + const url = wakil_caricustomer_endpoint + '/?icno=' + myKadNumberWithoutHyphens; + + const connectionConfig = { + headers: { + "Content-Type": "application/json", + "Accept": "application/json", + "X-Requested-With": "XMLHttpRequest", + "X-CSRF-Token": document.querySelector('input[name="_token"]').value + }, + credentials: "same-origin", + }; + + return fetch(url, connectionConfig) + .then(response => response.json()) + } + + let populateDaftarPelangganModal = (data, callbackAfterPopulateDaftarPelanggan) => { + $('#daftar_pelanggan_mykad_reader').modal('show'); + let modal_form = document.querySelector("#daftar_pelanggan_mykad_reader .modal-body .row.form-group"); + + const religions = [ + ['01', 'Islam'], + ['02', 'Hindu'], + ['03', 'Buddha'], + ['04', 'Kristian'], + ['05', 'Lain-lain'], + ]; + + const races = [ + ['M', 'Melayu'], + ['C', 'Cina'], + ['I', 'India'], + ['L', 'Lain-lain'], + ]; + + let getCodeFromValue = (needle, haystack) => { + let title_cased_text = needle.split(' ') + .map(w => w[0].toUpperCase() + w.substring(1).toLowerCase()) + .join(' '); + + return haystack.filter(x => x[1] == title_cased_text)[0][0]; + }; + + let getMyKadNumberWithoutHypens = (IDNum) => { + return IDNum.replace(/-/g, ''); + } + + let getFormattedDateOfBirth = (date_of_birth) => { + + let date_of_birth_hyphenated = date_of_birth.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3"); + + const [year, month, day] = date_of_birth_hyphenated.split('-'); + return day + '/' + month + '/' + year; + }; + + let getAgeFromDateOfBirth = (date_of_birth) => { + + let date_of_birth_hyphenated = date_of_birth.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3"); + + const [birth_year, birth_month, birth_day] = date_of_birth_hyphenated.split('-'); + + let formatBirthMonth = (birth_month) => { + let newbirthMonth = birth_month < 9 ? birth_month[1] : birth_month; + return newbirthMonth; + }; + + const count_leap_year = countLeapYears(birth_year, formatBirthMonth(birth_month), birth_day) - 1; + + const start = new Date(date_of_birth_hyphenated), + end = new Date(), + diff = new Date(end - start), + days = ((diff / 1000 / 60 / 60 / 24) - count_leap_year) / 365; + + return parseInt(days); + }; + + let getBumiputeraStatus = (race) => { + + const non_bumiputera_ethnicity = ['INDIA', 'CINA']; + + let isBumiputera = !non_bumiputera_ethnicity.includes(race); + + return isBumiputera; + }; + + let disablePointerEventsOnClickableInputs = () => { + modal_form.querySelector("input[name='bumiputera']").style.pointerEvents = 'none'; + modal_form.querySelector("input[name='warganegara']").style.pointerEvents = 'none'; + + modal_form.querySelector("select[name='bangsa']").style.pointerEvents = 'none'; + modal_form.querySelector("select[name='agama']").style.pointerEvents = 'none'; + } + + let mykad_modal = document.querySelector("#daftar_pelanggan_mykad_reader"); + let photo_container = mykad_modal.querySelector("#photo-mykad-container"); + + modal_form.querySelector("input[name='name']").value = data.OrgName; + modal_form.querySelector("input[name='noic']").value = getMyKadNumberWithoutHypens(data.IDNum); + modal_form.querySelector("input[name='tarikh_lahir']").value = getFormattedDateOfBirth(data.BirthDate); + modal_form.querySelector("input[name='negeri_lahir']").value = data.BirthPlace; + modal_form.querySelector("input[name='jantina']").value = data.Gender == 'LELAKI' ? 'Lelaki' : 'Perempuan'; + modal_form.querySelector("input[name='warganegara']").checked = data.Citizenship === 'WARGANEGARA' ? true : false; + modal_form.querySelector("input[name='bumiputera']").checked = getBumiputeraStatus(data.Race); + modal_form.querySelector("select[name='agama']").value = getCodeFromValue(data.Religion, religions); + modal_form.querySelector("textarea[name='alamat']").value = [data.Address1, data.Address2, data.Address3].join(", "); + + let getPostCode = (postCodeCity) => postCodeCity.replace(/\D/g, ''); + modal_form.querySelector("input[name='poskod']").value = getPostCode(data.PostcodeCity); + + let getCityName = (postCodeCity) => postCodeCity.replace(/\d/g, ''); + modal_form.querySelector("input[name='daerah']").value = getCityName(data.PostcodeCity).trim(); + + modal_form.querySelector("input[name='negeri']").value = data.State; + modal_form.querySelector("input[name='age']").value = getAgeFromDateOfBirth(data.BirthDate); + modal_form.querySelector("select[name='bangsa']").value = getCodeFromValue(data.Race, races); + + calculatePassportAge(); + + photo_container.classList.remove('d-none'); + photo_container.classList.add('d-flex'); + + $('#daftar_pelanggan_mykad_reader').modal('show'); + + + disablePointerEventsOnClickableInputs(); + callbackAfterPopulateDaftarPelanggan(); +} + + +function handleReadPhoto() +{ + WebSocketManager.init("wss://localhost:5963/mykadwebsocket"); + WebSocketManager.listReader(callbackDoneGetListCardReader2); +} + +function callbackDoneGetListCardReader2(data, respcode) +{ + if(respcode === -1){ + console.log({'location': 'callbackDoneGetListCardReader', 'data' : data} ); + } + + let slots = data.toString().split(','); + WebSocketManager.open(doneOpenReaderConnection2, slots[0]); +} + +function doneOpenReaderConnection2() +{ + WebSocketManager.readPhoto(callbackAfterReadPhoto2); +} + +function callbackAfterReadPhoto2(data, RespCode, RespSW12AndApiName) +{ + let mykad_modal = document.querySelector("#daftar_pelanggan_mykad_reader"); + let photo = mykad_modal.querySelector("#photo-mykad"); + + let isDataEmpty = data + && Object.keys(data).length === 0 + && Object.getPrototypeOf(data) === Object.prototype; + + if(isDataEmpty){ + photo.src = original_photo_loader; + return; + } + + photo.src = 'data:image/jpeg;base64, ' + data.Base64Photo; +} + +let hideMykadPhoto = () => { + + WebSocketManager.close(() => console.log('Websocket closed')); + + let photo = document.getElementById("photo-mykad"); + let photo_container = document.getElementById("photo-mykad-container"); + + photo.src = original_photo_loader; + + photo_container.classList.add('d-none'); + photo_container.classList.remove('d-flex'); +}; + +button_read_mykad.addEventListener("click", handleMyKadReader); +button_close_modal.addEventListener("click", hideMykadPhoto); diff --git a/resources/views/customers/index.blade.php b/resources/views/customers/index.blade.php index c6a3d0c..19ad2d9 100644 --- a/resources/views/customers/index.blade.php +++ b/resources/views/customers/index.blade.php @@ -37,6 +37,27 @@ + @php + $user_cawangan = strtolower(auth()->user()->cawangan_kerja->details_caw); + $enabled_cawangan = array_map(fn($x) => strtolower($x), config('mykad-reader.enabled_cawangan')); + $is_enabled_to_use_mykad_reader = function () use($user_cawangan, $enabled_cawangan){ + + if(sizeof($enabled_cawangan) == 0){ + return true; + } + + if(sizeof($enabled_cawangan) == 1 && $enabled_cawangan[0] === ''){ + return true; + } + + return in_array($user_cawangan, $enabled_cawangan); + + }; + @endphp + + @if( $is_enabled_to_use_mykad_reader() ) + Baca MyKad + @endif @@ -61,6 +82,9 @@