176 lines
6.8 KiB
PHP
176 lines
6.8 KiB
PHP
<?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 WhatsappNotisPeringatanKedua implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $user_id;
|
|
public $user_kodcaw;
|
|
protected $notisid;
|
|
protected $cawid;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($user_id, $user_kodcaw, $notisid,$cawid)
|
|
{
|
|
$this->user_id = $user_id;
|
|
$this->user_kodcaw = $user_kodcaw;
|
|
$this->notisid = $notisid;
|
|
$this->cawid = $cawid;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
// $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/tukar surat di premis kami dengan kadar yang segera. 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.';
|
|
|
|
|
|
}
|
|
if(config('app.env') != 'production'){
|
|
$mobile_no = config('app.admin_phone_number');
|
|
}
|
|
$response = Http::get(config('app.wabot_api'), [
|
|
'number' => $mobile_no,
|
|
'type' => 'text',
|
|
'message' => $message,
|
|
'instance_id' => config('app.wabot_instances_id'),
|
|
'access_token' => config('app.wabot_token_keys')
|
|
]);
|
|
|
|
Log::info("WABOT - notis peringatan kedua " . $response);
|
|
}
|
|
sleep(2);
|
|
}
|
|
}
|
|
}
|