diff --git a/app/CawanganNotis.php b/app/CawanganNotis.php index 2fd67ca..388ad53 100644 --- a/app/CawanganNotis.php +++ b/app/CawanganNotis.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; class CawanganNotis extends Model { protected $table = 'cawangan_notis'; - public $timestamps = false; + public $timestamps = true; protected $primaryKey = 'id'; /** * The attributes that are mass assignable. diff --git a/app/Http/Controllers/CallCenterController.php b/app/Http/Controllers/CallCenterController.php index 46c600e..3f29f6f 100644 --- a/app/Http/Controllers/CallCenterController.php +++ b/app/Http/Controllers/CallCenterController.php @@ -36,8 +36,8 @@ use App\Jobs\SMSPelangganSAGLAMA; use Illuminate\Http\Request; use App\CawanganDetail; use App\BlastSMS; -use App\Jobs\WhatsappPelangganSAGLAMAbysag; -use App\Jobs\SMSPelangganSAGLAMAbysag; +use App\Jobs\ARCCWhatsappPelangganSAGLAMAbysag; +use App\Jobs\ARCCSMSPelangganSAGLAMAbysag; use App\Services\OnePercentServices; @@ -47,9 +47,22 @@ use Carbon\Carbon; class CallCenterController extends Controller { - public function showAllCawangans() + public function showAllCawangans(Request $request) { - return response()->json(Cawangan::on('mysql7')->orderBy('details_caw','ASC')->get()); + $daritempoh = $request->daritempoh; + $hinggatempoh = $request->hinggatempoh; + $checkcawangannotis = Cawangan::on('mysql7') + // ->whereNotExists(function($query) use($daritempoh,$hinggatempoh) + // { + // $query->select(DB::raw(1)) + // ->from('cawangan_notis') + // ->whereRaw('cawangan_notis.kodcaw = arrahn_master_db.kodcaw') + // ->where('daritempoh','=',$daritempoh) + // ->where('hinggatempoh','=',$hinggatempoh); + // } ) + ->orderBy('details_caw','ASC')->get(); + // dd($checkcawangannotis); + return response()->json($checkcawangannotis); } public function datagadai($kodcaw,Request $request) { @@ -58,7 +71,7 @@ class CallCenterController extends Controller $hinggatempoh = $request->hinggatempoh; $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); $datagadai = Gadai::on($cawangan['mysql']) - ->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0]]) + ->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]]) ->orderBy('t_gadai', 'ASC') ->orderBy('sirig', 'ASC'); // ->get(); @@ -100,7 +113,7 @@ class CallCenterController extends Controller // ]); $datagadai = Gadai::on($cawangan['mysql']) - ->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0]]) + ->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]]) ->orderBy('t_gadai', 'ASC') ->orderBy('sirig', 'ASC'); // ->get(); @@ -143,6 +156,11 @@ class CallCenterController extends Controller $notis_to_be_inserted->percent = $surat->percentpinj; $notis_to_be_inserted->peringatan = '1'; $notis_peringatan_arr[] = $notis_to_be_inserted->attributesToArray(); + + //updatetagnotisdlmgadai + $updateTagNotis = Gadai::on($cawangan['mysql'])->where('norujukan',$surat->norujukan)->update([ + 'tagnotis'=> 1 + ]); } $notis_peringatan_collection = collect($notis_peringatan_arr); @@ -214,31 +232,140 @@ class CallCenterController extends Controller public function getcawnotisbycaw(Request $request) { + $notisid = $request->notisid; $current = Carbon::now(); $current = new Carbon(); + $arraybatch = []; + $batchnotis = Notis::on('mysql7')->where('id',$notisid)->get(); + $cawangan_all = Cawangan::on('mysql7')->get(); + $cawnotis_all = []; + + $notis = CawanganNotis::on('mysql7') + ->join('arrahn_master_db', 'arrahn_master_db.kodcaw', '=', 'cawangan_notis.kodcaw') + ->where('notis_id',$notisid)->get(); + + foreach ($notis as $index => $cawangan){ + // dd($cawangan['kodcaw']); + // dd($cawangan); + $notisbycaw = NotisPeringatan::on('mysql7') + ->where('notisperingatan.notis_id',$notisid)->where('notisperingatan.kodcaw',$cawangan['kodcaw']) + ->distinct() + ->get(); + // dd($notisbycaw); + + $totalsag = $notisbycaw->count('norujukan'); + $totalbakipjm = $notisbycaw->sum('pinjaman'); + + // if(sizeof($notis) != 0){ + array_push($cawnotis_all,['namacaw' => $notis, 'detailbycaw' => $notisbycaw,'totalsag' =>$totalsag,'totalbakipjm' =>$totalbakipjm]); + // } + } + return response()->json($cawnotis_all); + } + + public function bycawnotisperingatan($kodcaw,$notisid) + { + $cawnotis_all = []; + + $notisbycaw = NotisPeringatan::on('mysql7') + ->where('notisperingatan.notis_id',$notisid)->where('notisperingatan.kodcaw',$kodcaw) + ->distinct() + ->get(); + + $notisbycawarray = $notisbycaw->toArray(); + + foreach($notisbycawarray as $index=>$cal){ + $customer = Customer::where('kpbaru','=',$cal['nokp']) + ->orWhere('kplama','=',$cal['nokp']) + ->first(); + + $notisbycawarray[$index]['namacust'] = $customer; + } + + array_push($notisbycawarray); + return response()->json($notisbycawarray); + } + + public function blastwasapbysag(Request $request) + { + // dd($request->all()); + $current = Carbon::now(); + $current = new Carbon(); $kodcaw = $request->kodcaw; $notisid = $request->notisid; - $arraybatch = []; - $batchnotis = CawanganNotis::on('mysql7')->where('id',$notisid)->where('kodcaw',$kodcaw)->get(); - $cawnotis_all = []; - foreach ($batchnotis as $index => $cawangan){ - $notis = NotisPeringatan::on('mysql7') - ->join('arrahn_master_db', 'arrahn_master_db.kodcaw', '=', 'notisperingatan.kodcaw') - ->join('cawangan_notis', 'cawangan_notis.kodcaw', '=', 'notisperingatan.kodcaw') - ->where('cawangan_notis.notis_id',$notisid)->where('cawangan_notis.kodcaw',$kodcaw)->get(); + $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; - $totalsag = $notis->count('norujukan'); - // dd($totalsag); - if(sizeof($notis) != 0){ - array_push($cawnotis_all,$notis); + $statusblast = CawanganNotis::where('notis_id','=',$notisid) + ->where('kodcaw','=',$kodcaw) + ->first(); + if($statusblast->status == '1'){ + + $notisbycaw = NotisPeringatan::on('mysql7') + ->where('notisperingatan.notis_id',$notisid)->where('notisperingatan.kodcaw',$kodcaw) + ->distinct() + ->get(); + + $arraynorujukan = $notisbycaw->pluck('norujukan')->toArray(); + + $gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan) + ->get(); + $gadai_all_groupby_nokp = $notisbycaw->groupBy('nokp'); + + foreach($gadainokp as $index1=>$cal){ + if($gadai_all_groupby_nokp[$cal->nokp]){ + $gadainokp[$index1]['gadai'] = $gadai_all_groupby_nokp[$cal->nokp]; + } + $customer = Customer::on('mysql7')->where('kpbaru','=',$cal['nokp']) + ->orWhere('kplama','=',$cal['nokp']) + ->first(); + $nokp=$cal['nokp']; + // dd($customer); + if($customer->telefon != 'null'){ + $telefon=$customer->telefon; + //log auditrail + $audit = new Audit(); + $audit->users = $namapengguna; + $audit->actions = 'ARCC Blast Whatsapp & SMS: Notis ID'.$notisid; + $audit->norujukan = $cal->norujukan; + $audit->new_data = $customer->telefon; + $audit->old_data = $nokp; + $audit->kodcaw = $kodcaw; + $audit->created_at = $current; + $audit->updated_at = $current; + $audit->save(); + + $today = $current->toDateString(); + $harini = date('Y-m-d',strtotime($today)); + + //update tarikh dlm table notisperingatan + $updatenotis=NotisPeringatan::on('mysql7') + ->where('norujukan','=', $cal->norujukan) + ->update( + array('tarikhnotis1'=> $harini)); + + dispatch(new ARCCWhatsappPelangganSAGLAMAbysag($nokp,$customer->telefon,$caw_name,$nofoncaw,$kodcaw,$cal->norujukan,$cal->tempoh,$cal->t_matang,$cal->t_matang1,$cal->lelong_tawarruq,$namapengguna)); + dispatch(new ARCCSMSPelangganSAGLAMAbysag($nokp,$customer->telefon,$caw_name,$nofoncaw,$kodcaw,$cal->norujukan,$cal->tempoh,$cal->t_matang,$cal->t_matang1,$cal->lelong_tawarruq,$namapengguna)); + } + } + + $updatestatusnotis=CawanganNotis::on('mysql7') + ->where('notis_id','=', $notisid) + ->where('kodcaw','=', $kodcaw) + ->update( + array('status'=> 2)); + + return response()->json('success'); + } + else{ + return response()->json('failed'); } - } - // dd($cawnotis_all); - $arrayrekod = ['rekod' => $cawnotis_all,'totalsag' =>$totalsag]; - return response()->json($arrayrekod); } diff --git a/app/Jobs/ARCCSMSPelangganSAGLAMAbysag.php b/app/Jobs/ARCCSMSPelangganSAGLAMAbysag.php new file mode 100644 index 0000000..e3270da --- /dev/null +++ b/app/Jobs/ARCCSMSPelangganSAGLAMAbysag.php @@ -0,0 +1,102 @@ +nokp = $nokp; + $this->telefon = $telefon; + $this->caw_name = $caw_name; + $this->nofoncaw = $nofoncaw; + $this->kodcaw = $kodcaw; + $this->norujukan = $norujukan; + $this->tempoh = $tempoh; + $this->tmatang = $tmatang; + $this->tmatang1 = $tmatang1; + $this->lelong_tawarruq = $lelong_tawarruq; + $this->namapengguna = $namapengguna; + + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $current = Carbon::now(); + $current = new Carbon(); + $mobile_no = ltrim($this->telefon, '+6'); + // $mobile_no = '60178916936'; + // $message = 'test'; + $tarikhmatang = $this->tmatang; + $tarikhmatangnew = date('d-m-Y',strtotime($tarikhmatang)); + $tarikhmatang1 = $this->tmatang1; + $tarikhmatang1new = date('d-m-Y',strtotime($tarikhmatang1)); + $today = $current->toDateString(); + // $current_date = new Carbon($current->toDateString()); + if($this->lelong_tawarruq == '1'){ + if($tarikhmatang > $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum '.$tarikhmatangnew.'.'; + }elseif($tarikhmatang < $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah tamat tempoh pada '.$tarikhmatangnew.', Sila perbaharui SAG anda di cawangan Ar-Rahn.';} + }else + if($tarikhmatang1 > $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum '.$tarikhmatang1new.'.'; + }elseif($tarikhmatang1 <= $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, '.$this->norujukan.' telah tamat tempoh pada '.$tarikhmatang1new.', Sila perbaharui SAG anda di cawangan Ar-Rahn.';} + + if(env('APP_ENV') != 'production'){ + $mobile_no = env('ADMIN_PHONE_NUMBER'); + } + $response = Http::get(env('ONEWAYSMS_API'), [ + 'apiusername' => env('ONEWAYSMS_AUTH_USER'), + 'apipassword' => env('ONEWAYSMS_AUTH_PASS'), + 'senderid' => 'INFO', + 'mobileno' => $mobile_no, + 'message' => $message, + 'languagetype' => 1 + ]); + + //insert log blast sms + $logblastsms = new BlastSMS(); + $logblastsms->kodcaw = $this->kodcaw; + $logblastsms->nokp = $this->nokp; + $logblastsms->notelefon = $this->telefon; + $logblastsms->norujukan = $this->norujukan; + $logblastsms->tempoh = $this->tempoh; + $logblastsms->status = $response; + $logblastsms->created_at = $current; + $logblastsms->updated_at = $current; + $logblastsms->nama = $this->namapengguna; + $logblastsms->save(); + + Log::info("ARCC SMS - Pelanggan ".$this->caw_name." SAG Tawarruq -".$mobile_no); + + } +} diff --git a/app/Jobs/ARCCWhatsappPelangganSAGLAMAbysag.php b/app/Jobs/ARCCWhatsappPelangganSAGLAMAbysag.php new file mode 100644 index 0000000..e4e7668 --- /dev/null +++ b/app/Jobs/ARCCWhatsappPelangganSAGLAMAbysag.php @@ -0,0 +1,101 @@ +nokp = $nokp; + $this->telefon = $telefon; + $this->caw_name = $caw_name; + $this->nofoncaw = $nofoncaw; + $this->kodcaw = $kodcaw; + $this->norujukan = $norujukan; + $this->tempoh = $tempoh; + $this->tmatang = $tmatang; + $this->tmatang1 = $tmatang1; + $this->lelong_tawarruq = $lelong_tawarruq; + $this->namapengguna = $namapengguna; + + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $current = Carbon::now(); + $current = new Carbon(); + $mobile_no = ltrim($this->telefon, '+6'); + // $mobile_no = '60178916936'; + $tarikhmatang = $this->tmatang; + $tarikhmatangnew = date('d-m-Y',strtotime($tarikhmatang)); + $tarikhmatang1 = $this->tmatang1; + $tarikhmatang1new = date('d-m-Y',strtotime($tarikhmatang1)); + $today = $current->toDateString(); + if($this->lelong_tawarruq == '1'){ + if($tarikhmatang > $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum *'.$tarikhmatangnew.'*.'; + }elseif($tarikhmatang <= $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah tamat tempoh pada *'.$tarikhmatangnew.'*, Sila perbaharui SAG anda di cawangan AR-RAHN.';} + }else + if($tarikhmatang1 > $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah hampir tamat tempoh untuk tukar ke SAG baru, Sila perbaharui SAG anda di cawangan sebelum *'.$tarikhmatang1new.'*.'; + }elseif($tarikhmatang1 <= $today){ + $message = 'AR-RAHN '.$this->caw_name.': MAKLUMAN, *'.$this->norujukan.'* telah tamat tempoh pada *'.$tarikhmatang1new.'*, Sila perbaharui SAG anda di cawangan Ar-Rahn.';} + + 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') + ]); + + + + //insert log blast wasap + $logblastwasap = new BlastWasap(); + $logblastwasap->kodcaw = $this->kodcaw; + $logblastwasap->nokp = $this->nokp; + $logblastwasap->notelefon = $this->telefon; + $logblastwasap->norujukan = $this->norujukan; + $logblastwasap->tempoh = $this->tempoh; + $logblastwasap->status = $response; + $logblastwasap->nama = $this->namapengguna; + $logblastwasap->save(); + + Log::info("ARCC WABOT - Pelanggan SAG Tawarruq".$response); + + } +} diff --git a/app/Notis.php b/app/Notis.php index 45c85e8..703a8ff 100644 --- a/app/Notis.php +++ b/app/Notis.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Notis extends Model { protected $table = 'notis'; - public $timestamps = false; + public $timestamps = true; protected $primaryKey = 'id'; /** * The attributes that are mass assignable. diff --git a/app/NotisPeringatan.php b/app/NotisPeringatan.php index 25df947..4173469 100644 --- a/app/NotisPeringatan.php +++ b/app/NotisPeringatan.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; class NotisPeringatan extends Model { protected $table = 'notisperingatan'; - public $timestamps = false; + public $timestamps = true; protected $primaryKey = 'id'; /** * The attributes that are mass assignable. diff --git a/database/migrations/2023_12_19_141108_add_onepercent_to_lelong_table.php b/database/migrations/2023_12_19_141108_add_onepercent_to_lelong_table.php new file mode 100644 index 0000000..3fb6b8f --- /dev/null +++ b/database/migrations/2023_12_19_141108_add_onepercent_to_lelong_table.php @@ -0,0 +1,79 @@ +getPdo(); + return true; + } catch(\Exception $e){ + return false; + } + }); + return $db_connection; + } + + public function up() + { + $db_connection = $this->getActiveDB(); + + foreach($db_connection as $dbase){ + Schema::connection($dbase)->table('lelong', function (Blueprint $table) use($dbase) { + + $isUjrahExist = Schema::connection($dbase)->hasColumn('lelong', 'ujrah'); + $isOnePercentExist = Schema::connection($dbase)->hasColumn('lelong', 'onepercent'); + $isTagbaruExist = Schema::connection($dbase)->hasColumn('lelong', 'tagujrah'); + + + if(! $isUjrahExist){ + $table->decimal('ujrah', 9, 2); + } + + if(! $isOnePercentExist){ + $table->decimal('onepercent', 9, 2); + } + + if(! $isTagbaruExist){ + $table->tinyInteger('tagujrah')->default(0); + } + + }); + } + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $db_connection = $this->getActiveDB(); + + foreach($db_connection as $dbase){ + $columns = ['ujrah', 'onepercent','tagujrah']; + + + $columns_exist = array_filter($columns,function($column) use($dbase){ + return Schema::connection($dbase)->hasColumn('lelong', $column); + }); + + Schema::connection($dbase)->table('lelong', function(Blueprint $table) use($columns_exist){ + foreach($columns_exist as $column){ + $table->dropColumn($column); + } + }); + } + } +} diff --git a/database/migrations/2023_12_24_120200_add_tagnotis_to_gadai_table.php b/database/migrations/2023_12_24_120200_add_tagnotis_to_gadai_table.php new file mode 100644 index 0000000..40ddceb --- /dev/null +++ b/database/migrations/2023_12_24_120200_add_tagnotis_to_gadai_table.php @@ -0,0 +1,69 @@ +getPdo(); + return true; + } catch(\Exception $e){ + return false; + } + }); + return $db_connection; + } + + public function up() + { + $db_connection = $this->getActiveDB(); + + foreach($db_connection as $dbase){ + Schema::connection($dbase)->table('gadai', function (Blueprint $table) use($dbase) { + + $isTagNotisExist = Schema::connection($dbase)->hasColumn('gadai', 'tagnotis'); + + + if(! $isTagNotisExist){ + $table->tinyInteger('tagnotis')->default(0); + } + + }); + } + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $db_connection = $this->getActiveDB(); + + foreach($db_connection as $dbase){ + $columns = ['tagnotis']; + + + $columns_exist = array_filter($columns,function($column) use($dbase){ + return Schema::connection($dbase)->hasColumn('gadai', $column); + }); + + Schema::connection($dbase)->table('gadai', function(Blueprint $table) use($columns_exist){ + foreach($columns_exist as $column){ + $table->dropColumn($column); + } + }); + } + } +} \ No newline at end of file diff --git a/database/migrations/2023_12_24_170256_add_nama_to_table_log_blast_wasap.php b/database/migrations/2023_12_24_170256_add_nama_to_table_log_blast_wasap.php new file mode 100644 index 0000000..46adddd --- /dev/null +++ b/database/migrations/2023_12_24_170256_add_nama_to_table_log_blast_wasap.php @@ -0,0 +1,32 @@ +text('nama')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('log_blast_wasap', function (Blueprint $table) { + $table->dropColumn(['nama']); + }); + } +} diff --git a/database/migrations/2023_12_25_140355_add_nama_to_table_log_blast_sms.php b/database/migrations/2023_12_25_140355_add_nama_to_table_log_blast_sms.php new file mode 100644 index 0000000..2256757 --- /dev/null +++ b/database/migrations/2023_12_25_140355_add_nama_to_table_log_blast_sms.php @@ -0,0 +1,34 @@ +text('nama')->nullable(); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('log_blast_sms', function (Blueprint $table) { + $table->dropColumn(['nama']); + + }); + } +} diff --git a/routes/web.php b/routes/web.php index c449fee..6e941dc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -839,5 +839,7 @@ $router->group(['prefix'=>'arcc'], function () use ($router){ $router->get('senarainotisperingatan',['uses'=>'CallCenterController@senarainotisperingatan']); $router->get('getcawnotis/{notisid}',['uses'=>'CallCenterController@getcawnotis']); $router->get('getcawnotisbycaw',['uses'=>'CallCenterController@getcawnotisbycaw']); + $router->get('bycawnotisperingatan/{kodcaw}/{notisid}',['uses'=>'CallCenterController@bycawnotisperingatan']); + $router->post('blastwasapbysag',['uses'=>'CallCenterController@blastwasapbysag']); });