From dcede1f72a7f57f62a662ab7eb2443db9f495d2a Mon Sep 17 00:00:00 2001 From: wahyuun Date: Tue, 5 Sep 2023 17:01:28 +0700 Subject: [PATCH 01/17] query ProjectController@edit --- app/Http/Controllers/ProjectController.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 5e0fbde..a6fac6a 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -65,11 +65,16 @@ class ProjectController extends Controller return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); } - public function edit($id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + public function edit($id) + { + if (empty($id) || !is_int((int)$id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + + $result = Project::query() + ->select(array_diff(DB::getSchemaBuilder()->getColumnListing('m_proyek'), ['created_by', 'created_at', 'updated_at', 'updated_by', 'scurve'])) + ->whereId($id) + ->first(); - $result = Project::find($id); if(!$result) return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); From a4b2c9c21ed571a4b40b4b8b963e839795a2d5a6 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Sat, 9 Sep 2023 08:53:16 +0700 Subject: [PATCH 02/17] update ProjectController@edit and add fillable in Project Model --- app/Http/Controllers/ProjectController.php | 12 ++- app/Models/Project.php | 108 ++++++++++----------- 2 files changed, 63 insertions(+), 57 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index a6fac6a..27a3a94 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -71,10 +71,16 @@ class ProjectController extends Controller return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $result = Project::query() - ->select(array_diff(DB::getSchemaBuilder()->getColumnListing('m_proyek'), ['created_by', 'created_at', 'updated_at', 'updated_by', 'scurve'])) - ->whereId($id) - ->first(); + ->from('m_proyek AS mp') + ->where('mp.id', $id) + ->selectRaw('kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,lokasi_kantor,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status'); + if (!is_null($result->first()['divisi_id'])) { + $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') + ->addSelect(DB::raw('m_divisi.name AS nama_divisi')); + } + + $result = $result->first(); if(!$result) return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); diff --git a/app/Models/Project.php b/app/Models/Project.php index 6d3d5f4..cf2d0ad 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -1,54 +1,54 @@ - Date: Mon, 18 Sep 2023 09:42:00 +0700 Subject: [PATCH 03/17] fix search and add broadcast --- app/Http/Controllers/BroadcastController.php | 348 ++++++++++--------- 1 file changed, 177 insertions(+), 171 deletions(-) diff --git a/app/Http/Controllers/BroadcastController.php b/app/Http/Controllers/BroadcastController.php index 87eb02d..66ca433 100644 --- a/app/Http/Controllers/BroadcastController.php +++ b/app/Http/Controllers/BroadcastController.php @@ -1,171 +1,177 @@ -all(); - $data['status_send'] = true; - $data['created_by'] = $this->currentName; - if (isset($data['send_to_id'])) { - $idArray = $data['send_to_id']; - if (is_array($data['send_to_id'])) { - $data['send_to_id'] = implode(", ", $idArray); - } - } - // dd($data); - $result = Broadcast::create($data); - if($result){ - $this->sendNotification($data); - return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add broadcast failed!','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 = Broadcast::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Broadcast::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = Broadcast::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function list() - { - $data = Broadcast::all(); - $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 broadcast, please try again later!','code'=>400], 400); - } - } - - public function sendNotification($data) - { - // send_to_type (all, roles, user) - if (isset($data['send_to_type'])) { - switch ($data['send_to_type']) { - case 'all': - $users = User::whereNotNull('fcm_token')->get(); - if (isset($users)) { - foreach ($users as $user) { - FCMService::send( - $user->fcm_token, - [ - 'title' => $data['title_notif'], - 'body' => $data['message_notif'], - ] - ); - } - } - break; - - case 'roles': - $users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); - if (isset($users)) { - foreach ($users as $user) { - FCMService::send( - $user->fcm_token, - [ - 'title' => $data['title_notif'], - 'body' => $data['message_notif'], - ] - ); - } - } - break; - - case 'users': - $idArray = explode(", ", $data['send_to_id']); - foreach ($idArray as $key => $value) { - $user = User::where("id", $value)->whereNotNull('fcm_token')->first(); - if (isset($user)) { - FCMService::send( - $user->fcm_token, - [ - 'title' => $data['title_notif'], - 'body' => $data['message_notif'], - ] - ); - } - } - break; - - default: - # code... - break; - } - } - } -} +all(); + $data['created_by'] = $this->currentName; + if (isset($data['send_to_id'])) { + $idArray = $data['send_to_id']; + if (is_array($data['send_to_id'])) { + $data['send_to_id'] = implode(", ", $idArray); + } + } + $result = Broadcast::create($data); + if($result){ + $data['status_send'] !== "registered" ? $this->sendNotification($data) : ''; + return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add broadcast failed!','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 = Broadcast::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = Broadcast::find($id); + + $status_send = $request->status_send; + + if($status_send === 'resend' || $status_send === 'send' && !empty($data)) + { + $data['status_send'] = $status_send; + $this->sendNotification($data); + } + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = Broadcast::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = Broadcast::all(); + $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 broadcast, please try again later!','code'=>400], 400); + } + } + + public function sendNotification($data) + { + // send_to_type (all, roles, user) + if (isset($data['send_to_type'])) { + switch ($data['send_to_type']) { + case 'all': + $users = User::whereNotNull('fcm_token')->get(); + if (isset($users)) { + foreach ($users as $user) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + case 'roles': + $users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); + if (isset($users)) { + foreach ($users as $user) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + case 'users': + $idArray = explode(", ", $data['send_to_id']); + foreach ($idArray as $key => $value) { + $user = User::where("id", $value)->whereNotNull('fcm_token')->first(); + if (isset($user)) { + FCMService::send( + $user->fcm_token, + [ + 'title' => $data['title_notif'], + 'body' => $data['message_notif'], + ] + ); + } + } + break; + + default: + # code... + break; + } + } + } +} From afd447cdd38ecb393f64fcbdfd6de763ef38a005 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:43:43 +0700 Subject: [PATCH 04/17] fix search table,add divisi,edit divisi --- app/Http/Controllers/DivisiController.php | 211 ++++++++++++---------- 1 file changed, 112 insertions(+), 99 deletions(-) diff --git a/app/Http/Controllers/DivisiController.php b/app/Http/Controllers/DivisiController.php index ea7c3d4..a7d3617 100644 --- a/app/Http/Controllers/DivisiController.php +++ b/app/Http/Controllers/DivisiController.php @@ -1,99 +1,112 @@ -depth = $depth; - array_push($array, $divisi); - foreach($divisi->children as $child){ - $array = $this->getAllChildren($child, $depth + 1, $array); - } - return $array; - } - - public function add(Request $request){ - $this->validate($request, [ - 'name' => 'required', - 'description' => 'string', - 'parent' => 'integer' - ]); - - $data = $request->all(); - $data['created_by'] = $this->currentName; - - $result = Divisi::create($data); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); - - return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); - } - - public function update(Request $request, $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Divisi::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $result = $data->update($request->all()); - - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); - } - - public function delete($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Divisi::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - - $delete = $data->delete(); - - if(!$delete) - return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); - - return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); - } - - public function search() - { - return $this->list(); - // cant use builder for this case - } - - public function list() - { - $parentMenus = Divisi::whereNull('parent')->with('children')->get(); - $divisions = []; - foreach($parentMenus as $menu){ - $childs = $this->getAllChildren($menu); - foreach($childs as $d){ - $d->displayName = ' ' . $d->name; - for($i=0; $i < $d->depth; $i++){ - $d->displayName = '--' . $d->displayName ; - } - array_push($divisions, $d); - } - } - $countData = count($divisions); - if($countData == 0) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); - } -} +depth = $depth; + array_push($array, $divisi); + foreach($divisi->children as $child){ + $array = $this->getAllChildren($child, $depth + 1, $array); + } + return $array; + } + + public function add(Request $request){ + $this->validate($request, [ + 'name' => 'string|required|unique:m_divisi,name', + 'description' => 'nullable|string', + 'parent' => 'nullable|integer' + ]); + + $data = $request->all(); + $data['created_by'] = $this->currentName; + + $result = Divisi::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); + + return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); + } + + public function update(Request $request, $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $this->validate($request, [ + 'name' => 'string|required', + 'description' => 'nullable|string', + 'parent' => 'nullable|integer' + ]); + $data = Divisi::find($id); + + $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : ''; + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Divisi::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + + $delete = $data->delete(); + + if(!$delete) + return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); + + return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_divisi'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + + } + + public function list() + { + $parentMenus = Divisi::whereNull('parent')->with('children')->get(); + $divisions = []; + foreach($parentMenus as $menu){ + $childs = $this->getAllChildren($menu); + foreach($childs as $d){ + $d->displayName = ' ' . $d->name; + for($i=0; $i < $d->depth; $i++){ + $d->displayName = '--' . $d->displayName ; + } + array_push($divisions, $d); + } + } + $countData = count($divisions); + if($countData == 0) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); + } +} From abc80b780783902999ec986c256af4aefcead784 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:44:23 +0700 Subject: [PATCH 05/17] assign customer --- app/Http/Controllers/HumanResourceController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/HumanResourceController.php b/app/Http/Controllers/HumanResourceController.php index 86f886a..be26a1c 100644 --- a/app/Http/Controllers/HumanResourceController.php +++ b/app/Http/Controllers/HumanResourceController.php @@ -15,7 +15,7 @@ class HumanResourceController extends Controller $this->validate($request, [ 'role_id' => 'required', 'name' => 'required', - 'ktp_number' => 'required', + 'ktp_number' => 'required|numeric|unique:m_users,ktp_number', 'employee_type' => 'required' ]); @@ -56,9 +56,12 @@ class HumanResourceController extends Controller if (!$id || (int) $id < 0 || $id == "") { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } - $humanresource = HumanResource::find($id); + $request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|numeric']) : ''; + $request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : ''; + $request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; + $data = $request->all(); if (isset($request->password) && $request->password != "") { From c965d8bb153eaca468a4fa9bf8eb3c75c6c57305 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:45:14 +0700 Subject: [PATCH 06/17] fix add & edit set unik field name --- app/Http/Controllers/MenuController.php | 310 ++++++++++++------------ 1 file changed, 159 insertions(+), 151 deletions(-) diff --git a/app/Http/Controllers/MenuController.php b/app/Http/Controllers/MenuController.php index 679c533..6ff9324 100644 --- a/app/Http/Controllers/MenuController.php +++ b/app/Http/Controllers/MenuController.php @@ -1,151 +1,159 @@ -validate($request, [ - 'icon' => 'required', - 'name' => 'required', - 'url' => 'required', - 'sequence' => 'required', - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = Menu::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'add data menu failed!','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 = Menu::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); - } - } - - public function update(Request $request, $id) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = Menu::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = Menu::find($id); - - if($data){ - $delete = $data->delete(); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); - } - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'm_menu'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function listMenu($id) - { - $dataParent = RoleMenu::select("m_menu.*") - ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') - ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') - ->whereNull('m_menu.parent_id') - ->where('m_roles.id', $id) - ->orderBy('m_menu.sequence', 'ASC') - ->get(); - - $finalData = []; - foreach($dataParent as $data){ - $data->children = $this->getChildrenMenu($data->id, $id); - $finalData[] = $data; - } - - return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); - } - - protected function getChildrenMenu($id, $role_id) - { - $dataChildren = RoleMenu::select("m_menu.*") - ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') - ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') - ->where('m_roles.id', $role_id) - ->where('m_menu.parent_id', $id) - ->orderBy('m_menu.sequence', 'ASC') - ->get(); - $children = []; - if($dataChildren){ - foreach($dataChildren as $data) - { - $data->children = $this->getChildrenMenu($data->id, $role_id); - $children[] = $data; - } - } - return $children; - } - - public function list() - { - $data = Menu::all(); - $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 menu, please try again later!','code'=>400], 400); - } - } -} +validate($request, [ + 'icon' => 'required', + 'name' => 'string|required|unique:m_menu,name', + 'url' => 'required|unique:m_menu,url', + 'sequence' => 'required|integer', + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Menu::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data menu failed!','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 = Menu::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + $this->validate($request, [ + 'icon' => 'required', + 'name' => 'string|required', + 'url' => 'required', + 'sequence' => 'required|integer', + ]); + $data = Menu::find($id); + + $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_menu,name']) : ''; + $request->url !== $data['url'] ? $this->validate($request,['url'=>'unique:m_menu,url']) : ''; + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = Menu::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_menu'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function listMenu($id) + { + $dataParent = RoleMenu::select("m_menu.*") + ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') + ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') + ->whereNull('m_menu.parent_id') + ->where('m_roles.id', $id) + ->orderBy('m_menu.sequence', 'ASC') + ->get(); + + $finalData = []; + foreach($dataParent as $data){ + $data->children = $this->getChildrenMenu($data->id, $id); + $finalData[] = $data; + } + + return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); + } + + protected function getChildrenMenu($id, $role_id) + { + $dataChildren = RoleMenu::select("m_menu.*") + ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') + ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') + ->where('m_roles.id', $role_id) + ->where('m_menu.parent_id', $id) + ->orderBy('m_menu.sequence', 'ASC') + ->get(); + $children = []; + if($dataChildren){ + foreach($dataChildren as $data) + { + $data->children = $this->getChildrenMenu($data->id, $role_id); + $children[] = $data; + } + } + return $children; + } + + public function list() + { + $data = Menu::all(); + $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 menu, please try again later!','code'=>400], 400); + } + } +} From 4f4682c48fac9adf3cf9b33ea935e9235e9ddf05 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:46:18 +0700 Subject: [PATCH 07/17] add unique field name --- app/Http/Controllers/RoleController.php | 207 ++++++++++++------------ 1 file changed, 106 insertions(+), 101 deletions(-) diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index b420107..4a29066 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -1,101 +1,106 @@ -validate($request, [ - 'name' => 'required', - 'description' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = Role::create($data); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); - - return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); - } - - public function edit( $id){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $result = Role::find($id); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); - - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - } - - public function update(Request $request, $id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Role::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); - - $result = $data->update($request->all()); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); - - return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); - } - - public function delete($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - - $data = Role::find($id); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); - - $delete = $data->delete(); - - if(!$delete) - return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); - - return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); - } - - public function search(Request $request) - { - $payload = $request->all(); - - $dataBuilder = $this->setUpPayload($payload, 'm_roles'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function list() - { - $data = Role::all(); - $countData = $data->count(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); - - return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); - } -} +validate($request, [ + 'name' => 'string|required|unique:m_roles,name', + 'description' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Role::create($data); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); + } + + public function edit( $id){ + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $result = Role::find($id); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + } + + public function update(Request $request, $id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $this->validate($request, [ + 'name' => 'string|required', + 'description' => 'required' + ]); + $data = Role::find($id); + $request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_roles,name']) : ''; + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + $result = $data->update($request->all()); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + + $data = Role::find($id); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); + + $delete = $data->delete(); + + if(!$delete) + return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); + + return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + } + + public function search(Request $request) + { + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_roles'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = Role::all(); + $countData = $data->count(); + + if(!$data) + return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); + + return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); + } +} From 26a0884ccf0075e1410628975e2ea126ac4be19e Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:47:29 +0700 Subject: [PATCH 08/17] add addMultiple method for AssignCustomer add --- .../Controllers/UserToProyekController.php | 467 ++++++++++-------- 1 file changed, 253 insertions(+), 214 deletions(-) diff --git a/app/Http/Controllers/UserToProyekController.php b/app/Http/Controllers/UserToProyekController.php index fecdfec..a7a1cac 100644 --- a/app/Http/Controllers/UserToProyekController.php +++ b/app/Http/Controllers/UserToProyekController.php @@ -1,214 +1,253 @@ -validate($request, [ - 'user_id' => 'required', - 'proyek_id' => 'required' - ]); - - $data = $request->all(); - - $data['created_by'] = $this->currentName; - - $result = UserToProyek::create($data); - - if($result){ - return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','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 = UserToProyek::find($id); - - if($result){ - return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); - }else{ - 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) - { - if(!$id || (int) $id < 0 || $id==""){ - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); - } - - $data = UserToProyek::find($id); - - if($data){ - $result = $data->update($request->all()); - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); - die(); - } - - - if($result){ - return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); - } - } - - public function delete($id) - { - $data = UserToProyek::find($id); - if($data){ - $userId = $data->user_id; - $proyekId = $data->proyek_id; - $delete = $data->delete(); - if($delete){ - $this->deleteRelative($proyekId, $userId); - } - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); - die(); - } - - - if($delete){ - return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); - }else{ - return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); - } - } - - private function deleteRelative($proyekId, $userId) - { - $uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get(); - foreach ($uta as $value) { - $dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); - foreach ($dataRa as $ra) { - $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); - foreach ($images as $image) { - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); - } - } - Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); - } - ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete(); - } - UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete(); - } - - public function search(Request $request) - { - $payload = $request->all(); - $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function list() - { - $data = UserToProyek::all(); - $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 assign hr to proyek, please try again later!','code'=>400], 400); - } - } - - public function select(Request $request){ - - $search = $request->query('search'); - - $idProyek = (int)$request->query('idProyek'); - $idActivity = (int)$request->query('idact'); - - $include = []; - - if($idActivity && $idActivity > 0){ - $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); - foreach($dataF as $val){ - $include[] = $val->user_id; - } - } - - 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') - ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); - }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(); - } - - if($data instanceof \Illuminate\Database\Eloquent\Collection){ - $pm = array( - "id"=>$this->currentId, - "name"=> "Project Manager" - ); - $data->push($pm); - } - - 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); - } -} +validate($request, [ + 'user_id' => 'required', + 'proyek_id' => 'required' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = UserToProyek::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400); + } + } + + public function addMultiple(Request $request){ + $user_IDs = $request->user_id; + + $data = UserToProyek::where("proyek_id", $request->proyek_id); + + if($data){ + $data->delete(); + } + + if(is_array($user_IDs) && count($user_IDs) > 0){ + $countRes = 0; + foreach($user_IDs as $item){ + + $dataInsert = array( + "user_id" => $item, + "proyek_id" => $request->proyek_id, + "created_by" => $this->currentName, + 'is_customer'=>true + ); + + $result = UserToProyek::create($dataInsert); + + if($result){ + $countRes++; + }else{ + $countRes--; + } + } + if($countRes > 0){ + return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); + }else{ + return response()->json(['status'=>'success' ,'message'=>'Project customer failed created','code'=>400]); + } + }else{ + return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); + } + + } + + public function edit($id){ + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + die(); + } + + $result = UserToProyek::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + 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) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = UserToProyek::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = UserToProyek::find($id); + if($data){ + $userId = $data->user_id; + $proyekId = $data->proyek_id; + $delete = $data->delete(); + if($delete){ + $this->deleteRelative($proyekId, $userId); + } + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); + } + } + + private function deleteRelative($proyekId, $userId) + { + $uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get(); + foreach ($uta as $value) { + $dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); + foreach ($dataRa as $ra) { + $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); + foreach ($images as $image) { + if(file_exists($this->pathImage.$image->image)){ + unlink($this->pathImage.$image->image); + } + } + Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); + } + ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete(); + } + UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete(); + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = UserToProyek::all(); + $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 assign hr to proyek, please try again later!','code'=>400], 400); + } + } + + public function select(Request $request){ + + $search = $request->query('search'); + + $idProyek = (int)$request->query('idProyek'); + $idActivity = (int)$request->query('idact'); + + $include = []; + + if($idActivity && $idActivity > 0){ + $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); + foreach($dataF as $val){ + $include[] = $val->user_id; + } + } + + 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') + ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); + }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(); + } + + if($data instanceof \Illuminate\Database\Eloquent\Collection){ + $pm = array( + "id"=>$this->currentId, + "name"=> "Project Manager" + ); + $data->push($pm); + } + + 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); + } +} From 2a89a8667df85c0e77febab5bf076ea306515b63 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 09:48:24 +0700 Subject: [PATCH 09/17] add endpoint user-to-proyek/add-multiple --- routes/web.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/web.php b/routes/web.php index a207fe8..adae2bc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -381,6 +381,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); $router->post('/user-to-proyek/add', 'UserToProyekController@add'); + $router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple'); $router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit'); $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); $router->post('/user-to-proyek/search', 'UserToProyekController@search'); From 9e093bba04d94b307b8a181fcea126ba20623960 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 12:58:48 +0700 Subject: [PATCH 10/17] created delete method in deleteRelative method --- app/Http/Controllers/ProjectController.php | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 27a3a94..b4cc196 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -2,35 +2,38 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Models\Link; +use App\Models\User; +use App\Models\Image; +use App\Models\Holiday; use App\Models\Project; -use App\Models\UserToProyek; use App\Models\Activity; -use App\Models\UserToActivity; -use App\Models\User; +use App\Jobs\ProcessSCurve; +use App\Models\OfficeHours; +use App\Models\ProjectType; +use App\Models\ProjectPhase; +use App\Models\UserToProyek; +use App\Models\VersionGantt; +use Illuminate\Http\Request; +use App\Models\ProjectIssues; use App\Models\AssignMaterial; use App\Models\DokumenProject; -use App\Models\FolderDocumentProyek; use App\Models\ProjectCharter; -use App\Models\ProjectApproval; -use App\Models\ProjectPhase; -use App\Models\ProjectType; -use App\Models\ProjectMileStone; -use App\Models\ProjectParticipants; +use App\Models\ReportActivity; use App\Models\ShowHideColumn; -use App\Models\VersionGantt; -use App\Models\Image; -use App\Models\CommentActivity; -use App\Models\Link; +use App\Models\UserToActivity; use App\Models\ActivityDokumen; -use App\Models\Holiday; -use App\Models\ReportActivity; -use App\Models\OfficeHours; +use App\Models\CommentActivity; +use App\Models\ProjectApproval; +use App\Models\ProjectMileStone; +use App\Models\ProjectChecklists; use Illuminate\Support\Facades\DB; +use App\Models\ProjectParticipants; +use App\Models\FolderDocumentProyek; use App\Helpers\MasterFunctionsHelper; +use App\Models\ProjectRisks; use App\Models\ReportActivityMaterial; use Illuminate\Support\Facades\Artisan; -use App\Jobs\ProcessSCurve; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; @@ -156,6 +159,9 @@ class ProjectController extends Controller ProjectApproval::where('proyek_id', $project_id)->delete(); ProjectMileStone::where('proyek_id', $project_id)->delete(); ProjectParticipants::where('proyek_id', $project_id)->delete(); + ProjectChecklists::where('proyek_id', $project_id)->delete(); + ProjectIssues::where('proyek_id', $project_id)->delete(); + ProjectRisks::where('proyek_id', $project_id)->delete(); $this->deleteVersionGantt($project_id); $this->deleteDokumenProject($project_id); } From 047fba126bc13909df0eb5c337fbdcc2bdb13ad1 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 12:59:07 +0700 Subject: [PATCH 11/17] add endpoint api --- routes/web.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/routes/web.php b/routes/web.php index adae2bc..376bb43 100644 --- a/routes/web.php +++ b/routes/web.php @@ -292,6 +292,33 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete'); $router->get('/rate-sallary/list', 'RateSallaryController@list'); + $router->post('/project-checklists/add', 'ProjectChecklistsController@add'); + $router->get('/project-checklists/edit/{id}', 'ProjectChecklistsController@edit'); + $router->put('/project-checklists/update/{id}', 'ProjectChecklistsController@update'); + $router->post('/project-checklists/search', 'ProjectChecklistsController@search'); + $router->delete('/project-checklists/delete/{id}', 'ProjectChecklistsController@delete'); + $router->delete('/project-checklists/delete-by-proyek/{id}', 'ProjectChecklistsController@deleteByProyek'); + $router->get('/project-checklists/list', 'ProjectChecklistsController@list'); + $router->get('/project-checklists/{where}/{val}', 'ProjectChecklistsController@customWhere'); + + $router->post('/project-issues/add', 'ProjectIssuesController@add'); + $router->get('/project-issues/edit/{id}', 'ProjectIssuesController@edit'); + $router->put('/project-issues/update/{id}', 'ProjectIssuesController@update'); + $router->post('/project-issues/search', 'ProjectIssuesController@search'); + $router->delete('/project-issues/delete/{id}', 'ProjectIssuesController@delete'); + $router->delete('/project-issues/delete-by-proyek/{id}', 'ProjectIssuesController@deleteByProyek'); + $router->get('/project-issues/list', 'ProjectIssuesController@list'); + $router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere'); + + $router->post('/project-risks/add', 'ProjectRisksController@add'); + $router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit'); + $router->put('/project-issues/update/{id}', 'ProjectRisksController@update'); + $router->post('/project-risks/search', 'ProjectRisksController@search'); + $router->delete('/project-risks/delete/{id}', 'ProjectRisksController@delete'); + $router->delete('/project-risks/delete-by-proyek/{id}', 'ProjectRisksController@deleteByProyek'); + $router->get('/project-risks/list', 'ProjectRisksController@list'); + $router->get('/project-risks/{where}/{val}', 'ProjectRisksController@customWhere'); + $router->post('/project-participants/add', 'ProjectParticipantsController@add'); $router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit'); $router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update'); From 45d6ae61596f8fc526e1d988bc9afa3172750496 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 12:59:49 +0700 Subject: [PATCH 12/17] create controller --- .../ProjectChecklistsController.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 app/Http/Controllers/ProjectChecklistsController.php diff --git a/app/Http/Controllers/ProjectChecklistsController.php b/app/Http/Controllers/ProjectChecklistsController.php new file mode 100644 index 0000000..c7e0590 --- /dev/null +++ b/app/Http/Controllers/ProjectChecklistsController.php @@ -0,0 +1,136 @@ +status_exist==="") { + $request->merge(['status_exist' => true]); + } + + $this->validate($request, [ + 'proyek_id' => 'required', + 'item' => 'required|string', + 'status_exist' => 'boolean' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = ProjectChecklists::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data project participants failed!','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 = ProjectChecklists::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data project participants, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = ProjectChecklists::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = ProjectChecklists::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); + } + } + + public function deleteByProyek($id) + { + $data = ProjectChecklists::where('proyek_id', $id)->delete(); + + if($data){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); + } + } + + public function customWhere($where, $val) + { + $data = ProjectChecklists::where($where, $val)->orderBy('id', 'asc')->get(); + + if($data){ + return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'project_charter_checklist'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = ProjectChecklists::all(); + $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 project participants, please try again later!','code'=>400], 400); + } + } +} From cbac76e19c8946da2e1bdd84e742ecec22945bf4 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 13:00:01 +0700 Subject: [PATCH 13/17] create controller --- .../Controllers/ProjectIssuesController.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 app/Http/Controllers/ProjectIssuesController.php diff --git a/app/Http/Controllers/ProjectIssuesController.php b/app/Http/Controllers/ProjectIssuesController.php new file mode 100644 index 0000000..fc54850 --- /dev/null +++ b/app/Http/Controllers/ProjectIssuesController.php @@ -0,0 +1,136 @@ +level_issue === "") { + $request->merge(['level_issue' => 0]); + } + + $this->validate($request, [ + 'proyek_id' => 'required', + 'description' => 'required|string', + 'level_issue' => 'required|integer' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = ProjectIssues::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data project participants failed!','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 = ProjectIssues::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data project participants, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = ProjectIssues::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = ProjectIssues::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); + } + } + + public function deleteByProyek($id) + { + $data = ProjectIssues::where('proyek_id', $id)->delete(); + + if($data){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); + } + } + + public function customWhere($where, $val) + { + $data = ProjectIssues::where($where, $val)->orderBy('id', 'asc')->get(); + + if($data){ + return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'project_charter_issue'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = ProjectIssues::all(); + $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 project participants, please try again later!','code'=>400], 400); + } + } +} From 2e1567d9f1de5abcb2c1d5f8559fb26ceac21bba Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 13:00:13 +0700 Subject: [PATCH 14/17] create controller --- .../Controllers/ProjectRisksController.php | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 app/Http/Controllers/ProjectRisksController.php diff --git a/app/Http/Controllers/ProjectRisksController.php b/app/Http/Controllers/ProjectRisksController.php new file mode 100644 index 0000000..d5c53df --- /dev/null +++ b/app/Http/Controllers/ProjectRisksController.php @@ -0,0 +1,137 @@ +level_risk === "") { + $request->merge(['level_risk' => 0]); + } + + $this->validate($request, [ + 'proyek_id' => 'required', + 'level_risk' => 'required|integer', + 'description' => 'required|string', + 'preventive_risk' => 'required|string' + ]); + + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = ProjectRisks::create($data); + + if($result){ + return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'add data project participants failed!','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 = ProjectRisks::find($id); + + if($result){ + return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'failed get data project participants, please try again later!','code'=>400], 400); + } + } + + public function update(Request $request, $id) + { + if(!$id || (int) $id < 0 || $id==""){ + return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + } + + $data = ProjectRisks::find($id); + + if($data){ + $result = $data->update($request->all()); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($result){ + return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); + } + } + + public function delete($id) + { + $data = ProjectRisks::find($id); + + if($data){ + $delete = $data->delete(); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); + die(); + } + + + if($delete){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); + } + } + + public function deleteByProyek($id) + { + $data = ProjectRisks::where('proyek_id', $id)->delete(); + + if($data){ + return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); + } + } + + public function customWhere($where, $val) + { + $data = ProjectRisks::where($where, $val)->orderBy('id', 'asc')->get(); + + if($data){ + return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); + }else{ + return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'project_charter_risk'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function list() + { + $data = ProjectRisks::all(); + $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 project participants, please try again later!','code'=>400], 400); + } + } +} From 065ca6291c4fced4127eaadbbacdd2008b9a7c2d Mon Sep 17 00:00:00 2001 From: wahyuun Date: Wed, 20 Sep 2023 13:00:30 +0700 Subject: [PATCH 15/17] create model --- app/Models/ProjectChecklists.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/Models/ProjectChecklists.php diff --git a/app/Models/ProjectChecklists.php b/app/Models/ProjectChecklists.php new file mode 100644 index 0000000..fb37975 --- /dev/null +++ b/app/Models/ProjectChecklists.php @@ -0,0 +1,23 @@ + Date: Wed, 20 Sep 2023 13:00:44 +0700 Subject: [PATCH 16/17] create model --- app/Models/ProjectIssues.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/Models/ProjectIssues.php diff --git a/app/Models/ProjectIssues.php b/app/Models/ProjectIssues.php new file mode 100644 index 0000000..c3560b4 --- /dev/null +++ b/app/Models/ProjectIssues.php @@ -0,0 +1,23 @@ + Date: Wed, 20 Sep 2023 13:01:06 +0700 Subject: [PATCH 17/17] create model --- app/Models/ProjectRisks.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/Models/ProjectRisks.php diff --git a/app/Models/ProjectRisks.php b/app/Models/ProjectRisks.php new file mode 100644 index 0000000..dba2ecd --- /dev/null +++ b/app/Models/ProjectRisks.php @@ -0,0 +1,24 @@ +