@ -47,41 +47,46 @@ class DashboardBoDController extends Controller
{
if (empty($search))
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');
$token = config('api.adw_token');
$response = $this->curlReq($url, $token);
if (@$response->data->project_no == "")
return null;
if (@$response->data->project_no == "")
return null;
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 +119,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 +152,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 +278,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 +289,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();
}
@ -276,7 +313,7 @@ class DashboardBoDController extends Controller
}
$selisihProgress = $planningProgress - $actualProgress;
try {
if ($selisihProgress > 0 & & $selisihProgress < = 5 ) {
if ($selisihProgress > 0 & & $selisihProgress < = 20 ) {
$return['warning'] += 1;
$projects[$index]->status = 'warning';
} elseif ($selisihProgress == 0) {
@ -294,20 +331,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 +383,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 +394,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)
->count();
} else {
$response['data']['overrun'] = Project::where('mulai_proyek', 'like', $year)
->where('budget_health', 'overrun')
->where('created_by_id', $hierarchy)
if ($role === 'Super Admin') {
$response['data']['overrun'] = Project::where('budget_health', 'overrun')
->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 +485,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 +518,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 +558,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);
}