CasperSecurity
<?php
namespace App\Http\Livewire\Hrms;
use App\Exports\AttendanceFormatExport;
use App\Exports\SalaryFormatExport;
use App\Models\EmployeeRegistration;
use Carbon\CarbonPeriod;
use Illuminate\Support\Carbon;
use Livewire\Component;
use Livewire\WithFileUploads;
use Livewire\WithPagination;
use Maatwebsite\Excel\Facades\Excel;
use App\Imports\AttendanceImport;
class DailyAttendanceLivewire extends Component
{
use WithPagination;
use WithFileUploads;
protected $paginationTheme = 'bootstrap';
public $currentmonth;
public $monthlydates=[];
public $employee_id;
public $search;
public $perPage=10;
public $orderBy='id';
public $orderAsc='1';
public $present_count=0;
public $employee_attendance;
public function getEmployees(){
$employees=EmployeeRegistration::search($this->search)->where('wages_type','MONTHLY')->where('status',1)->orderBy($this->orderBy, $this->orderAsc ? 'asc' : 'desc')->paginate($this->perPage);
return $employees;
}
public function updatedMonth($value){
session(['selected_month' => $value]);
}
public function upload(){
//dd("hs hs");
$this->validate([
'employee_attendance'=>'required',
],[
'employee_attendance.required'=>'Please Upload Attendance List'
]);
//$file=$this->holiday_list->store('holiday_list');
$response=Excel::import(new AttendanceImport(), $this->employee_attendance);
//dd($response);
if($response) {
//session()->flash('success', $this->successmsg );
$this->dispatchBrowserEvent('closemodal');
$this->dispatchBrowserEvent('showsuccessmsg', [
'type' => 'success',
'title'=>'DATA UPLOADED SUCCESSFULLY',
'message' => 'Attendance Uploaded Successfully',
]);
}else{
$this->dispatchBrowserEvent('closemodal');
$this->dispatchBrowserEvent('showsuccessmsg', [
'type' => 'error',
'title'=>'Error',
'message' => 'Something went wrong',
]);
}
}
public function getAllEmployees(){
$employees=EmployeeRegistration::select('id','name','employee_photo','designation')->where('wages_type','MONTHLY')->where('status',1)->get();
return $employees;
}
public function attendance_format()
{
return Excel::download(new AttendanceFormatExport, 'attendance_format.xlsx');
}
public function mount(){
$this->currentmonth=date('Y-m');
}
public function render()
{
//dd('');
$employees=$this->getEmployees();
$allemployees=$this->getEmployees();
$this->monthlydates=[];
$period = CarbonPeriod::create(Carbon::parse($this->currentmonth)->startOfMonth()->format('Y-m-d'), Carbon::parse($this->currentmonth)->endOfMonth()->format('Y-m-d'));
foreach ($period as $date) {
$this->monthlydates[] = [
'date' => $date->toDateString(),
'day' => $date->format('D'),
];
}
return view('livewire.hrms.daily-attendance-livewire',compact('employees','allemployees'));
}
}