Browse Source

[Refactor] Menghapus company_id

pull/7/head
Fuad Hadisurya 4 months ago
parent
commit
0508c0e235
  1. 31
      app/Http/Controllers/ImageController.php
  2. 31
      app/Http/Controllers/ProjectController.php

31
app/Http/Controllers/ImageController.php

@ -124,23 +124,6 @@ class ImageController extends Controller
} }
} }
$totalSize += $sizeFile; $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);
}
}
} }
foreach ($dokumen as $file) { foreach ($dokumen as $file) {
$extension = $file->extension(); $extension = $file->extension();
@ -219,12 +202,11 @@ class ImageController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
public function deleteByRef($id, $category, $company_id) public function deleteByRef($id, $category)
{ {
$data = Image::where("ref_id", (int)$id)->where("category", $category)->first(); $data = Image::where("ref_id", (int)$id)->where("category", $category)->first();
$company = Company::find($company_id); if($data){
if($data && $company){ $destinationPath = $this->setCustomeDirectoryUpload();
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
unlink($destinationPath['pathImage'].$data->image); unlink($destinationPath['pathImage'].$data->image);
$delete = $data->delete(); $delete = $data->delete();
}else{ }else{
@ -240,16 +222,15 @@ class ImageController extends Controller
} }
} }
public function deleteByRefMultiple($id, $category, $company_id) public function deleteByRefMultiple($id, $category)
{ {
$successCount = 0; $successCount = 0;
$data = Image::where([ $data = Image::where([
["ref_id", intval($id)], ["ref_id", intval($id)],
["category", $category] ["category", $category]
])->get(); ])->get();
$company = Company::find($company_id); if($data->isNotEmpty()) {
if($data->isNotEmpty() && $company) { $destinationPath = $this->setCustomeDirectoryUpload();
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach($data as $img) { foreach($data as $img) {
unlink($destinationPath['pathImage'].$img->image); unlink($destinationPath['pathImage'].$img->image);
$delete = $img->delete(); $delete = $img->delete();

31
app/Http/Controllers/ProjectController.php

@ -181,15 +181,14 @@ class ProjectController extends Controller
return true; return true;
} }
public function delete($id, $company_id) public function delete($id)
{ {
DB::beginTransaction(); DB::beginTransaction();
$data = Project::find($id); $data = Project::find($id);
$dateNow = Carbon::now(); $dateNow = Carbon::now();
if ($data) { if ($data) {
$this->deleteRelative($id, $company_id); $this->deleteRelative($id);
if ($data->delete()) { if ($data->delete()) {
// if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) {
DB::commit(); DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} else { } 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(); UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete(); UserToActivity::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete(); AssignMaterial::where('proyek_id', $project_id)->delete();
@ -221,22 +220,20 @@ class ProjectController extends Controller
OfficeHours::where('proyek_id', $project_id)->delete(); OfficeHours::where('proyek_id', $project_id)->delete();
ReportK3::where('proyek_id', $project_id)->delete(); ReportK3::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete(); RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id, $company_id); $this->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id, $company_id); $this->deleteDokumenProject($project_id);
}, 5); }, 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"); $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
$vhIds = $dataVg->all(); $vhIds = $dataVg->all();
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
$activityIds = $activity->all(); $activityIds = $activity->all();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
$company = Company::find($company_id); $destinationPath = $this->setCustomeDirectoryUpload();
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) { foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) { foreach ($images as $image) {
@ -252,7 +249,6 @@ class ProjectController extends Controller
unlink($destinationPath['pathActivityDocument'] . $ad->file); unlink($destinationPath['pathActivityDocument'] . $ad->file);
} }
} }
}
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
CommentActivity::whereIn("activity_id", $activityIds)->delete(); CommentActivity::whereIn("activity_id", $activityIds)->delete();
Holiday::where("proyek_id", $project_id)->delete(); Holiday::where("proyek_id", $project_id)->delete();
@ -264,19 +260,16 @@ class ProjectController extends Controller
}, 5); }, 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(); $dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->get();
$company = Company::find($company_id); $destinationPath = $this->setCustomeDirectoryUpload();
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataDokumen as $dokumen) { foreach ($dataDokumen as $dokumen) {
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
unlink($destinationPath['pathDocument'] . $dokumen->file); unlink($destinationPath['pathDocument'] . $dokumen->file);
} }
} }
}
DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->delete(); DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->delete();
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
$ref_ids = $dataFolder->all(); $ref_ids = $dataFolder->all();

Loading…
Cancel
Save