Browse Source

feat(command): calculate shcedule health

pull/1/head
farhantock 7 months ago
parent
commit
6b6557a17d
  1. 73
      app/Console/Commands/ScheduleHealth.php
  2. 41
      app/Console/Kernel.php
  3. 3
      app/Models/Project.php

73
app/Console/Commands/ScheduleHealth.php

@ -0,0 +1,73 @@
<?php
namespace App\Console\Commands;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Project;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class ScheduleHealth extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'calculate:ScheduleHealth';
/**
* The console command description.
*
* @var string
*/
protected $description = 'for calculate ScheduleHealth per project';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
// Here is an optimized version of the code using the update method instead of save:
public function handle()
{
$projects = Project::whereNull('deleted_at')->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.";
}
}
}

41
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();
}
}

3
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'
];
}

Loading…
Cancel
Save