diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index aca1727..a57d1d8 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -179,7 +179,7 @@ class DashboardBoDController extends Controller ], 200); } - public function getTotalProjectPerScheduleHealth($year = '%') + public function getTotalProjectPerScheduleHealth($year = '%', $company_id, $all_project, $hierarchy) { $year = $this->interpolateYear($year); @@ -189,7 +189,17 @@ class DashboardBoDController extends Controller 'on-schedule' => 0, ]; - $projects = Project::where('mulai_proyek', 'like', $year)->get(); + $projects = null; + if ($all_project) { + $projects = Project::where('mulai_proyek', 'like', $year) + ->where('company_id', $company_id) + ->get(); + } else { + $projects = Project::where('mulai_proyek', 'like', $year) + ->where('created_by_id', $hierarchy) + ->get(); + } + foreach ($projects as $index => $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $selisihProgress = 0; @@ -319,15 +329,23 @@ class DashboardBoDController extends Controller ], 200); } - public function getTotalProjectPerPhase($year = '%') + public function getTotalProjectPerPhase($year = '%', $company_id, $all_project, $hierarchy) { $year = $this->interpolateYear($year); $projectPhases = ProjectPhase::orderBy('order')->get(); foreach ($projectPhases as $phase) { - $phase->totalProject = Project::where('phase_id', $phase->id) - ->where('mulai_proyek', 'like', $year) - /* ->orWhere('akhir_proyek', 'like', $year) */ - ->count(); + + if ($all_project) { + $phase->totalProject = Project::where('phase_id', $phase->id) + ->where('mulai_proyek', 'like', $year) + ->where('company_id', $company_id) + ->count(); + } else { + $phase->totalProject = Project::where('phase_id', $phase->id) + ->where('mulai_proyek', 'like', $year) + ->where('created_by_id', $hierarchy) + ->count(); + } } return response()->json([ 'data' => [ diff --git a/routes/web.php b/routes/web.php index f7d3f5f..057d0e9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,11 +25,11 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->get('/dashboard/get-company-cashflow/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure $router->get('/dashboard/get-invoice-outstanding[/{year}]', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in - $router->get('/dashboard/get-total-project-per-schedule-health[/{year}]', 'DashboardBoDController@getTotalProjectPerScheduleHealth'); + $router->get('/dashboard/get-total-project-per-schedule-health/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerScheduleHealth'); $router->get('/dashboard/get-total-project-per-budget-health[/{year}]', 'DashboardBoDController@getTotalProjectPerBudgetHealth'); $router->get('/dashboard/get-total-project-schedule-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision'); $router->get('/dashboard/get-total-project-budget-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision'); - $router->get('/dashboard/get-total-project-per-phase[/{year}]', 'DashboardBoDController@getTotalProjectPerPhase'); + $router->get('/dashboard/get-total-project-per-phase/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerPhase'); $router->get('/dashboard/get-total-project-per-division[/{year}]', 'DashboardBoDController@getTotalProjectPerDivision'); $router->get('/dashboard/get-total-project-value-per-division[/{year}]', 'DashboardBoDController@getTotalProjectValuePerDivision'); $router->get('/dashboard/get-detail-expenditure[/{year}]', 'DashboardBoDController@getDetailExpenditure');