From 67da512ce725fa0f1f14e534c19caad4de602188 Mon Sep 17 00:00:00 2001 From: farhantock Date: Wed, 13 Dec 2023 20:36:12 +0700 Subject: [PATCH] update filter project by company --- .../ProjectCarausellController.php | 40 +++++++++++++------ routes/web.php | 2 +- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/ProjectCarausellController.php b/app/Http/Controllers/ProjectCarausellController.php index e64aca9..6abd158 100644 --- a/app/Http/Controllers/ProjectCarausellController.php +++ b/app/Http/Controllers/ProjectCarausellController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use Illuminate\Http\Request; use App\Models\{ User, Project, @@ -9,33 +10,46 @@ use App\Models\{ ProjectIssues, ProjectRisks }; + class ProjectCarausellController extends Controller { - public function invoke() { + public function invoke(Request $request) + { // 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(); + $company_id = $request->route('company_id'); + $all_project = $request->route('all_project'); + $hierarchy = $request->route('hierarchy'); + + $query = Project::query() + ->select("id", "nama", "kode_sortname", "pm_id", "budget_health", "calculation_status", "mulai_proyek", "akhir_proyek", "rencana_biaya", "company", "scurve"); + + if ($all_project) { + $query->where('company_id', $company_id); + } else { + $query->where('created_by_id', $hierarchy); + } + + $projectData = $query->get(); $arr = []; - foreach($projectData as $project) { + foreach ($projectData as $project) { $projectRisk = ProjectRisks::query() - ->select('proyek_id','description','level_risk','preventive_risk') + ->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']) + ->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']) + ->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[]= [ + $arr[] = [ "project" => [ "id" => $project['id'], "pm_id" => $project['pm_id'], @@ -52,9 +66,9 @@ class ProjectCarausellController extends Controller "project_manager" => $projectManager, "project_risk" => $projectRisk, "project_issue" => $projectIssue, - "gantt"=> $ganttData + "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); } } diff --git a/routes/web.php b/routes/web.php index 0d334f0..77ce518 100644 --- a/routes/web.php +++ b/routes/web.php @@ -81,7 +81,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro /* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */ /* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */ - $router->get('/project-carausell', 'ProjectCarausellController@invoke'); + $router->get('/project-carausell/{company_id}/{all_project}/{hierarchy}', 'ProjectCarausellController@invoke'); $router->post('/project-charter/search', 'ProjectCharterController@search'); $router->post('/project-charter/add', 'ProjectCharterController@add');