Browse Source

fix(dashboard): optimize get schedule health

pull/1/head
farhantock 6 months ago
parent
commit
fc67ccab54
  1. 50
      app/Http/Controllers/DashboardBoDController.php

50
app/Http/Controllers/DashboardBoDController.php

@ -15,6 +15,7 @@ use App\Models\ProjectScheduleHealth;
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use App\Models\ProjectFinancialHealth; use App\Models\ProjectFinancialHealth;
use App\Models\ProjectInvoice; use App\Models\ProjectInvoice;
use Illuminate\Support\Facades\Artisan;
class DashboardBoDController extends Controller class DashboardBoDController extends Controller
{ {
@ -250,55 +251,29 @@ class DashboardBoDController extends Controller
'warning' => 0, 'warning' => 0,
'on-schedule' => 0, 'on-schedule' => 0,
]; ];
$divisi = Divisi::query()
->where('company_id', $company_id)
->pluck('id');
$projects = null; $projects = null;
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$projects = Project::get(); $projects = Project::get();
} elseif ($all_project == 'true') { } elseif ($all_project == 'true') {
$projects = Project::whereIn('divisi_id', $divisi) $projects = Project::where('company_id', $company_id)
->where('company_id', $company_id)
->get(); ->get();
} else { } else {
$projects = Project::whereIn('divisi_id', $divisi) $projects = Project::where('created_by_id', $replaceHierarchy)
->where('created_by_id', $replaceHierarchy)
->get(); ->get();
} }
foreach ($projects as $index => $project) { $return['behind-schedule'] = $projects->where('schedule_health', 'behind-schedule')->count();
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); $return['warning'] = $projects->where('schedule_health', 'warning')->count();
$selisihProgress = 0; $return['on-schedule'] = $projects->where('schedule_health', 'on-schedule')->count();
$planningProgress = 0;
$actualProgress = 0;
if ($project->scurve && $project->scurve[0]) { return response()->json(['data' => $return], 200);
$planningArray = $project->scurve[0]['data']['percentagePlan'];
$actualArray = $project->scurve[0]['data']['percentageReal'];
$planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
$selisihProgress = $planningProgress - $actualProgress;
try {
if ($selisihProgress > 0 && $selisihProgress <= 20) {
$return['warning'] += 1;
$projects[$index]->status = 'warning';
} elseif ($selisihProgress == 0) {
$return['on-schedule'] += 1;
$projects[$index]->status = 'on-schedule';
} else {
$return['behind-schedule'] += 1;
$projects[$index]->status = 'behind-schedule';
}
} catch (\Error $e) {
return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200);
}
}
return response()->json(['data' => $return, 'q' => $projects], 200); // Panggil Artisan command
Artisan::call('calculate:ScheduleHealth');
} }
public function getTotalProjectScheduleHealthPerDivision($role_name, $company_id) public function getTotalProjectScheduleHealthPerDivision($role_name, $company_id)
{ {
$role = urldecode($role_name); $role = urldecode($role_name);
@ -434,7 +409,6 @@ class DashboardBoDController extends Controller
} }
// to do : count in more than 1 level child
foreach ($divisions as $division) { foreach ($divisions as $division) {
$budgetData = new Collection(); $budgetData = new Collection();
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'overrun'), 'overrun'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'overrun'), 'overrun');
@ -585,7 +559,6 @@ class DashboardBoDController extends Controller
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 != "") {
$project->invoice = [ $project->invoice = [
'invoiced' => 0, 'invoiced' => 0,
@ -598,14 +571,13 @@ class DashboardBoDController extends Controller
$project->manPowers = 0; $project->manPowers = 0;
} else { } else {
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); $project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
} }
$project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id); $project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id);
} }
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);
} }
} }

Loading…
Cancel
Save