From c3ebdfc5eccae8ee1ca456b221af7b38944b01af Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 1 Dec 2023 13:58:51 +0700 Subject: [PATCH 1/3] update response carousel --- .../ProjectCarausellController.php | 129 +++--------------- 1 file changed, 17 insertions(+), 112 deletions(-) diff --git a/app/Http/Controllers/ProjectCarausellController.php b/app/Http/Controllers/ProjectCarausellController.php index 361b8b1..2850318 100644 --- a/app/Http/Controllers/ProjectCarausellController.php +++ b/app/Http/Controllers/ProjectCarausellController.php @@ -11,88 +11,6 @@ use App\Models\{ }; class ProjectCarausellController extends Controller { - // public function invoke() { - // // Master Data - // $projectData = Project::query() - // ->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve") - // ->get(); - // $projectRisk = ProjectRisks::query() - // ->select('proyek_id','description','level_risk','preventive_risk') - // ->get(); - // $projectIssue = ProjectIssues::query() - // ->select('proyek_id','description','level_issue') - // ->get(); - // $ganttData = VersionGantt::query() - // ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type') - // ->get(); - - // $arr = []; - // foreach ($ganttData as $gantt) { - // $projectArr = []; - // $riskProject = []; - // $issueProject = []; - // foreach($projectData as $project) { - // if($project['id'] === $gantt['proyek_id']) { - // foreach ($projectRisk as $risk) { - // if ($risk['proyek_id'] === $project['id']) { - // $riskProject[] = [ - // 'level_risk' => $risk['level_risk'], - // 'preventive_risk' => $risk['preventive_risk'], - // 'description' => $risk['description'] - // ]; - // } - // } - // foreach ($projectIssue as $issue) { - // if ($issue['proyek_id'] === $project['id']) { - // $issueProject[] = [ - // 'level_issue' => $issue['level_issue'], - // 'description' => $issue['description'] - // ]; - // } - // } - // $projectArr[] = [ - // "project" => [ - // "id" => $project['id'], - // "pm_id" => $project['pm_id'], - // "nama" => $project['nama'], - // "kode_sortname" => $project['kode_sortname'], - // "budget_health" => $project['budget_health'], - // "calculation_status" => $project['calculation_status'], - // "mulai_proyek" => $project['mulai_proyek'], - // "akhir_proyek" => $project['akhir_proyek'], - // "rencana_biaya" => $project['rencana_biaya'], - // "company" => $project['company'], - // "scurve" => $project['scurve'], - // "project_risk" => $riskProject, - // "project_issues" => $issueProject - // ], - // ]; - // } - // } - - // $arr[] = [ - // "gantt" => [ - // "gantt_id" => $gantt['id'], - // 'proyek_id' => $gantt['proyek_id'], - // "name_version" => $gantt['name_version'], - // "hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'], - // "cost_to_complete" => $gantt['cost_to_complete'], - // "calculation_type" => $gantt['calculation_type'], - // "project"=> $projectArr - // ], - // ]; - // } - // return response()->json(['status'=>'success','code'=> 200,'data'=>$projectArr, "total_project"=>count($arr)], 200); - // } - - // public function getParents(&$data, $id) { - // $ftth = HierarchyFtth::find($id); - // array_push($data, $ftth); - // if ($ftth->parent_id) { - // $this->getParents($data, $ftth->parent_id); - // } - // } - public function invoke() { // Master Data $projectData = Project::query() @@ -104,18 +22,13 @@ class ProjectCarausellController extends Controller $projectIssue = ProjectIssues::query() ->select('proyek_id','description','level_issue') ->get(); - $ganttData = VersionGantt::query() - ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type') - ->get(); - - // Nested looping $arr = []; - foreach ($ganttData as $gantt) { + foreach($projectData as $project) { $riskProject = []; $issueProject = []; foreach ($projectRisk as $risk) { - if ($risk['proyek_id'] === $gantt['proyek_id']) { + if ($risk['proyek_id'] === $project['id']) { $riskProject[] = [ 'level_risk' => $risk['level_risk'], 'preventive_risk' => $risk['preventive_risk'], @@ -123,33 +36,21 @@ class ProjectCarausellController extends Controller ]; } } - foreach ($projectIssue as $issue) { - if ($issue['proyek_id'] === $gantt['proyek_id']) { + if ($issue['proyek_id'] === $project['id']) { $issueProject[] = [ 'level_issue' => $issue['level_issue'], 'description' => $issue['description'] ]; } } - - $arr[$gantt['proyek_id']][] = [ - "gantt" => [ - "gantt_id" => $gantt['id'], - 'proyek_id' => $gantt['proyek_id'], - "name_version" => $gantt['name_version'], - "hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'], - "cost_to_complete" => $gantt['cost_to_complete'], - "calculation_type" => $gantt['calculation_type'], - ], - "project_risk" => $riskProject, - "project_issue"=>$issueProject - ]; - } - - foreach($projectData as $project) { + $ganttData = VersionGantt::query() + ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type') + ->where('proyek_id',$project['id']) + ->orderByDesc('id') + ->first(); $projectManager = User::where('id', $project['pm_id'])->value('name'); - $arr[$project['id']][] = [ + $arr[]= [ "project" => [ "id" => $project['id'], "pm_id" => $project['pm_id'], @@ -161,12 +62,16 @@ class ProjectCarausellController extends Controller "akhir_proyek" => $project['akhir_proyek'], "rencana_biaya" => $project['rencana_biaya'], "company" => $project['company'], - "project_manager" => $projectManager, - "scurve" => $project['scurve'] + "scurve" => $project['scurve'], + "project_risk" => $riskProject, + "project_issues" => $issueProject ], + "project_manager" => $projectManager, + "project_risk" => $riskProject, + "project_issue" => $projectIssue, + "gantt"=> $ganttData ]; } - - return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "total_project"=>count($arr)], 200); + return response()->json(['status'=>'success','code'=> 200,'data'=> $arr, "total_project"=>count($arr)], 200); } } From 07a14558933cb04d9bfa253e709ad4c1485e6d68 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Tue, 5 Dec 2023 08:24:08 +0700 Subject: [PATCH 2/3] update endpoint --- .../ProjectCarausellController.php | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/ProjectCarausellController.php b/app/Http/Controllers/ProjectCarausellController.php index 2850318..e64aca9 100644 --- a/app/Http/Controllers/ProjectCarausellController.php +++ b/app/Http/Controllers/ProjectCarausellController.php @@ -16,34 +16,19 @@ class ProjectCarausellController extends Controller $projectData = Project::query() ->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve") ->get(); - $projectRisk = ProjectRisks::query() - ->select('proyek_id','description','level_risk','preventive_risk') - ->get(); - $projectIssue = ProjectIssues::query() - ->select('proyek_id','description','level_issue') - ->get(); $arr = []; foreach($projectData as $project) { - $riskProject = []; - $issueProject = []; - foreach ($projectRisk as $risk) { - if ($risk['proyek_id'] === $project['id']) { - $riskProject[] = [ - 'level_risk' => $risk['level_risk'], - 'preventive_risk' => $risk['preventive_risk'], - 'description' => $risk['description'] - ]; - } - } - foreach ($projectIssue as $issue) { - if ($issue['proyek_id'] === $project['id']) { - $issueProject[] = [ - 'level_issue' => $issue['level_issue'], - 'description' => $issue['description'] - ]; - } - } + $projectRisk = ProjectRisks::query() + ->select('proyek_id','description','level_risk','preventive_risk') + ->where('proyek_id', $project['id']) + ->get() + ->toArray(); + $projectIssue = ProjectIssues::query() + ->select('proyek_id','description','level_issue') + ->where('proyek_id',$project['id']) + ->get() + ->toArray(); $ganttData = VersionGantt::query() ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id','calculation_type') ->where('proyek_id',$project['id']) @@ -63,11 +48,9 @@ class ProjectCarausellController extends Controller "rencana_biaya" => $project['rencana_biaya'], "company" => $project['company'], "scurve" => $project['scurve'], - "project_risk" => $riskProject, - "project_issues" => $issueProject ], "project_manager" => $projectManager, - "project_risk" => $riskProject, + "project_risk" => $projectRisk, "project_issue" => $projectIssue, "gantt"=> $ganttData ]; From 1046904ea508839437400017ac19899f49dc8c2d Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 5 Dec 2023 14:00:21 +0700 Subject: [PATCH 3/3] update company_id and all_project access --- app/Models/ChecklistK3.php | 13 +++++++------ app/Models/Role.php | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Models/ChecklistK3.php b/app/Models/ChecklistK3.php index a328fc7..564563f 100644 --- a/app/Models/ChecklistK3.php +++ b/app/Models/ChecklistK3.php @@ -12,11 +12,12 @@ class ChecklistK3 extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', - 'description', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' + 'name', + 'description', + 'created_at', + 'created_by', + 'updated_at', + 'updated_by', + 'company_id' ]; } diff --git a/app/Models/Role.php b/app/Models/Role.php index 4fdc897..09b75d2 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -12,6 +12,6 @@ class Role extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' + 'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', 'all_project' ]; }