Browse Source

Merge pull request 'handle delete' (#250) from dev-wahyun into staging

Reviewed-on: ordo/adw-backend#250
pull/3/head
farhantock 1 year ago
parent
commit
8d7ddd4c5c
  1. 34
      app/Http/Controllers/ActivityController.php
  2. 13
      app/Http/Controllers/ProjectController.php
  3. 21
      app/Http/Controllers/VersionGanttController.php

34
app/Http/Controllers/ActivityController.php

@ -1,22 +1,23 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper; use DateTime;
use App\Models\Activity;
use App\Models\AssignMaterial;
use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
use App\Models\User;
use App\Models\Project; use App\Models\Project;
use App\Models\TemplateGantt; use App\Models\Activity;
use App\Models\TmpImport; use App\Models\TmpImport;
use App\Models\VersionGantt;
use App\Models\UserToActivity;
use App\Models\UserToProyek; use App\Models\UserToProyek;
use App\Models\User; use App\Models\VersionGantt;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\TemplateGantt;
use App\Models\AssignMaterial;
use App\Models\UserToActivity;
use App\Models\ActivityDokumen;
use App\Models\CommentActivity;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use DateTime; use App\Helpers\MasterFunctionsHelper;
class ActivityController extends Controller class ActivityController extends Controller
{ {
@ -500,13 +501,26 @@ class ActivityController extends Controller
{ {
if (!$data = Activity::find($id)) if (!$data = Activity::find($id))
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404);
$this->deleteRelative($id);
if (!$data->delete()) if (!$data->delete())
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500);
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200);
} }
private function deleteRelative($activity_id)
{
UserToActivity::where('activity_id', $activity_id)->delete();
AssignMaterial::where('activity_id', $activity_id)->delete();
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get();
foreach ($dataAd as $ad) {
if(file_exists($this->pathActivityDocument.$ad->file)){
unlink($this->pathActivityDocument.$ad->file);
}
}
ActivityDokumen::where("activity_id", $activity_id)->delete();
}
public function getUpdate($id) public function getUpdate($id)
{ {
if (!$data = Activity::find($id)) if (!$data = Activity::find($id))

13
app/Http/Controllers/ProjectController.php

@ -9,13 +9,17 @@ use App\Models\Image;
use App\Models\Holiday; use App\Models\Holiday;
use App\Models\Project; use App\Models\Project;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ReportK3;
use App\Jobs\ProcessSCurve; use App\Jobs\ProcessSCurve;
use App\Models\AssignTools;
use App\Models\OfficeHours; use App\Models\OfficeHours;
use App\Models\ProjectType; use App\Models\ProjectType;
use App\Models\ProjectPhase; use App\Models\ProjectPhase;
use App\Models\ProjectRisks;
use App\Models\UserToProyek; use App\Models\UserToProyek;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
use App\Models\ProjectIssues; use App\Models\ProjectIssues;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\DokumenProject; use App\Models\DokumenProject;
@ -26,13 +30,14 @@ use App\Models\UserToActivity;
use App\Models\ActivityDokumen; use App\Models\ActivityDokumen;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\ProjectApproval; use App\Models\ProjectApproval;
use App\Models\RequestMaterial;
use App\Models\ProjectMileStone; use App\Models\ProjectMileStone;
use App\Models\ProjectChecklists; use App\Models\ProjectChecklists;
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\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use App\Models\ProjectRisks;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
@ -163,6 +168,12 @@ class ProjectController extends Controller
ProjectChecklists::where('proyek_id', $project_id)->delete(); ProjectChecklists::where('proyek_id', $project_id)->delete();
ProjectIssues::where('proyek_id', $project_id)->delete(); ProjectIssues::where('proyek_id', $project_id)->delete();
ProjectRisks::where('proyek_id', $project_id)->delete(); ProjectRisks::where('proyek_id', $project_id)->delete();
ProjectToChecklistK3::where('proyek_id', $project_id)->delete();
HierarchyFtth::where('project_id', $project_id)->delete();
AssignTools::where('proyek_id', $project_id)->delete();
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->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id); $this->deleteDokumenProject($project_id);
} }

21
app/Http/Controllers/VersionGanttController.php

@ -2,8 +2,15 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Models\Link;
use App\Models\Holiday;
use App\Models\Activity;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use Illuminate\Http\Request;
use App\Models\ShowHideColumn;
use App\Models\UserToActivity;
use App\Models\UserToVersionGantt;
use App\Models\ActivityProgressLog;
class VersionGanttController extends Controller class VersionGanttController extends Controller
{ {
@ -49,6 +56,7 @@ class VersionGanttController extends Controller
if($data){ if($data){
$delete = $data->delete(); $delete = $data->delete();
$this->deleteRelative($data['id']);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400);
die(); die();
@ -62,6 +70,17 @@ class VersionGanttController extends Controller
} }
} }
private function deleteRelative($version_gantt_id)
{
UserToActivity::where('version_gantt_id', $version_gantt_id)->delete();
Activity::where('version_gantt_id', $version_gantt_id)->delete();
ShowHideColumn::where('version_gantt_id', $version_gantt_id)->delete();
Link::where('version_gantt_id', $version_gantt_id)->delete();
UserToVersionGantt::where('version_gantt_id', $version_gantt_id)->delete();
Holiday::where('version_gantt_id', $version_gantt_id)->delete();
ActivityProgressLog::where('version_gantt_id', $version_gantt_id)->delete();
}
public function edit($id){ public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);

Loading…
Cancel
Save