From 0508c0e235f4019d22f9df1121d2c4cc762e3f4a Mon Sep 17 00:00:00 2001 From: Fuad Hadisurya Date: Thu, 18 Jul 2024 15:16:38 +0700 Subject: [PATCH] [Refactor] Menghapus company_id --- app/Http/Controllers/ImageController.php | 33 +++--------- app/Http/Controllers/ProjectController.php | 59 ++++++++++------------ 2 files changed, 33 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php index 1e3c194..ece127e 100644 --- a/app/Http/Controllers/ImageController.php +++ b/app/Http/Controllers/ImageController.php @@ -123,24 +123,7 @@ class ImageController extends Controller $totalSize += filesize($folderPath . '/' . $file); } } - $totalSize += $sizeFile; - $transaction = ProductTransaction::query() - ->where('company_id', $company['id']); - $cloneQueryTransaction = clone $transaction; - - $countCreate = false; - if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) { - $maximumSize = 500 * 1024 * 1024; - $countCreate = true; - } elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) { - $maximumSize = 50 * 1024 * 1024; - $countCreate = true; - } - if($countCreate) { - if ($totalSize > $maximumSize) { - return response()->json(['status'=>'failed','message'=>'Limited storage maximum!','code'=> 500], 500); - } - } + $totalSize += $sizeFile; } foreach ($dokumen as $file) { $extension = $file->extension(); @@ -219,12 +202,11 @@ class ImageController extends Controller return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); } - public function deleteByRef($id, $category, $company_id) + public function deleteByRef($id, $category) { $data = Image::where("ref_id", (int)$id)->where("category", $category)->first(); - $company = Company::find($company_id); - if($data && $company){ - $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); + if($data){ + $destinationPath = $this->setCustomeDirectoryUpload(); unlink($destinationPath['pathImage'].$data->image); $delete = $data->delete(); }else{ @@ -240,16 +222,15 @@ class ImageController extends Controller } } - public function deleteByRefMultiple($id, $category, $company_id) + public function deleteByRefMultiple($id, $category) { $successCount = 0; $data = Image::where([ ["ref_id", intval($id)], ["category", $category] ])->get(); - $company = Company::find($company_id); - if($data->isNotEmpty() && $company) { - $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); + if($data->isNotEmpty()) { + $destinationPath = $this->setCustomeDirectoryUpload(); foreach($data as $img) { unlink($destinationPath['pathImage'].$img->image); $delete = $img->delete(); diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index c9c6c26..23baa16 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -181,15 +181,14 @@ class ProjectController extends Controller return true; } - public function delete($id, $company_id) + public function delete($id) { DB::beginTransaction(); $data = Project::find($id); $dateNow = Carbon::now(); if ($data) { - $this->deleteRelative($id, $company_id); + $this->deleteRelative($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 { @@ -202,9 +201,9 @@ class ProjectController extends Controller } } - private function deleteRelative($project_id, $company_id) + private function deleteRelative($project_id) { - DB::transaction(function () use ($project_id, $company_id) { + DB::transaction(function () use ($project_id) { UserToProyek::where('proyek_id', $project_id)->delete(); UserToActivity::where('proyek_id', $project_id)->delete(); AssignMaterial::where('proyek_id', $project_id)->delete(); @@ -221,36 +220,33 @@ class ProjectController extends Controller OfficeHours::where('proyek_id', $project_id)->delete(); ReportK3::where('proyek_id', $project_id)->delete(); RequestMaterial::where('proyek_id', $project_id)->delete(); - $this->deleteVersionGantt($project_id, $company_id); - $this->deleteDokumenProject($project_id, $company_id); + $this->deleteVersionGantt($project_id); + $this->deleteDokumenProject($project_id); }, 5); } - private function deleteVersionGantt($project_id, $company_id) + private function deleteVersionGantt($project_id) { - DB::transaction(function () use ($project_id, $company_id) { + DB::transaction(function () use ($project_id) { $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); $vhIds = $dataVg->all(); $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); $activityIds = $activity->all(); $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); - $company = Company::find($company_id); - if ($company) { - $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); - foreach ($dataRa as $ra) { - $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); - foreach ($images as $image) { - if (file_exists($destinationPath['pathImage'] . $image->image)) { - unlink($destinationPath['pathImage'] . $image->image); - } + $destinationPath = $this->setCustomeDirectoryUpload(); + foreach ($dataRa as $ra) { + $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); + foreach ($images as $image) { + if (file_exists($destinationPath['pathImage'] . $image->image)) { + unlink($destinationPath['pathImage'] . $image->image); } - Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); } - $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); - foreach ($dataAd as $ad) { - if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { - unlink($destinationPath['pathActivityDocument'] . $ad->file); - } + Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); + } + $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); + foreach ($dataAd as $ad) { + if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { + unlink($destinationPath['pathActivityDocument'] . $ad->file); } } ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); @@ -264,17 +260,14 @@ class ProjectController extends Controller }, 5); } - private function deleteDokumenProject($project_id, $company_id) + private function deleteDokumenProject($project_id) { - DB::transaction(function () use ($project_id, $company_id) { + DB::transaction(function () use ($project_id) { $dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->get(); - $company = Company::find($company_id); - if ($company) { - $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); - foreach ($dataDokumen as $dokumen) { - if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { - unlink($destinationPath['pathDocument'] . $dokumen->file); - } + $destinationPath = $this->setCustomeDirectoryUpload(); + foreach ($dataDokumen as $dokumen) { + if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { + unlink($destinationPath['pathDocument'] . $dokumen->file); } } DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->delete();