From 4d1ce79e690fc496a25f5468b3ed60e85d9ad578 Mon Sep 17 00:00:00 2001 From: Nur Izzati Zulkifli Date: Tue, 2 May 2023 14:15:10 +0800 Subject: [PATCH] add jobs blast wabot notifikasi notis peringatan --- app/Http/Controllers/NotisController.php | 26 ++- app/Jobs/SendWabot.php | 183 ++++++++++++++++++ .../2023_04_18_100347_create_jobs_table.php | 36 ++++ 3 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 app/Jobs/SendWabot.php create mode 100644 database/migrations/2023_04_18_100347_create_jobs_table.php diff --git a/app/Http/Controllers/NotisController.php b/app/Http/Controllers/NotisController.php index fc171e4e..dde6d14c 100644 --- a/app/Http/Controllers/NotisController.php +++ b/app/Http/Controllers/NotisController.php @@ -27,6 +27,7 @@ use App\Models\TransaksiKeuntungan; use App\Models\LelongTebus; use App\Models\LogUser; use Illuminate\Support\Facades\Log; +use App\Jobs\SendWabot; use Carbon\Carbon; @@ -1000,7 +1001,7 @@ class NotisController extends Controller return redirect()->route('notisperingatan.jananotisperingatan')->with('failed','Tiada surat untuk di jana'); } - return redirect()->route('notisperingatan.shownotisperingatan',$notis->id); + return redirect()->route('notisperingatan.shownotisperingatanall',['tarikhnotis'=>$tarikh_notis,'notisid'=>$notis->id]); // return redirect()->route('analisa.senaraisimulasi')->with('success',"Success daftar simulasi!"); } @@ -1531,7 +1532,7 @@ public function jananotisperingatan2($notisid,$cawid) return $pdf->download('Penjanaan Notis Peringatan Fasa 2 ' . $notisid . '.pdf'); } - public function blastnotisperingatan($notisid,$cawid) + public function blastnotisperingatan1($notisid,$cawid) { $user = Auth::user(); $caw = Cawangan::where('id', '=', $cawid)->first(); @@ -1616,7 +1617,7 @@ public function jananotisperingatan2($notisid,$cawid) $message = '*NOTIS PEMBERITAHUAN* Nama: *'.$nama.'* -No.KP:'.$suratnotis->nokp.''.' +No.KP: *'.$suratnotis->nokp.'*'.' No.Rujukan: *'.$suratnotis->norujukan.'* Baki Pembiayaan: *RM'.$bakipjm.'*'.' Tarikh Matang: *'.$t_matangf1.'* @@ -1671,6 +1672,25 @@ Sekian, terima kasih.'; return redirect()->route('notisperingatan.shownotisperingatanall',[$notis->tarikh_notis,$notisid]) ->with('success','Kemaskini Berjaya'); } + + public function blastnotisperingatan($notisid,$cawid) + { + $user = Auth::user(); + $caw = Cawangan::where('id', '=', $cawid)->first(); + + $currentdate = Carbon::now(); + $tarikh_cetak = $currentdate->toDateString(); + + $notis = Notis::find($notisid); + $this->dispatch(new SendWabot($notisid,$cawid)); + + $updatestatus = CawanganNotis::where('notis_id', '=', $notisid)->where('caw_id', '=', $cawid)->first(); + $updatestatus->status = '3'; //blastwabot + $updatestatus->save(); + + return redirect()->route('notisperingatan.shownotisperingatanall',[$notis->tarikh_notis,$notisid]) + ->with('success','Kemaskini Dalam Proses'); + } diff --git a/app/Jobs/SendWabot.php b/app/Jobs/SendWabot.php new file mode 100644 index 00000000..ffb59eac --- /dev/null +++ b/app/Jobs/SendWabot.php @@ -0,0 +1,183 @@ +notisid = $notisid; + $this->cawid = $cawid; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Artisan::call('queue:work', []); + + // $user = Auth::user(); + $caw = Cawangan::where('id', '=', $this->cawid)->first(); + + $currentdate = Carbon::now(); + $tarikh_cetak = $currentdate->toDateString(); + + $notis = Notis::find($this->notisid); + // dd($notis->tarikh_notis); + $notis_bid_all = NotisBid::select('id','nokp','norujukan','jbg','pinjaman','fasa')->where('notis_id', $this->notisid)->where('kodcaw', $caw->caw_code)->get(); + $arraynorujukan_notis_bid_all = NotisBid::where('notis_id', $this->notisid)->where('kodcaw', $caw->caw_code)->pluck('norujukan'); + + $arraynorujukan = NotisBid::where('notis_id', $this->notisid)->where('kodcaw', $caw->caw_code)->pluck('norujukan'); + $gadai_all = Gadai::on($caw->caw_code)->whereIn('norujukan', $arraynorujukan)->select('nokp', 'norujukan','bakipjm','t_matang','t_matang1','tempoh')->orderBy('nokp', 'asc')->get(); + + $customers_list = $gadai_all->pluck('nokp')->unique(); + $customers = Customer::whereIn('kpbaru', $customers_list) + ->orWhereIn('kplama', $customers_list) + ->select('id','kpbaru','kplama' ,'nama', 'telefon') + ->get()->keyBy('id'); + + $customers_keyBy_noKp = $customers->keyBy(function ($item) { + if ($item->kpbaru != '') { + return $item->kpbaru; + } else if ($item->kplama != '') { + return $item->kplama; + } + }); + + $customers_pluck_notel = $customers_keyBy_noKp->pluck('telefon'); + // dd($customers_pluck_notel); + foreach($customers_pluck_notel as $index1 =>$custphone) { + // dd($custphone); + $special = preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $custphone); + // dump($special); + if($special == 0){ + if($custphone == ''){ + $newtel = ''; + }elseif($custphone <> ''){ + $newtel = '6'.$custphone; + } + } + elseif($special == 1){ + if($custphone == ''){ + $newtel = ''; + }elseif($custphone <> ''){ + $newtel = '6'.str_replace( array( '-' ), '', $custphone); + } + } + // dump($newtel); + + } + $notis_bid_all_groupby_norujukan = $notis_bid_all->groupBy('norujukan'); + $notis_all_keyBy_norujukan = $gadai_all->keyBy('norujukan'); + foreach($notis_bid_all_groupby_norujukan as $index7=>$notisbid){ + // dd($notis_all_keyBy_norujukan); + if($notis_all_keyBy_norujukan[$index7]){ + + $gadai_true = $notis_all_keyBy_norujukan[$index7]; + $gadai_true['data_notisbid'] = $notisbid; + } + + } + // dd($gadai_all); + foreach ($gadai_all as $index => $suratnotis) { + $datanotisbid = $suratnotis['data_notisbid'][0]->fasa; + // dd($suratnotis); + if($customers_keyBy_noKp[$suratnotis->nokp]) + { + $mobile_no = '60178916936'; + // $mobile_no = $newtel; + $user_true = $customers_keyBy_noKp[$suratnotis->nokp]; + $nama = $user_true->nama; + $bakipjm = number_format($suratnotis->bakipjm, 2, '.', ','); + $t_matang = Carbon::parse($suratnotis->t_matang); + $t_matang1 = Carbon::parse($suratnotis->t_matang1); + $t_matangf1 = $t_matang->format('d-m-Y'); + $t_matangf2 = $t_matang1->format('d-m-Y'); + $cawname = $caw->caw_name; + // dd($t_matang1); + if( $datanotisbid == '1'){ + $message = '*NOTIS PEMBERITAHUAN* + +Nama: *'.$nama.'* +No.KP: *'.$suratnotis->nokp.'*'.' +No.Rujukan: *'.$suratnotis->norujukan.'* +Baki Pembiayaan: *RM'.$bakipjm.'*'.' +Tarikh Matang: *'.$t_matangf1.'* +Tempoh: *'.$suratnotis->tempoh.' bulan* + +Tuan/puan atau wakil adalah dikehendaki menebus/membayar *KOS KEUNTUNGAN* tersebut secepat mungkin. Jika pihak tuan/puan menghadapi sebarang masalah, sila hubungi kami sebagaimana alamat di dalam *Surat Akaun Gadaian* ATAU datang sendiri ke *'.$cawname.'* dengan membawa bersama salinan asal Surat Akaun Gadaian tuan/puan. +Sekian, terima kasih.'; + } + else if( $datanotisbid == '2'){ + $message = '*NOTIS PEMBERITAHUAN* + +Nama: *'.$nama.'* +No.KP: *'.$suratnotis->nokp.'* +No.Rujukan: *'.$suratnotis->norujukan.'* +Baki Pembiayaan: *RM'.$bakipjm.'*'.' +Tarikh Tamat Kontrak: *'.$t_matangf2.'* +Tempoh: *'.$suratnotis->tempoh.' bulan*. + +Tuan/puan atau wakil adalah dikehendaki menebus/membayar *KOS KEUNTUNGAN* tersebut secepat mungkin. Jika pihak tuan/puan menghadapi sebarang masalah, sila hubungi kami sebagaimana alamat di dalam *Surat Akaun Gadaian* ATAU datang sendiri ke *'.$cawname.'* dengan membawa bersama salinan asal Surat Akaun Gadaian tuan/puan. +Sekian, terima kasih.'; + + + } + // dd($message); + // $message = 'Hello%20Nadine%0Ahow%20are%20you%0A'; + $response = Http::get(env('WABOT_API'), [ + 'number' => $mobile_no, + 'type' => 'text', + 'message' => $message, + 'instance_id' => env('WABOT_INSTANCES_ID'), + 'access_token' => env('WABOT_TOKEN_KEYS') + ]); + + $res_json = $response->json(); + if ($res_json['status'] == "error") { + $message = "WABOT: " . $res_json['message'] . " - " . $res_json['data']; + Log::error($message); + } else { + $message = "WABOT: Success " . $res_json['data']['key']['remoteJid'] . " - " . $res_json['data']['message']['extendedTextMessage']['text']; + Log::info($message); + } + } + // dd($suratnotis['data_notisbid'][$index]); + } + + // $updatestatus = CawanganNotis::where('notis_id', '=', $this->notisid)->where('caw_id', '=', $this->cawid)->first(); + // $updatestatus->status = '3'; //blastwabot + // $updatestatus->save(); + } +} diff --git a/database/migrations/2023_04_18_100347_create_jobs_table.php b/database/migrations/2023_04_18_100347_create_jobs_table.php new file mode 100644 index 00000000..1be9e8a8 --- /dev/null +++ b/database/migrations/2023_04_18_100347_create_jobs_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs'); + } +}