Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 30 |
| ReminderNotifications | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
156 | |
0.00% |
0 / 30 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| handle | |
0.00% |
0 / 1 |
132 | |
0.00% |
0 / 28 |
|||
| <?php | |
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use App\Models\Auth\User; | |
| use App\Models\Leave\ApplyLeave; | |
| use App\Notifications\AppNotifications; | |
| //use App\Models\NotificationModel\NotificationList; | |
| use DB; | |
| use Carbon\Carbon; | |
| class ReminderNotifications extends Command | |
| { | |
| /** | |
| * The name and signature of the console command. | |
| * | |
| * @var string | |
| */ | |
| protected $signature = 'reminder:notifications'; | |
| /** | |
| * The console command description. | |
| * | |
| * @var string | |
| */ | |
| protected $description = 'Reminder notifications for leave'; | |
| /** | |
| * Create a new command instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| } | |
| /** | |
| * Execute the console command. | |
| * | |
| * @return mixed | |
| */ | |
| public function handle() | |
| { | |
| //get all pending leaves | |
| $pendingLeaves = ApplyLeave::where('status', 'Pending')->get(); | |
| $currentDate = Carbon::now()->toDateString(); | |
| if (!empty($pendingLeaves)) { | |
| foreach ($pendingLeaves as $pendingLeave) { | |
| // check if pending leave is not approved for next day | |
| if (Carbon::parse($pendingLeave->created_at)->addDay()->toDateString() == $currentDate) { | |
| $user = User::find($pendingLeave->user_id); | |
| $title = "Leave Request"; | |
| //check if leave is half day | |
| if ($pendingLeave->leave_type == "half_day") { | |
| $leave_type = "Half Day"; | |
| } | |
| //check if leave is full day | |
| if ($pendingLeave->leave_type == "full_day") { | |
| $leave_type = "Full Day"; | |
| } | |
| $message = $leave_type . " requested by " . $user->name . ' ' . $user->lastName . " is pending for your approval / rejection"; | |
| $actionUrl = 'leave-report.index'; | |
| $primary_reporting_manager_id = $user->userdetail->primary_reporting_manager_id; | |
| if ($primary_reporting_manager_id != 0) { | |
| //primary reporting manager | |
| $primary_reporting_manager = User::find($primary_reporting_manager_id); | |
| //check if user is exists | |
| if(!empty($primary_reporting_manager)){ | |
| //notification to primary reporting manager | |
| $primary_reporting_manager->notify(new AppNotifications( | |
| [ | |
| $title, | |
| $message, | |
| $actionUrl | |
| ] | |
| )); | |
| } | |
| } | |
| //secondary reporting managers | |
| if (count($user->userdetail->secondaryManager) > 0) { | |
| foreach ($user->userdetail->secondaryManager as $secondaryManager) { | |
| if ($primary_reporting_manager_id != $secondaryManager->id){ | |
| $arr = null; | |
| $arr = [$title, $message, $actionUrl]; | |
| //notification to secondary reporting manager | |
| $secondaryManager->notify(new AppNotifications($arr)); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |