|
|
@ -6,6 +6,7 @@ use DateTime; |
|
|
|
use App\Models\Link; |
|
|
|
use App\Models\Link; |
|
|
|
use App\Models\User; |
|
|
|
use App\Models\User; |
|
|
|
use App\Models\Image; |
|
|
|
use App\Models\Image; |
|
|
|
|
|
|
|
use App\Models\Company; |
|
|
|
use App\Models\Holiday; |
|
|
|
use App\Models\Holiday; |
|
|
|
use App\Models\Project; |
|
|
|
use App\Models\Project; |
|
|
|
use App\Models\Activity; |
|
|
|
use App\Models\Activity; |
|
|
@ -33,15 +34,15 @@ use App\Models\ProjectApproval; |
|
|
|
use App\Models\RequestMaterial; |
|
|
|
use App\Models\RequestMaterial; |
|
|
|
use App\Models\ProjectMileStone; |
|
|
|
use App\Models\ProjectMileStone; |
|
|
|
use App\Models\ProjectChecklists; |
|
|
|
use App\Models\ProjectChecklists; |
|
|
|
|
|
|
|
use App\Models\ProductTransaction; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
use App\Models\ProjectParticipants; |
|
|
|
use App\Models\ProjectParticipants; |
|
|
|
use App\Models\FolderDocumentProyek; |
|
|
|
use App\Models\FolderDocumentProyek; |
|
|
|
use App\Models\ProjectToChecklistK3; |
|
|
|
use App\Models\ProjectToChecklistK3; |
|
|
|
use App\Helpers\MasterFunctionsHelper; |
|
|
|
use App\Helpers\MasterFunctionsHelper; |
|
|
|
use App\Models\ProductTransaction; |
|
|
|
|
|
|
|
use App\Models\ReportActivityMaterial; |
|
|
|
use App\Models\ReportActivityMaterial; |
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
|
|
|
|
|
|
use Illuminate\Database\Query\Builder; |
|
|
|
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"; |
|
|
|
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; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function delete($id) |
|
|
|
public function delete($id, $company_id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$data = Project::find($id); |
|
|
|
$data = Project::find($id); |
|
|
|
|
|
|
|
|
|
|
|
if (!$data) |
|
|
|
if (!$data) |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
|
|
|
|
|
|
|
|
$this->deleteRelative($id); |
|
|
|
$this->deleteRelative($id, $company_id); |
|
|
|
|
|
|
|
|
|
|
|
if (!$data->delete()) |
|
|
|
if (!$data->delete()) |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500); |
|
|
|
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); |
|
|
|
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(); |
|
|
|
UserToProyek::where('proyek_id', $project_id)->delete(); |
|
|
|
UserToActivity::where('proyek_id', $project_id)->delete(); |
|
|
|
UserToActivity::where('proyek_id', $project_id)->delete(); |
|
|
@ -239,32 +240,36 @@ 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); |
|
|
|
$this->deleteVersionGantt($project_id, $company_id); |
|
|
|
$this->deleteDokumenProject($project_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"); |
|
|
|
$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(); |
|
|
|
foreach ($dataRa as $ra) { |
|
|
|
$company = Company::find($company_id); |
|
|
|
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
|
|
|
if($company) { |
|
|
|
foreach ($images as $image) { |
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
if (file_exists($this->pathImage . $image->image)) { |
|
|
|
foreach ($dataRa as $ra) { |
|
|
|
unlink($this->pathImage . $image->image); |
|
|
|
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
|
|
|
} |
|
|
|
foreach ($images as $image) { |
|
|
|
} |
|
|
|
if (file_exists($destinationPath['pathImage'] . $image->image)) { |
|
|
|
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
|
|
|
unlink($destinationPath['pathImage'] . $image->image); |
|
|
|
} |
|
|
|
} |
|
|
|
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); |
|
|
|
} |
|
|
|
foreach ($dataAd as $ad) { |
|
|
|
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
|
|
|
if (file_exists($this->pathActivityDocument . $ad->file)) { |
|
|
|
} |
|
|
|
unlink($this->pathActivityDocument . $ad->file); |
|
|
|
$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(); |
|
|
|
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(); |
|
|
@ -275,23 +280,26 @@ class ProjectController extends Controller |
|
|
|
ReportActivity::whereIn("activity_id", $activityIds)->delete(); |
|
|
|
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(); |
|
|
|
$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($destinationPath['pathDocument'] . $dokumen->file)) { |
|
|
|
|
|
|
|
unlink($destinationPath['pathDocument'] . $dokumen->file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach ($dataDokumen as $dokumen) { |
|
|
|
|
|
|
|
if (file_exists($this->pathDocument . $dokumen->file)) { |
|
|
|
|
|
|
|
unlink($this->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"); |
|
|
|
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); |
|
|
|
$ref_ids = $dataFolder->all(); |
|
|
|
$ref_ids = $dataFolder->all(); |
|
|
|
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); |
|
|
|
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); |
|
|
|
foreach ($dataDokumen as $dokumen) { |
|
|
|
foreach ($dataDokumen as $dokumen) { |
|
|
|
if (file_exists($this->pathDocument . $dokumen->file)) { |
|
|
|
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { |
|
|
|
unlink($this->pathDocument . $dokumen->file); |
|
|
|
unlink($destinationPath['pathDocument'] . $dokumen->file); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -520,9 +528,6 @@ class ProjectController extends Controller |
|
|
|
} |
|
|
|
} |
|
|
|
$activity->save(); |
|
|
|
$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++) { |
|
|
|
for ($i = 0; $i < count($reports); $i++) { |
|
|
|
$activity = Activity::find($reports[$i]['activity_id']); |
|
|
|
$activity = Activity::find($reports[$i]['activity_id']); |
|
|
|
if ($reports[$i]['status'] != 'done') { |
|
|
|
if ($reports[$i]['status'] != 'done') { |
|
|
|