From 6b6557a17da39a69ff5116283ebbaec85c98a4ca Mon Sep 17 00:00:00 2001 From: farhantock Date: Wed, 22 May 2024 18:51:36 +0700 Subject: [PATCH] feat(command): calculate shcedule health --- app/Console/Commands/ScheduleHealth.php | 73 +++++++++++++++++++++++++ app/Console/Kernel.php | 41 +++++++------- app/Models/Project.php | 3 +- 3 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 app/Console/Commands/ScheduleHealth.php diff --git a/app/Console/Commands/ScheduleHealth.php b/app/Console/Commands/ScheduleHealth.php new file mode 100644 index 0000000..e03cb35 --- /dev/null +++ b/app/Console/Commands/ScheduleHealth.php @@ -0,0 +1,73 @@ +get(); + $totalProjects = $projects->count(); + $updatedProjects = []; + + foreach ($projects as $index => $project) { + $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + + if ($project->scurve && $project->scurve[0]) { + $planningArray = $project->scurve[0]['data']['percentagePlan']; + $actualArray = $project->scurve[0]['data']['percentageReal']; + $planningProgress = !empty($planningArray) ? end($planningArray) : 0; + $actualProgress = !empty($actualArray) ? end($actualArray) : 0; + + $selisihProgress = $planningProgress - $actualProgress; + + $scheduleHealth = ($selisihProgress > 0 && $selisihProgress <= 20) ? 'warning' : (($selisihProgress == 0) ? 'on-schedule' : 'behind-schedule'); + + Log::info("Updating project with ID: " . $project->id . " - Schedule Health: " . $scheduleHealth); + $project->update(['schedule_health' => $scheduleHealth]); + $updatedProjects[] = $project->id; + } + } + + if ($totalProjects > 0) { + echo "\n------------------------------------------\n"; + echo "All projects have been updated."; + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 726d069..1cafb1c 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -7,26 +7,25 @@ use Laravel\Lumen\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel { - /** - * The Artisan commands provided by your application. - * - * @var array - */ - protected $commands = [ - Commands\syncHumanResourceIntegration::class, - Commands\CalculateSCurve::class, - Commands\CalculateProgressGantt::class - ]; - - /** - * Define the application's command schedule. - * - * @param \Illuminate\Console\Scheduling\Schedule $schedule - * @return void - */ - protected function schedule(Schedule $schedule) - { - $schedule->command('sync:integration-human-resources')->twiceDaily(); - } + /** + * The Artisan commands provided by your application. + * + * @var array + */ + protected $commands = [ + Commands\ScheduleHealth::class, + Commands\CalculateSCurve::class, + Commands\CalculateProgressGantt::class + ]; + /** + * Define the application's command schedule. + * + * @param \Illuminate\Console\Scheduling\Schedule $schedule + * @return void + */ + protected function schedule(Schedule $schedule) + { + $schedule->command('sync:integration-human-resources')->twiceDaily(); + } } diff --git a/app/Models/Project.php b/app/Models/Project.php index 2e79784..9f93bff 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -55,6 +55,7 @@ class Project extends Model 'company_id', 'deleted_at', 'deleted_by_id', - 'income_year' + 'income_year', + 'schedule_health' ]; }