CasperSecurity
<?php
namespace App\Http\Livewire\Hrms;
use App\Models\BankInformation;
use App\Models\EmployeeProfile;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithPagination;
class EmployeeProfileLivewire extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public $search;
public $perPage = 10;
public $orderBy = 'id';
public $orderAsc = '1';
public $modelid;
public $showmodal = false;
//profile info variables
public $user_id,$employee_id,$employee_name,$primary_mobile,$alternate_mob,$blood_grp,$present_address,$permanent_address;
public $isprof_enable=false;
//bank info variables
public $bank_acc_type,$bank_name,$ifsc_code,$micr_code,$esi_no,$pf_no;
public $isbank_enable=false;
public $ispre_enable=false;
public $isfam_enable=false;
public $successmsg = "The Profile has been saved successfully.";
public $updatemsg = "The Profile has been updated successfully.";
/*public $deletemsg = "The Profile data has been deleted successfully.";
public $duplicateerrormsg = "Sorry !!! Profile name has already exists in our database. Please Try Another Name";
public $errormsg = "Sorry !!! Something went wrong. Please Try Again.";*/
protected $listeners = ['delete'];
public $profrules = [
'user_id' => 'required',
'employee_id' => 'required',
'employee_name' => 'required',
'primary_mobile' => 'required',
'alternate_mobile' => 'required',
'blood_grp' => 'required',
'present_address' => 'required',
'permanent_address' => 'required',
];
public $profupdatedrules = [
'user_id' => 'required',
'employee_id' => 'required',
'employee_name' => 'required',
'primary_mobile' => 'required',
'alternate_mobile' => 'required',
'blood_grp' => 'required',
'present_address' => 'required',
'permanent_address' => 'required',
'status'=>'required',
];
public $profmessages = [
'user_id.required' => 'This field is required',
'employee_id.required' => 'This field is required',
'employee_name.required' => 'This field is required',
'primary_mobile.required' => 'This field is required',
'alternate_mob.required' => 'This field is required',
'blood_grp.required' => 'This field is required',
'present_address.required' => 'This field is required',
'permanent_add.required' => 'This field is required',
];
public $bankrules = [
'user_id' => 'required',
'bank_acc_type' => 'required',
'bank_name' => 'required',
'ifsc_code' => 'required',
'micr_code' => 'required',
'esi_no' => 'required',
'pf_no' => 'required',
];
public $bankupdatedrules = [
'user_id' => 'required',
'bank_acc_type' => 'required',
'bank_name' => 'required',
'ifsc_code' => 'required',
'micr_code' => 'required',
'esi_no' => 'required',
'pf_no' => 'required',
'status' => 'required'
];
public $bankmessages = [
'user_id.required' => 'This field is required',
'bank_acc_type.required' => 'This field is required',
'bank_name.required' => 'This field is required',
'ifsc_code.required' => 'This field is required',
'micr_code.required' => 'This field is required',
'esi_no.required' => 'This field is required',
'pf_no.required' => 'This field is required',
];
public function updatingSearch()
{
$this->resetPage();
}
public function profeditclick(){
$this->isprof_enable=true;
}
public function bankeditclick(){
$this->isbank_enable=true;
}
public function fameditclick(){
$this->isfam_enable=true;
}
public function preeditclick(){
$this->ispre_enable=true;
}
public function showmodalclick()
{
$this->cleanVar();
$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 loadProfData($id)
{
$response = EmployeeProfile::find($id);
if ($response) {
$this->user_id = $response['user_id'];
$this->employee_name = $response['employee_name'];
$this->employee_id = $response['employee_id'];
$this->primary_mobile = $response['primary_mobile'];
$this->Alternate_mobile = $response['Alternate_mobile'];
$this->blood_group = $response['blood_group'];
$this->present_address = $response['present_address'];
$this->permanent_address = $response['permanent_address'];
$this->status = $response['status'];
}
}
public function loadBankData($id){
$response = BankInformation::find($id);
if($response) {
$this->user_id = $response['user_id'];
$this->bank_acc_type = $response['bank_acc_type'];
$this->bank_name = $response['bank_name'];
$this->ifsc_code = $response['ifsc_code'];
$this->micr_code = $response['micr_code'];
$this->esi_no = $response['esi_no'];
$this->pf_no = $response['pf_no'];
$this->status = $response['status'];
}
}
public function PorfSave(){
$this->validate($this->rules,$this->messages);
$response=EmployeeProfile::where('user_id',$this->user_id)->first();
if($response){
$this->dispatchBrowserEvent('showsuccessmsg',[
'type'=>'error',
'message'=>$this->duplicateerrormsg
]);
}else {
$response =EmployeeProfile::create([
'user_id' => $this->user_id,
'employee_name' => $this->employee_name,
'employee_id' => $this->employee_id,
'primary_mobile' => $this->primary_mobile,
'Alternate_mobile' => $this->Alternate_mobile,
'blood_group' => $this->blood_group,
'present_address' => $this->present_address,
'permanent_address' => $this->permanent_address,
]);
//dd($response);
if ($response) {
$this->cleanVar();
$this->dispatchBrowserEvent('closeOffCanvas');
$this->dispatchBrowserEvent('showsuccessmsg', [
'type' => 'success',
'message' => $this->successmsg
]);
} else {
$this->dispatchBrowserEvent('showsuccessmsg', [
'type' => 'error',
'message' => $this->errormsg
]);
}
}
}
public function BankSave(){
$this->validate($this->rules,$this->messages);
$response=BankInformation::where('bank_acc_type',$this->bank_acc_type)->first();
if($response){
$this->dispatchBrowserEvent('showsuccessmsg',[
'type'=>'error',
'message'=>$this->duplicateerrormsg
]);
}else {
$response =BankInformation::create([
'user_id' => $this->user_id,
'bank_acc_type' => $this->bank_acc_type,
'bank_name' => $this->bank_name,
'ifsc_code' => $this->ifsc_code,
'micr_code' => $this->micr_code,
'esi_no' => $this->esi_no,
'pf_no' => $this->pf_no,
]);
//dd($response);
if ($response) {
$this->cleanVar();
$this->dispatchBrowserEvent('closeOffCanvas');
$this->dispatchBrowserEvent('showsuccessmsg', [
'type' => 'success',
'message' => $this->successmsg
]);
} else {
$this->dispatchBrowserEvent('showsuccessmsg', [
'type' => 'error',
'message' => $this->errormsg
]);
}
}
}
public function PorfUpdate()
{
$this->empdata=Auth::user()->all;
$this->validate($this->updatedrules, $this->messages);
$response = EmployeeProfile::find($this->modelid);
if ($response) {
$response->update(
$empdata=[
'user_id' => $this->user_id,
'employee_name' => $this->employee_name,
'employee_id' => $this->employee_id,
'primary_mobile' => $this->primary_mobile,
'Alternate_mobile' => $this->Alternate_mobile,
'blood_group' => $this->blood_group,
'present_address' => $this->present_address,
'permanent_address' => $this->permanent_address,
'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 BankUpdate(){
$this->bankdata=Auth::user()->all;
$this->validate($this->updatedrules, $this->messages);
$response = BankInformation::find($this->modelid);
if ($response) {
$response->update(
$bankdata=[
'user_id' => $this->user_id,
'bank_acc_type' => $this->bank_acc_type,
'bank_name' => $this->bank_name,
'ifsc_code' => $this->ifsc_code,
'micr_code' => $this->micr_code,
'esi_no' => $this->esi_no,
'pf_no' => $this->pf_no,
'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 read(){
$employee_profiles=EmployeeProfile::search($this->search)
->orderBy($this->orderBy, $this->orderAsc ? 'asc' : 'desc')
->paginate($this->perPage);
return $employee_profiles;
}
public function render()
{
$dataTable = $this->read();
$emp_det=Auth::user();
$this->employee_name=$emp_det->name;
$this->employee_id=$emp_det->employee_id;
$profiledetails=EmployeeProfile::where('user_id',$emp_det->id)->first();
// if($profiledetails){
// $this->loadProfData($profiledetails->id);
// }
//dd($emp_det);
return view('livewire.hrms.employee-profile-livewire',compact('dataTable','emp_det'));
}
}