|
|
|
@ -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,22 +220,20 @@ 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']); |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
|
foreach ($dataRa as $ra) { |
|
|
|
|
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
|
|
|
|
foreach ($images as $image) { |
|
|
|
@ -252,7 +249,6 @@ class ProjectController extends Controller
|
|
|
|
|
unlink($destinationPath['pathActivityDocument'] . $ad->file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); |
|
|
|
|
CommentActivity::whereIn("activity_id", $activityIds)->delete(); |
|
|
|
|
Holiday::where("proyek_id", $project_id)->delete(); |
|
|
|
@ -264,19 +260,16 @@ 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']); |
|
|
|
|
$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(); |
|
|
|
|
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); |
|
|
|
|
$ref_ids = $dataFolder->all(); |
|
|
|
|