Browse Source

add select role_id in HumanResourceController@list

pull/3/head
wahyuun 1 year ago
parent
commit
464407d9ee
  1. 111
      app/Http/Controllers/HumanResourceController.php

111
app/Http/Controllers/HumanResourceController.php

@ -10,7 +10,8 @@ use Illuminate\Support\Facades\Artisan;
class HumanResourceController extends Controller class HumanResourceController extends Controller
{ {
public function add(Request $request){ public function add(Request $request)
{
$this->validate($request, [ $this->validate($request, [
'role_id' => 'required', 'role_id' => 'required',
'name' => 'required', 'name' => 'required',
@ -20,63 +21,65 @@ class HumanResourceController extends Controller
$data = $request->all(); $data = $request->all();
if(isset($request->password) && $request->password!=""){ if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password); $data['password'] = md5($request->password);
} }
$result = HumanResource::create($data); $result = HumanResource::create($data);
if($result){ if ($result) {
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfull created','code'=>200]); return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed created','code'=>400]); return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]);
} }
} }
public function edit($id){ public function edit($id)
if(!$id || (int) $id < 0 || $id==""){ {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die(); die();
} }
$result = HumanResource::find($id); $result = HumanResource::find($id);
if($result){ if ($result) {
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get data human resource, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get data human resource, please try again later!', 'code' => 400], 400);
} }
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){ if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
} }
$humanresource = HumanResource::find($id); $humanresource = HumanResource::find($id);
$data = $request->all(); $data = $request->all();
if(isset($request->password) && $request->password!="" ){ if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password); $data['password'] = md5($request->password);
} }
if(isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()){ if (isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()) {
return response()->json(['status'=>'failed','message'=>'Username already exists!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400);
} }
if($humanresource){ if ($humanresource) {
$result = $humanresource->update($data); $result = $humanresource->update($data);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
die(); die();
} }
if($result){ if ($result) {
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully updated!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed updated!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed updated!', 'code' => 400], 400);
} }
} }
@ -84,18 +87,18 @@ class HumanResourceController extends Controller
{ {
$data = HumanResource::find($id); $data = HumanResource::find($id);
if($data){ if ($data) {
$delete = $data->delete(); $delete = $data->delete();
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
die(); die();
} }
if($delete){ if ($delete) {
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully deleted!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed deleted!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed deleted!', 'code' => 400], 400);
} }
} }
@ -107,22 +110,23 @@ class HumanResourceController extends Controller
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
public function list() public function list()
{ {
$data = HumanResource::select('id', 'name')->get(); $data = HumanResource::select('id', 'name', 'role_id')->get();
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get list human resource, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get list human resource, please try again later!', 'code' => 400], 400);
} }
} }
public function select(Request $request){ public function select(Request $request)
{
$search = $request->query('search'); $search = $request->query('search');
@ -131,9 +135,9 @@ class HumanResourceController extends Controller
$forbidden = []; $forbidden = [];
if($idActivity && $idActivity > 0){ if ($idActivity && $idActivity > 0) {
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){ foreach ($dataF as $val) {
$forbidden[] = $val->user_id; $forbidden[] = $val->user_id;
} }
} }
@ -165,29 +169,28 @@ class HumanResourceController extends Controller
public function checkOldPassword(Request $request, $id) public function checkOldPassword(Request $request, $id)
{ {
if(!$id || (int) $id < 0 || $id==""){ if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die(); die();
} }
$data = $request->all(); $data = $request->all();
if(isset($request->old_password) && $request->old_password!="" ){ if (isset($request->old_password) && $request->old_password != "") {
$result = HumanResource::find($id); $result = HumanResource::find($id);
$data['old_password'] = md5($request->old_password); $data['old_password'] = md5($request->old_password);
if($data['old_password'] !== $result->password) { if ($data['old_password'] !== $result->password) {
return response()->json(['status'=>'failed','message'=>"old password seems doesn't match in records. please try again.",'code'=>400], 400); return response()->json(['status' => 'failed', 'message' => "old password seems doesn't match in records. please try again.", 'code' => 400], 400);
} } elseif ($data['old_password'] === $result->password) {
elseif($data['old_password'] === $result->password) { return response()->json(['status' => 'success', 'message' => "old password match", 'data' => $result, 'code' => 200], 200);
return response()->json(['status'=>'success','message'=>"old password match",'data'=>$result,'code'=>200], 200);
} }
} } else {
else { return response()->json(['status' => 'failed', 'message' => 'old_password is required!', 'code' => 400], 400);
return response()->json(['status'=>'failed','message'=>'old_password is required!','code'=>400], 400);
} }
} }
public function sync(){ public function sync()
{
Artisan::call('sync:integration-human-resources'); Artisan::call('sync:integration-human-resources');
} }
} }

Loading…
Cancel
Save