169 lines
6.1 KiB
PHP
169 lines
6.1 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\Lelong;
|
|
use App\Models\LelongCawangan;
|
|
use App\Models\LelongBid;
|
|
use App\Models\Gadai;
|
|
use App\Models\Customer;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Models\CawanganLelong;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
class WhatsappNotisTuntutBaki implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $user_id;
|
|
public $user_kodcaw;
|
|
protected $lelong_id;
|
|
protected $caw_id;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($user_id, $user_kodcaw, $lelong_id,$caw_id)
|
|
{
|
|
$this->user_id = $user_id;
|
|
$this->user_kodcaw = $user_kodcaw;
|
|
$this->lelong_id = $lelong_id;
|
|
$this->caw_id = $caw_id;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
// $user = Auth::user();
|
|
$caw = Cawangan::where('id', '=', $this->caw_id)->first();
|
|
|
|
$currentdate = Carbon::now();
|
|
|
|
$lel = Lelong::with('cawangan')->find($this->lelong_id);
|
|
|
|
$cawanganDetail = $lel->cawangan->find($this->caw_id);
|
|
$lelong_id = $this->lelong_id;
|
|
$cawangan = Cawangan::with(["lelongBid" => function($q) use ($lelong_id){
|
|
$q->where('lelong_id', '=', $lelong_id)->select('id','caw_id','kodcaw','norujukan','pinjaman','bakiupah','hargaasas','nilaimarhun','cajlelong','baki');
|
|
}])
|
|
->where('caw_code','=',$cawanganDetail->caw_code)->first();
|
|
$lelongbid_data_pluck_norujukan = $cawangan->lelongBid->pluck('norujukan')->toArray();
|
|
$gadai_all = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $lelongbid_data_pluck_norujukan)
|
|
->join('gadai','gadai.norujukan','=','lelong.norujukan')
|
|
->where('trkhtuntut','=',null)
|
|
->where('baki','>', '0.00')
|
|
->select('nokp', 'lelong.norujukan','lelong.t_lelong AS tarikhlelong','lelong.hargajual','lelong.gst_hj','gadai.bakipjm','lelong.bakiupah','lelong.cajlelong','lelong.gst_cl','lelong.cajlain','lelong.baki')
|
|
->orderBy('nokp', 'asc')
|
|
->orderBy('lelong.norujukan','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);
|
|
|
|
}
|
|
$lelong_bid_all_groupby_norujukan = $gadai_all->groupBy('norujukan');
|
|
$lelong_all_keyBy_norujukan = $gadai_all->keyBy('norujukan');
|
|
foreach($lelong_bid_all_groupby_norujukan as $index7=>$lelongbid){
|
|
// dd($notis_all_keyBy_norujukan);
|
|
if($lelong_all_keyBy_norujukan[$index7]){
|
|
|
|
$gadai_true = $lelong_all_keyBy_norujukan[$index7];
|
|
$gadai_true['data_lelongbid'] = $lelongbid;
|
|
}
|
|
|
|
}
|
|
// dd($gadai_all);
|
|
foreach ($gadai_all as $index => $suratnotis) {
|
|
$datanotisbid = $suratnotis['data_lelongbid'][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;
|
|
$baki = number_format($suratnotis->baki, 2, '.', ',');
|
|
$t_jual = Carbon::parse($suratnotis->t_jual);
|
|
$t_jualf1 = $t_jual->format('d-m-Y');
|
|
$cawname = $caw->caw_name;
|
|
$parabaki2 = $caw->parabaki2;
|
|
// dd($t_matang1);
|
|
$message = '*NOTIS MAKLUMAN LEBIHAN WANG LELONGAN BARANGAN*
|
|
|
|
Nama: *'.$nama.'*
|
|
No.KP: *'.$suratnotis->nokp.'*'.'
|
|
No.Rujukan: *'.$suratnotis->norujukan.'*
|
|
Tarikh Lelong: *'.$t_jualf1.'*
|
|
Wang Lebihan: *RM'.$baki.'*'.'
|
|
|
|
'.$parabaki2. ' *'.$cawname.'*.
|
|
|
|
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 Tuntutan Baki Lelong" . $response);
|
|
}
|
|
sleep(2);
|
|
}
|
|
}
|
|
}
|