CasperSecurity

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

<?php

namespace App\Http\Livewire\Hrms;

use App\Models\EmployeeRegistration;
use App\Models\LeaveRequest;
use App\Models\LeaveTypes;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithPagination;

class LeaveRequestLivewire extends Component
{
    use WithPagination;
    protected $paginationTheme = 'bootstrap';

    public $search;
    public $perPage = 10;
    public $orderBy = 'id';
    public $orderAsc = '1';
    public $leave_type,$from_date, $to_date,$req_id, $days_for_leave,$reason,$status, $data, $manager_id,$hr_id;
    public $modelid;
    public $showmodal = false;

    public $successmsg = "The  Leave Request  has been saved successfully.";
    public $updatemsg = "The Leave Request has been updated successfully.";
    public $deletemsg = "The Leave Request data has been deleted successfully.";
    public $duplicateerrormsg = "Sorry !!! Leave Request name has already exists in our database. Please Try Another Name";
    public $errormsg = "Sorry !!! Something went wrong. Please Try Again.";

    protected $listeners = ['delete'];

    public $rules = [
        'leave_type' => 'required',
        'req_id' => 'required',
        'from_date' => 'required',
        'to_date' => 'required',
        'days_for_leave' => 'required',
        'reason' =>'required',
//        'status' => 'required',
    ];

    public $updatedrules = [
        'leave_type' => 'required',
        'req_id' => 'required',
        'from_date' => 'required',
        'to_date' => 'required',
        'days_for_leave' => 'required',
        'reason' =>'required',
//        'status' => 'required',
    ];

    public $messages = [
        'leave_type.required' => 'This field is required',
        'req_id.required' => 'This field is required',
        'from_date.required' => 'This field is required',
        'to_date.required' => 'This field is required',
        'days_for_leave.required' => 'This field is required',
        'reason.required' =>'This field is required',
    ];

    public function updatingSearch()
    {
        $this->resetPage();
    }

    public function showmodalclick(){

        $this->employee_id=Auth::user()->employee_id;
        $req=LeaveRequest::all();
        if(sizeof($req)<10){
            $add="000".sizeof($req)+1;
        }
        elseif(sizeof($req)<100){
            $add="00".sizeof($req)+1;
        }
        elseif(sizeof($req)<1000){
            $add="0".sizeof($req)+1;
        }
        else{
            $add=sizeof($req+1);
        }
        $this->req_id="LR".$add;
        $this->resetValidation();
        $this->showmodal = true;
    }

    public function closemodalclick()
    {
        $this->resetValidation();
        $this->showmodal = false;
    }

    public function updateclick($id)
    {
        $this->modelid = $id;
        $this->loadData($this->modelid);
        $this->showmodal = true;
    }

    public function deleteclick($id)
    {
        $this->modelid = $id;
        $this->dispatchBrowserEvent('confirmdelete', [
            'message' => 'Are you sure want to delete this data ?',
            'funcname' => 'delete'
        ]);
    }

    public function cleanVar()
    {
        $this->modelid = null;
        $this->status = null;
        $this->showmodal = false;
    }

    public function loadData($id)
    {
        $response = LeaveRequest::find($id);
        if ($response) {
            $this->req_id = $response['req_id'];
            $this->leave_type = $response['leave_type'];
            $this->from_date = $response['from_date'];
            $this->to_date = $response['to_date'];
            $this->days_for_leave = $response['days_for_leave'];
            $this->reason = $response['reason'];
            $this->status = $response['status'];
        }
    }

    public function updatedToDate($value)
    {

        if ($this->from_date) {
            $formatted_from_Date = Carbon::parse($this->from_date);
            $formatted_to_Date = Carbon::parse($value);
            $this->days_for_leave = $formatted_from_Date->diffInDays($formatted_to_Date) + 1;
        }
    }
    public function submit()
    {

        $this->validate($this->rules, $this->messages);
            $empdet = EmployeeRegistration::where('employee_id', $this->employee_id)->first();
            if ($empdet->manager_id != null) {
                $this->manager_id = $empdet->manager_id;
            }
            if ($empdet->hr_id != null) {
                $this->hr_id = $empdet->hr_id;
            }
            if ($this->hr_id && $this->manager_id) {
                $leavedata=[
                    'employee_id' => $this->employee_id,
                    'req_id' => $this->req_id,
                    'leave_type' => $this->leave_type,
                    'from_date' => $this->from_date,
                    'to_date' => $this->to_date,
                    'days_for_leave' => $this->days_for_leave,
                    'reason' => $this->reason,
                    'manager_id' => $this->manager_id,
                    'hr_id' => $this->hr_id,
                ];

                $response = LeaveRequest::create($leavedata);
                if ($response) {
                    $this->cleanVar();
                    $this->dispatchBrowserEvent('closeOffCanvas');
                    $this->dispatchBrowserEvent('showsuccessmsg', [
                        'type' => 'success',
                        'message' => $this->successmsg
                    ]);
                } else {
                    $this->dispatchBrowserEvent('showsuccessmsg', [
                        'type' => 'error',
                        'message' => $this->errormsg
                    ]);
                }
            } elseif ($this->hr_id == null && $this->manager_id == null) {
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => 'You need to assigned Manager and HR.'
                ]);
            } elseif ($this->hr_id) {
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => 'You need to assigned manager.'
                ]);
            } else {
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => 'You need to assigned HR.'
                ]);
            }



    }
    public function update()
    {
        $this->validate($this->updatedrules, $this->messages);
        $response = LeaveRequest::find($this->modelid);
        if ($response) {
            $response->update([
                'req_id' => $this->req_id,
                'leave_type' => $this->leave_type,
                'from_date' => $this->from_date,
                'to_date' => $this->to_date,
                'days_for_leave' => $this->days_for_leave,
                'reason' => $this->reason,
                'status' => $this->status,
            ]);

            //dd($response);
            if ($response) {
                $this->cleanVar();
                $this->dispatchBrowserEvent('closeOffCanvas');
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'success',
                    'message' => $this->updatemsg
                ]);
            } else {
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => $this->errormsg
                ]);
            }
        }
    }

    public function delete()
    {
        $response = LeaveRequest::find($this->modelid);
        if ($response) {
            if ($response->delete()) {
                $this->cleanVar();
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'success',
                    'message' => $this->deletemsg
                ]);
            } else {
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => $this->errormsg
                ]);
            }
        }
    }

    public function read()
    {
        $leave_requests = LeaveRequest::search($this->search)
            ->orderBy($this->orderBy, $this->orderAsc ? 'asc' : 'desc')
            ->paginate($this->perPage);
        return $leave_requests;
    }
    public function render()
    {
        $datatable = [];
        $datatable = $this->read();
        if (sizeof($datatable) > 0) {
            foreach ($datatable as $key => $data) {
                $leave = LeaveTypes::where('id', $data->leave_type)->first();

                if ($leave) {
                    $datatable[$key]['leave_type'] = $leave->leave_type;
                } else {
                    $datatable[$key]['leave_type'] = "NA";
                }
            }
        }
        $leaveTypes = LeaveTypes::where('status', 1)->get();
        return view('livewire.hrms.leave-request-livewire', compact('datatable', 'leaveTypes'));
    }
}
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