|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Project;
|
|
|
|
use App\Models\Divisi;
|
|
|
|
use App\Models\ProjectPhase;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use DB;
|
|
|
|
|
|
|
|
class DashboardBoDController extends Controller
|
|
|
|
{
|
|
|
|
private function interpolateYear($year){
|
|
|
|
if($year)
|
|
|
|
$year = '%'.$year.'%';
|
|
|
|
return $year;
|
|
|
|
}
|
|
|
|
|
|
|
|
// to do
|
|
|
|
public function getCompanyCashFlow($year = '%') {
|
|
|
|
$year = $this->interpolateYear($year);
|
|
|
|
|
|
|
|
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
|
|
|
|
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
|
|
|
|
->where('mulai_proyek', 'like', $year)
|
|
|
|
->pluck('sum')
|
|
|
|
->first();
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'data' => [
|
|
|
|
'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 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 %
|
|
|
|
return response()->json([
|
|
|
|
'data' => [
|
|
|
|
'behind-schedule' => rand(0,10),
|
|
|
|
'warning' => rand(0,10),
|
|
|
|
'on-schedule' => rand(0,10),
|
|
|
|
]
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo
|
|
|
|
public function getTotalProjectScheduleHealthPerDivision($year = '%'){
|
|
|
|
$year = $this->interpolateYear($year);
|
|
|
|
|
|
|
|
$divisions = Divisi::whereNull('parent')->get();
|
|
|
|
foreach($divisions as $division){
|
|
|
|
$scheduleData = new Collection();
|
|
|
|
$scheduleData->prepend(rand(0, 10), 'behindSchedule');
|
|
|
|
$scheduleData->prepend(rand(0, 10), 'warning');
|
|
|
|
$scheduleData->prepend(rand(0, 10), 'onSchedule');
|
|
|
|
$division->scheduleData = $scheduleData;
|
|
|
|
}
|
|
|
|
return response()->json([
|
|
|
|
'data' => [
|
|
|
|
$divisions
|
|
|
|
]
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTotalProjectPerBudgetHealth($year = '%'){
|
|
|
|
$year = $this->interpolateYear($year);
|
|
|
|
return response()->json([
|
|
|
|
'data' => [
|
|
|
|
'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);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){
|
|
|
|
return Project::where('divisi_id', $divisi)
|
|
|
|
->where('mulai_proyek', 'like', $year)
|
|
|
|
->where('budget_health', $health)
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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($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
|
|
|
|
]
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTotalProjectPerPhase($year = '%'){
|
|
|
|
$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)
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
return response()->json([
|
|
|
|
'data' => [
|
|
|
|
$projectPhases
|
|
|
|
]
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function countTotalProjectInDivision($id, $year){
|
|
|
|
return Project::where('divisi_id', $id)
|
|
|
|
->where('mulai_proyek', 'like', $year)
|
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTotalProjectPerDivision($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 $v){
|
|
|
|
$v->total = $this->countTotalProjectInDivision($v->id, $year);
|
|
|
|
foreach($v->children as $d){
|
|
|
|
$v->total += $this->countTotalProjectInDivision($d->id, $year);
|
|
|
|
}
|
|
|
|
unset($v->children);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'data' => $divisions
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function countTotalProjectValueInDivision($id, $year){
|
|
|
|
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
|
|
|
|
->where('mulai_proyek', 'like', $year)
|
|
|
|
->where('divisi_id', $id)
|
|
|
|
->pluck('sum')
|
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTotalProjectValuePerDivision($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 $v){
|
|
|
|
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
|
|
|
|
foreach($v->children as $d){
|
|
|
|
$v->total += $this->countTotalProjectValueInDivision($d->id, $year);
|
|
|
|
}
|
|
|
|
unset($v->children);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'data' => $divisions
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|