@ -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,24 +115,32 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailExpenditureColor($company_id) {
public function getDetailExpenditureColor($role_name, $company_id)
$query = ProjectExpenditure::where('company_id',$company_id)->get();
{
$data = [];
$role = urldecode($role_name);
foreach($query as $value) {
$query = null;
if($value['name'] === 'Total Budget') {
if ($role === 'Super Admin') {
$data['total_budget'] = $value['color'];
$query = ProjectExpenditure::get();
}
} else {
if($value['name'] === 'Expenditure') {
$query = ProjectExpenditure::where('company_id', $company_id)->get();
$data['total_expenditure'] = $value['color'];
}
}
if($value['name'] === 'Invoice') {
$data = [];
$data['total_invoice'] = $value['color'];
foreach ($query as $value) {
}
if ($value['name'] === 'Total Budget') {
if($value['name'] === 'Cash In') {
$data['total_budget'] = $value['color'];
$data['total_paid_invoice'] = $value['color'];
}
}
if ($value['name'] === 'Expenditure') {
}
$data['total_expenditure'] = $value['color'];
return response()->json([
}
if ($value['name'] === 'Invoice') {
$data['total_invoice'] = $value['color'];
}
if ($value['name'] === 'Cash In') {
$data['total_paid_invoice'] = $value['color'];
}
}
return response()->json([
'data' => [
'data' => [
'total_budget' => $data['total_budget'] ?? '',
'total_budget' => $data['total_budget'] ?? '',
'total_expenditure' => $data['total_expenditure'] ?? '',
'total_expenditure' => $data['total_expenditure'] ?? '',
@ -139,85 +148,109 @@ class DashboardBoDController extends Controller
'total_paid_invoice' => $data['total_paid_invoice'] ?? '',
'total_paid_invoice' => $data['total_paid_invoice'] ?? '',
]
]
], 200);
], 200);
}
}
public function getDetailFinancialHealthColor($company_id) {
public function getDetailFinancialHealthColor($role_name, $company_id)
$query = ProjectFinancialHealth::where('company_id',$company_id)->get();
{
$data = [];
$role = urldecode($role_name);
foreach($query as $value) {
$query = null;
if($value['name'] === 'Cost Overrun') {
if ($role === 'Super Admin') {
$data['overrun'] = $value['color'];
$query = ProjectFinancialHealth::get();
}
} else {
if($value['name'] === 'Early Warning') {
$query = ProjectFinancialHealth::where('company_id', $company_id)->get();
$data['warning'] = $value['color'];
}
}
if($value['name'] === 'On Budget') {
$data['on-budget'] = $value['color'];
$data = [];
}
foreach ($query as $value) {
}
if ($value['name'] === 'Cost Overrun') {
return response()->json([
$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' => [
'data' => [
'overrun' => $data['overrun'] ?? '',
'overrun' => $data['overrun'] ?? '',
'warning' => $data['warning'] ?? '',
'warning' => $data['warning'] ?? '',
'on-budget' => $data['on-budget'] ?? '',
'on-budget' => $data['on-budget'] ?? '',
]
]
], 200);
], 200);
}
}
public function getDetailScheduleHealthColor($company_id) {
public function getDetailScheduleHealthColor($role_name, $company_id)
$query = ProjectScheduleHealth::where('company_id',$company_id)->get();
{
$data = [];
$role = urldecode($role_name);
foreach($query as $value) {
$query = null;
if($value['name'] === 'Behind Schedule') {
if ($role === 'Super Admin') {
$data['behind-schedule'] = $value['color'];
$query = ProjectScheduleHealth::get();
}
} else {
if($value['name'] === 'Early Warning') {
$query = ProjectScheduleHealth::where('company_id', $company_id)->get();
$data['warning'] = $value['color'];
}
}
if($value['name'] === 'On Schedule') {
$data = [];
$data['on-schedule'] = $value['color'];
foreach ($query as $value) {
}
if ($value['name'] === 'Behind Schedule') {
}
$data['behind-schedule'] = $value['color'];
return response()->json([
}
if ($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
}
if ($value['name'] === 'On Schedule') {
$data['on-schedule'] = $value['color'];
}
}
return response()->json([
'data' => [
'data' => [
'behind-schedule' => $data['behind-schedule'] ?? '',
'behind-schedule' => $data['behind-schedule'] ?? '',
'warning' => $data['warning'] ?? '',
'warning' => $data['warning'] ?? '',
'on-schedule' => $data['on-schedule'] ?? '',
'on-schedule' => $data['on-schedule'] ?? '',
]
]
], 200);
], 200);
}
}
public function getDetailInvoiceColor($company_id) {
public function getDetailInvoiceColor($role_name, $company_id)
$query = ProjectInvoice::where('company_id',$company_id)->get();
{
$data = [];
$role = urldecode($role_name);
foreach($query as $value) {
$query = null;
if($value['name'] === 'Invoiced') {
if ($role === 'Super Admin') {
$data['invoiced'] = $value['color'];
$query = ProjectInvoice::get();
}
} else {
if($value['name'] === 'Cash In') {
$query = ProjectInvoice::where('company_id', $company_id)->get();
$data['paid'] = $value['color'];
}
}
$data = [];
}
foreach ($query as $value) {
return response()->json([
if ($value['name'] === 'Invoiced') {
$data['invoiced'] = $value['color'];
}
if ($value['name'] === 'Cash In') {
$data['paid'] = $value['color'];
}
}
return response()->json([
'data' => [
'data' => [
'invoiced' => $data['invoiced'] ?? '',
'invoiced' => $data['invoiced'] ?? '',
'paid' => $data['paid'] ?? ''
'paid' => $data['paid'] ?? ''
]
]
], 200);
], 200);
}
}
// 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 = Divisi::whereNull('parent')
$divisions = null;
->where('company_id', $company_id)
if ($role === 'Super Admin') {
->whereNull('parent')
$divisions = Divisi::whereNull('parent')
->get();
->get();
} else {
$divisions = Divisi::whereNull('parent')
->where('company_id', $company_id)
->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 = Divisi::select('id', 'name')
$divisions = null;
->with('children')
if ($role === 'Super Admin') {
->whereNull('parent')
$divisions = Divisi::select('id', 'name')
->where('company_id', $company_id)
->with('children')
->get();
->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
// 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 = ProjectPhase::where('company_id', $company_id)->orderBy('order')->get();
$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) {
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')
->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
// 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')
->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) {
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);
}
}