Merge branch 'atie' into 'main'

add jobs blast wabot notifikasi notis peringatan

See merge request online-sistem1/lelong!443
This commit is contained in:
Nur Izzati Zulkifli
2023-05-02 06:18:55 +00:00
3 changed files with 242 additions and 3 deletions
+23 -3
View File
@@ -27,6 +27,7 @@ use App\Models\TransaksiKeuntungan;
use App\Models\LelongTebus; use App\Models\LelongTebus;
use App\Models\LogUser; use App\Models\LogUser;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use App\Jobs\SendWabot;
use Carbon\Carbon; 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.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!"); // 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'); return $pdf->download('Penjanaan Notis Peringatan Fasa 2 ' . $notisid . '.pdf');
} }
public function blastnotisperingatan($notisid,$cawid) public function blastnotisperingatan1($notisid,$cawid)
{ {
$user = Auth::user(); $user = Auth::user();
$caw = Cawangan::where('id', '=', $cawid)->first(); $caw = Cawangan::where('id', '=', $cawid)->first();
@@ -1616,7 +1617,7 @@ public function jananotisperingatan2($notisid,$cawid)
$message = '*NOTIS PEMBERITAHUAN* $message = '*NOTIS PEMBERITAHUAN*
Nama: *'.$nama.'* Nama: *'.$nama.'*
No.KP:'.$suratnotis->nokp.''.' No.KP: *'.$suratnotis->nokp.'*'.'
No.Rujukan: *'.$suratnotis->norujukan.'* No.Rujukan: *'.$suratnotis->norujukan.'*
Baki Pembiayaan: *RM'.$bakipjm.'*'.' Baki Pembiayaan: *RM'.$bakipjm.'*'.'
Tarikh Matang: *'.$t_matangf1.'* Tarikh Matang: *'.$t_matangf1.'*
@@ -1671,6 +1672,25 @@ Sekian, terima kasih.';
return redirect()->route('notisperingatan.shownotisperingatanall',[$notis->tarikh_notis,$notisid]) return redirect()->route('notisperingatan.shownotisperingatanall',[$notis->tarikh_notis,$notisid])
->with('success','Kemaskini Berjaya'); ->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');
}
+183
View File
@@ -0,0 +1,183 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\Cawangan;
use Carbon\Carbon;
use App\Models\Notis;
use App\Models\NotisBid;
use App\Models\Gadai;
use App\Models\Customer;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
use App\Models\CawanganNotis;
use Illuminate\Support\Facades\Artisan;
class SendWabot implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $notisid;
protected $cawid;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($notisid,$cawid)
{
$this->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();
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->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');
}
}