diff --git a/app/BlastWasap.php b/app/BlastWasap.php new file mode 100644 index 0000000..f62b6de --- /dev/null +++ b/app/BlastWasap.php @@ -0,0 +1,19 @@ +kodcaw); + $daritempoh = $request->daritempoh; + $hinggatempoh = $request->hinggatempoh; + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first(); + + $audit = Gadai::on($cawangan['mysql']) + ->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=','']]) + ->orderBy('t_gadai', 'ASC') + ->orderBy('sirig', 'ASC'); + // ->get(); + // dd($audit); + $arraynorujukan = $audit->pluck('norujukan')->toArray(); + $rekodaudit = $audit->get(); + $gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan) + ->select('nokp') + ->groupBy('nokp') + ->get(); + + // dd($gadainokp); + + foreach($gadainokp as $index1=>$cal){ + $customer = Customer::on('mysql7')->where('kpbaru','=',$cal['nokp']) + ->orWhere('kplama','=',$cal['nokp']) + ->first(); + + $listsag = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan) + // ->where('nokp','=',$cal['nokp']) + ->where('nokp', 'like', '%'.$cal['nokp'].'%') + ->get(); + + foreach($listsag as $index2=>$cal2){ + + if($cal2){ + $checkingnokp = BlastWasap::on('mysql7') + ->where('nokp','=',$cal['nokp']) + ->where('norujukan','=',$cal2['norujukan']) + ->where('kodcaw','=',$kodcaw) + ->first(); + + // $gadainokp[$index1]['blasted'] = $checkingnokp; + + + } + } + + $gadainokp[$index1]['info'] = $customer; + $gadainokp[$index1]['listsag'] = $listsag; + $gadainokp[$index1]['blasted'] = $checkingnokp; + } + + $totalrekod = $audit->sum('pinjaman'); + $totalberat = $audit->sum('berat'); + $totalnilaimarhun = $audit->sum('nilaimarhun'); + $totalpinjaman = $audit->sum('pinjaman'); + $totalbakipjm = $audit->sum('bakipjm'); + $totaltunggakan = $audit->sum('tunggakan'); + + $arrayrekod = ['rekod' => $gadainokp, 'total' => $totalrekod,'totalberat' => $totalberat,'totalnilaimarhun' => $totalnilaimarhun,'totalpinjaman'=>$totalpinjaman,'totalbakipjm'=>$totalbakipjm,'totaltunggakan'=>$totaltunggakan]; + // dd($arrayrekod); + return response()->json($arrayrekod,200); + } + + + public function blastwasap($kodcaw,Request $request) + { + $current = Carbon::now(); + $current = new Carbon(); + $daritempoh = $request->daritempoh; + $hinggatempoh = $request->hinggatempoh; + $namapengguna = $request->namapengguna; + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first(); + $cawangan_detail = CawanganDetail::on($cawangan['mysql'])->first(); + $caw_name = $cawangan->details_caw; + $nofoncaw = $cawangan_detail->notel; + // dd($cawangan_detail->notel); + + $audit = Gadai::on($cawangan['mysql']) + ->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=','']]) + ->orderBy('t_gadai', 'ASC') + ->orderBy('sirig', 'ASC'); + // ->get(); + // dd($audit); + $rekodaudit = $audit->get(); + $arraynorujukan = $audit->pluck('norujukan')->toArray(); + $keybynorujukan = $rekodaudit->keyBy('norujukan'); + + $gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan) + ->select('nokp') + ->groupBy('nokp') + ->get(); + $gadai_all_groupby_nokp = $rekodaudit->groupBy('nokp'); + // dd($gadai_all_groupby_nokp); + + // dd($gadainokp); + + foreach($gadainokp as $index1=>$cal){ + // dd($cal->nokp); + if($gadai_all_groupby_nokp[$cal->nokp]){ + $gadainokp[$index1]['gadai'] = $gadai_all_groupby_nokp[$cal->nokp]; + } + // dd($gadainokp[$index1]['gadai'][$index1]['norujukan']); + + + $customer = Customer::on('mysql7')->where('kpbaru','=',$cal['nokp']) + ->orWhere('kplama','=',$cal['nokp']) + ->first(); + $nokp=$cal['nokp']; + + foreach($gadainokp[$index1]['gadai'] as $index1=>$cal3){ + + $checkingnokp = BlastWasap::on('mysql7') + ->where('nokp','=',$cal['nokp']) + ->where('norujukan','=',$cal3->norujukan) + ->where('kodcaw','=',$kodcaw) + ->first(); + + if(!$checkingnokp){ + + if($customer->telefon != 'null'){ + $telefon=$customer->telefon; + dispatch(new WhatsappPelangganSAGLAMA($nokp,$customer->telefon,$caw_name,$nofoncaw)); + } + + //insert log blast wasap + $logblastwasap = new BlastWasap(); + $logblastwasap->kodcaw = $kodcaw; + $logblastwasap->nokp = $nokp; + $logblastwasap->notelefon = $customer->telefon; + $logblastwasap->norujukan = $cal3->norujukan; + $logblastwasap->created_at = $current; + $logblastwasap->updated_at = $current; + $logblastwasap->save(); + + //log auditrail + $audit = new Audit(); + $audit->users = $namapengguna; + $audit->actions = 'Blast Whatsapp'; + $audit->norujukan = $cal3->norujukan; + $audit->new_data = 'BLAST WHATSAPP: '.$customer->telefon; + $audit->old_data = $nokp; + $audit->kodcaw = $kodcaw; + $audit->created_at = $current; + $audit->updated_at = $current; + $audit->save(); + + } + else{ + return response()->json('failed'); + } + } + } + return response()->json('success'); + + } + +} diff --git a/app/Jobs/WhatsappPelangganSAGLAMA.php b/app/Jobs/WhatsappPelangganSAGLAMA.php new file mode 100644 index 0000000..b002954 --- /dev/null +++ b/app/Jobs/WhatsappPelangganSAGLAMA.php @@ -0,0 +1,57 @@ +nokp = $nokp; + $this->telefon = $telefon; + $this->caw_name = $caw_name; + $this->nofoncaw = $nofoncaw; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + // $mobile_no = ltrim($this->telefon, '+6'); + $mobile_no = '60178916936'; + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, selaras penambahbaikan Sistem Ar-Rahn, Tuan/Puan diminta hadir ke premis *sebelum 15/7/2024* bagi menukar SAG dengan cara: + +1. Tebus +atau +2. Tebus Gadai Semula + +Hubungi '.$this->nofoncaw.'(Ar-Rahn '.$this->caw_name.') untuk maklumat lanjut.'; + if(env('APP_ENV') != 'production'){ + $mobile_no = env('ADMIN_PHONE_NUMBER'); + } + $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') + ]); + + Log::info("WABOT - Pelanggan SAG Tawarruq Lama".$response); + + } +} diff --git a/database/migrations/2023_11_15_155547_create_jobs_table.php b/database/migrations/2023_11_15_155547_create_jobs_table.php new file mode 100644 index 0000000..1be9e8a --- /dev/null +++ b/database/migrations/2023_11_15_155547_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'); + } +} diff --git a/database/migrations/2023_11_19_111428_create_log_blast_wasap.php b/database/migrations/2023_11_19_111428_create_log_blast_wasap.php new file mode 100644 index 0000000..b551dc8 --- /dev/null +++ b/database/migrations/2023_11_19_111428_create_log_blast_wasap.php @@ -0,0 +1,35 @@ +id(); + $table->string('kodcaw')->nullable(); + $table->string('nokp')->nullable(); + $table->string('notelefon')->nullable(); + $table->string('norujukan')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('log_blast_wasap'); + } +}