@ -28,29 +28,24 @@ class DashboardBoDController extends Controller
public function getCompanyCashFlow($company_id, $ all_project, $hierarchy, $role_name)
public function getCompanyCashFlow($all_project, $hierarchy, $role_name)
{
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
$totalBudgets = null;
$role = urldecode($role_name);
if ($role === "Super Admin") {
if (!empty($all_project) || $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('created_by_id', $hierarchy)
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
}
$totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
dd($totalBudgets);
$projects = null;
if ($role === "Super Admin") {
if (!empty($all_project) || $role === "Super Admin") {
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('created_by_id', $hierarchy)
->get();
@ -85,15 +80,11 @@ class DashboardBoDController extends Controller
], 200);
}
public function getDetailExpenditureColor($role_name, $company_id )
public function getDetailExpenditureColor($role_name)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectExpenditure::get();
} else {
$query = ProjectExpenditure::where('company_id', $company_id)->get();
}
$query = ProjectExpenditure::get();
$data = [];
foreach ($query as $value) {
@ -120,16 +111,11 @@ class DashboardBoDController extends Controller
], 200);
}
public function getDetailFinancialHealthColor($role_name, $company_id )
public function getDetailFinancialHealthColor($role_name)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectFinancialHealth::get();
} else {
$query = ProjectFinancialHealth::where('company_id', $company_id)->get();
}
$query = ProjectFinancialHealth::get();
$data = [];
foreach ($query as $value) {
@ -152,15 +138,11 @@ class DashboardBoDController extends Controller
], 200);
}
public function getDetailScheduleHealthColor($role_name, $company_id )
public function getDetailScheduleHealthColor($role_name)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectScheduleHealth::get();
} else {
$query = ProjectScheduleHealth::where('company_id', $company_id)->get();
}
$query = ProjectScheduleHealth::get();
$data = [];
foreach ($query as $value) {
@ -183,15 +165,11 @@ class DashboardBoDController extends Controller
], 200);
}
public function getDetailInvoiceColor($role_name, $company_id )
public function getDetailInvoiceColor($role_name)
{
$role = urldecode($role_name);
$query = null;
if ($role === 'Super Admin') {
$query = ProjectInvoice::get();
} else {
$query = ProjectInvoice::where('company_id', $company_id)->get();
}
$query = ProjectInvoice::get();
$data = [];
foreach ($query as $value) {
if ($value['name'] === 'Invoiced') {
@ -210,15 +188,12 @@ class DashboardBoDController extends Controller
}
// integrasi
public function getInvoiceOutstanding($role_name, $company_id, $all_project, $hierarchy)
public function getInvoiceOutstanding($role_name, $all_project, $hierarchy)
{
$role = urldecode($role_name);
$projects = null;
if ($role === 'Super Admin') {
if (!empty($all_project) || $role === 'Super Admin') {
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('created_by_id', $hierarchy)
->get();
@ -241,7 +216,7 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerScheduleHealth($role_name, $company_id, $ all_project, $hierarchy)
public function getTotalProjectPerScheduleHealth($role_name, $all_project, $hierarchy)
{
$role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
@ -253,11 +228,8 @@ class DashboardBoDController extends Controller
];
$projects = null;
if ($role === 'Super Admin') {
if ($all_project == 'true' || $ role === 'Super Admin') {
$projects = Project::get();
} elseif ($all_project == 'true') {
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::where('created_by_id', $replaceHierarchy)
->get();
@ -274,18 +246,11 @@ class DashboardBoDController extends Controller
}
public function getTotalProjectScheduleHealthPerDivision($role_name, $company_id )
public function getTotalProjectScheduleHealthPerDivision($role_name)
{
$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();
}
$divisions = Divisi::whereNull('parent')
->get();
foreach ($divisions as $index => $division) {
$behindSchedule = $warning = $onSchedule = 0;
@ -311,7 +276,7 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $divisions], 200);
}
public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy)
public function getTotalProjectPerBudgetHealth($role_name, $all_project, $hierarchy)
{
$role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
@ -324,7 +289,6 @@ class DashboardBoDController extends Controller
]
];
$divisi = Divisi::query()
->where('company_id', $company_id)
->pluck('id');
// arr overrun
@ -333,7 +297,7 @@ class DashboardBoDController extends Controller
->count();
} elseif ($all_project == 'true') {
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun'], ['company_id', $company_id] ])
->where([['budget_health', 'overrun']])
->count();
} else {
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
@ -346,7 +310,7 @@ class DashboardBoDController extends Controller
->count();
} elseif ($all_project == 'true') {
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning'], ['company_id', $company_id] ])
->where([['budget_health', 'warning']])
->count();
} else {
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
@ -359,7 +323,7 @@ class DashboardBoDController extends Controller
->count();
} elseif ($all_project == 'true') {
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
->where([['company_id', $company_id], [' budget_health', 'on-budget']])
->where([['budget_health', 'on-budget']])
->count();
} else {
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
@ -376,7 +340,7 @@ class DashboardBoDController extends Controller
}
public function getTotalProjectBudgetHealthPerDivision($role_name, $company_id )
public function getTotalProjectBudgetHealthPerDivision($role_name)
{
$role = urldecode($role_name);
$divisions = null;
@ -389,7 +353,6 @@ class DashboardBoDController extends Controller
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->where('company_id', $company_id)
->get();
}
@ -414,26 +377,17 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerPhase($role_name, $company_id, $ all_project, $hierarchy)
public function getTotalProjectPerPhase($role_name, $all_project, $hierarchy)
{
$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::orderBy('order')->get();
foreach ($projectPhases as $phase) {
if ($role === 'Super Admin') {
if ($role === 'Super Admin' || $all_project) {
$phase->totalProject = Project::where('phase_id', $phase->id)
->count();
} elseif ($all_project) {
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('company_id', $company_id)
->count();
} else {
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('created_by_id', $hierarchy)
@ -453,25 +407,14 @@ class DashboardBoDController extends Controller
->count();
}
public function getTotalProjectPerDivision($role_name, $company_id )
public function getTotalProjectPerDivision($role_name)
{
$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')
->get();
// to do : count in more than 1 level child
foreach ($divisions as $v) {
@ -495,22 +438,13 @@ class DashboardBoDController extends Controller
->first();
}
public function getTotalProjectValuePerDivision($role_name, $company_id )
public function getTotalProjectValuePerDivision($role_name)
{
$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')
->get();
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id);
@ -526,13 +460,12 @@ class DashboardBoDController extends Controller
}
public function getDetailExpenditure($year = '%', $company_id, $ all_project, $hierarchy)
public function getDetailExpenditure($year = '%', $all_project, $hierarchy)
{
$year = $this->interpolateYear($year);
$projects = null;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
->orderBy('id', 'desc')
->get();
} else {
@ -562,7 +495,7 @@ class DashboardBoDController extends Controller
return response()->json([
'data' => $projects,
'total_manpowers' => User::where('company_id', $company_id)-> count()
'total_manpowers' => User::count()
], 200);
}
}