Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 149 |
| ManageTeamController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
1560 | |
0.00% |
0 / 149 |
| index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
| userlistdata | |
0.00% |
0 / 1 |
306 | |
0.00% |
0 / 65 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| store | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| show | |
0.00% |
0 / 1 |
306 | |
0.00% |
0 / 74 |
|||
| edit | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| update | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| <?php | |
| namespace App\Http\Controllers\Manage; | |
| use Illuminate\Http\Request; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Admin\attendanceRequest; | |
| use App\Models\Auth\User; | |
| use App\Models\Admin\UserDetail; | |
| use App\Models\Admin\Department; | |
| use App\Models\Admin\Organisation; | |
| use App\Models\Admin\Team; | |
| use App\Models\Admin\Shift; | |
| use App\Models\Admin\UserAddress; | |
| use App\Models\Admin\UserBankDetail; | |
| use App\Models\Admin\UserDocumentDetail; | |
| use Spatie\Permission\Models\Role; | |
| use Illuminate\Support\Facades\Hash; | |
| use Illuminate\Support\Facades\Validator; | |
| use Illuminate\Support\Facades\Storage; | |
| use Intervention\Image\Facades\Image; | |
| use Session; | |
| use Illuminate\Support\Facades\Crypt; | |
| use App\Notifications\AppNotifications; | |
| use Illuminate\Support\Facades\Auth; | |
| use DB; | |
| use Carbon\Carbon; | |
| use App\Models\Leave\LeaveEntitlement; | |
| use App\Helpers\GetShiftDetailHelper; | |
| use App\Helpers\AttendanceHelper; | |
| class ManageTeamController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index(Request $request) | |
| { | |
| $title = '/Setup/Manage Team'; | |
| $backurl = route('home'); | |
| /*$users = User::all();*/ | |
| // For Attendance Marking | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| return view('manage.UserDetailTable', compact('title','backurl','val','valTeam','valUser')); | |
| } | |
| public function userlistdata(Request $request) | |
| { | |
| $column_key = array("1"=>"user_details.employee_id","2"=>"name","3"=>"","4" =>"","5"=>"","6"=>""); | |
| $where_condition = "1 = 1"; | |
| $order_key = $request->input('order')[0]['column']; | |
| $order = $column_key[$order_key]; | |
| $dir = $request->input('order')[0]['dir']; | |
| if(trim($dir)==''){ | |
| $dir = 'desc'; | |
| } | |
| if ($order != '') { | |
| $orderBy = " ORDER BY ".$order." ".$dir; | |
| } | |
| // if(null !==($request->input('search.value')) && trim($request->input('search.value'))!=''){ | |
| // $search = $request->input('search.value'); | |
| // $where_condition .= " AND (name Like '%$search%' OR lastName Like '%$search%')"; | |
| // } | |
| if(null !==($request->input('search.value')) && trim($request->input('search.value'))!=''){ | |
| $search = trim($request->input('search.value')); | |
| $ser_array = explode(" ",$search); | |
| if(count($ser_array) >=2){ | |
| $where_condition .= " AND ((name Like '$ser_array[0]%') AND (lastName Like '%$ser_array[1]%') )"; | |
| }else{ | |
| $where_condition .= " AND ((name Like '$ser_array[0]%') OR (employee_id LIKE '$ser_array[0]%'))"; | |
| } | |
| } | |
| $teamUsers = GetShiftDetailHelper::getMyReportingEmployeesIds(); | |
| $where_condition .= ' and users.id in (' . implode(',', $teamUsers) . ')'; | |
| $count_model = User::join('user_details', 'users.id','=','user_details.user_id')->whereRaw($where_condition)->count(); | |
| $total_app_count = $count_model; | |
| $totalFiltered = $count_model; | |
| $data_model = User::join('user_details', 'users.id','=','user_details.user_id')->whereRaw($where_condition) | |
| ->orderBy($order , $dir) | |
| ->offset( intval($request->input('start')))->limit(intval($request->input('length'))) | |
| ->get(); | |
| $data = array(); | |
| if(count($data_model)>0){ | |
| foreach($data_model as $database_model){ | |
| $view_route = route('manage-team.show',$database_model->user_id); | |
| $nestedData['name'] = '<a href="#users_view_modal" data-toggle="modal" title="View" data-href="'.$view_route.'">'.$database_model->name.' '.$database_model->lastName.'</a>'; | |
| $role = Role::where('id','=',$database_model->role_id)->first(); | |
| $nestedData['role'] = '-'; | |
| if(!empty($role)){ | |
| $nestedData['role'] = $role->name; | |
| } | |
| $userDetail = UserDetail::where('user_id','=',$database_model->user_id)->first(); | |
| // $teams = Team::select('team')->leftJoin('team_user_detail','teams.id','=','team_user_detail.team_id')->where('team_user_detail.user_detail_id','=',$userDetailId->id)->first(); | |
| //get user detail | |
| //primary team id | |
| $teamId = $userDetail->primary_team_id; | |
| $nestedData['team'] = '-'; | |
| // if(isset($teams) && !empty($teams)) | |
| if($teamId != 0) | |
| { | |
| //primary team name | |
| $userInTeam = $userDetail->primaryTeamName->team; | |
| $nestedData['team'] = $userInTeam; | |
| //$nestedData['team'] = $teams->team; | |
| } | |
| $nestedData['action'] = '-'; | |
| $edit_link = ''; | |
| if(auth()->user()->can('Edit Users module')) | |
| { | |
| $edit_route = route('user-tab.edit',$database_model->user_id); | |
| $edit_link = '<a href="'.$edit_route.'" data-original-title="Edit"> <i class="icon-pencil7" title="edit" style="color:#3699FF !important;"></i> </a>'; | |
| $nestedData['action'] = $edit_link; | |
| } | |
| if(auth()->user()->can('Delete Users module')) | |
| { | |
| $isused = '0'; | |
| $userIsPrimaryReportingManager = UserDetail::where('primary_reporting_manager_id',$database_model->user_id)->where('deleted_at',NULL)->get(); | |
| $userIsScondaryManager = GetShiftDetailHelper::checkUserIsSecondaryManager($database_model->user_id); | |
| if( count($userIsPrimaryReportingManager) > 0 || count($userIsScondaryManager) > 0) | |
| { | |
| $isused = '1'; | |
| } | |
| } | |
| if($database_model->profile_pic){ | |
| $user_image = url('storage/'. $database_model->profile_pic); | |
| }else{ | |
| if($database_model->gender == 'Male') { | |
| $user_image = url("global_assets/images/favicon_io/default-avatar-boy.png"); | |
| } else { | |
| $user_image = url("global_assets/images/favicon_io/default-avatar-girl.jpg"); | |
| } | |
| } | |
| $show_image_container = '<span style="width: 110px;"><div class="img-screen"><img class="rounded-circle" src="'.$user_image.'" alt="No Image" style="width:50px;height:50px;overflow:hidden;"></div></span>'; | |
| $nestedData['profile_image'] = $show_image_container; | |
| $nestedData['employee_id'] = $database_model->employee_id ? $database_model->employee_id: '--' ; | |
| $data[] = $nestedData; | |
| } | |
| } | |
| $json_data = array( | |
| "draw" => intval( $request->input('draw')), | |
| "recordsTotal" => intval( $total_app_count ), | |
| "recordsFiltered" => intval($total_app_count ), | |
| "data" => $data, // total data array | |
| ); | |
| echo json_encode($json_data);exit; | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create() | |
| { | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function show($id) | |
| { | |
| $tab = 'user'; | |
| $title = '/Setup/Edit Users'; | |
| $user = User::find($id); | |
| $userPassword = $user->password; | |
| $userdetail = $user->userdetail; | |
| $user_addresses = $userdetail->userAddress; | |
| $user_bank_details = $userdetail->userBankdetail; | |
| $user_document_details = $userdetail->userDocumentdetail; | |
| //$departments = Department::all(); | |
| $departmentArr = $userdetail->departments; | |
| //$teams = Team::all(); | |
| $teamArr =$userdetail->teams; | |
| //$roles = Role::all(); | |
| // $roleArr = $userdetail->roles; | |
| //$shifts= Shift::all(); | |
| $selectShift = $userdetail->shifts; | |
| //$attendances = attendanceRequest::all(); | |
| $attendanceArr = $userdetail->attendanceRequests; | |
| //$organisations = Organisation::all(); | |
| $editUserdetail = true; | |
| $users = User::all(); | |
| $secondaryManagerArr = $userdetail->secondaryManager; | |
| //$employeeTeam = $user->userdetailWithTeam()->first() != null ? (count($user->userdetailWithTeam()->first()->teams) > 0 ? $user->userdetailWithTeam()->first()->teams[0]['team'] : ''): '-' ; | |
| $employeeTeam = !empty($user->userdetail->primaryTeamName->team) ? $user->userdetail->primaryTeamName->team : '-'; | |
| $leaves = DB::table('leaves')->get(); | |
| $leaveBalances = []; | |
| foreach ($leaves as $leave) { | |
| $leaveEntitlementQuery = array( | |
| 'user_id' => $user->id, | |
| 'year' => Carbon::now()->year, | |
| 'leave_id' => $leave->id | |
| ); | |
| $leaveEntitlementArr = LeaveEntitlement::where($leaveEntitlementQuery)->get(); | |
| $leaveBalance = null; | |
| foreach ($leaveEntitlementArr as $leaveEntitlement) { | |
| $leaveBalance = $leaveEntitlement->leave_balance; | |
| } | |
| if ($leaveBalance == null) { | |
| $leaveBalance = 0; | |
| } | |
| $leaveBalances[] = array( | |
| 'id' => $leave->id, | |
| 'name' => $leave->name, | |
| 'abbr' => $leave->abbr, | |
| 'leave_balance' => $leaveBalance | |
| ); | |
| // $leaveBalances[$leave->id] = $leaveBalance; | |
| } | |
| $employee_id = ''; | |
| if(config('settings.default_employee_id') == 'automatic') | |
| { | |
| $startId = config('settings.id_starts_from'); | |
| $prefix = config('settings.default_id'); | |
| for ($i=$startId; $employee_id == '' ; $i++) { | |
| if (UserDetail::where('employee_id', '=', $prefix.$i)->exists()) | |
| { | |
| } | |
| else | |
| { | |
| $employee_id = $prefix.$i; | |
| break; | |
| } | |
| } | |
| } | |
| $organisations = Organisation::where('id','=',$userdetail->organisation_id)->first(); | |
| $orgname = ''; | |
| if(!empty($organisations)){ | |
| $orgname = $organisations->organisation; | |
| } | |
| // $teamname = array(); | |
| // foreach($teamArr as $teamselect) | |
| // { | |
| // $team = Team::where('id','=',$teamselect->id)->first(); | |
| // array_push($teamname, $team->team); | |
| // } | |
| // $teamname = implode(',', $teamname); | |
| $teamname = ''; | |
| if(!empty($userdetail->primary_team_id)){ | |
| $teamname = $userdetail->primaryTeamName->team; | |
| } | |
| $rolename = ''; | |
| if(!empty($user->getRoleNames()->first())){ | |
| $rolename = $user->getRoleNames()->first(); | |
| } | |
| $shiftname = array(); | |
| foreach($selectShift as $shiftelect) | |
| { | |
| $shift = Shift::where('id','=',$shiftelect->id)->first(); | |
| array_push($shiftname, $shiftelect->shift); | |
| } | |
| $shiftname = implode(',', $shiftname); | |
| $attendancename = array(); | |
| foreach($attendanceArr as $sattendanceselect) | |
| { | |
| $attendance = attendanceRequest::where('id','=',$sattendanceselect->id)->first(); | |
| array_push($attendancename, $attendance->name); | |
| } | |
| $attendancename = implode(',', $attendancename); | |
| $reportingmanager = array(); | |
| $primaryManager = $userdetail->primary_reporting_manager_id; | |
| $primaryReportingManager = ''; | |
| if($primaryManager != 0 || $primaryManager != NULL){ | |
| $primaryReportingManager = $userdetail->primaryReportingManager->name.' '.$userdetail->primaryReportingManager->lastName; | |
| } | |
| foreach($secondaryManagerArr as $secondaryManager) | |
| { | |
| if($primaryManager != $secondaryManager->id){ | |
| $username = User::where('id','=',$secondaryManager->id)->first(); | |
| $name = $username->name.' '.$username->lastName; | |
| array_push($reportingmanager, $name); | |
| } | |
| } | |
| $reportingmanager = implode(',', $reportingmanager); | |
| // return $leaveBalances; | |
| return view('administrationForms.UserDetail.User.ViewUserDetail', compact('user','userdetail','user_addresses','user_bank_details','orgname','editUserdetail','shiftname','teamname','departmentArr','rolename','attendancename','reportingmanager','user_document_details','tab','leaveBalances','employee_id','employeeTeam','primaryReportingManager')); | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit($id) | |
| { | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function update(Request $request, $id) | |
| { | |
| } | |
| } |