%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/public_html/admin1/app/Console/Commands/ |
Upload File : |
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\LogTimeFor;
use App\Models\Holiday;
use App\Models\Leave;
use App\Models\User;
use App\Models\Company;
use App\Models\ProjectTimeLog;
use App\Events\TimeTrackerReminderEvent;
use Carbon\Carbon;
class SendTimeTracker extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'send-time-tracker';
/**
* The console command description.
*
* @var string
*/
protected $description = 'send time tracker';
/**
*
*/
public function handle()
{
$currentDay = now()->format('Y-m-d');
$companies = Company::select('id', 'timezone')->get();
foreach ($companies as $company) {
$trackerReminder = LogTimeFor::where('company_id', $company->id)->first();
$startDateTime = Carbon::parse($currentDay . ' ' . $trackerReminder->time);
$currentDateTime = now()->timezone($company->timezone);
if ($trackerReminder->tracker_reminder == 1 && $currentDateTime->format('H:i') == $startDateTime->format('H:i')) {
// Check if there's a holiday for the current day and company
$holiday = Holiday::where('company_id', $company->id)
->where('date', $currentDay)
->exists();
if (!$holiday) {
$employeeIds = User::allEmployees(null, false, null, $company->id)->pluck('id');
$employeeIds->each(function ($employeeId) use ($currentDay) {
$leaveExists = Leave::where('leave_date', $currentDay)
->where('status', 'approved')
->where('user_id', $employeeId)
->exists();
$timeLogExists = ProjectTimeLog::whereDate('start_time', $currentDay)
->where('user_id', $employeeId)
->exists();
$user = User::find($employeeId);
if (!$leaveExists && !$timeLogExists && $user) {
event(new TimeTrackerReminderEvent($user));
}
});
}
}
}
}
}