From 8e49f34b26ced03dcc0e80aaf4674e94325178c4 Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Tue, 4 Oct 2022 16:29:29 +0700 Subject: [PATCH] add dummy api --- .../Controllers/DashboardBoDController.php | 95 ++++++++++++++----- 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index ec845e2..b903ff6 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -16,6 +16,7 @@ class DashboardBoDController extends Controller return $year; } + // to do public function getCompanyCashFlow($year = '%') { $year = $this->interpolateYear($year); @@ -27,15 +28,39 @@ class DashboardBoDController extends Controller return response()->json([ 'data' => [ - 'total_budget' => (int) $totalBudgets ?? rand(0,10), - 'total_expenditure' => rand(0,10), // to do integrasi - 'total_invoice' => rand(0,10), - 'total_paid_invoice' => rand(0,10), + 'total_budget' => (int) $totalBudgets ?? rand(0,10000000000), + 'total_expenditure' => rand(0,10000000000), // to do integrasi + 'total_invoice' => rand(0,10000000000), + 'total_paid_invoice' => rand(0,10000000000), ] ], 200); } - public function getProjectPerScheduleHealth($year = '%'){ + public function getInvoiceOutstanding($year = '%'){ + return response()->json([ + 'data' => [ + 0 => [ + 'project' => 'Project A', + 'invoiced' => rand(0, 9000000000), + 'paid' => rand(0, 9000000000), + ], + 1 => [ + 'project' => 'Project B', + 'invoiced' => rand(0, 9000000000), + 'paid' => rand(0, 9000000000), + ], + 2 => [ + 'project' => 'Project C', + 'invoiced' => rand(0, 9000000000), + 'paid' => rand(0, 9000000000), + ], + ] + ], 200); + + } + + // to do + public function getTotalProjectPerScheduleHealth($year = '%'){ $year = $this->interpolateYear($year); // get data plan (vol) in % // get data actual in % @@ -48,7 +73,8 @@ class DashboardBoDController extends Controller ], 200); } - public function getProjectScheduleHealthPerDivision($year = '%'){ + // todo + public function getTotalProjectScheduleHealthPerDivision($year = '%'){ $year = $this->interpolateYear($year); $divisions = Divisi::whereNull('parent')->get(); @@ -66,28 +92,47 @@ class DashboardBoDController extends Controller ], 200); } - public function getProjectPerBudgetHealth($year = '%'){ + public function getTotalProjectPerBudgetHealth($year = '%'){ $year = $this->interpolateYear($year); return response()->json([ 'data' => [ - 'overrun' => rand(0,10), - 'warning' => rand(0,10), - 'on-budget' => rand(0,10), + 'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(), + 'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(), + 'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(), ] ], 200); } - public function getProjectBudgetHealthPerDivision($year = '%'){ - $year = $this->interpolateYear($year); + private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){ + return Project::where('divisi_id', $divisi) + ->where('mulai_proyek', 'like', $year) + ->where('budget_health', $health) + ->count(); + } - $divisions = Divisi::whereNull('parent')->get(); + + public function getTotalProjectBudgetHealthPerDivision($year = '%'){ + $year = $this->interpolateYear($year); + $divisions = Divisi::select('id','name') + ->with('children') + ->whereNull('parent') + ->get(); + // to do : count in more than 1 level child foreach($divisions as $division){ $budgetData = new Collection(); - $budgetData->prepend(rand(0, 10), 'overrun'); - $budgetData->prepend(rand(0, 10), 'warning'); - $budgetData->prepend(rand(0, 10), 'onBudget'); + $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun'); + $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning'); + $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget'); + foreach($division->children as $d){ + $budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun'); + $budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning'); + $budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget'); + } + unset($division->children); $division->budgetData = $budgetData; } + foreach($divisions as $division){ + } return response()->json([ 'data' => [ $divisions @@ -95,11 +140,13 @@ class DashboardBoDController extends Controller ], 200); } - public function getProjectPerPhase($year = '%'){ + public function getTotalProjectPerPhase($year = '%'){ $year = $this->interpolateYear($year); $projectPhases = ProjectPhase::orderBy('order')->get(); foreach($projectPhases as $phase){ - $phase->totalProject = rand(0,10); + $phase->totalProject = Project::where('phase_id', $phase->id) + ->where('mulai_proyek', 'like', $year) + ->count(); } return response()->json([ 'data' => [ @@ -117,13 +164,13 @@ class DashboardBoDController extends Controller public function getTotalProjectPerDivision($year = '%') { $year = $this->interpolateYear($year); - $totalProjectPerDivision = Divisi::select('id','name') + $divisions = Divisi::select('id','name') ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child - foreach($totalProjectPerDivision as $v){ + foreach($divisions as $v){ $v->total = $this->countTotalProjectInDivision($v->id, $year); foreach($v->children as $d){ $v->total += $this->countTotalProjectInDivision($d->id, $year); @@ -132,7 +179,7 @@ class DashboardBoDController extends Controller } return response()->json([ - 'data' => $totalProjectPerDivision + 'data' => $divisions ], 200); } @@ -147,13 +194,13 @@ class DashboardBoDController extends Controller public function getTotalProjectValuePerDivision($year = '%') { $year = $this->interpolateYear($year); - $totalProjectValuePerDivision = Divisi::select('id','name') + $divisions = Divisi::select('id','name') ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child - foreach($totalProjectValuePerDivision as $v){ + foreach($divisions as $v){ $v->total = $this->countTotalProjectValueInDivision($v->id, $year); foreach($v->children as $d){ $v->total += $this->countTotalProjectValueInDivision($d->id, $year); @@ -162,7 +209,7 @@ class DashboardBoDController extends Controller } return response()->json([ - 'data' => $totalProjectValuePerDivision + 'data' => $divisions ], 200); }