Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 38 |
| CompOffAddLeaveBalanceForFutureDates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
132 | |
0.00% |
0 / 38 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| handle | |
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 36 |
|||
| <?php | |
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use Carbon\Carbon; | |
| use App\Models\Dashboard\AttendanceDetail; | |
| use App\Models\Leave\LeaveEntitlement; | |
| use App\Models\Admin\Leave; | |
| use App\Models\Leave\CompOffLeave; | |
| use App\Models\Admin\Setting; | |
| use App\Models\Auth\User; | |
| class CompOffAddLeaveBalanceForFutureDates extends Command | |
| { | |
| /** | |
| * The name and signature of the console command. | |
| * | |
| * @var string | |
| */ | |
| protected $signature = 'compOff:addLeaveBalanceForFutureDates'; | |
| /** | |
| * The console command description. | |
| * | |
| * @var string | |
| */ | |
| protected $description = 'Add Leave balance For future dates when mark attendance'; | |
| /** | |
| * Create a new command instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| } | |
| /** | |
| * Execute the console command. | |
| * | |
| * @return int | |
| */ | |
| public function handle() | |
| { | |
| $subDate = Carbon::now(config('settings.time_zone'))->subday()->format('Y-m-d'); | |
| $compOff = Setting::where('name', 'comp_off')->first(); | |
| $subdayDate = Carbon::now(config('settings.time_zone'))->subday()->toDateString(); | |
| //converted dates to UTC | |
| $startDateForSubday = Carbon::parse($subdayDate . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| $endDateForSubday = Carbon::parse(Carbon::parse($subdayDate)->addDay()->toDateString() . '00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone')); | |
| if (!empty($compOff)) { | |
| if ($compOff->value == 'enable') { | |
| //get all users | |
| $users = User::all(); | |
| if(!empty($users)){ | |
| foreach($users as $user){ | |
| if(!empty($user->userdetail)){ | |
| $compOffLeave = CompOffLeave::where('user_id',$user->id) | |
| ->whereDate('date',$subDate) | |
| ->first(); | |
| if(!empty($compOffLeave)){ | |
| //if comp off is_furute is true | |
| if($compOffLeave->is_future == "true"){ | |
| $attendance = AttendanceDetail::where('user_id', $user->id) | |
| ->whereBetween('check_in', [$startDateForSubday, $endDateForSubday]) | |
| ->first(); | |
| if(!empty($attendance)){ | |
| // if attendance is marked, update comp off leave | |
| $compOffLeave->update(['is_process' => 'true']); | |
| $leaveEntitlementFindQuery = array( | |
| 'user_id' => $user->id, | |
| 'leave_id' => $compOffLeave->leave_id, | |
| 'year' => Carbon::now(config('settings.time_zone'))->year | |
| ); | |
| $leaveEntitlement = LeaveEntitlement::where($leaveEntitlementFindQuery)->first(); | |
| if(isset($leaveEntitlement)) { | |
| //update leave balance | |
| $leaveEntitlement->leave_balance = 1 + $leaveEntitlement->leave_balance; | |
| $leaveEntitlement->save(); | |
| } else { | |
| $checkCompOffLeave = Leave::where('id',$compOffLeave->leave_id)->first(); | |
| //create new leave entitlement | |
| $leaveEntitlementData = array( | |
| 'user_id' => $user->id, | |
| 'leave_id' => $compOffLeave->leave_id, | |
| 'leave_balance' => 1, | |
| 'year' => Carbon::now(config('settings.time_zone'))->year, | |
| 'entitled_leaves' => $checkCompOffLeave->n_days | |
| ); | |
| // return $leaveEntitlementData; | |
| LeaveEntitlement::create($leaveEntitlementData); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |