cron lelong

This commit is contained in:
Afiq
2023-01-10 11:58:00 +08:00
parent 05f85e7e4a
commit 0f21b09fee
3 changed files with 762 additions and 563 deletions
+158
View File
@@ -0,0 +1,158 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Model\LelongBid;
use App\Model\Gadai;
use Carbon\Carbon;
use App\Model\TransaksiKeuntungan;
use App\Model\LelongTebus;
use App\Model\LogUser;
use App\Model\User;
class kemaskiniLelong extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kemaskini:lelong';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Kemaskini data lelong';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$currentdate = Carbon::now();
$currentdate = $currentdate->toDateTimeString();
$data = [];
$lelongbids = LelongBid::where('status_jual',0)->get();
foreach($lelongbids as $index=>$lelongbid){
$gadai = Gadai::on($lelongbid->kodcaw)->where('norujukan',$lelongbid->norujukan)->first();
$keluar_lelong = false;
$sebab_keluar = '';
if($lelongbid->fasa == '1'){
if($gadai->sttebus == 'T'){
$keluar_lelong = true;
$sebab_keluar = 'T';
}else{
$telahbayar = $gadai->hargajualan - $gadai->bakihargajualan;
if($telahbayar >= $gadai->bakiupah){
$keluar_lelong = true;
$sebab_keluar = 'A';
$updategadai = Http::withOptions(['verify' => config('app.api_verify')])
->post(config('app.api_url').'taglel/revert',[
'kodcaw'=>$lelongbid->kodcaw,
'norujukan'=>$lelongbid->norujukan
])
->json();
}else{
$total_untung_rebet = TransaksiKeuntungan::on('main')->where('norujukan',$lelongbid->norujukan)->sum('keuntungan_rebet');
$total_untung_asal = TransaksiKeuntungan::on('main')->where('norujukan',$lelongbid->norujukan)->sum('bayaran_keuntungan');
$beza_keuntungan = $total_untung_asal - $total_untung_rebet;
if($gadai->tempohbayar == $gadai->tempoh ){
$keuntungan = 0.00;
}else{
$jbg = $gadai->tempoh - $gadai->tempohbayar;
$jbg2 = 12 - $gadai->tempohbayar;
if($gadai->tempoh <= '12.00'){
$keuntungan = bcdiv(($jbg)*$gadai->kadarupah/100*$gadai->bakipjm,1,1)-$beza_keuntungan;
}else{
$keuntungan = bcdiv(($jbg2)*$gadai->kadarupah/100*$gadai->bakipjm,1,1)-$beza_keuntungan;
}
$lelongbid->jbg = $gadai->tempoh;
$lelongbid->pinjaman = $gadai->bakipjm;
$lelongbid->bakiupah = bcdiv($keuntungan,1,1);
$lelongbid->save();
}
}
}
}else{
if($gadai->sttebus == 'T'){
$keluar_lelong = true;
$sebab_keluar = 'T';
}else{
$total_untung_rebet = TransaksiKeuntungan::on('main')->where('norujukan',$lelongbid->norujukan)->sum('keuntungan_rebet');
$total_untung_asal = TransaksiKeuntungan::on('main')->where('norujukan',$lelongbid->norujukan)->sum('bayaran_keuntungan');
$beza_keuntungan = $total_untung_asal - $total_untung_rebet;
if($gadai->tempohbayar == $gadai->tempoh ){
$keuntungan = 0.00;
}else{
$jbg = $gadai->tempoh - $gadai->tempohbayar;
$jbg2 = 12 - $gadai->tempohbayar;
if($gadai->tempoh <= '12.00'){
$keuntungan = bcdiv(($jbg)*$gadai->kadarupah/100*$gadai->bakipjm,1,1)-$beza_keuntungan;
}else{
$keuntungan = bcdiv(($jbg2)*$gadai->kadarupah/100*$gadai->bakipjm,1,1)-$beza_keuntungan;
}
$lelongbid->jbg = $gadai->tempoh;
$lelongbid->pinjaman = $gadai->bakipjm;
$lelongbid->bakiupah = bcdiv($keuntungan,1,1);
$lelongbid->save();
}
}
}
if($keluar_lelong == true){
$lelongtebus = new LelongTebus;
$lelongtebus->tarikh = $currentdate;
$lelongtebus->kodcaw = $lelongbid->kodcaw;
$lelongtebus->teller = 'System';
$lelongtebus->norujukan = $lelongbid->norujukan;
$lelongtebus->batch_no = $lelongbid->lelong_id;
$lelongtebus->nilaimarhun = $lelongbid->nilaimarhun;
$lelongtebus->pinjaman = $gadai->bakipjm;
$lelongtebus->upah = $gadai->bakiupah;
$lelongtebus->jbg = $gadai->tempoh;
$lelongtebus->jenis_tebus = $sebab_keluar;
$lelongtebus->save();
$loguser = new LogUser;
$loguser->user_id = User::where('name','System')->first()->id;
$loguser->date = $currentdate;
$loguser->username = 'System';
$loguser->nama_user = 'System';
$loguser->norujukan = $gadai->norujukan;
$loguser->nota = $sebab_keluar == 'A' ? ' KELUAR LELONG '.$lelongbid->lelong_id : ' LELONG LELONG '.$lelongbid->lelong_id ;
$loguser->save();
$lelongbid->delete();
}else{
$loguser = new LogUser;
$loguser->user_id = User::where('name','System')->first()->id;
$loguser->date = $currentdate;
$loguser->username = 'System';
$loguser->nama_user = 'System';
$loguser->norujukan = $gadai->norujukan;
$loguser->nota = $lelongbid->lelong_id.' Kemaskini Tempoh/Bakipjm/Keuntungan' ;
$loguser->save();
}
}
}
}