|
|
|
@ -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(); |
|
|
|
|