Commit 13475f90 by Azhan Hannan

Cron Job -> reminder for unsubmission timesheet for 3 times each for each phase.

parent d308a692
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Portal\Timesheet\Model\Ts_master;
use Portal\Timesheet\Model\VwStaff;
use Mail;
use App\Mail\Reminder;
class DemoCron extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'demo:cron';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$today = date('d-m-Y');
$currday = date('j');
$currmonth = date('n');
$curryear = date('Y');
// $currday = 20;
// $currmonth = 11;
// $curryear = 2022;
if ($currday > 15)
{
$checkphase = 1;
$checkyear = $curryear;
$checkmonth = $currmonth;
}
else
{
$checkphase = 2;
if ($currmonth == 1)
{
$checkmonth = 12;
$checkyear = $curryear-1;
}
else
{
$checkmonth = $currmonth-1;
$checkyear = $curryear;
}
}
$timesheets = Ts_master::select('tm_staff_id')
->where('tm_year', $checkyear)
->where('tm_month', $checkmonth)
->where('tm_phase', $checkphase)
->whereIn('tm_timesheet_master_sts', ['2,3,4,5,6'])
->get();
$staffsubmitted = [];
foreach ($timesheets as $key => $value) {
$staffsubmitted[] = $value->tm_staff_id;
}
$users = VwStaff::whereNotIn('staffid', $staffsubmitted)
->where('deptID', '<>', 8)
->with('penyokong')
->get();
if (env('EMAIL_ENV') == 'local')
{
foreach ($users as $key => $value)
{
$mailTo = '3fetimesheet@gmail.com';
\Log::info($mailTo);
$data_email = [
'subject' => 'Timesheet: Reminder for Timesheet Submission',
'sender_name' => '3fetimesheet@gmail.com',
'name' => data_get($value,'name'),
'cc' => '143hannan@gmail.com',
'today' => $today,
'phase' => $checkphase,
'month' => $checkmonth,
'year' => $checkyear,
];
// Mail::to($mailTo)->cc($data_email['cc'])->send(new Reminder($data_email));
}
}
elseif (env('EMAIL_ENV') == 'PRODUCTION')
{
foreach ($users as $key => $value)
{
$mailTo = $value->email;
$data_email = [
'subject' => 'Timesheet: Reminder for Timesheet Submission',
'sender_name' => '3fetimesheet@gmail.com',
'name' => data_get($value,'name'),
'cc' => data_get($value,'penyokong.email'),
'today' => $today,
'phase' => $checkphase,
'month' => $checkmonth,
'year' => $checkyear,
];
Mail::to($mailTo)->cc($data_email['cc'])->send(new Reminder($data_email));
}
}
/*
Write your database logic we bellow:
Item::create(['name'=>'hello new']);
*/
}
}
...@@ -26,6 +26,14 @@ class Kernel extends ConsoleKernel ...@@ -26,6 +26,14 @@ class Kernel extends ConsoleKernel
{ {
// $schedule->command('inspire') // $schedule->command('inspire')
// ->hourly(); // ->hourly();
$schedule->command('demo:cron')->monthlyOn(5, '09:00');
$schedule->command('demo:cron')->monthlyOn(7, '09:00');
$schedule->command('demo:cron')->monthlyOn(10, '09:00');
$schedule->command('demo:cron')->monthlyOn(20, '09:00');
$schedule->command('demo:cron')->monthlyOn(22, '09:00');
$schedule->command('demo:cron')->monthlyOn(25, '09:00');
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment