CasperSecurity
<?php
namespace App\Console\Commands;
use App\Models\CreateTender;
use App\Models\User;
use App\Notifications\ReminderBeforeActivityEndDate;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Notifications\Notification;
class ReminderBeforeEndDate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'oss:tender-reminder-end-date';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Reminder For Tender Activity Before End Date';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$tenders=CreateTender::whereDate('tender_closing_date','>=',date('Y-m-d'))
->where('tender_status','>','4')
->where('tender_status','<','6')
->get();
foreach ($tenders as $tender){
$tender->getClient;
$employees=explode(',',$tender['tender_assigned_to']);
$tender->assignTo=$employees;
foreach ($tender->tenderYetToStartActivites as $activity){
$employees=explode(',',$activity['activity_assigned_to']);
$activity->assignTo=$employees;
foreach ($employees as $userid){
if($activity['activity_end_date']== Carbon::now()->addDay('1')->format('Y-m-d')){
$sendtouser=User::find($userid);
Notification::sendNow($sendtouser,new ReminderBeforeActivityEndDate($activity,$sendtouser));
}
}
}
}
return true;
}
}