mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
update send permits reminder
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\PermitsReminder;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SendPermitsReminderEmails extends Command
|
||||
{
|
||||
@@ -41,26 +42,26 @@ class SendPermitsReminderEmails extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$now = now();
|
||||
$startRange = $now->subDays(3)->startOfDay();
|
||||
$endRange = $now->copy()->addDays(6)->endOfDay();
|
||||
$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');
|
||||
|
||||
$this->info($this->getTimeStamp() . json_encode($reminders));
|
||||
if ($reminders->isEmpty()) {
|
||||
Log::info('No reminders expiring within the specified range.');
|
||||
return;
|
||||
}
|
||||
|
||||
$users = User::whereIn(
|
||||
'email',
|
||||
[
|
||||
'edmond.wuiming2021@gmail.com',
|
||||
'anithagurl96@gmail.com'
|
||||
]
|
||||
)->get();
|
||||
Log::info($this->getTimeStamp() . 'Reminders: ' . $reminders->toJson());
|
||||
|
||||
$users = User::whereIn('email', $this->getEmailList())->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->info($this->getTimeStamp() . 'Reminder email sent to ' . $user->email);
|
||||
Log::info($this->getTimeStamp() . 'Reminder email sent to ' . $user->email);
|
||||
if (app()->environment('production')) {
|
||||
$user->notify(new PermitsReminderEmail($user, $reminders));
|
||||
}
|
||||
@@ -71,4 +72,12 @@ class SendPermitsReminderEmails extends Command
|
||||
{
|
||||
return '[' . Carbon::now()->format('Y-m-d H:i:s') . '] - ';
|
||||
}
|
||||
|
||||
protected function getEmailList(): array
|
||||
{
|
||||
return [
|
||||
'edmond.wuiming2021@gmail.com',
|
||||
'anithagurl96@gmail.com'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\PermitsReminder;
|
||||
|
||||
use App\Models\PermitsReminder;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -15,14 +16,25 @@ class ListPermitsReminderController
|
||||
public function list(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = 10; // Number of items per page
|
||||
$page = request('page', 1); // Get the current page from the request
|
||||
$page = $request->query('page', 1); // Get the current page from the request
|
||||
|
||||
// Paginate the PermitsReminder model
|
||||
$query = PermitsReminder::orderBy('id', 'desc');
|
||||
$paginator = $query->paginate($perPage, ['*'], 'page', $page);
|
||||
$paginator = PermitsReminder::orderBy('reminder_date')->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
// Convert paginated data to an array
|
||||
// Get current date and time
|
||||
$currentDateTime = now();
|
||||
|
||||
// Define date range
|
||||
$startRange = $currentDateTime->subDays(3)->startOfDay();
|
||||
$endRange = $currentDateTime->copy()->addDays(6)->endOfDay();
|
||||
|
||||
// Process paginated items
|
||||
$data = $paginator->items();
|
||||
foreach ($data as &$item) {
|
||||
// Check if the reminder_date is within the date range or after the current date
|
||||
$reminderDate = Carbon::parse($item->reminder_date);
|
||||
$item->show_remind = $reminderDate->between($startRange, $endRange) || $reminderDate->isBefore($currentDateTime);
|
||||
}
|
||||
|
||||
// Create pagination links
|
||||
$links = [
|
||||
@@ -32,6 +44,7 @@ class ListPermitsReminderController
|
||||
"next" => $paginator->nextPageUrl(),
|
||||
];
|
||||
|
||||
// Prepare response
|
||||
$response = [
|
||||
"title" => "List Permits Reminder",
|
||||
"message" => "You have successfully retrieved a list of Permits Reminder",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">{{ data.model }}</div>
|
||||
<div class="font-heading all-caps" :class="[{ 'text-danger': data.show_remind }]">{{ data.model }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,7 +41,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">{{ data.expiry_date }}</div>
|
||||
<div class="font-heading all-caps" :class="[{ 'text-danger': data.show_remind }]">{{ data.expiry_date }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -53,7 +53,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">{{ data.reminder_date }}</div>
|
||||
<div class="font-heading all-caps" :class="[{ 'text-danger': data.show_remind }]">{{ data.reminder_date }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -65,7 +65,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">{{ data.created_at }}</div>
|
||||
<div class="font-heading all-caps" :class="[{ 'text-danger': data.show_remind }]">{{ data.created_at }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user