Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 21 |
| UpdateLeaves | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
182 | |
0.00% |
0 / 21 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| handle | |
0.00% |
0 / 1 |
156 | |
0.00% |
0 / 19 |
|||
| <?php | |
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use App\Models\Leave\LeaveEntitlement; | |
| //use App\Models\NotificationModel\NotificationList; | |
| use App\Notifications\UpdateLeavesNotification; | |
| use Illuminate\Support\Facades\Log; | |
| use App\Exceptions\Handler; | |
| use App\Models\Admin\Leave; | |
| use App\Models\Auth\User; | |
| class UpdateLeaves extends Command | |
| { | |
| /** | |
| * The name and signature of the console command. | |
| * | |
| * @var string | |
| */ | |
| protected $signature = 'leaves:update'; | |
| /** | |
| * The console command description. | |
| * | |
| * @var string | |
| */ | |
| protected $description = 'Update Leaves - Casual Leave / Sick Leaves'; | |
| /** | |
| * Create a new command instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| } | |
| /** | |
| * Execute the console command. | |
| * | |
| * @return mixed | |
| */ | |
| public function handle() | |
| { | |
| $users = User::all(); | |
| try { | |
| $leaveEntitlements = LeaveEntitlement::all(); | |
| foreach($leaveEntitlements as $leave) | |
| { | |
| $leaveObject = Leave::find($leave->leave_id); | |
| // if( isset($leaveObject) && $leaveObject->to_carry == 0 ) | |
| // $leave->leave_balance = 0; | |
| if( isset($leaveObject) && $leaveObject->to_carry == 2 ) | |
| $leave->leave_balance = $leave->leave_balance > $leaveObject->carry_days ? $leaveObject->carry_days : $leave->leave_balance; | |
| if( isset($leaveObject) && $leaveObject->leave_allocation_type == 'pro_rata' ) { | |
| $leave->leave_balance = $leave->leave_balance + ($leaveObject->n_days / 12); | |
| $leave->save(); | |
| } | |
| // if($leave->leave_id == 1 ) //Casual Leave | |
| // { | |
| // $leave->save(); | |
| // } | |
| // elseif($leave->leave_id == 2) | |
| // { | |
| // $leave->leave_balance = $leave->leave_balance + .58; | |
| // $leave->save(); | |
| // } | |
| } | |
| // $notificationList = NotificationList::firstOrFail(); | |
| // foreach($notificationList->users as $notification_user) | |
| // { | |
| // $notification_user->notify(new UpdateLeavesNotification('Success')); | |
| // } | |
| foreach ($users as $user) { | |
| if($user->can('Administration Module')){ | |
| $user->notify(new UpdateLeavesNotification('Success')); | |
| } | |
| } | |
| return; | |
| } | |
| catch (Throwable $e) | |
| { | |
| // $notificationList = NotificationList::firstOrFail(); | |
| // foreach($notificationList->users as $notification_user) | |
| // { | |
| // $notification_user->notify(new UpdateLeavesNotification('Failed')); | |
| // } | |
| foreach ($users as $user) { | |
| if($user->can('Administration Module')){ | |
| $user->notify(new UpdateLeavesNotification('Failed')); | |
| } | |
| } | |
| Log::info('Error updating leave : '.$e->getMessage()); | |
| return; | |
| } | |
| } | |
| } |