From 8a77c82c6c707c9ac378712ca8ec9195f70fe08c Mon Sep 17 00:00:00 2001 From: Fuad Hadisurya Date: Thu, 25 Jul 2024 14:21:27 +0700 Subject: [PATCH 1/2] [Fix] command ActualProgressProject.php --- app/Console/Commands/ActualProgressProject.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/ActualProgressProject.php b/app/Console/Commands/ActualProgressProject.php index de21595..a56a4e1 100644 --- a/app/Console/Commands/ActualProgressProject.php +++ b/app/Console/Commands/ActualProgressProject.php @@ -6,6 +6,7 @@ use App\Helpers\MasterFunctionsHelper; use App\Models\Project; use App\Models\VersionGantt; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Log; class ActualProgressProject extends Command { @@ -40,7 +41,7 @@ class ActualProgressProject extends Command */ public function handle() { - $projects = Project::join('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') + $projects = Project::leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') ->select('m_proyek.*', 'm_type_proyek.is_multiLocation') ->get(); @@ -55,6 +56,7 @@ class ActualProgressProject extends Command $progress[$key] = $gantt->progress; } $actualProgress = round(array_sum($progress) / count($versionGantt), 2); + $progress = array(); // unset/kosongkan array progress untuk project selanjutnya } else { // untuk project single location $gantt = MasterFunctionsHelper::getLatestGantt($project->id); @@ -65,12 +67,15 @@ class ActualProgressProject extends Command 'gantt_id' => $lastGantt, 'periode' => 'week' ]; - - $project->scurve = MasterFunctionsHelper::getSCurve(collect($arr)); - $actualArray = $project->scurve[0]['data']['percentageReal']; - $actualProgress = !empty($actualArray) ? round(end($actualArray), 2) : 0; + // kondisi jika tidak ada gantt_id + if (empty($arr['gantt_id'])) { + $actualProgress = 0; + } else { + $project->scurve = MasterFunctionsHelper::getSCurve(collect($arr)); + $actualArray = $project->scurve[0]['data']['percentageReal']; + $actualProgress = !empty($actualArray) ? round(end($actualArray), 2) : 0; + } } - Project::where('id', $project->id)->update(['persentase_progress' => $actualProgress]); } } From 6c44a2ce16f9f613c05dbce91b0c7126034f4ef2 Mon Sep 17 00:00:00 2001 From: Fuad Hadisurya Date: Mon, 29 Jul 2024 12:16:28 +0700 Subject: [PATCH 2/2] [Fix] Command ActualProgressProject: project multi jika ada gantt tetapi tidak ada hierarcy tidak dihitung --- app/Console/Commands/ActualProgressProject.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/ActualProgressProject.php b/app/Console/Commands/ActualProgressProject.php index a56a4e1..1af8a85 100644 --- a/app/Console/Commands/ActualProgressProject.php +++ b/app/Console/Commands/ActualProgressProject.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Helpers\MasterFunctionsHelper; +use App\Models\HierarchyFtth; use App\Models\Project; use App\Models\VersionGantt; use Illuminate\Console\Command; @@ -53,7 +54,13 @@ class ActualProgressProject extends Command ->where('m_version_gantt.proyek_id', $project->id) ->get(); foreach ($versionGantt as $key => $gantt) { - $progress[$key] = $gantt->progress; + $hierarchy = HierarchyFtth::where('id',$gantt->hierarchy_ftth_id)->count(); + // Perhitungan jika project memiliki gantt tetapi tidak ada hierarchy (Kasus perpindahan tipe project dari single location ke multi location) + if($hierarchy == 0){ + $progress[$key] = 0; + } else { + $progress[$key] = $gantt->progress; + } } $actualProgress = round(array_sum($progress) / count($versionGantt), 2); $progress = array(); // unset/kosongkan array progress untuk project selanjutnya