Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 139 |
| TeamController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 10 |
1332 | |
0.00% |
0 / 139 |
| index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
| teamlistdata | |
0.00% |
0 / 1 |
156 | |
0.00% |
0 / 43 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 9 |
|||
| store | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 18 |
|||
| show | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| edit | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 12 |
|||
| storeAttendanceTeam | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 16 |
|||
| getAttendanceTeam | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 8 |
|||
| update | |
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 21 |
|||
| destroy | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| <?php | |
| namespace App\Http\Controllers\Admin; | |
| use Illuminate\Http\Request; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Admin\Team; | |
| use App\Models\Admin\Shift; | |
| use App\Models\Admin\TeamShiftDetail; | |
| use Illuminate\Support\Facades\Validator; | |
| use App\Models\Admin\UserDetail; | |
| use App\Models\Admin\HolidayList; | |
| use Session; | |
| use App\Helpers\AttendanceHelper; | |
| use App\Models\Admin\Setting; | |
| use \DB; | |
| use App\Models\Admin\TeamSetting; | |
| use App\Helpers\GeoFenceHelper; | |
| class TeamController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index(Request $request) | |
| { | |
| $title = '/Setup/Team'; | |
| $backurl = route('home'); | |
| // For Attendance Marking | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| return view('administrationForms.Team.TeamTable', compact('title','backurl','val','valTeam','valUser')); | |
| } | |
| public function teamlistdata(Request $request) | |
| { | |
| $column_key = array("0"=>"team","1"=>"has_schedule"); | |
| $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 (team Like '%$search%')"; | |
| } | |
| $count_model = Team::whereRaw($where_condition)->count(); | |
| $total_app_count = $count_model; | |
| $totalFiltered = $count_model; | |
| $data_model = Team::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){ | |
| $nestedData['name'] = $database_model->team; | |
| $nestedData['schedule'] = $database_model->has_schedule == 1 ? 'Yes' : '---'; | |
| $nestedData['action'] = '-'; | |
| $edit_link = ''; | |
| if(auth()->user()->can('Edit Team module')) | |
| { | |
| $edit_route = route('team.edit',$database_model->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 Team module')) | |
| { | |
| $userTeam = UserDetail::where('primary_team_id','=',$database_model->id)->whereNull('deleted_at')->count(); | |
| $isused = '0'; | |
| if(isset($userTeam) && !empty($userTeam)) | |
| { | |
| $isused = '1'; | |
| } | |
| $delete_link = '<a href="#" title="Delete" data-original-title="Delete" style="padding-left: 5px"; onclick="deleteTeam('.$database_model->id.','.$isused.');"><i class="icon-bin" style="color:#dc3545 !important;"></i></a>'; | |
| $nestedData['action'] = $edit_link.' '.$delete_link; | |
| } | |
| $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(Request $request) | |
| { | |
| $title = '/Setup/Create Team'; | |
| $shifts = Shift::all(); | |
| $backurl = route('team.index'); | |
| $holidaylist = HolidayList::all(); | |
| // For Attendance Marking | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| $team_geofence = null; | |
| return view('administrationForms.Team.Team',compact('title', 'shifts','holidaylist','backurl','val','valTeam','valUser','team_geofence')); | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| $this->validate($request,[ | |
| 'team' => 'required|unique:teams,team|max:255', | |
| ]); | |
| $team = Team::create($request->only(['team','has_schedule', 'has_holiday'])); | |
| $team_id = $team->id; | |
| if(isset($request->holiday_list) && !empty($request->holiday_list)) | |
| { | |
| Team::where('id','=',$team_id)->update(['holiday_list_id' => $request->holiday_list]); | |
| } | |
| if($request->has_schedule == '1') | |
| { | |
| $shiftIds = $request->shift_id; | |
| } | |
| else | |
| { | |
| $shiftIds = $request->single_shift_id; | |
| } | |
| if(!empty($shiftIds)){ | |
| foreach ($shiftIds as $k => $v) { | |
| $shift = new TeamShiftDetail; | |
| $shift->team_id =$team_id; | |
| $shift->shift_id = $v; | |
| $shift->save(); | |
| } | |
| } | |
| $this->storeAttendanceTeam($request, $team_id); | |
| Session::flash('success', 'Team Added Successfully!'); | |
| return redirect()->route('team.index')->withErrors($this); | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function show($id) | |
| { | |
| // | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit(Request $request,$id) | |
| { | |
| $title = '/Setup/Edit Team'; | |
| $teams = Team::find($id); | |
| $shifts= Shift::all(); | |
| $holidaylist = HolidayList::all(); | |
| $teamshift = TeamShiftDetail::where('team_id', $id)->get(); | |
| //return $teamshift; | |
| $backurl = route('team.index'); | |
| // For Attendance Marking | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = $this->getAttendanceTeam($id); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| $team_geofence = GeoFenceHelper::getteamFence($id); | |
| Session::flash('warning', 'Edit Team'); | |
| return view('administrationForms.Team.Team', compact('teams','title', 'shifts', 'teamshift','holidaylist','backurl','val','valTeam','valUser','team_geofence'))->with('team',Team::find($id)); | |
| } | |
| public function storeAttendanceTeam(Request $request,$id) | |
| { | |
| if(auth()->user()->can('Edit Settings module')){ | |
| $value = $request->input('check'); | |
| $checkin_lat = $request->input('checkin_lat'); | |
| $checkin_long = $request->input('checkin_long'); | |
| $checkin_radius = $request->input('checkin_radius'); | |
| $checkin_address = $request->input('checkin_address'); | |
| $checkout_lat = $request->input('checkout_lat'); | |
| $checkout_long = $request->input('checkout_long'); | |
| $checkout_radius = $request->input('checkout_radius'); | |
| $checkout_address = $request->input('checkout_address'); | |
| $keyexist = TeamSetting::where('name', 'attendance')->where('category', 'Team')->where('team_id', $id)->exists(); | |
| if($keyexist){ | |
| TeamSetting::where('name', 'attendance')->where('category', 'Team')->where('team_id', $id)->update(['value' => $value,'check_in_lat' => $checkin_lat,'check_in_long' => $checkin_long,'check_in_radius' => $checkin_radius,'check_in_address' => $checkin_address,'check_out_lat' => $checkout_lat,'check_out_long' => $checkout_long,'check_out_radius' => $checkout_radius,'check_out_address' => $checkout_address]); | |
| } else { | |
| TeamSetting::create(['name' => "attendance", 'value' => $value, 'category' => 'Team', 'team_id' => $id,'check_in_lat' => $checkin_lat,'check_in_long' => $checkin_long,'check_in_radius' => $checkin_radius,'check_in_address' => $checkin_address,'check_out_lat' => $checkout_lat,'check_out_long' => $checkout_long,'check_out_radius' => $checkout_radius,'check_out_address' => $checkout_address]); | |
| } | |
| return redirect()->back()->with('success', "Attendance Setting Saved Successfully!"); | |
| } else { | |
| return redirect()->back()->with('warning', "You don't have permission to edit it!"); | |
| } | |
| } | |
| public function getAttendanceTeam($id) | |
| { | |
| $valTeam = TeamSetting::where('name','attendance') | |
| ->where('category','Team') | |
| ->where('team_id',$id) | |
| ->first(); | |
| if ($valTeam) { | |
| $valTeam = $valTeam->value; | |
| } else { | |
| $valTeam = ''; | |
| } | |
| return $valTeam; | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function update(Request $request, $id) | |
| { | |
| $this->storeAttendanceTeam($request,$id); | |
| $this->validate($request,[ | |
| 'team' => 'required|unique:teams,team,'.$id.',id' | |
| ]); | |
| $request['has_schedule'] = $request->has_schedule ? $request->has_schedule : 0 ; | |
| $request['has_holiday'] = $request->has_holiday ? $request->has_holiday : 0; | |
| $teams = Team::find($id); | |
| $teams->update($request->only(['team', 'has_schedule', 'has_holiday'])); | |
| if($request->has_schedule == '1') | |
| { | |
| $shiftIds = $request->shift_id; | |
| } | |
| else | |
| { | |
| $shiftIds = $request->single_shift_id; | |
| } | |
| if(isset($request->holiday_list) && !empty($request->holiday_list)) | |
| { | |
| //$teams->update($request->only(['team','has_schedule'])); | |
| Team::where('id','=',$id)->update(['holiday_list_id' => $request->holiday_list]); | |
| } | |
| if(!empty($shiftIds)){ | |
| TeamShiftDetail::where('team_id', $id)->delete(); | |
| foreach ($shiftIds as $k => $v) { | |
| $shift = new TeamShiftDetail; | |
| $shift->team_id =$id; | |
| $shift->shift_id = $v; | |
| $shift->save(); | |
| } | |
| } | |
| Session::flash('success', 'Team Updated Successfully!'); | |
| return redirect()->route('team.index')->withErrors($this); | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy(Request $request) | |
| { | |
| $id = $request->id; | |
| $team = Team::find($id); | |
| $team->delete(); | |
| TeamShiftDetail::where('team_id', $id)->delete(); | |
| return response()->json(['success_flag'=>1,'success_message'=>'Team Deleted Successfully']); | |
| } | |
| } |