|
|
|
@ -6,6 +6,7 @@ use DateTime;
|
|
|
|
|
use App\Models\Link; |
|
|
|
|
use App\Models\User; |
|
|
|
|
use App\Models\Image; |
|
|
|
|
use App\Models\Company; |
|
|
|
|
use App\Models\Holiday; |
|
|
|
|
use App\Models\Project; |
|
|
|
|
use App\Models\Activity; |
|
|
|
@ -33,15 +34,15 @@ use App\Models\ProjectApproval;
|
|
|
|
|
use App\Models\RequestMaterial; |
|
|
|
|
use App\Models\ProjectMileStone; |
|
|
|
|
use App\Models\ProjectChecklists; |
|
|
|
|
use App\Models\ProductTransaction; |
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
use App\Models\ProjectParticipants; |
|
|
|
|
use App\Models\FolderDocumentProyek; |
|
|
|
|
use App\Models\ProjectToChecklistK3; |
|
|
|
|
use App\Helpers\MasterFunctionsHelper; |
|
|
|
|
use App\Models\ProductTransaction; |
|
|
|
|
use App\Models\ReportActivityMaterial; |
|
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
|
|
|
use Illuminate\Database\Query\Builder; |
|
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
|
|
|
|
|
|
|
|
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; |
|
|
|
|
|
|
|
|
@ -206,14 +207,14 @@ class ProjectController extends Controller
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function delete($id) |
|
|
|
|
public function delete($id, $company_id) |
|
|
|
|
{ |
|
|
|
|
$data = Project::find($id); |
|
|
|
|
|
|
|
|
|
if (!$data) |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
|
|
|
|
|
|
$this->deleteRelative($id); |
|
|
|
|
$this->deleteRelative($id, $company_id); |
|
|
|
|
|
|
|
|
|
if (!$data->delete()) |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500); |
|
|
|
@ -221,7 +222,7 @@ class ProjectController extends Controller
|
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function deleteRelative($project_id) |
|
|
|
|
private function deleteRelative($project_id, $company_id) |
|
|
|
|
{ |
|
|
|
|
UserToProyek::where('proyek_id', $project_id)->delete(); |
|
|
|
|
UserToActivity::where('proyek_id', $project_id)->delete(); |
|
|
|
@ -239,30 +240,34 @@ 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); |
|
|
|
|
$this->deleteDokumenProject($project_id); |
|
|
|
|
$this->deleteVersionGantt($project_id, $company_id); |
|
|
|
|
$this->deleteDokumenProject($project_id, $company_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function deleteVersionGantt($project_id) |
|
|
|
|
private function deleteVersionGantt($project_id, $company_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($this->pathImage . $image->image)) { |
|
|
|
|
unlink($this->pathImage . $image->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($this->pathActivityDocument . $ad->file)) { |
|
|
|
|
unlink($this->pathActivityDocument . $ad->file); |
|
|
|
|
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { |
|
|
|
|
unlink($destinationPath['pathActivityDocument'] . $ad->file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); |
|
|
|
@ -275,23 +280,26 @@ class ProjectController extends Controller
|
|
|
|
|
ReportActivity::whereIn("activity_id", $activityIds)->delete(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function deleteDokumenProject($project_id) |
|
|
|
|
private function deleteDokumenProject($project_id, $company_id) |
|
|
|
|
{ |
|
|
|
|
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('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($this->pathDocument . $dokumen->file)) { |
|
|
|
|
unlink($this->pathDocument . $dokumen->file); |
|
|
|
|
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { |
|
|
|
|
unlink($destinationPath['pathDocument'] . $dokumen->file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); |
|
|
|
|
|
|
|
|
|
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); |
|
|
|
|
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); |
|
|
|
|
$ref_ids = $dataFolder->all(); |
|
|
|
|
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); |
|
|
|
|
foreach ($dataDokumen as $dokumen) { |
|
|
|
|
if (file_exists($this->pathDocument . $dokumen->file)) { |
|
|
|
|
unlink($this->pathDocument . $dokumen->file); |
|
|
|
|
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { |
|
|
|
|
unlink($destinationPath['pathDocument'] . $dokumen->file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -520,9 +528,6 @@ class ProjectController extends Controller
|
|
|
|
|
} |
|
|
|
|
$activity->save(); |
|
|
|
|
} |
|
|
|
|
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ |
|
|
|
|
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ |
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($reports); $i++) { |
|
|
|
|
$activity = Activity::find($reports[$i]['activity_id']); |
|
|
|
|
if ($reports[$i]['status'] != 'done') { |
|
|
|
|