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 / 322
SendAttendanceNotifications
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
8742
0.00% covered (danger)
0.00%
0 / 322
 __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
8556
0.00% covered (danger)
0.00%
0 / 320
<?php
namespace App\Console\Commands;
use App\Http\Controllers\FirebaseController\FirebaseCloudMessaging;
use Illuminate\Console\Command;
use App\Models\Admin\Shift;
use Carbon\Carbon;
use App\Models\Dashboard\AttendanceDetail;
use App\Models\NotificationModel\Notification;
//use App\Models\NotificationModel\NotificationList;
use App\Models\Auth\User;
use App\Notifications\AppNotifications;
use App\Models\Leave\ApplyLeave;
use App\Models\Admin\Team;
use App\Models\Admin\Holiday;
use App\Models\Auth\UserWeeklyOff;
use App\Models\Auth\UserShift;
use GetShiftDetailHelper;
use App\Models\Admin\UserDetail;
use App\Helpers\HolidayHelper;
class SendAttendanceNotifications extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'send:attendanceNotifications';
    /**
     * The console command description.c
     *
     * @var string
     */
    protected $description = 'Notifications for no check in check out ';
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $users = User::all();
        // current date and time
        $currentTime = Carbon::now(config('settings.time_zone'))->toTimeString();
        
        $currentDate = Carbon::now(config('settings.time_zone'))->toDateString();
        $startDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->toDateString().'00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone'));
        $endDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->addDay()->toDateString().'00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone'));
        
        //sub day start and end time for timezone
        $subdayStartDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->subDay()->toDateString().'00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone'));
        $subdayEndDate = Carbon::parse(Carbon::now(config('settings.time_zone'))->toDateString().'00:00:00', config('settings.time_zone'))->setTimezone(config('app.time_zone'));
        
        
        $subdayWithTimezone = Carbon::now(config('settings.time_zone'))->subday()->toDateString();
        
          
                    
        
        foreach ($users as $key => $user) {
            
            
            if (!empty($user->userdetail)) {
                //get holidays
                $holidayIds = HolidayHelper::getholidayList($user->id);
               
                //check subday holiday
                $holidaySubday = Holiday::where('date',$subdayWithTimezone)->whereIn('id', $holidayIds)->first();
                //check holiday
                $holiday = Holiday::where('date',$currentDate)->whereIn('id', $holidayIds)->first();
                
                //primary reporting manager
                $primary_reporting_manager_id = $user->userdetail->primary_reporting_manager_id;
                //secondary reporting manager
                $secondaryManagers = $user->userdetail->secondaryManager;
                //if user is on leave
                $userOnLeave = ApplyLeave::where('from_date', '<=', $currentDate)
                                            ->where('to_date', '>=', $currentDate)
                                            ->where('status', 'Approve')
                                            ->where('user_id', $user->id)
                                            ->first();
                
                //if user is on leave
                $userOnLeaveSubday = ApplyLeave::where('from_date', '<=', $subdayWithTimezone)
                                                ->where('to_date', '>=', $subdayWithTimezone)
                                                ->where('status', 'Approve')
                                                ->where('user_id', $user->id)
                                                ->first();
                //user weekly off
                $userWeeklyOff = UserWeeklyOff::where('user_id',$user->id)
                                               ->whereBetween('created_at', [$startDate, $endDate])
                                               ->where('weekly_off',1)->first();
                
                //user sub day weekly off
                $userWeeklyOffSubday = UserWeeklyOff::where('user_id',$user->id)
                                                     ->whereBetween('created_at', [$subdayStartDate, $subdayEndDate])
                                                     ->where('weekly_off',1)->first();
                
                
                //get shift details    
                $shift = GetShiftDetailHelper::getShiftDetail($user->id,$startDate,$endDate);
                
                
                if($shift  != null){ 
                  
                    $shiftStartTime =  $shift['shiftStartTime'];
                    $shiftEndTime =  $shift['shiftEndTime'];
                   
                    //shift buffer checkin time
                    $bufferCheckinTime = $shift['bufferCheckinTime'];
                    //shift buffer checkout time
                    $bufferCheckoutTime =$shift['bufferCheckoutTime'];
                    $bufferCheckinSecs = strtotime($bufferCheckinTime) - strtotime("00:00:00");
                    $bufferCheckoutSecs = strtotime($bufferCheckoutTime) - strtotime("00:00:00");
                    //shift start time + buffer checkin time
                    $timeWithBuffer = date("H:i:s", strtotime($shiftStartTime) + $bufferCheckinSecs);
                    //shift end time + buffer checkout time
                    $shiftEndTimeWithBuffer = date("H:i:s", strtotime($shiftEndTime) + $bufferCheckoutSecs);
                    //offset start time
                    $offsetStartTime = Carbon::parse($shiftStartTime);
                    $offsetStartTime = $offsetStartTime->subHours(4)->toTimeString();
                    $offsetEndTime = Carbon::parse($shiftEndTime);
                    $offsetEndTime = $offsetEndTime->addHours(4)->toTimeString();
                    $today_date_time  = Carbon::now(config('settings.time_zone'));
                    $time_now = $today_date_time->toTimeString();
                    $time = Carbon::now(config('settings.time_zone'));
                    $day  = $time->day+1;
                    //set time to shift start time
                    $setShiftStartTime = Carbon::createFromFormat('Y-m-d H:i:s',$time->year.'-'.$time->month.'-'.$time->day.' '. $shiftStartTime,config('settings.time_zone'));
                    
                     //set time to shift end buffer time
                     $setshiftEndTimeWithBuffer = Carbon::createFromFormat('Y-m-d H:i:s',$time->year.'-'.$time->month.'-'.$time->day.' '. $shiftEndTimeWithBuffer,config('settings.time_zone'));
                   
                    //set time to next day 12am
                    $set12am = Carbon::createFromFormat('Y-m-d H:i:s',$time->year.'-'.$time->month.'-'.$day.' 00:00:00',config('settings.time_zone')); 
           
                        //primary team name
                        $userInTeam = $user->userdetail->primaryTeamName->team;
                      
                       
                        //check if user is on leave dont show checkin, checkout and absent notifications
                        // No checkin users
                           
                        // if shift start time is greater than shift end time, that is two day shift
                           if ($shiftStartTime > $shiftEndTime)    // to check if the shift ends the next day
                                {
                                    
                                    //check if current time is between shift start time and next day 12am and below shift end time
                                    if(!$time->between($setShiftStartTime, $set12am, true) && $currentTime < $shiftEndTimeWithBuffer) {
                                       
                                        //check for sub day
                                        if(empty($userWeeklyOffSubday) && empty($userOnLeaveSubday) && empty($holidaySubday) ){
                                            
                                            //get attendance data
                                            $attendanceDetail = AttendanceDetail::where('user_id', '=', $user->id)
                                                                            ->whereBetween('check_in', [$subdayStartDate, $subdayEndDate])
                                                                            ->get();
                                            $nocheckinNotificationStartDate = $subdayStartDate;
                                            $nocheckinNotificationEndDate = $subdayEndDate;
                                           
                                        }else{
                                            // 1 is just for non empty array
                                            $attendanceDetail = [1];
                                        }                                     
                                    } else {
                                        
                                        //check for current day
                                        if (empty($userWeeklyOff) && empty($userOnLeave) && empty($holiday)) {
                                            
                                            
                                        if ($currentTime > $timeWithBuffer) {
                                            
                                            $attendanceDetail = AttendanceDetail::where('user_id', '=', $user->id)
                                                                            ->whereBetween('check_in', [$startDate, $endDate])
                                                                            ->get();
                                            $nocheckinNotificationStartDate = $startDate;
                                            $nocheckinNotificationEndDate = $endDate;                                
                                                                          
                                        }else{
                                            // 1 is just for non empty array
                                            $attendanceDetail = [1];
                                        } 
                                        }else{
                                            // 1 is just for non empty array
                                            $attendanceDetail = [1];
                                        }                                   
                                        
                                    }
                                } else { //single day shift
                                     if (empty($userWeeklyOff) && empty($userOnLeave) && empty($holiday)) {
                        
                                    if ($currentTime > $timeWithBuffer) {
                                    //get attendance data
                                    $attendanceDetail = AttendanceDetail::where('user_id', $user->id)
                                                                        ->whereBetween('created_at', [$startDate, $endDate])
                                                                        ->get();
                                    $nocheckinNotificationStartDate = $startDate;
                                    $nocheckinNotificationEndDate = $endDate; 
                                    }else{
                                        // 1 is just for non empty array
                                        $attendanceDetail = [1];
                                    } 
                                    }else{
                                      // 1 is just for non empty array
                                        $attendanceDetail = [1];
                                    } 
                                }
                                // check if attedance data is empty
                                if (count($attendanceDetail) == 0) {
                                    //No checkin Notifications
                                    $title = "No Checkin";
                                    
                                    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)){
                                            $noCheckinMessage =  $user->name . ' ' . $user->lastName . ' has not checked-in today.';
                                            $arr = null;
                                            $arr = [$title,$noCheckinMessage, null];
                                            $check_data = [
                                                'notification' =>  $arr[0],
                                                'message' =>  $arr[1],
                                                'actionUrl' =>  $arr[2]
                                            ];
                                            //checking notification already exists or not with date
                                            $notifications  = Notification::where('notifiable_id', $primary_reporting_manager->id)
                                                                            ->where('data', json_encode($check_data))
                                                                            ->whereBetween('created_at', [$nocheckinNotificationStartDate, $nocheckinNotificationEndDate])
                                                                            ->first();      
                                            if (empty($notifications)) {
                                                $primary_reporting_manager->notify(new AppNotifications($arr));
                                                $firebaseObject = new FirebaseCloudMessaging();
                                                $firebaseObject->sendFirebaseNotification($title,$noCheckinMessage,$primary_reporting_manager->id);
                                            }
                                            }
                                        
                                    }
                                    //secondary reporting managers
                                    if (count($secondaryManagers) > 0) {
                                        foreach ($secondaryManagers as $secondaryManager) {
                                            if ($primary_reporting_manager_id != $secondaryManager->id){
                                                $noCheckinMessage =  $user->name . ' ' . $user->lastName . ' has not checked-in today.';
                                                $arr = null;
                                                $arr = [$title, $noCheckinMessage, null];
                                                $check_data = [
                                                    'notification' =>  $arr[0],
                                                    'message' =>  $arr[1],
                                                    'actionUrl' =>  $arr[2]
                                                ];
                                                //checking notification already exists or not with date
                                                $notifications  = Notification::where('notifiable_id', $secondaryManager->id)
                                                                                ->where('data', json_encode($check_data))
                                                                                ->whereBetween('created_at', [$nocheckinNotificationStartDate, $nocheckinNotificationEndDate])
                                                                                ->first();
                                                if (empty($notifications)) {
                                                    $secondaryManager->notify(new AppNotifications($arr));
                                                    $firebaseObject = new FirebaseCloudMessaging();
                                                    $firebaseObject->sendFirebaseNotification($title,$noCheckinMessage,$secondaryManager->id);
                                            
                                            }    
                                            
                                        }
                                    } 
                                    
                                    //notification to user
                                    $noCheckinMessage =  'You have missed check-in.';
                                    $url = 'home';
                                    $arr = null;
                                    $arr = [$title, $noCheckinMessage, $url];
                                    $check_data = [
                                        'notification' =>  $arr[0],
                                        'message' =>  $arr[1],
                                        'actionUrl' =>  $arr[2]
                                    ];
                                    //checking notification already exists or not with date
                                    $notifications  = Notification::where('notifiable_id', $user->id)
                                        ->where('data', json_encode($check_data))
                                        ->whereBetween('created_at', [$nocheckinNotificationStartDate, $nocheckinNotificationEndDate])
                                        ->first();
                                    if (empty($notifications)) {
                                        $user->notify(new AppNotifications($arr));
                                        $firebaseObject = new FirebaseCloudMessaging();
                                        $firebaseObject->sendFirebaseNotification($title,$noCheckinMessage,$user->id);
                                        
                                    }
                                
                                }
                          
                            //checkout notifications
                            $noCheckoutAttendanceDetail = [];
                           
                               // if shift start time is greater than shift end time, that is two day shift
                                if ($shiftStartTime > $shiftEndTime) // to check if the shift ends the next day
                                {
                                    
                                   
                                    //check user is on leave yesterday
                                    if(empty($userWeeklyOffSubday) && empty($userOnLeaveSubday) && empty($holidaySubday)){
                                    
                                  
                                    
                                    // check current time is not between shift start time and morning 00:00 && after shift end time
                                    if(!$time->between($setShiftStartTime, $set12am, true) && $currentTime > $shiftEndTimeWithBuffer) {
                                        
                                       
                                        $noCheckoutAttendanceDetail = AttendanceDetail::where('user_id', '=', $user->id)
                                                                                       ->whereBetween('check_in', [$subdayStartDate, $subdayEndDate])
                                                                                       ->where('check_out', '=', null)
                                                                                       ->get();
                                                                           
                                                                          
                                    } 
                                    }
                                } else { //single day shift
                                    
                                    if(!$time->between($setShiftStartTime, $set12am, true) && $currentTime > $shiftEndTimeWithBuffer) {
                                            
                                        //check user is on leave yesterday
                                      if(empty($userWeeklyOffSubday) && empty($userOnLeaveSubday) && empty($holidaySubday)){
                                       
                                            $noCheckoutAttendanceDetail = AttendanceDetail::where('user_id', '=', $user->id)
                                            ->whereBetween('check_in', [$subdayStartDate, $subdayEndDate])
                                            ->where('check_out', '=', null)
                                            ->get();                }
                                   }else if($time->between($setShiftStartTime, $set12am, true) && $currentTime > $shiftEndTimeWithBuffer && $setshiftEndTimeWithBuffer->between($setShiftStartTime, $set12am, true)){
                                       if (empty($userWeeklyOff) && empty($userOnLeave) && empty($holiday)) {
                                            $noCheckoutAttendanceDetail = AttendanceDetail::where('user_id', $user->id)
                                            ->whereBetween('check_in', [$startDate, $endDate])
                                            ->where('check_out', '=', null)
                                            ->get();
                                       }
                                   }
                                }
                                if (count($noCheckoutAttendanceDetail) > 0) {
                                    $title = "No Checkout";
                                    if ($primary_reporting_manager_id != 0) {
                                        //primary reporting manager
                                        $primary_reporting_manager = User::find($primary_reporting_manager_id);
                                                   $noCheckoutMessage= $user->name . ' ' . $user->lastName . ' has not checked-out today.';
                                        //check if user is exists  
                                        if(!empty($primary_reporting_manager)){
                                        $arr = [$title, $noCheckinMessage, null]  ;
                                        $check_data = [
                                            'notification' =>  $arr[0],
                                            'message' =>  $arr[1],
                                            'actionUrl' =>  $arr[2]
                                        ];
                                        $notifications  = Notification::where('notifiable_id', $primary_reporting_manager->id)
                                            ->where('data', json_encode($check_data))
                                            ->whereBetween('created_at', [$startDate, $endDate])
                                            ->first();
                                        if (empty($notifications)) {
                                            $primary_reporting_manager->notify(new AppNotifications($arr));
                                            $firebaseObject = new FirebaseCloudMessaging();
                                            $firebaseObject->sendFirebaseNotification($title,$noCheckoutMessage,$user->id);
                                        }
                                        }
                                    }
                                    //secondary reporting managers
                                    if (count($secondaryManagers) > 0) {
                                        foreach ($secondaryManagers as $secondaryManager) {
                                            if ($primary_reporting_manager_id != $secondaryManager->id){
                                                $noCheckoutMessage =  $user->name . ' ' . $user->lastName . ' has not checked-out today.';
                                            $arr = null;
                                            $arr = [$title, $noCheckoutMessage, null];
                                            $check_data = [
                                                'notification' =>  $arr[0],
                                                'message' =>  $arr[1],
                                                'actionUrl' =>  $arr[2]
                                            ];
                                            //checking notification already exists or not with date
                                            $notifications  = Notification::where('notifiable_id', $secondaryManager->id)
                                                                ->where('data', json_encode($check_data))
                                                                ->whereBetween('created_at', [$startDate, $endDate])
                                                                ->first();
                                            if (empty($notifications)) {
                                                $secondaryManager->notify(new AppNotifications($arr));
                                                $firebaseObject = new FirebaseCloudMessaging();
                                                $firebaseObject->sendFirebaseNotification($title,$noCheckoutMessage,$secondaryManager->id);
                                            }
                                         }
                                        }
                                    } 
                                   
                                    //notification to user
                                    $noCheckoutMessage =  'You have missed check-out.';
                                    $url = 'home';
                                    $arr = null;
                                    $arr = [$title, $noCheckoutMessage, $url];
                                    $check_data = [
                                        'notification' =>  $arr[0],
                                        'message' =>  $arr[1],
                                        'actionUrl' =>  $arr[2]
                                    ];
                                    //checking notification already exists or not with date
                                    $notifications  = Notification::where('notifiable_id', $user->id)
                                        ->where('data', json_encode($check_data))
                                        ->whereBetween('created_at', [$startDate, $endDate])
                                        ->first();
                                    if (empty($notifications)) {
                                        $user->notify(new AppNotifications($arr));
                                        $firebaseObject = new FirebaseCloudMessaging();
                                        $firebaseObject->sendFirebaseNotification($title,$noCheckoutMessage,$user->id);
                                    }
                                }
                            
                            // Absent notifications
                            //Marked Absent - in case of no check in 
                            $absentAttendanceDetail = [1];
                                   // if shift start time is greater than shift end time, that is two day shift
                                    if ($shiftStartTime > $shiftEndTime) // to check if the shift ends the next day
                                    {
                                   
                                    //check user is on leave yesterday
                                    if(empty($userWeeklyOffSubday) && empty($userOnLeaveSubday) && empty($holidaySubday)){
                                        
                                        // check current time is not between shift start time and morning 00:00 && before shift time
                                        if(!$time->between($setShiftStartTime, $set12am, true) && $currentTime > $shiftEndTimeWithBuffer) {
                                       
                                        $absentAttendanceDetail = AttendanceDetail::where('user_id', '=', $user->id)
                                                                                   ->whereBetween('check_in', [$subdayStartDate, $subdayEndDate])
                                                                                   ->get();
                                        $messsage = ' marked absent on ' . Carbon::parse($subdayWithTimezone)->format('d-m-Y').'.';
                                        $absentMessage =  'You are marked absent on ' . Carbon::parse($subdayWithTimezone)->format('d-m-Y').'.';
                                    }
                                    }
                                } else {
                                    
                                        if(!$time->between($setShiftStartTime, $set12am, true) && $currentTime > $shiftEndTimeWithBuffer) {
                                            
                                             //check user is on leave yesterday
                                           if(empty($userWeeklyOffSubday) && empty($userOnLeaveSubday) && empty($holidaySubday)) {
                                            
                                            $absentAttendanceDetail = AttendanceDetail::where('user_id', '=', $user->id)
                                                                                   ->whereBetween('check_in', [$subdayStartDate, $subdayEndDate])
                                                                                   ->get();
                                            $messsage = ' marked absent on ' . Carbon::parse($subdayWithTimezone)->format('d-m-Y').'.';
                                            $absentMessage =  'You are marked absent on ' . Carbon::parse($subdayWithTimezone)->format('d-m-Y').'.';
                                           }
                                        }else if($time->between($setShiftStartTime, $set12am, true) && $currentTime > $shiftEndTimeWithBuffer && $setshiftEndTimeWithBuffer->between($setShiftStartTime, $set12am, true)){
                                            if (empty($userWeeklyOff) && empty($userOnLeave) && empty($holiday)) {
                                            $absentAttendanceDetail = AttendanceDetail::where('user_id', $user->id)
                                            ->whereBetween('check_in', [$startDate, $endDate])
                                            ->get();
                     
                                            $messsage = ' marked absent for the day.';
                                            $absentMessage =  'You are marked absent for the day.';
                                            }
                                        }
                                    
                                }
                                
                                
                                if (count($absentAttendanceDetail) == 0) {
                                    $title = "Absent";
                                    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))
                                        {
                                        $absentFullMessage =  $user->name . ' ' . $user->lastName . $messsage;
                                            $arr = null;
                                            $arr = [$title, $absentFullMessage, null];
                                        $check_data = [
                                            'notification' =>  $arr[0],
                                            'message' =>  $arr[1],
                                            'actionUrl' =>  $arr[2]
                                        ];
                                        
                                        //checking notification already exists or not with date
                                        $notifications  = Notification::where('notifiable_id', $primary_reporting_manager->id)
                                                                        ->where('data', json_encode($check_data))
                                                                        ->whereBetween('created_at', [$startDate, $endDate])
                                                                        ->first();
                                        if (empty($notifications)) {
                                            $primary_reporting_manager->notify(new AppNotifications($arr));
                                            $firebaseObject = new FirebaseCloudMessaging();
                                            $firebaseObject->sendFirebaseNotification($title,$absentFullMessage,$primary_reporting_manager->id);
                                        }
                                     }
                                    }
                                    //secondary reporting managers
                                    if (count($secondaryManagers) > 0) {
                                        foreach ($secondaryManagers as $secondaryManager) {
                                            if ($primary_reporting_manager_id != $secondaryManager->id){
                                            $absentFullMessage =  $user->name . ' ' . $user->lastName . $messsage;
                                            $arr = null;
                                            $arr = [$title, $absentFullMessage, null];
                                            $check_data = [
                                                'notification' =>  $arr[0],
                                                'message' =>  $arr[1],
                                                'actionUrl' =>  $arr[2]
                                            ];
                                            //checking notification already exists or not with date
                                            $notifications  = Notification::where('notifiable_id', $secondaryManager->id)
                                                                            ->where('data', json_encode($check_data))
                                                                            ->whereBetween('created_at', [$startDate, $endDate])
                                                                            ->first();
                                            if (empty($notifications)) {
                                                $secondaryManager->notify(new AppNotifications($arr));
                                                $firebaseObject = new FirebaseCloudMessaging();
                                                $firebaseObject->sendFirebaseNotification($title,$absentFullMessage,$secondaryManager->id);
                                            }
                                            }
                                        }
                                    } 
                                   
                                    //notification to user
                                    $url = "request-attendance.index";
                                    $arr = null;
                                    $arr = [$title, $absentMessage, $url];
                                    $check_data = [
                                        'notification' =>  $arr[0],
                                        'message' =>  $arr[1],
                                        'actionUrl' =>  $arr[2]
                                    ];
                                    //checking notification already exists or not with date
                                    $notifications  = Notification::where('notifiable_id', $user->id)
                                                                    ->where('data', json_encode($check_data))
                                                                    ->whereBetween('created_at', [$startDate, $endDate])
                                                                    ->first();
                                    if (empty($notifications)) {
                                        $user->notify(new AppNotifications($arr));
                                        $firebaseObject = new FirebaseCloudMessaging();
                                        $firebaseObject->sendFirebaseNotification($title,$absentMessage, $user->id);
                                    }
                                }
                            
                        
                        //if user is  on leave, inform to team members
                        if ($currentTime > $shiftStartTime) {
                            if (!empty($userOnLeave)) {
                                
                                //primary team id
                                $teamId = $user->userdetail->primary_team_id;
                                $team =  Team::find($teamId);
                                //check half day or full day
                                if ($userOnLeave->leave_type == "full_day") {
                                    $leaveMessage = " is on leave today";
                                } else {
                                    $leaveMessage = " is on leave for " . ucwords(str_replace("_", " ", $userOnLeave->half_day_type)) . " today";
                                }
                                //notification to team user 
                                $title = "On Leave";
                                $message = $user->name . ' ' . $user->lastName . $leaveMessage;
                                $actionUrl = null;
                                $arr = null;
                                $arr = [$title, $message, $actionUrl];
                                //get primary team users
                                $primaryTeamUsers = UserDetail::where('primary_team_id',$teamId)->get();
                                if(!empty($primaryTeamUsers)){
                                    foreach($primaryTeamUsers as $primaryTeamUser){
                                        if($user->id  != $primaryTeamUser->user_id){
                                            $teamUser = User::find($primaryTeamUser->user_id);
                                            if(!empty($teamUser)){
                                                $check_data = [
                                                    'notification' =>  $arr[0],
                                                    'message' =>  $arr[1],
                                                    'actionUrl' =>  $arr[2]
                                                ];
                                                $notifications  = Notification::where('notifiable_id', $teamUser->id)
                                                                                ->where('data', json_encode($check_data))
                                                                                ->whereBetween('created_at', [$startDate, $endDate])
                                                                                ->first();
                                                if (empty($notifications)) {
                                                $teamUser->notify(new AppNotifications($arr));
                                                $firebaseObject = new FirebaseCloudMessaging();
                                                $firebaseObject->sendFirebaseNotification($title,$message,$teamUser->id);
                                                }
                                            }
                                        }                                 
                                    
                                    }
                
                                }
                                if (!empty($team->userTeams)) {
                                    foreach ($team->userTeams as $userTeam) {
                                        if ($user->id  != $userTeam->user_id) {
                                            $teamUser = User::find($userTeam->user_id);
                                            if (!empty($teamUser)) {
                                                $check_data = [
                                                    'notification' =>  $arr[0],
                                                    'message' =>  $arr[1],
                                                    'actionUrl' =>  $arr[2]
                                                ];
                                                //checking notification already exists or not with date
                                                $notifications  = Notification::where('notifiable_id', $teamUser->id)
                                                                                ->where('data', json_encode($check_data))
                                                                                ->whereBetween('created_at', [$startDate, $endDate])
                                                                                ->first();
                                                if (empty($notifications)) {
                                                $teamUser->notify(new AppNotifications($arr));
                                                $firebaseObject = new FirebaseCloudMessaging();
                                                $firebaseObject->sendFirebaseNotification($title,$message,$teamUser->id);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    
                }
            
        }
        }
    }
    
}
}