@ -28,23 +28,29 @@ class DashboardBoDController extends Controller
public function getCompanyCashFlow($all_project, $hierarchy, $role_name)
public function getCompanyCashFlow($company_id, $ all_project, $hierarchy, $role_name)
{
{
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
$totalBudgets = null;
$totalBudgets = null;
$role = urldecode($role_name);
$role = urldecode($role_name);
if (!empty($all_project) || $role === "Super Admin") {
if ($role === "Super Admin") {
$totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
$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 {
} else {
$totalBudgets = Project::where('created_by_id', $hierarchy)
$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)'));
$projects = null;
$projects = null;
if (!empty($all_project) || $role === "Super Admin") {
if ($role === "Super Admin") {
$projects = Project::get();
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
} else {
$projects = Project::where('created_by_id', $hierarchy)
$projects = Project::where('created_by_id', $hierarchy)
->get();
->get();
@ -79,11 +85,15 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailExpenditureColor($role_name)
public function getDetailExpenditureColor($role_name, $company_id )
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$query = null;
$query = null;
if ($role === 'Super Admin') {
$query = ProjectExpenditure::get();
$query = ProjectExpenditure::get();
} else {
$query = ProjectExpenditure::where('company_id', $company_id)->get();
}
$data = [];
$data = [];
foreach ($query as $value) {
foreach ($query as $value) {
@ -110,11 +120,16 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailFinancialHealthColor($role_name)
public function getDetailFinancialHealthColor($role_name, $company_id )
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$query = null;
$query = null;
if ($role === 'Super Admin') {
$query = ProjectFinancialHealth::get();
$query = ProjectFinancialHealth::get();
} else {
$query = ProjectFinancialHealth::where('company_id', $company_id)->get();
}
$data = [];
$data = [];
foreach ($query as $value) {
foreach ($query as $value) {
@ -137,11 +152,15 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailScheduleHealthColor($role_name)
public function getDetailScheduleHealthColor($role_name, $company_id )
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$query = null;
$query = null;
if ($role === 'Super Admin') {
$query = ProjectScheduleHealth::get();
$query = ProjectScheduleHealth::get();
} else {
$query = ProjectScheduleHealth::where('company_id', $company_id)->get();
}
$data = [];
$data = [];
foreach ($query as $value) {
foreach ($query as $value) {
@ -164,11 +183,15 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getDetailInvoiceColor($role_name)
public function getDetailInvoiceColor($role_name, $company_id )
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$query = null;
$query = null;
if ($role === 'Super Admin') {
$query = ProjectInvoice::get();
$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') {
@ -187,12 +210,15 @@ class DashboardBoDController extends Controller
}
}
// integrasi
// integrasi
public function getInvoiceOutstanding($role_name, $all_project, $hierarchy)
public function getInvoiceOutstanding($role_name, $company_id, $all_project, $hierarchy)
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$projects = null;
$projects = null;
if (!empty($all_project) || $role === 'Super Admin') {
if ($role === 'Super Admin') {
$projects = Project::get();
$projects = Project::get();
} elseif (!empty($all_project)) {
$projects = Project::where('company_id', $company_id)
->get();
} else {
} else {
$projects = Project::where('created_by_id', $hierarchy)
$projects = Project::where('created_by_id', $hierarchy)
->get();
->get();
@ -215,7 +241,7 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getTotalProjectPerScheduleHealth($role_name, $all_project, $hierarchy)
public function getTotalProjectPerScheduleHealth($role_name, $company_id, $ all_project, $hierarchy)
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
@ -227,8 +253,11 @@ class DashboardBoDController extends Controller
];
];
$projects = null;
$projects = null;
if ($all_project == 'true' || $ role === 'Super Admin') {
if ($role === 'Super Admin') {
$projects = Project::get();
$projects = Project::get();
} elseif ($all_project == 'true') {
$projects = Project::where('company_id', $company_id)
->get();
} else {
} else {
$projects = Project::where('created_by_id', $replaceHierarchy)
$projects = Project::where('created_by_id', $replaceHierarchy)
->get();
->get();
@ -245,11 +274,18 @@ class DashboardBoDController extends Controller
}
}
public function getTotalProjectScheduleHealthPerDivision($role_name)
public function getTotalProjectScheduleHealthPerDivision($role_name, $company_id )
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::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) {
$behindSchedule = $warning = $onSchedule = 0;
$behindSchedule = $warning = $onSchedule = 0;
@ -275,7 +311,7 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $divisions], 200);
return response()->json(['data' => $divisions], 200);
}
}
public function getTotalProjectPerBudgetHealth($role_name, $all_project, $hierarchy)
public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy)
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
@ -288,6 +324,7 @@ class DashboardBoDController extends Controller
]
]
];
];
$divisi = Divisi::query()
$divisi = Divisi::query()
->where('company_id', $company_id)
->pluck('id');
->pluck('id');
// arr overrun
// arr overrun
@ -296,7 +333,7 @@ class DashboardBoDController extends Controller
->count();
->count();
} elseif ($all_project == 'true') {
} elseif ($all_project == 'true') {
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun']])
->where([['budget_health', 'overrun'], ['company_id', $company_id] ])
->count();
->count();
} else {
} else {
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
@ -309,7 +346,7 @@ class DashboardBoDController extends Controller
->count();
->count();
} elseif ($all_project == 'true') {
} elseif ($all_project == 'true') {
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning']])
->where([['budget_health', 'warning'], ['company_id', $company_id] ])
->count();
->count();
} else {
} else {
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
@ -322,7 +359,7 @@ class DashboardBoDController extends Controller
->count();
->count();
} elseif ($all_project == 'true') {
} elseif ($all_project == 'true') {
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'on-budget']])
->where([['company_id', $company_id], [' budget_health', 'on-budget']])
->count();
->count();
} else {
} else {
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
@ -339,7 +376,7 @@ class DashboardBoDController extends Controller
}
}
public function getTotalProjectBudgetHealthPerDivision($role_name)
public function getTotalProjectBudgetHealthPerDivision($role_name, $company_id )
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$divisions = null;
$divisions = null;
@ -352,6 +389,7 @@ class DashboardBoDController extends Controller
$divisions = Divisi::select('id', 'name')
$divisions = Divisi::select('id', 'name')
->with('children')
->with('children')
->whereNull('parent')
->whereNull('parent')
->where('company_id', $company_id)
->get();
->get();
}
}
@ -376,15 +414,25 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getTotalProjectPerPhase($role_name, $all_project, $hierarchy)
public function getTotalProjectPerPhase($role_name, $company_id, $ all_project, $hierarchy)
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$projectPhases = null;
if ($role === 'Super Admin') {
$projectPhases = ProjectPhase::orderBy('order')->get();
$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 ($role === 'Super Admin' || $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('company_id', $company_id)
->count();
->count();
} else {
} else {
$phase->totalProject = Project::where('phase_id', $phase->id)
$phase->totalProject = Project::where('phase_id', $phase->id)
@ -405,14 +453,25 @@ class DashboardBoDController extends Controller
->count();
->count();
}
}
public function getTotalProjectPerDivision($role_name)
public function getTotalProjectPerDivision($role_name, $company_id )
{
{
$role = urldecode($role_name);
$role = urldecode($role_name);
$divisions = null;
$divisions = null;
if ($role === 'Super Admin') {
$divisions = Divisi::select('id', 'name', 'parent', 'color')
$divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children')
->with('children')
->whereNull('parent')
->whereNull('parent')
->get();
->get();
} else {
$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) {
@ -436,13 +495,22 @@ class DashboardBoDController extends Controller
->first();
->first();
}
}
public function getTotalProjectValuePerDivision($role_name)
public function getTotalProjectValuePerDivision($role_name, $company_id )
{
{
$role = urldecode($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')
$divisions = Divisi::select('id', 'name', 'color')
->with('children')
->with('children')
->whereNull('parent')
->whereNull('parent')
->where('company_id', $company_id)
->get();
->get();
}
foreach ($divisions as $v) {
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id);
$v->total = $this->countTotalProjectValueInDivision($v->id);
@ -458,15 +526,18 @@ class DashboardBoDController extends Controller
}
}
public function getDetailExpenditure($all_project, $hierarchy, $role_name )
public function getDetailExpenditure($year = '%', $company_id, $ all_project, $hierarchy)
{
{
// $year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$projects = null;
$projects = null;
if ($all_project) {
if ($all_project) {
$projects = Project::orderBy('id', 'desc')
$projects = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
->orderBy('id', 'desc')
->get();
->get();
} else {
} else {
$projects = Project::where('created_by_id', $hierarchy)
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
->orderBy('id', 'desc')
->orderBy('id', 'desc')
->get();
->get();
}
}
@ -491,7 +562,7 @@ class DashboardBoDController extends Controller
return response()->json([
return response()->json([
'data' => $projects,
'data' => $projects,
'total_manpowers' => User::count()
'total_manpowers' => User::where('company_id', $company_id)-> count()
], 200);
], 200);
}
}
}
}