Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 23
UpdateAdvanceLeaves
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
240
0.00% covered (danger)
0.00%
0 / 23
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 handle
0.00% covered (danger)
0.00%
0 / 1
210
0.00% covered (danger)
0.00%
0 / 21
<?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\Auth\User;
class UpdateAdvanceLeaves extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'advanceleaves:update';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Update Advance 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 == 'advance') {
                        $leave->leave_balance = $leave->leave_balance + $leaveObject->n_days;
                        $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;
            }
    }
}