Browse Source

fix(dashboard): optimize get schedule health

pull/1/head
farhantock 4 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\Models\ProjectFinancialHealth;
use App\Models\ProjectInvoice;
use Illuminate\Support\Facades\Artisan;
class DashboardBoDController extends Controller
{
@ -250,55 +251,29 @@ class DashboardBoDController extends Controller
'warning' => 0,
'on-schedule' => 0,
];
$divisi = Divisi::query()
->where('company_id', $company_id)
->pluck('id');
$projects = null;
if ($role === 'Super Admin') {
$projects = Project::get();
} elseif ($all_project == 'true') {
$projects = Project::whereIn('divisi_id', $divisi)
->where('company_id', $company_id)
$projects = Project::where('company_id', $company_id)
->get();
} else {
$projects = Project::whereIn('divisi_id', $divisi)
->where('created_by_id', $replaceHierarchy)
$projects = Project::where('created_by_id', $replaceHierarchy)
->get();
}
foreach ($projects as $index => $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
$planningProgress = 0;
$actualProgress = 0;
$return['behind-schedule'] = $projects->where('schedule_health', 'behind-schedule')->count();
$return['warning'] = $projects->where('schedule_health', 'warning')->count();
$return['on-schedule'] = $projects->where('schedule_health', 'on-schedule')->count();
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;
$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], 200);
return response()->json(['data' => $return, 'q' => $projects], 200);
// Panggil Artisan command
Artisan::call('calculate:ScheduleHealth');
}
public function getTotalProjectScheduleHealthPerDivision($role_name, $company_id)
{
$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) {
$budgetData = new Collection();
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'overrun'), 'overrun');
@ -585,7 +559,6 @@ class DashboardBoDController extends Controller
foreach ($projects as $project) {
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);
if ($project->kode_sortname != "") {
$project->invoice = [
'invoiced' => 0,
@ -598,14 +571,13 @@ class DashboardBoDController extends Controller
$project->manPowers = 0;
} else {
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
}
$project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id);
}
return response()->json([
'data' => $projects,
'total_manpowers' => User::count()
'total_manpowers' => User::where('company_id', $company_id)->count()
], 200);
}
}

Loading…
Cancel
Save