Server : Apache System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64 User : vapecompany ( 2719) PHP Version : 7.4.33 Disable Function : NONE Directory : /proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/ |
Upload File : |
<?php namespace App\Http\Controllers\Backend; use App\Http\Controllers\Controller; use App\Models\Emplyoee; use Illuminate\Http\Request; use App\Models\Department; use App\Models\Designation; use App\Models\Division; use App\Models\UserRole; use App\Models\District; use App\Models\User; use DB; class EmplyoeeController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function __construct() { $this->middleware('admin'); } public function index() { if(!auth()->user()->canEvent('all_emplyee')) { return redirect('/'); } return view('employee.list'); } public function get_Employee_byDesignation_Id(Request $request){ $d_id=$request->designation_id; $division_id=$request->division_id; $district_id=$request->district_id; $con =array(); if($d_id){ $con['designation_id'] =$d_id; } if($division_id){ $con['division_id'] =$division_id; } if($district_id){ $con['district_id'] =$district_id; } //return $con; $employees = Emplyoee::where($con)->get(); return $employees; } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { if(!auth()->user()->canEvent('new_employee')) { return redirect('/'); } $designations = Designation::where('status',1)->get(); $departments = Department::where('status',1)->get(); $divisions=Division::where('status',1)->get(); return view('employee.create',['designations'=>$designations,'departments'=>$departments,'divisions'=>$divisions]); } function get_all_employee(Request $request){ $draw = $request->get('draw'); $start = $request->get("start"); $rowperpage = $request->get("length"); // Rows display per page $columnIndex_arr = $request->get('order'); $columnName_arr = $request->get('columns'); $order_arr = $request->get('order'); $search_arr = $request->get('search'); $columnIndex = $columnIndex_arr[0]['column']; // Column index $columnName = $columnName_arr[$columnIndex]['data']; // Column name $columnSortOrder = $order_arr[0]['dir']; // asc or desc $searchValue = $search_arr['value']; // Search value $totalRecords = Emplyoee::count(); $employees =Emplyoee::orderBy($columnName,$columnSortOrder) ->leftJoin('designations','designations.designation_id','emplyoees.designation_id') ->leftJoin('departments','departments.department_id','emplyoees.department_id'); if($columnName_arr[0]['search']['value'] != null){ $employees=$employees->Where('employee_id', $columnName_arr[0]['search']['value'] ); } if($columnName_arr[1]['search']['value'] != null){ $employees=$employees->Where('employee_name', 'like', $columnName_arr[1]['search']['value'] . '%'); } if($columnName_arr[2]['search']['value'] != null){ $employees=$employees->Where('department_name', 'like', $columnName_arr[2]['search']['value'] . '%'); } if($columnName_arr[3]['search']['value'] != null){ $employees=$employees->Where('designation_name', 'like', $columnName_arr[3]['search']['value'] . '%'); } if($columnName_arr[4]['search']['value'] != null){ $employees=$employees->Where('employee_phone', 'like', $columnName_arr[4]['search']['value'] . '%'); } if($columnName_arr[5]['search']['value'] != null){ $employees=$employees->Where('employee_email', 'like', $columnName_arr[5]['search']['value'] . '%'); } if($columnName_arr[6]['search']['value'] != null){ $employees=$employees->Where('employee_address', 'like', $columnName_arr[6]['search']['value'] . '%'); } if($columnName_arr[7]['search']['value'] != null){ $employees=$employees->Where('user_type', $columnName_arr[7]['search']['value']); } if($columnName_arr[8]['search']['value'] != null){ $employees=$employees->Where('emp_status', $columnName_arr[8]['search']['value']); } if($rowperpage < 0) { $rowperpage = 8999999999999999999; } $employees=$employees->skip($start) ->take($rowperpage) ->get(); $data_arr = array(); $sl=0; foreach($employees as $employee){ $sl++; $action ='<div role="group" aria-label="Basic example" class="btn-group btn-group-sm">'; if(auth()->user()->canEvent('edit_employee')) { $action .='<a href="'.url('edit_employee/'.$employee->employee_id).'" class="mr-2"> <i class="fa fa-edit text-warning"></i> </a> '; } $action .='</div>'; if($employee->user_type == 1){ $user_type="Admin"; }else if($employee->user_type == 2){ $user_type="General User"; }else{ $user_type="Sales Man"; } if($employee->emp_status == 1){ $status="Current"; }else if($employee->emp_status == 2){ $status="Terminated"; }else{ $status="Resigned"; } $data_arr[] = array( "employee_id" => $sl, "employee_name" => $employee->employee_name, "designation_name" => $employee->designation->designation_name, "department_name" => $employee->department->department_name, "division" => $employee->division ? $employee->division->division_name : '', "district" => $employee->district ? $employee->district->district_name : '', "employee_email" => $employee->employee_email, "employee_phone" => $employee->employee_phone, "employee_address" => $employee->employee_address, "user_type" => $user_type, "emp_status" => $status, "Action" => $action, ); } $response = array( "draw" => intval($draw), "recordsTotal" => $totalRecords, "recordsFiltered" => $totalRecords, "data" => $data_arr ); echo json_encode($response); exit; } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //return response()->json(['er'=>$request->employee_name]); $validator = \Validator::make($request->all(), [ 'employee_name' => 'required|max:150', 'employee_email' => 'required|unique:emplyoees|max:150', 'password' => 'required', 'employee_phone' => 'required|max:14', 'employee_address' => 'required', 'department' => 'required', 'designation' => 'required', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ //return response()->json(['re'=> auth()->user()->user_id]); //DB::transaction(function () { try { DB::beginTransaction(); $user = new User; $user->name=$request->employee_name; $user->email=$request->employee_email; $user->password=bcrypt($request->password); $user->is_admin=$request->user_type == 1 ? 1 : 0; $user->created_by=auth()->user()->user_id; $user->status=$request->emp_status == 1 ? 1 : 0; $user->save(); $uid=$user->user_id; $emplyoee = new Emplyoee; $emplyoee->user_id = $uid; $emplyoee->user_type = $request->user_type; $emplyoee->emp_status = $request->emp_status; $emplyoee->department_id = $request->department; $emplyoee->designation_id = $request->designation; $emplyoee->employee_name = $request->employee_name; $emplyoee->employee_email = $request->employee_email; $emplyoee->employee_phone = $request->employee_phone; $emplyoee->employee_address = $request->employee_address; $emplyoee->division_id = $request->division ? $request->division : 0; $emplyoee->district_id = $request->district ? $request->district : 0; $emplyoee->created_by = auth()->user()->user_id; $emplyoee->save(); $userRole = new UserRole; $userRole->user_id=$uid; if($request->user_type == 3){ $userRole->role_id=1; }else{ $userRole->role_id=2; } $userRole->save(); DB::commit(); } catch (\PDOException $e) { // Woopsy DB::rollBack(); return response()->json(['errors'=>$e]); } // }); } return response()->json(['errors'=>'0','success'=>$request->employee_name.' is successfully added']); } /** * Display the specified resource. * * @param \App\Models\Emplyoee $emplyoee * @return \Illuminate\Http\Response */ public function show(Emplyoee $emplyoee) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Emplyoee $emplyoee * @return \Illuminate\Http\Response */ public function edit($id) { if(!auth()->user()->canEvent('edit_employee')) { return redirect('/'); } $designations = Designation::get(); $departments = Department::get(); $employee = Emplyoee::where('employee_id',$id)->first(); $divisions=Division::get(); $districts=District::where('division_id',$employee->division_id)->get(); return view('employee.edit',['designations'=>$designations,'departments'=>$departments,'employee'=>$employee,'divisions'=>$divisions,'districts'=>$districts]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Emplyoee $emplyoee * @return \Illuminate\Http\Response */ public function update(Request $request) { $id=$request->employee_id; $validator = \Validator::make($request->all(), [ 'employee_name' => 'required|max:150', 'employee_email' => 'required|max:150|unique:emplyoees,employee_email,'.$id.',employee_id', 'employee_phone' => 'required|max:14', 'employee_address' => 'required', 'department' => 'required', 'designation' => 'required', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ $emplyoee = Emplyoee::where('employee_id',$id)->first(); $user = User::where('user_id',$emplyoee->user_id)->first(); $user->name=$request->employee_name; $user->email=$request->employee_email; //$user->password=bcrypt($request->password); $user->is_admin=$request->user_type == 1 ? 1 : 0; $user->updated_by=auth()->user()->user_id; $user->status=$request->emp_status == 1 ? 1 : 0;; $user->save(); //$uid=$user->user_id; // $emplyoee = new Emplyoee; $emplyoee->user_type = $request->user_type; $emplyoee->emp_status = $request->emp_status; $emplyoee->department_id = $request->department; $emplyoee->designation_id = $request->designation; $emplyoee->employee_name = $request->employee_name; $emplyoee->employee_email = $request->employee_email; $emplyoee->employee_phone = $request->employee_phone; $emplyoee->employee_address = $request->employee_address; $emplyoee->updated_by = auth()->user()->user_id; $emplyoee->division_id = $request->division ? $request->division : 0; $emplyoee->district_id = $request->district ? $request->district : 0; $emplyoee->save(); // }); } return response()->json(['errors'=>'0','success'=>$request->employee_name.' is successfully Updated']); } /** * Remove the specified resource from storage. * * @param \App\Models\Emplyoee $emplyoee * @return \Illuminate\Http\Response */ public function destroy(Emplyoee $emplyoee) { // } }