This commit is contained in:
LAPTOP-DGCU80CH\user1
2020-11-08 15:59:21 +08:00
parent ba7e18eee1
commit 4f463412b0
11 changed files with 325 additions and 45 deletions
+69
View File
@@ -0,0 +1,69 @@
<?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
));
}
}
}
}
+7 -1
View File
@@ -5,6 +5,10 @@ namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
use App\Cawangan;
use App\Gadai;
use Carbon\Carbon;
class Kernel extends ConsoleKernel
{
/**
@@ -13,7 +17,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
//
Commands\DailyGadai::class,
];
/**
@@ -25,5 +29,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
//
$schedule->command('gadai:daily')->daily()->at('00:00')->timezone('Asia/Kuala_Lumpur');
}
}