@ -41,49 +41,63 @@ class DashboardBoDController extends Controller
private function getInvoiceIntegration($search)
private function getInvoiceIntegration($search)
{
{
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);
$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 == "")
return null;
return null;
return $response;
return $response;
}
}
// to do
public function getCompanyCashFlow($year = '%', $company_id, $all_project, $hierarchy)
public function getCompanyCashFlow($year = '%')
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
$totalBudgets = null;
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
if ($all_project) {
->where('mulai_proyek', 'like', $year)
$totalBudgets = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('company_id', $company_id)
->pluck('sum')
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
->first();
} else {
$totalBudgets = Project::where('mulai_proyek', 'like', $year)
->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)
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('company_id', $company_id)
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
->get();
->get();
}
foreach ($projects as $project) {
foreach ($projects as $project) {
$project->expenses = 0;
$project->expenses = 0;
$resp = null;
$resp = null;
if ($project->kode_sortname != "") {
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;
}
// $resp = $this->getInvoiceIntegration($project->kode_sortname);
// $cost = $resp->data->total_cost ?? 0;
// $cost = substr($cost, 0, strpos($cost, "."));
$cost = 0;
$totalExpenditure = 0;
$totalInvoice = 0;
$totalPaidInvoice = 0;
// $totalExpenditure += (int) $cost;
// $totalInvoice += $resp->data->total_invoice_amount ?? 0;
// $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0;
}
}
}
return response()->json([
return response()->json([
@ -96,6 +110,7 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
// integrasi
public function getInvoiceOutstanding($year = '%')
public function getInvoiceOutstanding($year = '%')
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
@ -122,7 +137,7 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getTotalProjectPerScheduleHealth($year = '%')
public function getTotalProjectPerScheduleHealth($year = '%', $company_id, $all_project, $hierarchy )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
@ -132,7 +147,17 @@ class DashboardBoDController extends Controller
'on-schedule' => 0,
'on-schedule' => 0,
];
];
$projects = Project::where('mulai_proyek', 'like', $year)->get();
$projects = null;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('company_id', $company_id)
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
->get();
}
foreach ($projects as $index => $project) {
foreach ($projects as $index => $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
$selisihProgress = 0;
@ -147,15 +172,13 @@ class DashboardBoDController extends Controller
}
}
$selisihProgress = $planningProgress - $actualProgress;
$selisihProgress = $planningProgress - $actualProgress;
try {
try {
if ($selisihProgress > 0 & & $selisihProgress < = 5){
if ($selisihProgress > 0 & & $selisihProgress < = 5) {
$return['warning'] += 1;
$return['warning'] += 1;
$projects[$index]->status = 'warning';
$projects[$index]->status = 'warning';
}
} elseif ($selisihProgress == 0) {
elseif ($selisihProgress == 0){
$return['on-schedule'] += 1;
$return['on-schedule'] += 1;
$projects[$index]->status = 'on-schedule';
$projects[$index]->status = 'on-schedule';
}
} else {
else {
$return['behind-schedule'] += 1;
$return['behind-schedule'] += 1;
$projects[$index]->status = 'behind-schedule';
$projects[$index]->status = 'behind-schedule';
}
}
@ -167,9 +190,13 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $return, 'q' => $projects], 200);
return response()->json(['data' => $return, 'q' => $projects], 200);
}
}
public function getTotalProjectScheduleHealthPerDivision($year = '%')
public function getTotalProjectScheduleHealthPerDivision($year = '%', $company_id )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')
->where('company_id', $company_id)
->get();
$divisions = Divisi::whereNull('parent')->get();
$divisions = Divisi::whereNull('parent')->get();
foreach ($divisions as $index => $division) {
foreach ($divisions as $index => $division) {
@ -191,13 +218,11 @@ class DashboardBoDController extends Controller
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
}
$selisihProgress = $planningProgress - $actualProgress;
$selisihProgress = $planningProgress - $actualProgress;
if ($selisihProgress > 0 & & $selisihProgress < = 5){
if ($selisihProgress > 0 & & $selisihProgress < = 5) {
$warning++;
$warning++;
}
} elseif ($selisihProgress == 0) {
elseif ($selisihProgress == 0){
$onSchedule++;
$onSchedule++;
}
} else {
else {
$behindSchedule++;
$behindSchedule++;
}
}
}
}
@ -214,16 +239,62 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getTotalProjectPerBudgetHealth($year = '%')
public function getTotalProjectPerBudgetHealth($year = '%', $company_id, $all_project, $hierarchy )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
return response()->json( [
$response = [
'data' => [
'data' => [
'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count() ,
'overrun' => 0 ,
'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count() ,
'warning' => 0 ,
'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count() ,
'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)
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health)
@ -236,12 +307,13 @@ class DashboardBoDController extends Controller
}
}
public function getTotalProjectBudgetHealthPerDivision($year = '%')
public function getTotalProjectBudgetHealthPerDivision($year = '%', $company_id )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$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();
// 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) {
@ -266,16 +338,24 @@ class DashboardBoDController extends Controller
], 200);
], 200);
}
}
public function getTotalProjectPerPhase($year = '%')
public function getTotalProjectPerPhase($year = '%', $company_id, $all_project, $hierarchy )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get();
$projectPhases = ProjectPhase::where('company_id', $company_id)-> orderBy('order')->get();
foreach ($projectPhases as $phase) {
foreach ($projectPhases as $phase) {
if ($all_project) {
$phase->totalProject = Project::where('phase_id', $phase->id)
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_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();
->count();
}
}
}
return response()->json([
return response()->json([
'data' => [
'data' => [
$projectPhases
$projectPhases
@ -290,15 +370,17 @@ class DashboardBoDController extends Controller
->count();
->count();
}
}
public function getTotalProjectPerDivision($year = '%')
public function getTotalProjectPerDivision($year = '%', $company_id )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$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)
->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, $year);
@ -323,16 +405,16 @@ class DashboardBoDController extends Controller
->first();
->first();
}
}
public function getTotalProjectValuePerDivision($year = '%')
public function getTotalProjectValuePerDivision($year = '%', $company_id )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$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();
// to do : count in more than 1 level child
foreach ($divisions as $v) {
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
foreach ($v->children as $d) {
foreach ($v->children as $d) {
@ -347,21 +429,29 @@ class DashboardBoDController extends Controller
}
}
public function getDetailExpenditure($year = '%')
public function getDetailExpenditure($year = '%', $company_id, $all_project, $hierarchy )
{
{
$year = $this->interpolateYear($year);
$year = $this->interpolateYear($year);
$projects = null;
if ($all_project) {
$projects = Project::where('mulai_proyek', 'like', $year)
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('company_id', $company_id)
->orderBy('id', 'desc')
->orderBy('id', 'desc')
->get();
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
->orderBy('id', 'desc')
->get();
}
foreach ($projects as $project) {
foreach ($projects as $project) {
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);
if ($project->kode_sortname != "") {
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
$project->invoice = [
$project->invoice = [
'invoiced' => $resp->data->total_invoice_amount ?? 0,
'invoiced' => 0,
'paid' => $resp->data->total_invoice_paid_amount ?? 0,
'paid' => 0,
];
];
}
}