From f60369a226ff6e49afa2a4049e4354df4ce5b76a Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Mon, 6 May 2024 08:35:22 +0700 Subject: [PATCH 1/8] fix(activity): param delete activity --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index bb539c7..840db36 100644 --- a/routes/web.php +++ b/routes/web.php @@ -272,7 +272,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->get('/task/edit/{id}', 'ActivityController@edit'); $router->put('/task/{id}', 'ActivityController@update'); $router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); - $router->delete('/task/{id}/{company_id}', 'ActivityController@delete'); + $router->delete('/task/{id}', 'ActivityController@delete'); $router->get('/task/get-update/{id}', 'ActivityController@getUpdate'); $router->post('/tmp-import/upload', 'ActivityController@uploadTmpImport'); From aa6538153c2453fd23bdfadcaee9f2fa54af58c9 Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Mon, 6 May 2024 08:35:43 +0700 Subject: [PATCH 2/8] feat: add fillable --- app/Models/ProjectType.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/Models/ProjectType.php b/app/Models/ProjectType.php index f6e9604..e3f1dff 100644 --- a/app/Models/ProjectType.php +++ b/app/Models/ProjectType.php @@ -1,17 +1,17 @@ - Date: Mon, 6 May 2024 08:36:36 +0700 Subject: [PATCH 3/8] fix(activity): fixed activity delete --- app/Http/Controllers/ActivityController.php | 50 ++++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index a804f8a..2571438 100755 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -629,32 +629,48 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); } - public function delete($id, $company_id) + public function delete($id) { - if (!$data = Activity::find($id)) + DB::beginTransaction(); + $activity_id = (int)$id; + $data = Activity::query() + ->from('m_activity as ma') + ->select('mp.company_id') + ->join('m_proyek as mp','ma.proyek_id','mp.id') + ->where('ma.id', $activity_id); + $cloneQuery = clone $data; + if (!$data->exists()) { + DB::rollBack(); return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); - $this->deleteRelative($id, $company_id); - if (!$data->delete()) - return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); + } + + $this->deleteRelative($activity_id, $cloneQuery->first()->company_id); - return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); + if (!$data->delete()) { + DB::rollBack(); + return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data activity failed deleted!', 'code' => 500], 500); + } + DB::commit(); + return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'Data activity successfully deleted!', 'code' => 200], 200); } private function deleteRelative($activity_id, $company_id) { - UserToActivity::where('activity_id', $activity_id)->delete(); - AssignMaterial::where('activity_id', $activity_id)->delete(); - $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); - $company = Company::find($company_id); - if($company) { - $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); - foreach ($dataAd as $ad) { - if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { - unlink($destinationPath['pathActivityDocument'] . $ad->file); + DB::transaction(function() use($activity_id, $company_id) { + UserToActivity::where('activity_id', $activity_id)->delete(); + AssignMaterial::where('activity_id', $activity_id)->delete(); + $dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); + $company = Company::find($company_id); + if($company) { + $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); + foreach ($dataAd as $ad) { + if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { + unlink($destinationPath['pathActivityDocument'] . $ad->file); + } } + ActivityDokumen::where("activity_id", $activity_id)->delete(); } - ActivityDokumen::where("activity_id", $activity_id)->delete(); - } + }); } public function getUpdate($id) From 4a4e912ed06dd9480d3ffdd5f92f29a41c0905a2 Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Mon, 6 May 2024 08:37:04 +0700 Subject: [PATCH 4/8] fix(project): fixed project delete --- app/Http/Controllers/ProjectController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index d293cab..f644ed2 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -181,9 +181,9 @@ class ProjectController extends Controller $data = Project::find($id); $dateNow = Carbon::now(); if ($data) { - // $this->deleteRelative($id, $company_id); - // if ($data->delete()) { - if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) { + $this->deleteRelative($id, $company_id); + if ($data->delete()) { + // if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) { DB::commit(); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); } else { From ed924c78593ec2c2de12cfc2c4b45e83ba157d28 Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Mon, 6 May 2024 08:37:31 +0700 Subject: [PATCH 5/8] fix(maximum size): fixed condition maximum size --- app/Http/Controllers/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 2b6aeb2..3e82edd 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -185,7 +185,7 @@ class Controller extends BaseController $countCreate = true; } - if ($countCreate) { + if ($countCreate && isset($maximumSize)) { // kondisi $maximumSize sementara karena blm ada paket enterprise if (floatval($totalSize) > floatval($maximumSize)) { $countCreate = false; } From 45f15cb129c6353a0682c60df6ec108959f21c19 Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Mon, 6 May 2024 08:38:03 +0700 Subject: [PATCH 6/8] fix(login): fixed login condition --- app/Http/Controllers/AuthController.php | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index fbb2e3b..292670a 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -35,14 +35,18 @@ class AuthController extends Controller return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); } - if (User::where('username', $username)->exists()) { + $userQuery = User::query() + ->where('username',$username); + + if ($userQuery->exists()) { $usernameCheck = true; - } - if (User::where('password', md5($password))->exists()) { - $passwordCheck = true; + $passwordValue = $userQuery->first()->password; + if($passwordValue === md5($password)) { + $passwordCheck = true; + } } - if ($usernameCheck & $passwordCheck) { + if ($usernameCheck && $passwordCheck) { $user = User::where([['username', $username],['password', md5($password)]])->first(); $checkExpiredOspro = $this->setExpiredTimeOspro($user['company_id']); if($checkExpiredOspro === false && $user['company_id'] != null) { @@ -113,14 +117,10 @@ class AuthController extends Controller ), ]); } else { - if (!$usernameCheck && !$passwordCheck) { - return response()->json(['code' => 201, 'message' => "Username and password doesn't match"], 201); - } - if (!$passwordCheck) { - return response()->json(['code' => 201, 'message' => "Password doesn't match"], 201); - } - if (!$usernameCheck) { - return response()->json(['code' => 201, 'message' => "Username doesn't match"], 201); + if (!$usernameCheck || !$passwordCheck) { + return response()->json(['code' => 201, 'message' => "Username or password doesn't match"], 201); + } else { + return response()->json(['code' => 500, 'message' => "Server error"], 500); } } } From 1a78790efcd98b5c425f0f307de84a8a1bfd2dfa Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Mon, 6 May 2024 08:38:47 +0700 Subject: [PATCH 7/8] fix(user proyek): fixed join --- app/Http/Controllers/UserToActivityController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 5313b5d..a17fdad 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -153,6 +153,7 @@ class UserToActivityController extends Controller $builder->groupBy("selfTable.start_date"); $builder->groupBy("selfTable.end_date"); $builder->groupBy("assign_material_to_activity.qty_planning"); + $builder->groupBy("assign_material_to_activity.id"); $builder->groupBy("m_version_gantt.name_version"); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); From 1c74aaf3026e4893d435e389d504bf816e498a9c Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Mon, 6 May 2024 08:39:04 +0700 Subject: [PATCH 8/8] fix: clear comment --- .../Controllers/DashboardBoDController.php | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index f1c8e16..ef211cb 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -262,7 +262,6 @@ class DashboardBoDController extends Controller foreach ($projects as $project) { $resp = null; if ($project->kode_sortname != "") { - // $resp = $this->getInvoiceIntegration($project->kode_sortname); array_push($return, [ 'project' => $project->nama, 'project_code' => $project->kode_sortname, @@ -281,22 +280,28 @@ class DashboardBoDController extends Controller public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy) { $role = urldecode($role_name); + $replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy); $return = [ 'behind-schedule' => 0, 'warning' => 0, 'on-schedule' => 0, ]; + $divisi = Divisi::query() + ->where('company_id',$company_id) + ->pluck('id'); $projects = null; if ($role === 'Super Admin') { $projects = Project::get(); - } elseif ($all_project) { - $projects = Project::where('company_id', $company_id) - ->get(); + } elseif ($all_project == 'true') { + $projects = Project::whereIn('divisi_id',$divisi) + ->where('company_id', $company_id) + ->get(); } else { - $projects = Project::where('created_by_id', $hierarchy) - ->get(); + $projects = Project::whereIn('divisi_id',$divisi) + ->where('created_by_id', $replaceHierarchy) + ->get(); } foreach ($projects as $index => $project) { @@ -386,6 +391,8 @@ class DashboardBoDController extends Controller public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy) { $role = urldecode($role_name); + $replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy); + $response = [ 'data' => [ 'overrun' => 0, @@ -393,43 +400,47 @@ class DashboardBoDController extends Controller 'on-budget' => 0, ] ]; + $divisi = Divisi::query() + ->where('company_id',$company_id) + ->pluck('id'); + // arr overrun if ($role === 'Super Admin') { $response['data']['overrun'] = Project::where('budget_health', 'overrun') ->count(); - } elseif ($all_project) { - $response['data']['overrun'] = Project::where('budget_health', 'overrun') - ->where('company_id', $company_id) + } elseif ($all_project == 'true') { + $response['data']['overrun'] = Project::whereIn('divisi_id',$divisi) + ->where([['budget_health', 'overrun'],['company_id', $company_id]]) ->count(); } else { - $response['data']['overrun'] = Project::where('budget_health', 'overrun') - ->where('created_by_id', $hierarchy) + $response['data']['overrun'] = Project::whereIn('divisi_id',$divisi) + ->where([['budget_health', 'overrun'],['created_by_id', $replaceHierarchy]]) ->count(); } - + // arr warning if ($role === 'Super Admin') { - $response['data']['overrun'] = Project::where('budget_health', 'warning') - ->count(); - } elseif ($all_project) { $response['data']['warning'] = Project::where('budget_health', 'warning') - ->where('company_id', $company_id) + ->count(); + } elseif ($all_project == 'true') { + $response['data']['warning'] = Project::whereIn('divisi_id',$divisi) + ->where([['budget_health', 'warning'],['company_id', $company_id]]) ->count(); } else { - $response['data']['warning'] = Project::where('budget_health', 'warning') - ->where('created_by_id', $hierarchy) + $response['data']['warning'] = Project::whereIn('divisi_id',$divisi) + ->where([['budget_health', 'warning'],['created_by_id', $replaceHierarchy]]) ->count(); } + // arr on-budget if ($role === 'Super Admin') { - Log::info('on-budget'); $response['data']['on-budget'] = Project::where('budget_health', 'on-budget') ->count(); - } elseif ($all_project) { - $response['data']['on-budget'] = Project::where('budget_health', 'on-budget') - ->where('company_id', $company_id) + } elseif ($all_project == 'true') { + $response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi) + ->where([['company_id', $company_id],['budget_health', 'on-budget']]) ->count(); } else { - $response['data']['on-budget'] = Project::where('budget_health', 'on-budget') - ->where('created_by_id', $hierarchy) + $response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi) + ->where([['budget_health', 'on-budget'],['created_by_id', $replaceHierarchy]]) ->count(); } return response()->json($response, 200); @@ -437,10 +448,8 @@ class DashboardBoDController extends Controller private function countTotalProjectByBudgetHealthInDivision($divisi, $health) { - return Project::where('divisi_id', $divisi) - /* ->orWhere('akhir_proyek', 'like', $year) */ - ->where('budget_health', $health) - ->count(); + $project = Project::where([['divisi_id', $divisi],['budget_health', $health]])->count(); + return $project; } @@ -476,8 +485,6 @@ class DashboardBoDController extends Controller unset($division->children); $division->budgetData = $budgetData; } - foreach ($divisions as $division) { - } return response()->json([ 'data' => [ $divisions