Browse Source

update filter dashboard

pull/1/head
farhantock 11 months ago
parent
commit
4cc57c18ec
  1. 245
      app/Http/Controllers/DashboardBoDController.php
  2. 28
      routes/web.php

245
app/Http/Controllers/DashboardBoDController.php

@ -58,30 +58,31 @@ class DashboardBoDController extends Controller
return $response; return $response;
} }
public function getCompanyCashFlow($year = '%', $company_id, $all_project, $hierarchy) public function getCompanyCashFlow($company_id, $all_project, $hierarchy, $role_name)
{ {
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; $totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
$totalBudgets = null; $totalBudgets = null;
if ($all_project) { $role = urldecode($role_name);
$totalBudgets = Project::where('mulai_proyek', 'like', $year) if ($role === "Super Admin") {
->where('company_id', $company_id) $totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
} elseif (!empty($all_project)) {
$totalBudgets = Project::where('company_id', $company_id)
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); ->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
} else { } else {
$totalBudgets = Project::where('mulai_proyek', 'like', $year) $totalBudgets = Project::where('created_by_id', $hierarchy)
->where('created_by_id', $hierarchy)
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); ->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
} }
$projects = null; $projects = null;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year) if ($role === "Super Admin") {
->where('company_id', $company_id) $projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get(); ->get();
} else { } else {
$projects = Project::where('mulai_proyek', 'like', $year) $projects = Project::where('created_by_id', $hierarchy)
->where('created_by_id', $hierarchy)
->get(); ->get();
} }
@ -114,8 +115,16 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getDetailExpenditureColor($company_id) { public function getDetailExpenditureColor($role_name, $company_id)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectExpenditure::get();
} else {
$query = ProjectExpenditure::where('company_id', $company_id)->get(); $query = ProjectExpenditure::where('company_id', $company_id)->get();
}
$data = []; $data = [];
foreach ($query as $value) { foreach ($query as $value) {
if ($value['name'] === 'Total Budget') { if ($value['name'] === 'Total Budget') {
@ -141,8 +150,17 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getDetailFinancialHealthColor($company_id) { public function getDetailFinancialHealthColor($role_name, $company_id)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectFinancialHealth::get();
} else {
$query = ProjectFinancialHealth::where('company_id', $company_id)->get(); $query = ProjectFinancialHealth::where('company_id', $company_id)->get();
}
$data = []; $data = [];
foreach ($query as $value) { foreach ($query as $value) {
if ($value['name'] === 'Cost Overrun') { if ($value['name'] === 'Cost Overrun') {
@ -164,8 +182,16 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getDetailScheduleHealthColor($company_id) { public function getDetailScheduleHealthColor($role_name, $company_id)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectScheduleHealth::get();
} else {
$query = ProjectScheduleHealth::where('company_id', $company_id)->get(); $query = ProjectScheduleHealth::where('company_id', $company_id)->get();
}
$data = []; $data = [];
foreach ($query as $value) { foreach ($query as $value) {
if ($value['name'] === 'Behind Schedule') { if ($value['name'] === 'Behind Schedule') {
@ -187,8 +213,15 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getDetailInvoiceColor($company_id) { public function getDetailInvoiceColor($role_name, $company_id)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectInvoice::get();
} else {
$query = ProjectInvoice::where('company_id', $company_id)->get(); $query = ProjectInvoice::where('company_id', $company_id)->get();
}
$data = []; $data = [];
foreach ($query as $value) { foreach ($query as $value) {
if ($value['name'] === 'Invoiced') { if ($value['name'] === 'Invoiced') {
@ -207,17 +240,17 @@ class DashboardBoDController extends Controller
} }
// integrasi // integrasi
public function getInvoiceOutstanding($year = '%', $company_id, $all_project, $hierarchy) public function getInvoiceOutstanding($role_name, $company_id, $all_project, $hierarchy)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
$projects = null; $projects = null;
if ($all_project) { if ($role === 'Super Admin') {
$projects = Project::where('mulai_proyek', 'like', $year) $projects = Project::get();
->where('company_id', $company_id) } elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get(); ->get();
} else { } else {
$projects = Project::where('mulai_proyek', 'like', $year) $projects = Project::where('created_by_id', $hierarchy)
->where('created_by_id', $hierarchy)
->get(); ->get();
} }
@ -241,9 +274,9 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getTotalProjectPerScheduleHealth($year = '%', $company_id, $all_project, $hierarchy) public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
$return = [ $return = [
'behind-schedule' => 0, 'behind-schedule' => 0,
@ -252,13 +285,13 @@ class DashboardBoDController extends Controller
]; ];
$projects = null; $projects = null;
if ($all_project) { if ($role === 'Super Admin') {
$projects = Project::where('mulai_proyek', 'like', $year) $projects = Project::get();
->where('company_id', $company_id) } elseif ($all_project) {
$projects = Project::where('company_id', $company_id)
->get(); ->get();
} else { } else {
$projects = Project::where('mulai_proyek', 'like', $year) $projects = Project::where('created_by_id', $hierarchy)
->where('created_by_id', $hierarchy)
->get(); ->get();
} }
@ -294,20 +327,24 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $return, 'q' => $projects], 200); return response()->json(['data' => $return, 'q' => $projects], 200);
} }
public function getTotalProjectScheduleHealthPerDivision($year = '%', $company_id) public function getTotalProjectScheduleHealthPerDivision($role_name, $company_id)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::whereNull('parent')
->get();
} else {
$divisions = Divisi::whereNull('parent') $divisions = Divisi::whereNull('parent')
->where('company_id', $company_id) ->where('company_id', $company_id)
->whereNull('parent')
->get(); ->get();
}
foreach ($divisions as $index => $division) { foreach ($divisions as $index => $division) {
$scheduleData = new Collection(); $scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0; $behindSchedule = $warning = $onSchedule = 0;
$projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get(); $projects = Project::where('divisi_id', $division->id)->get();
foreach ($projects as $project) { foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); $project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0; $selisihProgress = 0;
@ -342,9 +379,9 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getTotalProjectPerBudgetHealth($year = '%', $company_id, $all_project, $hierarchy) public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
$response = [ $response = [
'data' => [ 'data' => [
'overrun' => 0, 'overrun' => 0,
@ -353,81 +390,84 @@ class DashboardBoDController extends Controller
] ]
]; ];
if ($all_project) { if ($role === 'Super Admin') {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year) $response['data']['overrun'] = Project::where('budget_health', 'overrun')
->where('budget_health', 'overrun')
->where('company_id', $company_id)
->count(); ->count();
} else { } elseif ($all_project) {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year) $response['data']['overrun'] = Project::where('budget_health', 'overrun')
->where('budget_health', 'overrun')
->where('created_by_id', $hierarchy)
->count();
}
if ($all_project) {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'overrun')
->where('company_id', $company_id) ->where('company_id', $company_id)
->count(); ->count();
} else { } else {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year) $response['data']['overrun'] = Project::where('budget_health', 'overrun')
->where('budget_health', 'overrun')
->where('created_by_id', $hierarchy) ->where('created_by_id', $hierarchy)
->count(); ->count();
} }
if ($all_project) {
$response['data']['warning'] = Project::where('mulai_proyek', 'like', $year) if ($role === 'Super Admin') {
->where('budget_health', 'warning') $response['data']['overrun'] = Project::where('budget_health', 'warning')
->count();
} elseif ($all_project) {
$response['data']['warning'] = Project::where('budget_health', 'warning')
->where('company_id', $company_id) ->where('company_id', $company_id)
->count(); ->count();
} else { } else {
$response['data']['warning'] = Project::where('mulai_proyek', 'like', $year) $response['data']['warning'] = Project::where('budget_health', 'warning')
->where('budget_health', 'warning')
->where('created_by_id', $hierarchy) ->where('created_by_id', $hierarchy)
->count(); ->count();
} }
if ($all_project) { if ($role === 'Super Admin') {
$response['data']['on-budget'] = Project::where('mulai_proyek', 'like', $year) Log::info('on-budget');
->where('budget_health', 'on-budget') $response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->count();
} elseif ($all_project) {
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->where('company_id', $company_id) ->where('company_id', $company_id)
->count(); ->count();
} else { } else {
$response['data']['on-budget'] = Project::where('mulai_proyek', 'like', $year) $response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->where('budget_health', 'on-budget')
->where('created_by_id', $hierarchy) ->where('created_by_id', $hierarchy)
->count(); ->count();
} }
return response()->json($response, 200); return response()->json($response, 200);
} }
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health) private function countTotalProjectByBudgetHealthInDivision($divisi, $health)
{ {
return Project::where('divisi_id', $divisi) return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
->where('budget_health', $health) ->where('budget_health', $health)
->count(); ->count();
} }
public function getTotalProjectBudgetHealthPerDivision($year = '%', $company_id) public function getTotalProjectBudgetHealthPerDivision($role_name, $company_id)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
} else {
$divisions = Divisi::select('id', 'name') $divisions = Divisi::select('id', 'name')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->where('company_id', $company_id) ->where('company_id', $company_id)
->get(); ->get();
}
// to do : count in more than 1 level child // to do : count in more than 1 level child
foreach ($divisions as $division) { foreach ($divisions as $division) {
$budgetData = new Collection(); $budgetData = new Collection();
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'overrun'), 'overrun');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'warning'), 'warning');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'on-budget'), 'on-budget');
foreach ($division->children as $d) { foreach ($division->children as $d) {
$budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun'); $budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'overrun');
$budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning'); $budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'warning');
$budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget'); $budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'on-budget');
} }
unset($division->children); unset($division->children);
$division->budgetData = $budgetData; $division->budgetData = $budgetData;
@ -441,20 +481,28 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getTotalProjectPerPhase($year = '%', $company_id, $all_project, $hierarchy) public function getTotalProjectPerPhase($role_name, $company_id, $all_project, $hierarchy)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
$projectPhases = null;
if ($role === 'Super Admin') {
$projectPhases = ProjectPhase::orderBy('order')->get();
} else {
$projectPhases = ProjectPhase::where('company_id', $company_id)->orderBy('order')->get(); $projectPhases = ProjectPhase::where('company_id', $company_id)->orderBy('order')->get();
}
foreach ($projectPhases as $phase) { foreach ($projectPhases as $phase) {
if ($all_project) { if ($role === 'Super Admin') {
$phase->totalProject = Project::where('phase_id', $phase->id)
->count();
} elseif ($all_project) {
$phase->totalProject = Project::where('phase_id', $phase->id) $phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year)
->where('company_id', $company_id) ->where('company_id', $company_id)
->count(); ->count();
} else { } else {
$phase->totalProject = Project::where('phase_id', $phase->id) $phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy) ->where('created_by_id', $hierarchy)
->count(); ->count();
} }
@ -466,29 +514,37 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
private function countTotalProjectInDivision($id, $year) private function countTotalProjectInDivision($id)
{ {
return Project::where('divisi_id', $id) return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year)
->count(); ->count();
} }
public function getTotalProjectPerDivision($year = '%', $company_id) public function getTotalProjectPerDivision($role_name, $company_id)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children')
->whereNull('parent')
->get();
} else {
$divisions = Divisi::select('id', 'name', 'parent', 'color') $divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->where('company_id', $company_id) ->where('company_id', $company_id)
->get(); ->get();
}
// to do : count in more than 1 level child // to do : count in more than 1 level child
foreach ($divisions as $v) { foreach ($divisions as $v) {
$v->total = $this->countTotalProjectInDivision($v->id, $year); $v->total = $this->countTotalProjectInDivision($v->id);
foreach ($v->children as $d) { foreach ($v->children as $d) {
$v->total += $this->countTotalProjectInDivision($d->id, $year); $v->total += $this->countTotalProjectInDivision($d->id);
} }
unset($v->children); unset($v->children);
} }
@ -498,30 +554,35 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
private function countTotalProjectValueInDivision($id, $year) private function countTotalProjectValueInDivision($id)
{ {
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('divisi_id', $id) ->where('divisi_id', $id)
->pluck('sum') ->pluck('sum')
->first(); ->first();
} }
public function getTotalProjectValuePerDivision($year = '%', $company_id) public function getTotalProjectValuePerDivision($role_name, $company_id)
{ {
$year = $this->interpolateYear($year); $role = urldecode($role_name);
if ($role === 'Super Admin') {
$divisions = Divisi::select('id', 'name', 'color')
->with('children')
->whereNull('parent')
->get();
} else {
$divisions = Divisi::select('id', 'name', 'color') $divisions = Divisi::select('id', 'name', 'color')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->where('company_id', $company_id) ->where('company_id', $company_id)
->get(); ->get();
}
foreach ($divisions as $v) { foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id, $year); $v->total = $this->countTotalProjectValueInDivision($v->id);
foreach ($v->children as $d) { foreach ($v->children as $d) {
$v->total += $this->countTotalProjectValueInDivision($d->id, $year); $v->total += $this->countTotalProjectValueInDivision($d->id);
} }
unset($v->children); unset($v->children);
} }

28
routes/web.php

@ -23,20 +23,20 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->group(['middleware' => ['auth', 'cors']], function () use ($router) { $router->group(['middleware' => ['auth', 'cors']], function () use ($router) {
$router->get('/dashboard/get-company-cashflow/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure $router->get('/dashboard/get-company-cashflow/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure
$router->get('/dashboard/get-invoice-outstanding/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in $router->get('/dashboard/get-invoice-outstanding/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in
$router->get('/dashboard/get-total-project-per-schedule-health/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerScheduleHealth'); $router->get('/dashboard/get-total-project-per-schedule-health/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerScheduleHealth');
$router->get('/dashboard/get-total-project-per-budget-health/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerBudgetHealth'); $router->get('/dashboard/get-total-project-per-budget-health/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerBudgetHealth');
$router->get('/dashboard/get-total-project-schedule-health-per-division/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision'); $router->get('/dashboard/get-total-project-schedule-health-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision');
$router->get('/dashboard/get-total-project-budget-health-per-division/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision'); $router->get('/dashboard/get-total-project-budget-health-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision');
$router->get('/dashboard/get-total-project-per-phase/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerPhase'); $router->get('/dashboard/get-total-project-per-phase/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerPhase');
$router->get('/dashboard/get-total-project-per-division/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerDivision'); $router->get('/dashboard/get-total-project-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerDivision');
$router->get('/dashboard/get-total-project-value-per-division/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectValuePerDivision'); $router->get('/dashboard/get-total-project-value-per-division/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectValuePerDivision');
$router->get('/dashboard/get-detail-expenditure/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getDetailExpenditure'); $router->get('/dashboard/get-detail-expenditure/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getDetailExpenditure');
$router->get('/dashboard/get-detail-expenditure-color/{company_id}', 'DashboardBoDController@getDetailExpenditureColor'); $router->get('/dashboard/get-detail-expenditure-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailExpenditureColor');
$router->get('/dashboard/get-detail-financial-health-color/{company_id}', 'DashboardBoDController@getDetailFinancialHealthColor'); $router->get('/dashboard/get-detail-financial-health-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailFinancialHealthColor');
$router->get('/dashboard/get-detail-schedule-health-color/{company_id}', 'DashboardBoDController@getDetailScheduleHealthColor'); $router->get('/dashboard/get-detail-schedule-health-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailScheduleHealthColor');
$router->get('/dashboard/get-detail-invoice-color/{company_id}', 'DashboardBoDController@getDetailInvoiceColor'); $router->get('/dashboard/get-detail-invoice-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailInvoiceColor');
$router->post('/role/search', 'RoleController@search'); $router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add'); $router->post('/role/add', 'RoleController@add');

Loading…
Cancel
Save