CasperSecurity

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

<?php

namespace App\Http\Livewire\Hrms;

use Livewire\Component;
use Livewire\WithFileUploads;
use Carbon\CarbonPeriod;
use Illuminate\Support\Carbon;
use Livewire\WithPagination;
use App\Models\EmployeeWageDetailsModel;
use App\Exports\EmployeeWageExport;
use App\Imports\EmployeeWageImport;

use Maatwebsite\Excel\Facades\Excel;

class WageDetailsLivewire extends Component
{
    use WithPagination;
    use WithFileUploads;
    protected $paginationTheme = 'bootstrap';
    public $modelid;
    public $showmodal=false;

    public $emp_name,$emp_designation,$emp_location,$emp_attendance,$uan_no,$ESI_no,$totaldays,$netPayInWords,$salary_info,$month_year,$employee_wages;
    public $earning_array=[];
    public $deduction_array=[];
    public $filter_type,$search_info,$month;
    public $slip_month;
    public $gross_salary=0;
    public $employees=[];
    public $total_deduction=0;
    public $net_salary=0;

    public $sal_arr=[];


    public function exportWage()
    {
        if (!$this->month_year) {
            $this->dispatchBrowserEvent('showsuccessmsg',[
                'type'=>'error',
                'message'=>"Enter Month first"
            ]);
            return;  // You can return early if the validation fails
        }

        // Split the month_year value into month and year
        list($year, $month)= explode('-', $this->month_year);

        // Create the export instance with the selected month and year
        $export = new EmployeeWageExport($month, $year);

        // Download the Excel file




        $this->dispatchBrowserEvent('showsuccessmsg',[
            'type'=>'success',
            'message'=>"The format has been exported"
        ]);
        $this->dispatchBrowserEvent('closeModal');
        return Excel::download($export, 'employee_wage_details.xlsx');
    }
    public function importWageSheet()
    {
        // Ensure the file is provided

        if (!$this->month_year) {
            $this->dispatchBrowserEvent('showsuccessmsg',[
                'type'=>'error',
                'message'=>"Enter Month first"
            ]);
            session()->flash('error', 'Please select a month.');
            return;
        }

        // Split the month_year value into month and year
        list($year, $month) = explode('-', $this->month_year);
        if (!$this->employee_wages) {
            $this->dispatchBrowserEvent('showsuccessmsg',[
                'type'=>'error',
                'message'=>"No file provided"
            ]);
            return response()->json(['message' => 'No file provided'], 400);
        }

        // Check if the month_year is provided
        if (!$this->month_year) {
            return response()->json(['message' => 'Month and Year are required'], 400);
        }

        // Extract month and year from the month_year input (YYYY-MM)
        list($year, $month) = explode('-', $this->month_year);

        // Ensure the file has a valid extension
        $file = $this->employee_wages;
        $extension = $file->getClientOriginalExtension();

        if (in_array($extension, ['xlsx', 'xls', 'csv'])) {

            // Pass month and year along with the file to the import class
            Excel::import(new EmployeeWageImport($month, $year), $file);

            $this->dispatchBrowserEvent('showsuccessmsg',[
                'type'=>'success',
                'message'=>"Wage details uploaded successfully"
            ]);

            return response()->json(['message' => 'Employee wages imported successfully']);
        } else {
            return response()->json(['message' => 'Invalid file type. Only .xlsx, .xls, or .csv are allowed'], 400);
        }
    }




    public function downloadPdf()
    {
        return redirect()->route('salary-slip.pdf', ['month' => 'January']);
    }


    //Messages
    public $errorsearchmsg="Search  field can not be empty";

    public function updatedMonth($value){
        session(['selected_month' => $value]);

    }

    public function showmodalclick($id,$empid,$month,$year){

        $this->modelid=$id;
        //dd($this->modelid);
        $this->resetValidation();
        $this->showmodal=true;
        $this->slipGeneration($empid,$month,$year);
    }


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

    public function cleanSlip(){
        $this->emp_name=null;
        $this->emp_designation=null;
        $this->emp_location=null;
        $this->emp_attendance=null;
        $this->uan_no=null;
        $this->ESI_no=null;
        $this->slip_month=null;
    }

    public function salary_format()
    {
        return Excel::download(new SalaryFormatExport, 'salary_format.xlsx');
    }

    public function getIndianCurrency($number)
    {
        $decimal = round($number - ($no = floor($number)), 2) * 100;
        $hundred = null;
        $digits_length = strlen($no);
        $i = 0;
        $str = [];
        $words = [
            0 => "",
            1 => "One",
            2 => "Two",
            3 => "Three",
            4 => "Four",
            5 => "Five",
            6 => "Six",
            7 => "Seven",
            8 => "Eight",
            9 => "Nine",
            10 => "Ten",
            11 => "Eleven",
            12 => "Twelve",
            13 => "Thirteen",
            14 => "Fourteen",
            15 => "Fifteen",
            16 => "Sixteen",
            17 => "Seventeen",
            18 => "Eighteen",
            19 => "Nineteen",
            20 => "Twenty",
            30 => "Thirty",
            40 => "Forty",
            50 => "Fifty",
            60 => "Sixty",
            70 => "Seventy",
            80 => "Eighty",
            90 => "Ninety",
        ];
        $digits = ["", "Hundred", "Thousand", "Lakh", "Crore"];
        while ($i < $digits_length) {
            $divider = $i == 2 ? 10 : 100;
            $number = floor($no % $divider);
            $no = floor($no / $divider);
            $i += $divider == 10 ? 1 : 2;
            if ($number) {
                $plural = ($counter = count($str)) && $number > 9 ? "s" : null;
                $hundred = $counter == 1 && $str[0] ? " and " : null;
                $str[] =
                    $number < 21
                        ? $words[$number] .
                        " " .
                        $digits[$counter] .
                        $plural .
                        " " .
                        $hundred
                        : $words[floor($number / 10) * 10] .
                        " " .
                        $words[$number % 10] .
                        " " .
                        $digits[$counter] .
                        $plural .
                        " " .
                        $hundred;
            } else {
                $str[] = null;
            }
        }
        $Rupees = implode("", array_reverse($str));
        $paise =
            $decimal > 0
                ? "." .
                ($words[$decimal / 10] . " " . $words[$decimal % 10]) .
                " Paise"
                : "";
        return ($Rupees ? $Rupees . "Rupee " : "") . $paise;
    }


    public function slipGeneration($id,$month,$year){
        session()->forget('salary_slip');

        $this->cleanSlip();

        $emp = EmployeeWageDetailsModel::where('id', $id)
            ->where('month', $month)
            ->where('year', $year)
            ->first();

       // dd($emp);

        $this->deduction_array = [];
        $this->earning_array = [];
        $this->total_deduction = 0;

        $date = Carbon::create($year, $month, 1);

// Format the date as "F-Y" (e.g., November-2023)
        $formattedDate = $date->format('F-Y');
        $this->slip_month=$formattedDate;
        $this->emp_name = $emp->name;
        $this->emp_designation = $emp->designation;

        $this->earning_array[] = $emp->gross_pay;
        $this->earning_array[] = $emp->extra_wages;
        $this->deduction_array[] = $emp->epf;
        $this->deduction_array[] = $emp->esic;

        $this->gross_salary = $emp->gross_pay + $emp->extra_wages;
        $this->total_deduction = $emp->epf + $emp->esic;
        $this->net_salary = $this->gross_salary - $this->total_deduction;

        $this->netPayInWords = $this->getIndianCurrency($this->net_salary);

        $this->emp_attendance=$emp->paid_days;

        // Store salary data in session
        session([
            'salary_slip' => [
                'emp_name' => $this->emp_name,
                'emp_designation' => $this->emp_designation,
                'earning_array' => $this->earning_array,
                'deduction_array' => $this->deduction_array,
                'gross_salary' => $this->gross_salary,
                'total_deduction' => $this->total_deduction,
                'net_salary' => $this->net_salary,
                'netPayInWords' => $this->netPayInWords,
                'attendance'=>$this->emp_attendance,
                'slip_month'=>$this->slip_month
            ]
        ]);

        // Trigger modal event
        $this->dispatchBrowserEvent('slip_modal');

    }

    public function salary_upload(){
        $this->validate([
            'salary_info'=>'required',
        ],[
            'salary_info.required'=>'Please Upload Attendance List'
        ]);
        $response=Excel::import(new SalaryCalculationImport(), $this->salary_info);
        //dd($response);

        if($response) {
            //session()->flash('success', $this->successmsg );
            $this->dispatchBrowserEvent('closemodal');
            $this->dispatchBrowserEvent('showsuccessmsg', [
                'type' => 'success',
                'title'=>'DATA UPLOADED SUCCESSFULLY',
                'message' => 'Data Uploaded Successfully',
            ]);

        }else{
            $this->dispatchBrowserEvent('closemodal');
            $this->dispatchBrowserEvent('showsuccessmsg', [
                'type' => 'error',
                'title'=>'Error',
                'message' => 'Something went Wrong',
            ]);
        }
    }


    public function salary_view(){
//        dd();
        //dd('');
        $this->sal_arr=[];


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

       // dd($month,$year);
        if($this->month){
            $this->employees=EmployeeWageDetailsModel::where('month',$month)
                ->where('year',$year)->get();
        }
        else{
            $this->dispatchBrowserEvent('showsuccessmsg',[
                'type'=>'error',
                'message'=>"Enter Month first"
            ]);
            return;
        }





       // dd($this->employees);

       if(sizeof($this->employees)==0){
           $this->dispatchBrowserEvent('showsuccessmsg',[
               'type'=>'success',
               'message'=>"Wage Details fetched successfully"
           ]);
           return $this->employees;
       }else{
           $this->dispatchBrowserEvent('showsuccessmsg',[
               'type'=>'success',
               'message'=>"Wage Details fetched successfully"
           ]);
       }


    }
    public function render()
    {
//        $employees=EmployeeWageDetailsModel::where('month',$month)
//            ->where('year',$year)->get();
      //  $employees=$this->salary_view();
        return view('livewire.hrms.wage-details-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