function($q){ $q->with('Department'); }])->orderBy('updated_at', 'desc')->get(); }else{ $staff = Staff::with(['StaffDetail' => function($q){ $q->with('Department'); }])->orderBy('updated_at', 'desc')->where('roles_access','!=','sysadmin')->where('roles_access','!=','PPegawai')->where('roles_access','!=','PPenguatKuasa')->get(); } $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($staff as $a) { $n1 = ''; $jabatan = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } $temp = []; if(!empty($a->StaffDetail->department_ids)){ foreach ($a->StaffDetail->Department as $key => $d) { $temp[] = $d->jbkod; $jabatan = implode( ", ", $temp ); } }else{ $jabatan = '-'; } array_push($nested_data, array( 'index' => $n1.$i, 'nama' => $a->StaffDetail->full_name, 'ic' => $a->StaffDetail->identity, 'phone' => $a->StaffDetail->mobile, 'no_badan' => $a->StaffDetail->no_badan, 'jawatan' => $a->roles_access, 'jabatan' => $jabatan, 'tindakan' => $a->_id )); $i++; } return \DataTables::of($nested_data)->make(true); } public function officerStaffList($jbkod,$roles) { $nested_data = array(); if($roles == 'sysadmin'){ $staff = Staff::with(['StaffDetail' => function($q) use($jbkod){ $q->where('department_ids',$jbkod); }])->orderBy('updated_at', 'desc')->where('roles_access','PenguatKuasa')->orWhere('roles_access','PPenguatKuasa')->get(); }else if($jbkod == 'null'){ $staff = Staff::with(['StaffDetail' => function($q){ $q->with('Department'); }])->orderBy('updated_at', 'desc')->where('roles_access','PenguatKuasa')->get(); }else{ $staff = Staff::with(['StaffDetail' => function($q) use($jbkod){ $q->where('department_ids',$jbkod); }])->orderBy('updated_at', 'desc')->where('roles_access','PenguatKuasa')->get(); } $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($staff as $a) { $n1 = ''; $jabatan = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } if(!empty($a->StaffDetail)){ if($jbkod == 'null'){ $temp = []; $user = StaffDetail::with('Department')->where('_id', $roles)->first(); if(!empty($a->StaffDetail->department_ids)){ foreach ($a->StaffDetail->Department as $key => $d) { $temp[] = $d->jbkod; $jabatan = implode( ", ", $temp ); } foreach ($a->StaffDetail->department_ids as $key => $d) { if (in_array($d, (array)$user->department_ids)) { array_push($nested_data, array( 'index' => $n1.$i, 'nama' => $a->StaffDetail->full_name, 'ic' => $a->StaffDetail->identity, 'phone' => $a->StaffDetail->mobile, 'no_badan' => $a->StaffDetail->no_badan, 'jawatan' => $a->roles_access, 'jabatan' => $jabatan, 'tindakan' => $a->_id )); $i++; break; }else{ continue; } } } }else{ $temp = []; if(!empty($a->StaffDetail->department_ids)){ foreach ($a->StaffDetail->department_ids as $key => $d) { $department = Department::where('_id',$d)->first(); if(!empty($department)){ $temp[] = '['.$department->jbkod.'] '.$department->jnama; $jabatan = implode( ", ", $temp ); } } }else{ $jabatan = '-'; } array_push($nested_data, array( 'index' => $n1.$i, 'nama' => $a->StaffDetail->full_name, 'ic' => $a->StaffDetail->identity, 'phone' => $a->StaffDetail->mobile, 'no_badan' => $a->StaffDetail->no_badan, 'jawatan' => $a->roles_access, 'jabatan' => $jabatan, 'tindakan' => $a->_id )); $i++; } } } return \DataTables::of($nested_data)->make(true); } public function staffFilterList($department,$position,$module) { $nested_data = array(); if($department == "null" && $position == "null" && $module == "null"){ $staff = StaffDetail::orderBy('updated_at', 'desc')->get(); }else if($department != "null" && $position == "null" && $module == "null"){ $staff = StaffDetail::orderBy('updated_at', 'desc')->where('department_ids',$department)->get(); }else if($department != "null" && $position != "null" && $module == "null"){ $staff = StaffDetail::orderBy('updated_at', 'desc')->where('department_ids',$department)->where('roles_access',$position)->get(); } else if($department != "null" && $position != "null" && $module != "null"){ $staff = StaffDetail::whereHas('roles', function($q) use($module) { $q->where('_id', $module)->first(); })->orderBy('updated_at', 'desc')->where('department_ids',$department)->where('roles_access',$position)->get(); } else if($department == "null" && $position != "null" && $module == "null"){ $staff = StaffDetail::orderBy('updated_at', 'desc')->where('roles_access',$position)->get(); } else if($department == "null" && $position != "null" && $module != "null"){ $staff = StaffDetail::whereHas('roles', function($q) use($module) { $q->where('_id', $module)->first(); })->orderBy('updated_at', 'desc')->where('roles_access',$position)->get(); } else if($department == "null" && $position == "null" && $module != "null"){ $staff = StaffDetail::whereHas('roles', function($q) use($module) { $q->where('_id', $module)->first(); })->orderBy('updated_at', 'desc')->where('roles_access',$position)->get(); } $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($staff as $a) { $n1 = ''; $jabatan = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } $temp = []; if(!empty($a->department_ids)){ foreach ($a->department_ids as $key => $d) { $department = Department::where('_id',$d)->first(); if(!empty($department)){ $temp[] = '['.$department->jbkod.'] '.$department->jnama; $jabatan = implode( ", ", $temp ); } } }else{ $jabatan = '-'; } array_push($nested_data, array( 'index' => $n1.$i, 'nama' => $a->full_name, 'ic' => $a->identity, 'phone' => $a->mobile, 'no_badan' => $a->no_badan, 'jawatan' => $a->roles_access, 'jabatan' => $jabatan, 'tindakan' => $a->_id )); $i++; } return \DataTables::of($nested_data)->make(true); } public function staffDetail(Request $request) { $staff = StaffDetail::with('Roles')->where('_id', $request->id)->first(); if(!empty($staff)){ $akses = ''; if($staff->roles_access == "Pegawai"){ foreach($staff->roles_ids as $r){ $role = Roles::where('_id',$r)->first(); $akses .= $role->name . ", "; } $akses = rtrim($akses, ", "); } $department = '';$temp = []; if(!empty($staff->department_ids)){ foreach ($staff->department_ids as $key => $d) { $depart = Department::where('_id',$d)->first(); if(!empty($depart)){ $temp[] = '['.$depart->jbkod.'] '.$depart->jnama; $department = implode( ", ", $temp ); } } }else{ $department = '-'; } $data = [ 'profile_img' => $staff->profile_img, 'full_name' => $staff->full_name, 'username' => $staff->username, 'identity' => $staff->identity, 'mobile' => $staff->mobile, 'jbkod' => $department, 'roles_access' => $staff->roles_access, 'gred' => $staff->gred, 'no_badan' => $staff->no_badan, 'email' => $staff->email, 'address' => $staff->address, 'access' => $akses ]; return response()->json(['status' => 'true', 'desc' => $data]); }else{ return response()->json(['status' => 'false', 'desc' => 'Rekod ini tidak ditemui']); } } public function deleteStaff(Request $request) { $staff = Staff::with('StaffDetail')->where('_id',$request->id)->first(); if(!empty($staff)){ $staff->StaffDetail->department()->detach(); if($staff->roles_access == "Pegawai"){ $staff->StaffDetail->roles()->detach(); } $staff->staffdetail()->delete(); $staff->delete(); return response()->json(['status' => 'true', 'desc' => 'Buang rekod kakitangan ( '.$staff->email.' )']); }else{ return response()->json(['status' => 'false', 'desc' => 'Buang rekod kakitangan ( '.$staff->email.' )']); } } }