|
|
|
@ -54,48 +54,6 @@ class DashboardBoDController extends Controller
|
|
|
|
|
return $response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// OLD |
|
|
|
|
// public function getCompanyCashFlow($year = '%') |
|
|
|
|
// { |
|
|
|
|
// $year = $this->interpolateYear($year); |
|
|
|
|
// $totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) |
|
|
|
|
// ->where('mulai_proyek', 'like', $year) |
|
|
|
|
// /* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
// ->pluck('sum') |
|
|
|
|
// ->first(); |
|
|
|
|
|
|
|
|
|
// $projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
// /* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
// ->get(); |
|
|
|
|
// foreach ($projects as $project) { |
|
|
|
|
// $project->expenses = 0; |
|
|
|
|
|
|
|
|
|
// $resp = null; |
|
|
|
|
// if ($project->kode_sortname != "") { |
|
|
|
|
// $resp = $this->getInvoiceIntegration($project->kode_sortname); |
|
|
|
|
// /* $resp = $project->kode_sortname; */ |
|
|
|
|
// $cost = $resp->data->total_cost ?? 0; |
|
|
|
|
// $cost = substr($cost, 0, strpos($cost, ".")); |
|
|
|
|
// $totalExpenditure += (int) $cost; |
|
|
|
|
// $totalInvoice += $resp->data->total_invoice_amount ?? 0; |
|
|
|
|
// $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// return response()->json([ |
|
|
|
|
// 'data' => [ |
|
|
|
|
// 'total_budget' => (int) $totalBudgets ?? 0, |
|
|
|
|
// 'total_expenditure' => $totalExpenditure, |
|
|
|
|
// 'total_invoice' => $totalInvoice, |
|
|
|
|
// 'total_paid_invoice' => $totalPaidInvoice, |
|
|
|
|
// ] |
|
|
|
|
// ], 200); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
public function getCompanyCashFlow($year = '%', $company_id, $all_project, $hierarchy) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
@ -128,9 +86,9 @@ class DashboardBoDController extends Controller
|
|
|
|
|
$resp = null; |
|
|
|
|
if ($project->kode_sortname != "") { |
|
|
|
|
|
|
|
|
|
$resp = $this->getInvoiceIntegration($project->kode_sortname); |
|
|
|
|
$cost = $resp->data->total_cost ?? 0; |
|
|
|
|
$cost = substr($cost, 0, strpos($cost, ".")); |
|
|
|
|
// $resp = $this->getInvoiceIntegration($project->kode_sortname); |
|
|
|
|
// $cost = $resp->data->total_cost ?? 0; |
|
|
|
|
// $cost = substr($cost, 0, strpos($cost, ".")); |
|
|
|
|
$cost = 0; |
|
|
|
|
$totalExpenditure = 0; |
|
|
|
|
$totalInvoice = 0; |
|
|
|
@ -152,7 +110,7 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// integrasi |
|
|
|
|
public function getInvoiceOutstanding($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
@ -232,9 +190,13 @@ class DashboardBoDController extends Controller
|
|
|
|
|
return response()->json(['data' => $return, 'q' => $projects], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectScheduleHealthPerDivision($year = '%') |
|
|
|
|
public function getTotalProjectScheduleHealthPerDivision($year = '%', $company_id) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$divisions = Divisi::whereNull('parent') |
|
|
|
|
->where('company_id', $company_id) |
|
|
|
|
->get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$divisions = Divisi::whereNull('parent')->get(); |
|
|
|
|
foreach ($divisions as $index => $division) { |
|
|
|
@ -277,16 +239,62 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectPerBudgetHealth($year = '%') |
|
|
|
|
public function getTotalProjectPerBudgetHealth($year = '%', $company_id, $all_project, $hierarchy) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
return response()->json([ |
|
|
|
|
$response = [ |
|
|
|
|
'data' => [ |
|
|
|
|
'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(), |
|
|
|
|
'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(), |
|
|
|
|
'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(), |
|
|
|
|
'overrun' => 0, |
|
|
|
|
'warning' => 0, |
|
|
|
|
'on-budget' => 0, |
|
|
|
|
] |
|
|
|
|
], 200); |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
->count(); |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
->count(); |
|
|
|
|
} |
|
|
|
|
if ($all_project) { |
|
|
|
|
$response['data']['warning'] = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->where('budget_health', 'warning') |
|
|
|
|
->where('company_id', $company_id) |
|
|
|
|
->count(); |
|
|
|
|
} else { |
|
|
|
|
$response['data']['warning'] = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->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') |
|
|
|
|
->where('company_id', $company_id) |
|
|
|
|
->count(); |
|
|
|
|
} else { |
|
|
|
|
$response['data']['on-budget'] = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->where('budget_health', 'on-budget') |
|
|
|
|
->where('created_by_id', $hierarchy) |
|
|
|
|
->count(); |
|
|
|
|
} |
|
|
|
|
return response()->json($response, 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health) |
|
|
|
@ -299,12 +307,13 @@ class DashboardBoDController extends Controller
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTotalProjectBudgetHealthPerDivision($year = '%') |
|
|
|
|
public function getTotalProjectBudgetHealthPerDivision($year = '%', $company_id) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$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) { |
|
|
|
@ -332,7 +341,7 @@ class DashboardBoDController extends Controller
|
|
|
|
|
public function getTotalProjectPerPhase($year = '%', $company_id, $all_project, $hierarchy) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$projectPhases = ProjectPhase::orderBy('order')->get(); |
|
|
|
|
$projectPhases = ProjectPhase::where('company_id', $company_id)->orderBy('order')->get(); |
|
|
|
|
foreach ($projectPhases as $phase) { |
|
|
|
|
|
|
|
|
|
if ($all_project) { |
|
|
|
@ -361,15 +370,17 @@ class DashboardBoDController extends Controller
|
|
|
|
|
->count(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectPerDivision($year = '%') |
|
|
|
|
public function getTotalProjectPerDivision($year = '%', $company_id) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
|
|
|
|
|
$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); |
|
|
|
@ -394,16 +405,16 @@ class DashboardBoDController extends Controller
|
|
|
|
|
->first(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectValuePerDivision($year = '%') |
|
|
|
|
public function getTotalProjectValuePerDivision($year = '%', $company_id) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
|
|
|
|
|
$divisions = Divisi::select('id', 'name', 'color') |
|
|
|
|
$divisions = Divisi::select('id', 'name', '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->countTotalProjectValueInDivision($v->id, $year); |
|
|
|
|
foreach ($v->children as $d) { |
|
|
|
@ -418,21 +429,29 @@ class DashboardBoDController extends Controller
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getDetailExpenditure($year = '%') |
|
|
|
|
public function getDetailExpenditure($year = '%', $company_id, $all_project, $hierarchy) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
->orderBy('id', 'desc') |
|
|
|
|
->get(); |
|
|
|
|
$projects = null; |
|
|
|
|
if ($all_project) { |
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->where('company_id', $company_id) |
|
|
|
|
->orderBy('id', 'desc') |
|
|
|
|
->get(); |
|
|
|
|
} else { |
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->where('created_by_id', $hierarchy) |
|
|
|
|
->orderBy('id', 'desc') |
|
|
|
|
->get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($projects as $project) { |
|
|
|
|
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id); |
|
|
|
|
|
|
|
|
|
if ($project->kode_sortname != "") { |
|
|
|
|
$resp = $this->getInvoiceIntegration($project->kode_sortname); |
|
|
|
|
$project->invoice = [ |
|
|
|
|
'invoiced' => $resp->data->total_invoice_amount ?? 0, |
|
|
|
|
'paid' => $resp->data->total_invoice_paid_amount ?? 0, |
|
|
|
|
'invoiced' => 0, |
|
|
|
|
'paid' => 0, |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|