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