Browse Source

update filter dashboard

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

405
app/Http/Controllers/DashboardBoDController.php

@ -58,30 +58,31 @@ class DashboardBoDController extends Controller
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;
$totalBudgets = null;
if ($all_project) {
$totalBudgets = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
$role = urldecode($role_name);
if ($role === "Super Admin") {
$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)'));
} else {
$totalBudgets = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
$totalBudgets = Project::where('created_by_id', $hierarchy)
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
}
$projects = null;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
if ($role === "Super Admin") {
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
$projects = Project::where('created_by_id', $hierarchy)
->get();
}
@ -114,24 +115,32 @@ class DashboardBoDController extends Controller
], 200);
}
public function getDetailExpenditureColor($company_id) {
$query = ProjectExpenditure::where('company_id',$company_id)->get();
$data = [];
foreach($query as $value) {
if($value['name'] === 'Total Budget') {
$data['total_budget'] = $value['color'];
}
if($value['name'] === 'Expenditure') {
$data['total_expenditure'] = $value['color'];
}
if($value['name'] === 'Invoice') {
$data['total_invoice'] = $value['color'];
}
if($value['name'] === 'Cash In') {
$data['total_paid_invoice'] = $value['color'];
}
}
return response()->json([
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();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Total Budget') {
$data['total_budget'] = $value['color'];
}
if ($value['name'] === 'Expenditure') {
$data['total_expenditure'] = $value['color'];
}
if ($value['name'] === 'Invoice') {
$data['total_invoice'] = $value['color'];
}
if ($value['name'] === 'Cash In') {
$data['total_paid_invoice'] = $value['color'];
}
}
return response()->json([
'data' => [
'total_budget' => $data['total_budget'] ?? '',
'total_expenditure' => $data['total_expenditure'] ?? '',
@ -139,85 +148,109 @@ class DashboardBoDController extends Controller
'total_paid_invoice' => $data['total_paid_invoice'] ?? '',
]
], 200);
}
public function getDetailFinancialHealthColor($company_id) {
$query = ProjectFinancialHealth::where('company_id',$company_id)->get();
$data = [];
foreach($query as $value) {
if($value['name'] === 'Cost Overrun') {
$data['overrun'] = $value['color'];
}
if($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
}
if($value['name'] === 'On Budget') {
$data['on-budget'] = $value['color'];
}
}
return response()->json([
}
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();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Cost Overrun') {
$data['overrun'] = $value['color'];
}
if ($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
}
if ($value['name'] === 'On Budget') {
$data['on-budget'] = $value['color'];
}
}
return response()->json([
'data' => [
'overrun' => $data['overrun'] ?? '',
'warning' => $data['warning'] ?? '',
'on-budget' => $data['on-budget'] ?? '',
]
], 200);
}
public function getDetailScheduleHealthColor($company_id) {
$query = ProjectScheduleHealth::where('company_id',$company_id)->get();
$data = [];
foreach($query as $value) {
if($value['name'] === 'Behind Schedule') {
$data['behind-schedule'] = $value['color'];
}
if($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
}
if($value['name'] === 'On Schedule') {
$data['on-schedule'] = $value['color'];
}
}
return response()->json([
}
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();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Behind Schedule') {
$data['behind-schedule'] = $value['color'];
}
if ($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
}
if ($value['name'] === 'On Schedule') {
$data['on-schedule'] = $value['color'];
}
}
return response()->json([
'data' => [
'behind-schedule' => $data['behind-schedule'] ?? '',
'warning' => $data['warning'] ?? '',
'on-schedule' => $data['on-schedule'] ?? '',
]
], 200);
}
public function getDetailInvoiceColor($company_id) {
$query = ProjectInvoice::where('company_id',$company_id)->get();
$data = [];
foreach($query as $value) {
if($value['name'] === 'Invoiced') {
$data['invoiced'] = $value['color'];
}
if($value['name'] === 'Cash In') {
$data['paid'] = $value['color'];
}
}
return response()->json([
}
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();
}
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Invoiced') {
$data['invoiced'] = $value['color'];
}
if ($value['name'] === 'Cash In') {
$data['paid'] = $value['color'];
}
}
return response()->json([
'data' => [
'invoiced' => $data['invoiced'] ?? '',
'paid' => $data['paid'] ?? ''
]
], 200);
}
}
// 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;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
if ($role === 'Super Admin') {
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
$projects = Project::where('created_by_id', $hierarchy)
->get();
}
@ -241,9 +274,9 @@ class DashboardBoDController extends Controller
], 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 = [
'behind-schedule' => 0,
@ -252,13 +285,13 @@ class DashboardBoDController extends Controller
];
$projects = null;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
if ($role === 'Super Admin') {
$projects = Project::get();
} elseif ($all_project) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
$projects = Project::where('created_by_id', $hierarchy)
->get();
}
@ -294,20 +327,24 @@ class DashboardBoDController extends Controller
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);
$divisions = Divisi::whereNull('parent')
->where('company_id', $company_id)
->whereNull('parent')
->get();
$role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::whereNull('parent')
->get();
} else {
$divisions = Divisi::whereNull('parent')
->where('company_id', $company_id)
->get();
}
foreach ($divisions as $index => $division) {
$scheduleData = new Collection();
$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) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
@ -342,9 +379,9 @@ class DashboardBoDController extends Controller
], 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 = [
'data' => [
'overrun' => 0,
@ -353,81 +390,84 @@ class DashboardBoDController extends Controller
]
];
if ($all_project) {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'overrun')
->where('company_id', $company_id)
if ($role === 'Super Admin') {
$response['data']['overrun'] = Project::where('budget_health', 'overrun')
->count();
} else {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year)
->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')
} elseif ($all_project) {
$response['data']['overrun'] = Project::where('budget_health', 'overrun')
->where('company_id', $company_id)
->count();
} else {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'overrun')
$response['data']['overrun'] = Project::where('budget_health', 'overrun')
->where('created_by_id', $hierarchy)
->count();
}
if ($all_project) {
$response['data']['warning'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'warning')
if ($role === 'Super Admin') {
$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)
->count();
} else {
$response['data']['warning'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'warning')
$response['data']['warning'] = Project::where('budget_health', 'warning')
->where('created_by_id', $hierarchy)
->count();
}
if ($all_project) {
$response['data']['on-budget'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'on-budget')
if ($role === 'Super Admin') {
Log::info('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)
->count();
} else {
$response['data']['on-budget'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'on-budget')
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->where('created_by_id', $hierarchy)
->count();
}
return response()->json($response, 200);
}
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health)
private function countTotalProjectByBudgetHealthInDivision($divisi, $health)
{
return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('budget_health', $health)
->count();
}
public function getTotalProjectBudgetHealthPerDivision($year = '%', $company_id)
public function getTotalProjectBudgetHealthPerDivision($role_name, $company_id)
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
$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')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->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');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'overrun'), 'overrun');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'warning'), 'warning');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, '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');
$budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'overrun');
$budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'warning');
$budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'on-budget');
}
unset($division->children);
$division->budgetData = $budgetData;
@ -441,20 +481,28 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerPhase($year = '%', $company_id, $all_project, $hierarchy)
public function getTotalProjectPerPhase($role_name, $company_id, $all_project, $hierarchy)
{
$year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::where('company_id', $company_id)->orderBy('order')->get();
$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();
}
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)
->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();
}
@ -466,29 +514,37 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectInDivision($id, $year)
private function countTotalProjectInDivision($id)
{
return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year)
->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')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
}
$divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
// to do : count in more than 1 level child
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectInDivision($v->id, $year);
$v->total = $this->countTotalProjectInDivision($v->id);
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectInDivision($d->id, $year);
$v->total += $this->countTotalProjectInDivision($d->id);
}
unset($v->children);
}
@ -498,30 +554,35 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectValueInDivision($id, $year)
private function countTotalProjectValueInDivision($id)
{
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)
->pluck('sum')
->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')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
}
$divisions = Divisi::select('id', 'name', 'color')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
$v->total = $this->countTotalProjectValueInDivision($v->id);
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectValueInDivision($d->id, $year);
$v->total += $this->countTotalProjectValueInDivision($d->id);
}
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->get('/dashboard/get-company-cashflow/{year}/{company_id}/{all_project}/{hierarchy}', '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-total-project-per-schedule-health/{year}/{company_id}/{all_project}/{hierarchy}', '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-schedule-health-per-division/{year}/{company_id}/{all_project}/{hierarchy}', '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-per-phase/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerPhase');
$router->get('/dashboard/get-total-project-per-division/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectPerDivision');
$router->get('/dashboard/get-total-project-value-per-division/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getTotalProjectValuePerDivision');
$router->get('/dashboard/get-detail-expenditure/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getDetailExpenditure');
$router->get('/dashboard/get-detail-expenditure-color/{company_id}', 'DashboardBoDController@getDetailExpenditureColor');
$router->get('/dashboard/get-detail-financial-health-color/{company_id}', 'DashboardBoDController@getDetailFinancialHealthColor');
$router->get('/dashboard/get-detail-schedule-health-color/{company_id}', 'DashboardBoDController@getDetailScheduleHealthColor');
$router->get('/dashboard/get-detail-invoice-color/{company_id}', 'DashboardBoDController@getDetailInvoiceColor');
$router->get('/dashboard/get-company-cashflow/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure
$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/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerScheduleHealth');
$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/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision');
$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/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectPerPhase');
$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/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getTotalProjectValuePerDivision');
$router->get('/dashboard/get-detail-expenditure/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getDetailExpenditure');
$router->get('/dashboard/get-detail-expenditure-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailExpenditureColor');
$router->get('/dashboard/get-detail-financial-health-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailFinancialHealthColor');
$router->get('/dashboard/get-detail-schedule-health-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailScheduleHealthColor');
$router->get('/dashboard/get-detail-invoice-color/{company_id}/{role_name}', 'DashboardBoDController@getDetailInvoiceColor');
$router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add');

Loading…
Cancel
Save