Browse Source

Merge pull request 'dev-wahyun' (#183) from dev-wahyun into staging

Reviewed-on: ordo/adw-backend#183
pull/3/head
ibnu 1 year ago
parent
commit
6599771ec7
  1. 389
      app/Http/Controllers/HumanResourceController.php

389
app/Http/Controllers/HumanResourceController.php

@ -1,193 +1,196 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\HumanResource; use App\Models\HumanResource;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\UserToProyek; use App\Models\UserToProyek;
use Illuminate\Support\Facades\Artisan; 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, [ {
'role_id' => 'required', $this->validate($request, [
'name' => 'required', 'role_id' => 'required',
'ktp_number' => 'required', 'name' => 'required',
'employee_type' => 'required' 'ktp_number' => 'required',
]); 'employee_type' => 'required'
]);
$data = $request->all();
$data = $request->all();
if(isset($request->password) && $request->password!=""){
$data['password'] = md5($request->password); if (isset($request->password) && $request->password != "") {
} $data['password'] = md5($request->password);
}
$result = HumanResource::create($data);
$result = HumanResource::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfull created','code'=>200]); if ($result) {
}else{ return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed created','code'=>400]); } else {
} return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]);
} }
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ public function edit($id)
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); {
die(); 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){ $result = HumanResource::find($id);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ if ($result) {
return response()->json(['status'=>'failed','message'=>'failed get data human resource, please try again later!','code'=>400], 400); 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){ }
if(!$id || (int) $id < 0 || $id==""){ public function update(Request $request, $id)
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); {
}
if (!$id || (int) $id < 0 || $id == "") {
$humanresource = HumanResource::find($id); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$data = $request->all();
$humanresource = HumanResource::find($id);
if(isset($request->password) && $request->password!="" ){
$data['password'] = md5($request->password); $data = $request->all();
}
if (isset($request->password) && $request->password != "") {
if(isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()){ $data['password'] = md5($request->password);
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()) {
if($humanresource){ return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400);
$result = $humanresource->update($data); }
}else{
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); if ($humanresource) {
die(); $result = $humanresource->update($data);
} } else {
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
if($result){ die();
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);
public function delete($id) }
{ }
$data = HumanResource::find($id);
public function delete($id)
if($data){ {
$delete = $data->delete(); $data = HumanResource::find($id);
}else{
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400); if ($data) {
die(); $delete = $data->delete();
} } 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);
public function search(Request $request) }
{ }
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_users'); public function search(Request $request)
$builder = $dataBuilder['builder']; {
$countBuilder = $dataBuilder['count']; $payload = $request->all();
$dataGet = $builder->get(); $dataBuilder = $this->setUpPayload($payload, 'm_users');
$totalRecord = $countBuilder->count(); $builder = $dataBuilder['builder'];
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $countBuilder = $dataBuilder['count'];
} $dataGet = $builder->get();
$totalRecord = $countBuilder->count();
public function list() return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
{ }
$data = HumanResource::select('id', 'name')->get();
$countData = $data->count(); public function list()
{
if($data){ $data = HumanResource::select('id', 'name', 'role_id')->get();
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); $countData = $data->count();
}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){ }
}
$search = $request->query('search');
public function select(Request $request)
$idActivity = (int)$request->query('idact'); {
$idProyek = (int)$request->query('idProyek');
$search = $request->query('search');
$forbidden = [];
$idActivity = (int)$request->query('idact');
if($idActivity && $idActivity > 0){ $idProyek = (int)$request->query('idProyek');
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){ $forbidden = [];
$forbidden[] = $val->user_id;
} if ($idActivity && $idActivity > 0) {
} $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach ($dataF as $val) {
if ($search && !empty($search)) { $forbidden[] = $val->user_id;
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") }
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') }
->where("assign_hr_to_proyek.proyek_id", $idProyek)
->where(function ($query) { if ($search && !empty($search)) {
$query->where("assign_hr_to_proyek.is_customer", "!=", true) $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")
->orWhereNull("assign_hr_to_proyek.is_customer"); ->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
}) ->where("assign_hr_to_proyek.proyek_id", $idProyek)
->where("m_users.name", 'like', '%' . $search . '%') ->where(function ($query) {
->whereNotIn("m_users.id", $forbidden)->get(); $query->where("assign_hr_to_proyek.is_customer", "!=", true)
} else { ->orWhereNull("assign_hr_to_proyek.is_customer");
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role") })
->where("assign_hr_to_proyek.proyek_id", $idProyek) ->where("m_users.name", 'like', '%' . $search . '%')
->where(function ($query) { ->whereNotIn("m_users.id", $forbidden)->get();
$query->where("assign_hr_to_proyek.is_customer", "!=", true) } else {
->orWhereNull("assign_hr_to_proyek.is_customer"); $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")
}) ->where("assign_hr_to_proyek.proyek_id", $idProyek)
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') ->where(function ($query) {
->whereNotIn("m_users.id", $forbidden) $query->where("assign_hr_to_proyek.is_customer", "!=", true)
->get(); ->orWhereNull("assign_hr_to_proyek.is_customer");
} })
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
return response()->json($data); ->whereNotIn("m_users.id", $forbidden)
} ->get();
}
public function checkOldPassword(Request $request, $id)
{ return response()->json($data);
if(!$id || (int) $id < 0 || $id==""){ }
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die(); public function checkOldPassword(Request $request, $id)
} {
if (!$id || (int) $id < 0 || $id == "") {
$data = $request->all(); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
if(isset($request->old_password) && $request->old_password!="" ){ }
$result = HumanResource::find($id);
$data['old_password'] = md5($request->old_password); $data = $request->all();
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); if (isset($request->old_password) && $request->old_password != "") {
} $result = HumanResource::find($id);
elseif($data['old_password'] === $result->password) { $data['old_password'] = md5($request->old_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) {
else { return response()->json(['status' => 'success', 'message' => "old password match", 'data' => $result, 'code' => 200], 200);
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');
}
}

Loading…
Cancel
Save