%PDF- %PDF-
Direktori : /var/www/html/hrsys/api/app/Console/Commands/ |
Current File : /var/www/html/hrsys/api/app/Console/Commands/AddYearlyHolidaysCommand.php |
<?php namespace App\Console\Commands; use App\Models\AnnualLeaveTransaction; use App\Models\Configuration; use App\Models\User; use Carbon\Carbon; use Illuminate\Console\Command; use Throwable; class AddYearlyHolidaysCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'addYearlyHolidaysCommand'; /** * The console command description. * * @var string */ protected $description = 'Adds yearly holidays to each user'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed * @throws Throwable */ public function handle() { $users = User::query() ->where('is_enabled', true) ->get(); /** @var Configuration $config */ $config = Configuration::getCurrent(); foreach ($users as $user) { /** @var User $user */ $leave = $user->annualLeave; $leave->quantity += $config->annual_leave_quantity; $leave->save(); $leave->transactions() ->create([ 'type' => AnnualLeaveTransaction::ADD, 'notes' => 'Annual leave', 'quantity' => $config->annual_leave_quantity, 'expires_at' => Carbon::now() ->startOfYear() ->addMonths($config->holidays_validity_in_months), ]); } } }