CasperSecurity

Current Path : /var/www/orientalss.com/app/Http/Livewire/Hrms/
Upload File :
Current File : /var/www/orientalss.com/app/Http/Livewire/Hrms/MonthlyAttendanceLivewire.php

<?php

namespace App\Http\Livewire\Hrms;

use Livewire\Component;
use Carbon\Carbon;
use App\Models\MonthlyAttendance;
use App\Models\EmployeeRegistration;

class MonthlyAttendanceLivewire extends Component
{
    public $search;
    public $perPage=10;
    public $orderBy='id';
    public $orderAsc='1';
    public $status;
    public $modelid;
    public $showmodal=false;

    public $month,$emps,$search_data,$start_date,$end_date,$search_info,$filter_type,$filter,$employee_id,$leave_days,$od_days,$travel_days;

    public $total_days,$working_days;

    public $details=[];

    public function updatedStartDate($date){
       $this->month=$date;

    }

    public function updatedSearchData($data){
       $this->search_info=$data;
       //dd($this->search_info);
    }

    public function updatedFilter($data){
        $this->filter_type=$data;
        //dd($this->filter_type);
    }


    // ----------------------------Functions-----------------------



    public function getHolidaydates($st_date,$en_date){

        $holidays = HolidayInfo::where(function ($query) use ($st_date, $en_date) {
            $query->where('start_dt', '<=', $en_date)
                ->where('end_dt', '>=', $st_date);
        })
        ->orWhere(function ($query) use ($st_date, $en_date) {
            $query->where('start_dt', '<=', $st_date)
                ->where('end_dt', '>=', $st_date);
        })
        ->orWhere(function ($query) use ($st_date, $en_date) {
            $query->where('start_dt', '>=', $st_date)
                ->where('start_dt', '<=', $en_date)
                ->where('end_dt', '>', $en_date);
        })
        ->where('status', 1)
        ->get();

    foreach ($holidays as $holiday) {
        $startDt = max($st_date, $holiday->start_dt);
        $endDt = min($en_date, $holiday->end_dt);

        $datesInRange = CarbonPeriod::create($startDt, $endDt)->toArray();

        $formattedDates = array_map(function ($date) {
            return $date->format('Y-m-d');
        }, $datesInRange);

        $holidayDates = array_merge($holidayDates, $formattedDates);
    }


    $uniqueHolidayDates = array_unique($holidayDates);
    return $uniqueHolidayDates;
     }

// --------------------Leave Days--------------------
public function getLeavedates($st_date,$en_date){
    $leaves = ManageLeave::where(function ($query) {
        $query->where('from_date', '<=', $en_date)
            ->where('to_date', '>=', $st_date);
    })
    ->orWhere(function ($query) {
        $query->where('from_date', '<=', $st_date)
            ->where('to_date', '>=', $st_date);
    })
    ->orWhere(function ($query) {
        $query->where('from_date', '>=', $st_date)
            ->where('from_date', '<=', $en_date)
            ->where('to_date', '>', $en_date);
    })
    ->where('status', 1)
    ->get();

    foreach ($leaves as $leave) {
    $startDt = max($st_date, $leave->from_date);
    $endDt = min($en_date, $leave->to_date);

    $datesInRange = CarbonPeriod::create($startDt, $endDt)->toArray();

    $formattedDates = array_map(function ($date) {
        return $date->format('Y-m-d');
    }, $datesInRange);

    $leaveDates = array_merge($leaveDates, $formattedDates);
    }


    $uniqueleaveDates = array_unique($leaveDates);
    return  $uniqueleaveDates;
}



// ------------------------Od days---------------------








    public function getMonthlyAttendance(){
        if($this->month!=null){

           $onlymonth=Carbon::parse($this->month)->format('m');
           $year=Carbon::parse($this->month)->format('Y');

           $this->start_date=Carbon::parse($this->month)->startOfMonth()->format('Y-m-d');
           $this->end_date=Carbon::parse($this->month)->endOfMonth()->format('Y-m-d');
          // dd($start_Date,$end_Date);
        }
        else{
            $this->dispatchBrowserEvent('showsuccessmsg', [
                'type' => 'error',
                'message' => 'The start date can not be empty...'
            ]);
           return;
        }

        $overlappingRecords = MonthlyAttendance::where(function ($query) {
            $query->where('start_date', '<=', $this->start_date)
                ->where('end_date', '>=',  $this->end_date);
        })->get();

        if(sizeof($overlappingRecords)>0){
           dd($overlappingRecords);
        }
        else{
            $this->emps = EmployeeRegistration::where('status', 1)->where('wages_type','MONTHLY')
            ->get();

            $this->total_days= Carbon::parse($this->start_date)->diffInDays(Carbon::parse($this->end_date))+1;

            $this->details=[];

            foreach($this->emps as $key=>$emp){

                $odRequests=OdRequest::where('employee_id',$emp->employee_id)
                ->where('status',2)
                ->whereBetween('od_from',[$this->start_date,$this->end_date])
                ->get();
                $this->od_days=0;
                //$this->od_hours=0;
                $odDates=[];
                if($odRequests){
                foreach ($odRequests as $odRequest) {
                    $startodDate = Carbon::parse($odRequest->od_from);
                    $endodDate = Carbon::parse($odRequest->od_to);
                    $days = $endodDate->diffInDays($startodDate);
                    $this->od_days += $days+1;
                    $dateRange = CarbonPeriod::create($startodDate, $endodDate);
                    $dates = array_map(function ($date) {
                        return $date->format('y-m-d');
                    }, iterator_to_array($dateRange));
                    $odDates = array_merge($odDates, $dates);
                }
                }

                //$this->od_hours=$this->od_days*$totalTimeInHours;
                 $this->emps[$key]['od_days']= $this->od_days;



                //  ---------------------------------------

                $travelRequests=TravelRequest::where('employee_id',$emp->employee_id)
                    ->where('status',2)
                     ->whereBetween('travel_from',[$this->start_date,$this->end_date])
                    ->get();


                    $this->travel_days = 0;
                    //$this->travel_hours=0;
                    $travelDates=[];

                    if($travelRequests){
                        foreach ($travelRequests as $travelRequest) {
                            $starttravelDate = Carbon::parse($travelRequest->travel_from);
                            $endtravelDate = Carbon::parse($travelRequest->travel_to);


                            $days = $endtravelDate->diffInDays($starttravelDate);


                            $this->travel_days += $days+1;
                            $dateRange = CarbonPeriod::create($starttravelDate, $endtravelDate);


                            $dates = array_map(function ($date) {
                                return $date->format('y-m-d');
                            }, iterator_to_array($dateRange));


                            $travelDates = array_merge($travelDates, $dates);
                        }
                    }
                    $this->emps[$key]['travel_days']= $this->travel_days;
                    //$this->travel_hours=$this->travel_days*$totalTimeInHours;

                //  -----------------------------------

                $approvedLeaves=LeaveRequest::where('employee_no',$emp->employee_id)
                         ->whereBetween('from_date',[$this->start_date,$this->end_date])
                         ->where('status',2)->get();


                        $this->leave_days=0;
                        //$this->leave_hours=0;
                        $leaveDates=[];

                        if($approvedLeaves){
                            foreach ($approvedLeaves as $approvedLeave) {
                                $startleaveDate = Carbon::parse($approvedLeave->from_date);
                                $endleaveDate = Carbon::parse($approvedLeave->to_date);


                                $days = $endleaveDate->diffInDays($startleaveDate);


                                $this->leave_days += $days+1;
                                $dateRange = CarbonPeriod::create($startleaveDate, $endleaveDate);


                                $dates = array_map(function ($date) {
                                    return $date->format('y-m-d');
                                }, iterator_to_array($dateRange));


                                $leaveDates = array_merge($leaveDates, $dates);
                            }
                        }

                        $this->emps[$key]['leave_days']= $this->leave_days;
                       // $this->leave_hours=$this->leave_days*$totalTimeInHours;

                    //    ------------------------------------------------

                    $weekendDays = [];

                    for ($date = Carbon::parse($this->start_date)->copy(); $date->lte(Carbon::parse($this->end_date)); $date->addDay()) {
                        // Check if the current date is a Saturday or Sunday
                        if ($date->isWeekend()) {
                            $weekendDays[] = $date->format('Y-m-d');
                        }
                    }


                $holidays=HolidayInfo::where('status',1)
                ->whereBetween('start_date',[$this->start_date,$this->end_date])

                ->get();

                        $this->holiday_days = 0;
                        $holidayDates=[];
                        if($holidays){
                        foreach($holidays as $holiday){
                        $startholidayDate = Carbon::parse($holiday->start_date);
                        $endholidayDate = Carbon::parse($holiday->end_date);


                        $days = $endholidayDate->diffInDays($startholidayDate);


                        $this->holiday_days += $days+1;
                        $dateRange = CarbonPeriod::create($startholidayDate, $endholidayDate);


                        $dates = array_map(function ($date) {
                            return $date->format('y-m-d');
                        }, iterator_to_array($dateRange));


                        $holidayDates = array_merge($holidayDates, $dates);
                        }
                        }

                $total_offdays=sizeof($holidayDates)+sizeof($weekendDays);

                $this->working_days=$this->total_days- $total_offdays;

                $start = Carbon::parse($this->start_date);
                $end = Carbon::parse($this->end_date);

                $dateArray = [];

                while ($start <= $end) {
                    $dateArray[] = $start->format('Y-m-d');
                    $start->addDay(); // Move to the next day
                }

                foreach($dateArray as $date){
                    $punch=EmployeeAttendance::where('user_id',$emp->user_id)
                    ->where('date',$date)
                    // ->where('attendance_time','!=',null)
                    // ->where('attendance_out_time','!=',null)
                    ->whereNotIn('date', $odDates)
                    ->whereNotIn('date', $travelDates)
                    ->whereNotIn('date', $holidayDates)
                    ->whereNotIn('date', $weekendDays)
                    ->whereNotIn('date', $leaveDates)
                    ->first();
                }

            }

        }


    }

    public function render()
    {
        return view('livewire.hrms.monthly-attendance-livewire');
    }
}
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY