@ -47,41 +47,46 @@ class DashboardBoDController extends Controller
{
{
if (empty($search))
if (empty($search))
return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
if (empty($search))
return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$token = config('api.adw_token');
$token = config('api.adw_token');
$response = $this->curlReq($url, $token);
$response = $this->curlReq($url, $token);
if (@$response->data->project_no == "")
if (@$response->data->project_no == "")
if (@$response->data->project_no == "")
return null;
return null;
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,20 +119,28 @@ 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();
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectExpenditure::get();
} else {
$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') {
$data['total_budget'] = $value['color'];
$data['total_budget'] = $value['color'];
}
}
if($value['name'] === 'Expenditure') {
if ($value['name'] === 'Expenditure') {
$data['total_expenditure'] = $value['color'];
$data['total_expenditure'] = $value['color'];
}
}
if ($value['name'] === 'Invoice') {
if ($value['name'] === 'Invoice') {
$data['total_invoice'] = $value['color'];
$data['total_invoice'] = $value['color'];
}
}
if ($value['name'] === 'Cash In') {
if ($value['name'] === 'Cash In') {
$data['total_paid_invoice'] = $value['color'];
$data['total_paid_invoice'] = $value['color'];
}
}
}
}
@ -141,17 +154,26 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailFinancialHealthColor($company_id) {
public function getDetailFinancialHealthColor($role_name, $company_id)
$query = ProjectFinancialHealth::where('company_id',$company_id)->get();
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectFinancialHealth::get();
} else {
$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') {
$data['overrun'] = $value['color'];
$data['overrun'] = $value['color'];
}
}
if($value['name'] === 'Early Warning') {
if ($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
$data['warning'] = $value['color'];
}
}
if($value['name'] === 'On Budget') {
if ($value['name'] === 'On Budget') {
$data['on-budget'] = $value['color'];
$data['on-budget'] = $value['color'];
}
}
}
}
@ -164,17 +186,25 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailScheduleHealthColor($company_id) {
public function getDetailScheduleHealthColor($role_name, $company_id)
$query = ProjectScheduleHealth::where('company_id',$company_id)->get();
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectScheduleHealth::get();
} else {
$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') {
$data['behind-schedule'] = $value['color'];
$data['behind-schedule'] = $value['color'];
}
}
if($value['name'] === 'Early Warning') {
if ($value['name'] === 'Early Warning') {
$data['warning'] = $value['color'];
$data['warning'] = $value['color'];
}
}
if ($value['name'] === 'On Schedule') {
if ($value['name'] === 'On Schedule') {
$data['on-schedule'] = $value['color'];
$data['on-schedule'] = $value['color'];
}
}
}
}
@ -187,14 +217,21 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailInvoiceColor($company_id) {
public function getDetailInvoiceColor($role_name, $company_id)
$query = ProjectInvoice::where('company_id',$company_id)->get();
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectInvoice::get();
} else {
$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') {
$data['invoiced'] = $value['color'];
$data['invoiced'] = $value['color'];
}
}
if($value['name'] === 'Cash In') {
if ($value['name'] === 'Cash In') {
$data['paid'] = $value['color'];
$data['paid'] = $value['color'];
}
}
}
}
@ -207,17 +244,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 +278,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 +289,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();
}
}
@ -276,7 +313,7 @@ class DashboardBoDController extends Controller
}
}
$selisihProgress = $planningProgress - $actualProgress;
$selisihProgress = $planningProgress - $actualProgress;
try {
try {
if ($selisihProgress > 0 & & $selisihProgress < = 5 ) {
if ($selisihProgress > 0 & & $selisihProgress < = 20 ) {
$return['warning'] += 1;
$return['warning'] += 1;
$projects[$index]->status = 'warning';
$projects[$index]->status = 'warning';
} elseif ($selisihProgress == 0) {
} elseif ($selisihProgress == 0) {
@ -294,20 +331,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 +383,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 +394,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 +485,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 +518,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 +558,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);
}
}