mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-30 01:44:05 +00:00
69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs\Commands\V2;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use App\Classes\Notifications\PermitsReminderEmail;
|
|
use App\Models\PermitsReminder;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SendPermitsReminderEmailsV2CommandJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
public function handle()
|
|
{
|
|
Log::info(Carbon::now() . ': Start job - Send Permits Reminders Email.');
|
|
$start = new Carbon();
|
|
|
|
$currentDateTime = now();
|
|
$startRange = $currentDateTime->subDays(3)->startOfDay();
|
|
$endRange = $currentDateTime->copy()->addDays(6)->endOfDay();
|
|
|
|
$reminders = PermitsReminder::whereDate('reminder_date', '>=', $startRange)
|
|
->whereDate('reminder_date', '<=', $endRange)
|
|
->orWhere('reminder_date', '<', now())
|
|
->pluck('model');
|
|
|
|
if ($reminders->isEmpty()) {
|
|
Log::info('No reminders expiring within the specified range.');
|
|
return;
|
|
}
|
|
|
|
Log::info($this->getTimeStamp() . 'Reminders: ' . $reminders->toJson());
|
|
|
|
$users = User::whereIn('email', $this->getEmailList())->get();
|
|
|
|
foreach ($users as $user) {
|
|
Log::info($this->getTimeStamp() . 'Reminder email sent to ' . $user->email);
|
|
if (app()->environment('production')) {
|
|
$user->notify(new PermitsReminderEmail($user, $reminders));
|
|
}
|
|
}
|
|
|
|
$end = new Carbon();
|
|
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
|
Log::info(Carbon::now() . ': End job - Send Permits Reminders Email. ElapsedTime: ' . $elapsedTime . '.');
|
|
}
|
|
|
|
public function getTimeStamp()
|
|
{
|
|
return '[' . Carbon::now()->format('Y-m-d H:i:s') . '] - ';
|
|
}
|
|
|
|
protected function getEmailList(): array
|
|
{
|
|
return [
|
|
// 'edmond.wuiming2021@gmail.com',
|
|
'anithagurl96@gmail.com'
|
|
];
|
|
}
|
|
}
|