@ -24,114 +24,115 @@ class UserToProyekController extends Controller
$result = UserToProyek::create($data);
$result = UserToProyek::create($data);
if($result){
if ($result) {
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200);
return response()->json(['status' => 'success', 'message' => 'assign hr to proyek successfully!', 'code' => 200], 200);
}else{
} else {
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'assign hr to proyek failed!', 'code' => 400], 400);
}
}
}
}
public function addMultiple(Request $request){
public function addMultiple(Request $request)
{
$user_IDs = $request->user_id;
$user_IDs = $request->user_id;
$data = UserToProyek::where([
$data = UserToProyek::where([
["proyek_id" , $request->proyek_id],
["proyek_id", $request->proyek_id],
['is_customer',true]
['is_customer', true]
]);
]);
if($data){
if ($data) {
$data->delete();
$data->delete();
}
}
if(is_array($user_IDs) & & count($user_IDs) > 0){
if (is_array($user_IDs) & & count($user_IDs) > 0) {
$countRes = 0;
$countRes = 0;
foreach($user_IDs as $item){
foreach ($user_IDs as $item) {
$dataInsert = array(
$dataInsert = array(
"user_id" => $item,
"user_id" => $item,
"proyek_id" => $request->proyek_id,
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName,
"created_by" => $this->currentName,
'is_customer'=>true,
'is_customer' => true,
'project_role'=> $request->project_role
'project_role' => $request->project_role
);
);
$result = UserToProyek::create($dataInsert);
$result = UserToProyek::create($dataInsert);
if($result){
if ($result) {
$countRes++;
$countRes++;
}else{
} else {
$countRes--;
$countRes--;
}
}
}
}
if($countRes > 0){
if ($countRes > 0) {
return response()->json(['status'=>'success' , 'message'=>'Project customer successfull created','code'=>200]);
return response()->json(['status' => 'success', 'message' => 'Project customer successfull created', 'code' => 200]);
}else{
} else {
return response()->json(['status'=>'failed' , 'message'=>'Project customer failed created','code'=>400]);
return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 400]);
}
}
}else{
} else {
return response()->json(['status'=>'failed' , 'message'=>'Project customer failed created','code'=>200]);
return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 200]);
}
}
}
}
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 = UserToProyek::find($id);
$result = UserToProyek::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 assign hr to proyek, please try again later!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'failed get data assign hr to proyek, 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);
}
}
$data = UserToProyek::find($id);
$data = UserToProyek::find($id);
if($data){
if ($data) {
$result = $data->update($request->all());
$result = $data->update($request->all());
}else{
} else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
die();
die();
}
}
if($result){
if ($result) {
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200);
return response()->json(['status' => 'success', 'message' => 'data assign hr to proyek successfully updated!', 'code' => 200], 200);
}else{
} else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek failed updated!', 'code' => 400], 400);
}
}
}
}
public function delete($id, $company_id)
public function delete($id, $company_id)
{
{
$data = UserToProyek::find($id);
$data = UserToProyek::find($id);
if($data){
if ($data) {
$userId = $data->user_id;
$userId = $data->user_id;
$proyekId = $data->proyek_id;
$proyekId = $data->proyek_id;
$delete = $data->delete();
$delete = $data->delete();
if($delete){
if ($delete) {
$this->deleteRelative($proyekId, $userId, $company_id);
$this->deleteRelative($proyekId, $userId, $company_id);
}
}
}else{
} else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
die();
die();
}
}
if($delete){
if ($delete) {
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200);
return response()->json(['status' => 'success', 'message' => 'data assign hr to proyek successfully deleted!', 'code' => 200], 200);
}else{
} else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek failed deleted!', 'code' => 400], 400);
}
}
}
}
@ -141,13 +142,13 @@ class UserToProyekController extends Controller
foreach ($uta as $value) {
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$company = Company::find($company_id);
$company = Company::find($company_id);
if($company) {
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
foreach ($images as $image) {
if(file_exists($destinationPath['pathImage'].$image->image)){
if (file_exists($destinationPath['pathImage'] . $image->image)) {
unlink($destinationPath['pathImage'].$image->image);
unlink($destinationPath['pathImage'] . $image->image);
}
}
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
@ -166,7 +167,7 @@ class UserToProyekController 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()
@ -174,14 +175,15 @@ class UserToProyekController extends Controller
$data = UserToProyek::all();
$data = UserToProyek::all();
$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 assign hr to proyek, please try again later!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'failed get list assign hr to proyek, 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');
@ -190,73 +192,28 @@ class UserToProyekController extends Controller
$include = [];
$include = [];
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) {
$include[] = $val->user_id;
$include[] = $val->user_id;
}
}
}
}
if($search & & !empty($search)){
if ($search & & !empty($search)) {
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->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.'%')->whereIn("m_users.id", $include)->get();
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%' . $search . '%')->whereIn("m_users.id", $include)->get();
}else{
} else {
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get();
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get();
}
}
if($data instanceof \Illuminate\Database\Eloquent\Collection){
if ($data instanceof \Illuminate\Database\Eloquent\Collection) {
$pm = array(
$pm = array(
"id"=>$this->currentId,
"id" => $this->currentId,
"name"=> "Project Manager"
"name" => "Project Manager"
);
);
$data->push($pm);
$data->push($pm);
}
}
return response()->json($data);
return response()->json($data);
}
}
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
'Authorization: '.$token
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
public function getEmployeeIntegration(Request $request) {
$search = urlencode($request->name);
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH');
$token = config('api.adw_token');
$firstResponse = $this->curlReq($url, $token);
if($firstResponse->total == 0)
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404);
$data = $firstResponse->data;
return response()->json([$data]);
$currentPage = 1;
if($firstResponse->last_page > 0) {
do {
$currentPage++;
$response = $this->curlReq($url.'& page='.$currentPage, $token);
foreach($response->data as $d){
array_push($data, $d);
}
} while ($currentPage < $firstResponse->last_page);
}
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200);
}
}
}