diff --git a/app/Events/Teller/NotifyDeposit.php b/app/Events/Teller/NotifyDeposit.php new file mode 100644 index 0000000..a10bc46 --- /dev/null +++ b/app/Events/Teller/NotifyDeposit.php @@ -0,0 +1,34 @@ +jenis = $jenis; + $this->cawangan = $cawangan; + $this->kodlaluan = $kodlaluan; + } + + public function broadcastOn() + { + return ['notify-deposit']; + } + + public function broadcastAs() + { + return 'deposit-event'; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/EventTriggerController.php b/app/Http/Controllers/EventTriggerController.php new file mode 100644 index 0000000..37803d3 --- /dev/null +++ b/app/Http/Controllers/EventTriggerController.php @@ -0,0 +1,20 @@ +middleware('auth'); + } + + public function TellerCash(){ + event(new NotifyDeposit("pendahuluan",Auth::user()->cawangan,Auth::user()->name)); + } + + +} diff --git a/app/Http/Controllers/KhazanahController.php b/app/Http/Controllers/KhazanahController.php index c288fa2..5d2f2d3 100644 --- a/app/Http/Controllers/KhazanahController.php +++ b/app/Http/Controllers/KhazanahController.php @@ -1295,140 +1295,16 @@ class KhazanahController extends Controller { $peti_besi_terkini=Http::withOptions(['verify' => config('app.api_verify')])->post(config('api.url').'/api/daftarVault/'.$auth_user['cawangan'])->json(); } - - $amount = $request->amt; - - $tarikh=$request->tarikh; - $kodlaluan=$request->teller; - - $kurang=$request->amt; - $nota=$request->nota; - $kodcaw=$auth_user['cawangan']; - $tambahT = 0; - $kurangvault = $request->amt; - - $addTunai=Http::withOptions(['verify' => config('app.api_verify')])->post(config('api.url').'/api/add/addTunai/'.$auth_user['cawangan'],[ - 'kodcaw'=>$kodcaw, - 'kodlaluan'=>$kodlaluan, - 'tambah'=>$tambahT, - 'kurang'=>$kurang, - 'nota'=>$nota]); - - $getTunai=Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/GetCurrentTunai/'.$auth_user['cawangan'],['kodlaluan' => $kodlaluan])->json(); - - if(sizeof($getTunai) == 0) - { - // dd($getTunai); - } - else - { - $getTunai2=Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/GetCurrentTunai/'.$auth_user['cawangan'],['kodlaluan' => $kodlaluan])->json(); - $bakiAwalT=$getTunai2['bakiawal']; - $keluarT=$getTunai2['keluar']; - $baki=$getTunai2['baki']; - $tambahT=$getTunai2['tambah']; - $kurangT=$getTunai2['kurang']; - $masukT=$getTunai2['masuk']; - - $serahanakhir = $kurang; - $tambah_T=0;$kurang_T=0;$baki_AwalT=0.0; - - if($tambahT==0) - $tambah_T=0; - - else - $tambah_T=$tambahT; - - - if($kurangT==0) - $kurang_T=$kurang; - - else - { - $kurang=$kurang+$kurangT; - $kurang_T=$kurang; - } - - if($bakiAwalT==0) - $baki_AwalT=0; - - else - $baki_AwalT=$bakiAwalT; - - //$bakiAkhirT=$baki_AwalT+$tambah_T+$masukT-$keluarT-$kurang_T; //untuk kegunaan urgent - $bakiAkhirT = $baki - $serahanakhir; - - $updateTunai=Http::withOptions(['verify' => config('app.api_verify')])->put( config('api.url').'/api/updateTunai/'.$auth_user['cawangan'], [ - 'kodlaluan'=>$kodlaluan, - 'tambah'=>$tambah_T, - 'kurang'=>$kurang_T, - 'bakiakhir'=>$bakiAkhirT - ]); - - - $latestVault=Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/VaultController/'.$auth_user['cawangan'])->json(); - - $masukV=$latestVault[0]['masuk']; - $keluarV=$latestVault[0]['keluar']; - $pendahuluanV=$latestVault[0]['pendahuluan']; - $serahanV=$latestVault[0]['serahan']; - $bakiAwalV=$latestVault[0]['bakiawal']; - $totpanjar = $latestVault[0]['totpanjar']; - - - $masuk_V = 0;$pendahuluan_V = 0;$keluar_V = 0;$serahan_V = 0; - - if($masukV == 0) - { - $masuk_V = 0 + $kurangvault; - } - else - { - $masuk_V = $masukV + $kurangvault; - } - - if($keluarV == 0) - $keluar_V = 0; - - else - $keluar_V=$keluarV; - - - if($pendahuluanV == 0) - $pendahuluan_V = 0; - - else - $pendahuluan_V = $pendahuluanV; - - - if($serahanV == 0) - $serahan_V = 0; - - else - $serahan_V = $serahanV; - - } - - $GetLatestBakiTunai=Http::withOptions(['verify' => config('app.api_verify')])->get( config('api.url').'/api/getLatestBaki/'.$auth_user['cawangan'])->json(); - $sumBaki=$GetLatestBakiTunai; - - - $bakiAkhirV = $bakiAwalV - $keluar_V + $masuk_V + $pendahuluan_V - $serahan_V - $totpanjar; - - $BakiEOD=$bakiAkhirV; - //$BakiEOD=$bakiAkhirV+$sumBaki; - - $updateVault=Http::withOptions(['verify' => config('app.api_verify')])->put( config('api.url').'/api/UpdateVault/'.$auth_user['cawangan'],[ - 'masuk'=>$masuk_V, - 'keluar'=>$keluar_V, - 'bakiawal'=>$bakiAwalV, - 'bakiakhir'=>$bakiAkhirV, - 'bakieod'=>$BakiEOD - ]); - - //--FINAL RESULT...KENA RIDERECT KE PAGE SEBELUMNYA.. - - return $this->denominasicalculationserahan($request); + $response_data = $request->except('_token'); + $test = Http::withOptions(['verify' => config('app.api_verify')])->post(config('api.url').'/api/test/serahantunai/'.$auth_user['cawangan'],$response_data)->json(); + + if($test == 'success'){ + event(new PendahuluanSerahan("Lulus","serahan",$auth_user['cawangan'],$request->teller)); + return redirect()->route('khazanah.serahan'); + }else{ + return redirect()->route('khazanah.serahan')->with('error','Permohonan tidak berjaya! Permohonan Semula perlu melebihi 1 minit.'); + } + } diff --git a/public/css/main.css b/public/css/main.css index 7c3b343..5baef76 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -94,3 +94,22 @@ span#basic-hargaemas { padding: 5px 10px; text-align: center; } + + @keyframes heartbeat { + 0% { + transform: scale(1); + } + 30% { + transform: scale(1.2); + } + 60% { + transform: scale(1); + } + 100% { + transform: scale(1); + } +} + +.heartbeat { + animation: heartbeat 1s infinite; +} diff --git a/public/js/Class/SubscribePusher.js b/public/js/Class/SubscribePusher.js new file mode 100644 index 0000000..7778361 --- /dev/null +++ b/public/js/Class/SubscribePusher.js @@ -0,0 +1,16 @@ +class SubscribePusher { + constructor(subscribe, event, apikey) { + this.subscribe = subscribe; + this.event = event; + this.apikey = apikey; + } + + channel_subscribe() { + let channel = pusher.subscribe(this.subscribe); + channel.bind(this.event, function(data){ + callback(data); + }); + } +} + +export default SubscribePusher; \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index a4fb40b..d40633b 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -434,6 +434,17 @@ async function openuptambahdanserah(e) } else { + $.ajax({ + method: "GET", + url: "{{ route('event.tellercash') }}", + success:function(data){ + console.log('successfull trigger'); + }, + error: function(xhRequest, ajaxOptions, thrownError){ + console.log(xhRequest,thrownError); + } + }) + $.ajax({ method:"POST", url: api_url + '/api/requestTeller/' + kodcaw, @@ -589,6 +600,14 @@ function tambahdanserahanfunc(e) if(id == "serahanmodal") { + $.ajax({ + method: "GET", + url: "{{ route('event.tellercash') }}", + success:function(data){ + console.log('successfull trigger'); + } + }) + $.ajax({ method:"POST", url: api_url + '/api/requestTeller/' + kodcaw, diff --git a/public/js/notification.js b/public/js/notification.js new file mode 100644 index 0000000..c585000 --- /dev/null +++ b/public/js/notification.js @@ -0,0 +1,75 @@ +import NotifyKhazanah from './Class/SubscribePusher.js'; + +let channel = 'notify-deposit'; +let event = 'deposit-event'; +let apikey = "{{ env('PUSHER_APP_KEY') }}"; +let api = "{{ config('api.url') }}"; +let kodcaw = "{{ Auth::user()->kodcaw }}"; + +let requestApi = (url, method, datarequest, callback) => { + $.ajax({ + method: method, + url: url, + data: datarequest, + success: function(data) { + callback(data); + }, + error: function(xhRequest, ajaxOptions, thrownError) { + console.error("Request failed:", xhRequest, thrownError); + } + }); +}; + +let triggerPage = () =>{ + const notify = new NotifyKhazanah(channel,event,apikey); + notify.channel_subscribe((data) => { + console.log(data); + + const currentPath = window.location.pathname; + + if (currentPath === "/home") { + notify_main(); + } else if (currentPath === "/menu") { + notify_khazanah_main(); + }else if(currentPath === '/pendahuluan'){ + notify_pendahuluan(); + }else if(currentPath === '/serahan'){ + notify_serahan(); + } + + }); +} + +let notify_main = () =>{ + const button = document.getElementById("btn-khazanah"); + + if(!button){ + return; + } + + button.classList.add('btn-danger'); + button.classList.add('heartbeat'); +} + +let notify_khazanah_main = () =>{ + requestApi(api + '/api/requestTeller/get/' + kodcaw,"GET",{}, (response) =>{ + let countModal = 0; + let countSerahan = 0; + + response.forEach((req) => { + if (req.modal !== 0) { + countModal++; + } else if (req.serahan !== 0) { + countSerahan++; + } + }); + }); +} + +let notify_pendahuluan = () =>{ + +} + +let notify_serahan = () =>{ + +} diff --git a/resources/views/homepage/khazanah/home.blade.php b/resources/views/homepage/khazanah/home.blade.php index bcb1270..66578f8 100644 --- a/resources/views/homepage/khazanah/home.blade.php +++ b/resources/views/homepage/khazanah/home.blade.php @@ -255,6 +255,7 @@