From 18780a09c31e5210cba80e647e0da678757c5b8e Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 27 Jun 2023 08:41:55 +0700 Subject: [PATCH 1/2] Fix project by schedule health --- app/Http/Controllers/DashboardBoDController.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 273d568..8e851cb 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -127,13 +127,19 @@ class DashboardBoDController extends Controller $projects = Project::where('mulai_proyek', 'like', $year)->get(); foreach($projects as $project) { - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + $selisihProgress = 0; + if($project->scurve && $project->scurve[0]){ + $planningProgress = $project->scurve[0]['data']['percentagePlan'][count($project->scurve[0]['data']['percentagePlan'])-1]; + $actualProgress = $project->scurve[0]['data']['percentageReal'][count($project->scurve[0]['data']['percentageReal'])-1]; + } + $selisihProgress = $planningProgress - $actualProgress; try { - if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) + if($selisihProgress > 0 && $selisihProgress <= 5) $return['warning'] += 1; - elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) + elseif($selisihProgress > 5 && $selisihProgress <= 100) $return['behind-schedule'] += 1; - elseif(@$project->scurve['difference'] == 0) + elseif($selisihProgress == 0) $return['on-schedule'] += 1; } catch (\Error $e) { return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); From 60b45418a6b1f6199799262ee0653d124ad4606c Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Sun, 2 Jul 2023 13:48:36 +0700 Subject: [PATCH 2/2] Initial linear curve --- app/Helpers/MasterFunctionsHelper.php | 54 +++++++++++++++++++ .../Controllers/HierarchyFtthController.php | 7 ++- app/Http/Controllers/ProjectController.php | 7 ++- .../Controllers/VersionGanttController.php | 3 +- app/Models/HierarchyFtth.php | 2 +- app/Models/VersionGantt.php | 1 + routes/web.php | 1 + 7 files changed, 71 insertions(+), 4 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 24cd2a1..49877be 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -5,6 +5,7 @@ namespace App\Helpers; use App\Models\Activity; use App\Models\Project; use App\Models\VersionGantt; +use App\Models\HierarchyFtth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -82,6 +83,59 @@ class MasterFunctionsHelper { } } + public function getLinearSCurve($request){ + $ftths = HierarchyFtth::where('project_id', $request->project_id)->get(); + $ttlProgress = 0; + $ttlPlanning = 0; + + foreach ($ftths as $ftth) { + $progress = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('progress'); + $planning = VersionGantt::where('hierarchy_ftth_id', $ftth->id)->sum('bobot'); + $ttlProgress += $progress; + $ttlPlanning += $planning; + } + + $minDate = Project::select('mulai_proyek')->where('id', $request->project_id)->first(); + $maxDate = Project::select('akhir_proyek')->where('id', $request->project_id)->first(); + + $begin = new \DateTime($minDate->mulai_proyek. ' Monday'); + $begin->modify('last Monday'); + + $end = new \DateTime($maxDate->akhir_proyek. ' Friday'); + $end->modify('next Friday'); + $end->modify('next Friday'); + + $interval = new \DateInterval('P7D'); + + $period = new \DatePeriod($begin, $interval, $end); + $dates = iterator_to_array($period); + $count = count($dates); + + $avgProgress = $ttlProgress/$count; + $avgPlanning = $ttlPlanning/$count; + $progressData = []; + $planningData = []; + $tempProgress = 0; + $tempPlanning = 0; + + foreach($period as $p){ + array_push($progressData, $tempProgress); + array_push($planningData, $tempPlanning); + $tempProgress += $avgProgress; + $tempPlanning += $avgPlanning; + } + + $dataResponse = array( + "percentagePlan" => $progressData, + "percentageReal" => $planningData, + ); + + $dataFinal[] = array( + "data"=>$dataResponse, + ); + return $dataFinal; + } + public function calculateProgressBasedOnReportMaterial($keyGantt) { DB::enableQueryLog(); diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php index 6df56a9..3b3f64f 100644 --- a/app/Http/Controllers/HierarchyFtthController.php +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -110,12 +110,15 @@ class HierarchyFtthController extends Controller if($ftthIds){ foreach ($ftthIds as $ftthId) { $gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress'); + $bobot_planning = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('bobot'); $ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); $ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); if($ftth){ $round = $gantts/$ganttCount; + $round_bobot = $bobot_planning/$ganttCount; $ftth->progress = round($round, 2); + $ftth->bobot_planning = round($round_bobot, 2); try { $ftth->save(); } catch (\Exception $e) { @@ -189,6 +192,7 @@ class HierarchyFtthController extends Controller foreach ($progress as $p) { if ($p->id == $gantt->id) { $gantt->progress = $p->persentase_progress; + $gantt->bobot_planning = $p->bobot_planning ? $p->bobot_planning : 0; } } } @@ -216,6 +220,7 @@ class HierarchyFtthController extends Controller foreach ($progress as $p) { if ($p->id == $gantt->id) { $gantt->progress = $p->persentase_progress; + $gantt->bobot_planning = $p->bobot_planning ? $p->bobot_planning : 0; } } } @@ -228,7 +233,7 @@ class HierarchyFtthController extends Controller } public function ganttProgress($column, $value){ - $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress') + $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning') ->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id') ->where("m_version_gantt.".$column, $value) ->where('m_activity.type_activity', "project") diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 41d1b51..ba90377 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -330,6 +330,11 @@ class ProjectController extends Controller public function getSCurve(Request $request){ $data = MasterFunctionsHelper::getSCurve($request); return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); + } + + public function getLinearSCurve(Request $request){ + $data = MasterFunctionsHelper::getLinearSCurve($request); + return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); } public function synchronizeReport($gantt_id) @@ -412,7 +417,7 @@ class ProjectController extends Controller $gantt = MasterFunctionsHelper::getLatestGantt($id); $result->projectManager = User::where('id', $result->pm_id)->value('name'); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first(); - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); } public function getOverdueActivities(Request $request){ diff --git a/app/Http/Controllers/VersionGanttController.php b/app/Http/Controllers/VersionGanttController.php index b66dc3f..97b5857 100644 --- a/app/Http/Controllers/VersionGanttController.php +++ b/app/Http/Controllers/VersionGanttController.php @@ -91,7 +91,7 @@ class VersionGanttController extends Controller } public function ganttProgress($column, $value){ - $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress') + $progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning') ->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id') ->where("m_version_gantt.".$column, $value) // ->where('m_activity.type_activity', "project") @@ -100,6 +100,7 @@ class VersionGanttController extends Controller foreach($progress as $item) { if($item->persentase_progress){ $item->progress = $item->persentase_progress; + $item->bobot = $item->bobot_planning; $item->save(); } } diff --git a/app/Models/HierarchyFtth.php b/app/Models/HierarchyFtth.php index 9a94bfc..34fd7d3 100644 --- a/app/Models/HierarchyFtth.php +++ b/app/Models/HierarchyFtth.php @@ -12,6 +12,6 @@ class HierarchyFtth extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress' + 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning' ]; } diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 05abbf6..4409af8 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -25,6 +25,7 @@ class VersionGantt extends Model 'committed_cost', 'cost_to_complete', 'progress', + 'bobot', 'hierarchy_ftth_id', 'created_at', 'created_by', diff --git a/routes/web.php b/routes/web.php index 7eacf60..c65786d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -66,6 +66,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR'); $router->post('/project/get-s-curve', 'ProjectController@getSCurve'); + $router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve'); $router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities'); $router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration'); $router->post('/project/get-report-distribution', 'ProjectController@getReportDistribution');