|
|
|
@ -14,16 +14,18 @@ use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class DashboardBoDController extends Controller |
|
|
|
|
{ |
|
|
|
|
private function interpolateYear($year){ |
|
|
|
|
if($year) |
|
|
|
|
$year = '%'.$year.'%'; |
|
|
|
|
private function interpolateYear($year) |
|
|
|
|
{ |
|
|
|
|
if ($year) |
|
|
|
|
$year = '%' . $year . '%'; |
|
|
|
|
return $year; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function curlReq($url, $token){ |
|
|
|
|
private function curlReq($url, $token) |
|
|
|
|
{ |
|
|
|
|
$ch = curl_init(); |
|
|
|
|
$headers = [ |
|
|
|
|
'Authorization: '.$token |
|
|
|
|
'Authorization: ' . $token |
|
|
|
|
]; |
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
|
|
@ -37,7 +39,8 @@ class DashboardBoDController extends Controller
|
|
|
|
|
return json_decode($response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function getInvoiceIntegration($search) { |
|
|
|
|
private function getInvoiceIntegration($search) |
|
|
|
|
{ |
|
|
|
|
// if(empty($search)) |
|
|
|
|
// return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); |
|
|
|
|
// |
|
|
|
@ -52,7 +55,8 @@ class DashboardBoDController extends Controller
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// to do |
|
|
|
|
public function getCompanyCashFlow($year = '%') { |
|
|
|
|
public function getCompanyCashFlow($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; |
|
|
|
|
|
|
|
|
@ -66,16 +70,16 @@ class DashboardBoDController extends Controller
|
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
->get(); |
|
|
|
|
foreach($projects as $project){ |
|
|
|
|
foreach ($projects as $project) { |
|
|
|
|
$project->expenses = 0; |
|
|
|
|
|
|
|
|
|
$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; |
|
|
|
|
$totalExpenditure += (int) $cost; |
|
|
|
|
$totalInvoice += $resp->data->total_invoice_amount ?? 0; |
|
|
|
|
$totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; |
|
|
|
|
} |
|
|
|
@ -87,20 +91,21 @@ class DashboardBoDController extends Controller
|
|
|
|
|
'total_budget' => (int) $totalBudgets ?? 0, |
|
|
|
|
'total_expenditure' => $totalExpenditure, |
|
|
|
|
'total_invoice' => $totalInvoice, |
|
|
|
|
'total_paid_invoice' => $totalPaidInvoice , |
|
|
|
|
'total_paid_invoice' => $totalPaidInvoice, |
|
|
|
|
] |
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getInvoiceOutstanding($year = '%'){ |
|
|
|
|
public function getInvoiceOutstanding($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
->get(); |
|
|
|
|
$return = []; |
|
|
|
|
foreach($projects as $project){ |
|
|
|
|
foreach ($projects as $project) { |
|
|
|
|
$resp = null; |
|
|
|
|
if($project->kode_sortname != ""){ |
|
|
|
|
if ($project->kode_sortname != "") { |
|
|
|
|
$resp = $this->getInvoiceIntegration($project->kode_sortname); |
|
|
|
|
array_push($return, [ |
|
|
|
|
'project' => $project->nama, |
|
|
|
@ -117,7 +122,8 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectPerScheduleHealth($year = '%'){ |
|
|
|
|
public function getTotalProjectPerScheduleHealth($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
|
|
|
|
|
$return = [ |
|
|
|
@ -127,10 +133,10 @@ class DashboardBoDController extends Controller
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year)->get(); |
|
|
|
|
foreach($projects as $project) { |
|
|
|
|
foreach ($projects as $project) { |
|
|
|
|
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); |
|
|
|
|
$selisihProgress = 0; |
|
|
|
|
if($project->scurve && $project->scurve[0]){ |
|
|
|
|
if ($project->scurve && $project->scurve[0]) { |
|
|
|
|
$planningArray = $project->scurve[0]['data']['percentagePlan']; |
|
|
|
|
$actualArray = $project->scurve[0]['data']['percentageReal']; |
|
|
|
|
$planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0; |
|
|
|
@ -138,9 +144,9 @@ class DashboardBoDController extends Controller
|
|
|
|
|
} |
|
|
|
|
$selisihProgress = $planningProgress - $actualProgress; |
|
|
|
|
try { |
|
|
|
|
if($selisihProgress > 0 && $selisihProgress <= 5) |
|
|
|
|
if ($selisihProgress > 0 && $selisihProgress <= 5) |
|
|
|
|
$return['warning'] += 1; |
|
|
|
|
elseif($selisihProgress == 0) |
|
|
|
|
elseif ($selisihProgress == 0) |
|
|
|
|
$return['on-schedule'] += 1; |
|
|
|
|
else |
|
|
|
|
$return['behind-schedule'] += 1; |
|
|
|
@ -152,23 +158,24 @@ class DashboardBoDController extends Controller
|
|
|
|
|
return response()->json(['data' => $return, 'q' => $projects], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectScheduleHealthPerDivision($year = '%'){ |
|
|
|
|
public function getTotalProjectScheduleHealthPerDivision($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
|
|
|
|
|
$divisions = Divisi::whereNull('parent')->get(); |
|
|
|
|
foreach($divisions as $division){ |
|
|
|
|
foreach ($divisions as $division) { |
|
|
|
|
|
|
|
|
|
$scheduleData = new Collection(); |
|
|
|
|
$behindSchedule = $warning = $onSchedule = 0; |
|
|
|
|
|
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get(); |
|
|
|
|
foreach($projects as $project) { |
|
|
|
|
foreach ($projects as $project) { |
|
|
|
|
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); |
|
|
|
|
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) |
|
|
|
|
if (@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) |
|
|
|
|
$warning++; |
|
|
|
|
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) |
|
|
|
|
elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) |
|
|
|
|
$behindSchedule++; |
|
|
|
|
elseif(@$project->scurve['difference'] == 0) |
|
|
|
|
elseif (@$project->scurve['difference'] == 0) |
|
|
|
|
$onSchedule++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -184,7 +191,8 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectPerBudgetHealth($year = '%'){ |
|
|
|
|
public function getTotalProjectPerBudgetHealth($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
return response()->json([ |
|
|
|
|
'data' => [ |
|
|
|
@ -195,7 +203,8 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){ |
|
|
|
|
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health) |
|
|
|
|
{ |
|
|
|
|
return Project::where('divisi_id', $divisi) |
|
|
|
|
->where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
@ -204,19 +213,20 @@ class DashboardBoDController extends Controller
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getTotalProjectBudgetHealthPerDivision($year = '%'){ |
|
|
|
|
public function getTotalProjectBudgetHealthPerDivision($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$divisions = Divisi::select('id','name') |
|
|
|
|
$divisions = Divisi::select('id', 'name') |
|
|
|
|
->with('children') |
|
|
|
|
->whereNull('parent') |
|
|
|
|
->get(); |
|
|
|
|
// to do : count in more than 1 level child |
|
|
|
|
foreach($divisions as $division){ |
|
|
|
|
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'); |
|
|
|
|
foreach($division->children as $d){ |
|
|
|
|
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'); |
|
|
|
@ -224,7 +234,7 @@ class DashboardBoDController extends Controller
|
|
|
|
|
unset($division->children); |
|
|
|
|
$division->budgetData = $budgetData; |
|
|
|
|
} |
|
|
|
|
foreach($divisions as $division){ |
|
|
|
|
foreach ($divisions as $division) { |
|
|
|
|
} |
|
|
|
|
return response()->json([ |
|
|
|
|
'data' => [ |
|
|
|
@ -233,10 +243,11 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectPerPhase($year = '%'){ |
|
|
|
|
public function getTotalProjectPerPhase($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$projectPhases = ProjectPhase::orderBy('order')->get(); |
|
|
|
|
foreach($projectPhases as $phase){ |
|
|
|
|
foreach ($projectPhases as $phase) { |
|
|
|
|
$phase->totalProject = Project::where('phase_id', $phase->id) |
|
|
|
|
->where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
@ -249,24 +260,26 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function countTotalProjectInDivision($id, $year){ |
|
|
|
|
private function countTotalProjectInDivision($id, $year) |
|
|
|
|
{ |
|
|
|
|
return Project::where('divisi_id', $id) |
|
|
|
|
->where('mulai_proyek', 'like', $year) |
|
|
|
|
->count(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectPerDivision($year = '%') { |
|
|
|
|
public function getTotalProjectPerDivision($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
|
|
|
|
|
$divisions = Divisi::select('id','name') |
|
|
|
|
$divisions = Divisi::select('id', 'name') |
|
|
|
|
->with('children') |
|
|
|
|
->whereNull('parent') |
|
|
|
|
->get(); |
|
|
|
|
|
|
|
|
|
// to do : count in more than 1 level child |
|
|
|
|
foreach($divisions as $v){ |
|
|
|
|
foreach ($divisions as $v) { |
|
|
|
|
$v->total = $this->countTotalProjectInDivision($v->id, $year); |
|
|
|
|
foreach($v->children as $d){ |
|
|
|
|
foreach ($v->children as $d) { |
|
|
|
|
$v->total += $this->countTotalProjectInDivision($d->id, $year); |
|
|
|
|
} |
|
|
|
|
unset($v->children); |
|
|
|
@ -277,7 +290,8 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function countTotalProjectValueInDivision($id, $year){ |
|
|
|
|
private function countTotalProjectValueInDivision($id, $year) |
|
|
|
|
{ |
|
|
|
|
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) |
|
|
|
|
->where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
@ -286,18 +300,19 @@ class DashboardBoDController extends Controller
|
|
|
|
|
->first(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getTotalProjectValuePerDivision($year = '%') { |
|
|
|
|
public function getTotalProjectValuePerDivision($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
|
|
|
|
|
$divisions = Divisi::select('id','name') |
|
|
|
|
$divisions = Divisi::select('id', 'name') |
|
|
|
|
->with('children') |
|
|
|
|
->whereNull('parent') |
|
|
|
|
->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); |
|
|
|
|
foreach($v->children as $d){ |
|
|
|
|
foreach ($v->children as $d) { |
|
|
|
|
$v->total += $this->countTotalProjectValueInDivision($d->id, $year); |
|
|
|
|
} |
|
|
|
|
unset($v->children); |
|
|
|
@ -309,16 +324,17 @@ class DashboardBoDController extends Controller
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getDetailExpenditure($year = '%'){ |
|
|
|
|
public function getDetailExpenditure($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
->orderBy('id', 'desc') |
|
|
|
|
->get(); |
|
|
|
|
foreach($projects as $project){ |
|
|
|
|
foreach ($projects as $project) { |
|
|
|
|
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id); |
|
|
|
|
|
|
|
|
|
if($project->kode_sortname != ""){ |
|
|
|
|
if ($project->kode_sortname != "") { |
|
|
|
|
$resp = $this->getInvoiceIntegration($project->kode_sortname); |
|
|
|
|
$project->invoice = [ |
|
|
|
|
'invoiced' => $resp->data->total_invoice_amount ?? 0, |
|
|
|
@ -328,7 +344,7 @@ class DashboardBoDController extends Controller
|
|
|
|
|
|
|
|
|
|
$project->pm = User::find($project->pm_id); |
|
|
|
|
/* $project->header = Activity::where('proyek_id', $project->id)->where('version_gantt_id', $lastGantt['last_gantt_id'])->whereNull('parent_id')->first(); */ |
|
|
|
|
if(!isset($lastGantt['last_gantt_id'])){ |
|
|
|
|
if (!isset($lastGantt['last_gantt_id'])) { |
|
|
|
|
$project->manPowers = 0; |
|
|
|
|
} else { |
|
|
|
|
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); |
|
|
|
@ -343,4 +359,3 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|