Files
api_arrahn/app/Console/Commands/DailyGadai.php
T
LAPTOP-DGCU80CH\user1 4f463412b0 add api
2020-11-08 15:59:21 +08:00

69 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use App\Cawangan;
use App\Gadai;
use Carbon\Carbon;
class DailyGadai extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'gadai:daily';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update JBG for every active gadai';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$cawangan = Cawangan::on('mysql7')->get();
$current = Carbon::now();
foreach($cawangan as $cawangan_mysql){
$all_gadai = Gadai::on($cawangan_mysql['mysql'])->where('sttebus','!=','L')->orWhere('sttebus','!=','T')->get();
foreach($all_gadai as $gadai){
$tarikh_gadai = Carbon::parse($gadai['t_gadai'].' '. $gadai['masa']);
$diff = date_diff($tarikh_gadai,$current);
$month = $diff->format("%m");
$days = $diff->format("%d");
$days = $days + 1;
if($days >= 1 && $days <= 15)
{
$extensivemonth = 0.5;
}
else if($days >= 16)
{
$extensivemonth = 1;
}
$tempoh_gadai = $month + $extensivemonth;
Gadai::on($cawangan_mysql['mysql'])->where('norujukan','=',$gadai['norujukan'])->update(array(
'jbg' => $tempoh_gadai
));
}
}
}
}