[Feat] Menambah command untuk update actual Progress Project #10

Merged
farhantock merged 1 commits from Dev-Fuad into staging 2 months ago
  1. 77
      app/Console/Commands/ActualProgressProject.php
  2. 2
      app/Console/Commands/ScheduleHealth.php
  3. 3
      app/Console/Kernel.php
  4. 2
      app/Http/Controllers/ProjectController.php

77
app/Console/Commands/ActualProgressProject.php

@ -0,0 +1,77 @@
<?php
namespace App\Console\Commands;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Project;
use App\Models\VersionGantt;
use Illuminate\Console\Command;
class ActualProgressProject extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'calculate:ActualProgressProject';
/**
* The console command description.
*
* @var string
*/
protected $description = 'For show Actual Progress Project';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$projects = Project::join('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.is_multiLocation')
->get();
foreach ($projects as $project) {
if ($project->is_multiLocation == 1) {
// untuk project multi location
$versionGantt = VersionGantt::join('m_proyek', 'm_version_gantt.proyek_id', 'm_proyek.id')
->select('m_version_gantt.*')
->where('m_version_gantt.proyek_id', $project->id)
->get();
foreach ($versionGantt as $key => $gantt) {
$progress[$key] = $gantt->progress;
}
$actualProgress = round(array_sum($progress) / count($versionGantt), 2);
} else {
// untuk project single location
$gantt = MasterFunctionsHelper::getLatestGantt($project->id);
isset($gantt['last_gantt_id']) ? $lastGantt = $gantt['last_gantt_id'] : $lastGantt = 0;
$arr = [
'project_id' => $project->id,
'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;
}
Project::where('id', $project->id)->update(['persentase_progress' => $actualProgress]);
}
}
}

2
app/Console/Commands/ScheduleHealth.php

@ -45,7 +45,7 @@ class ScheduleHealth extends Command
echo "\n------------------------------------------\n";
echo "Command Start. \n";
Log::info("Command Start.");
$projects = Project::where('company_id', 5)->get();
$projects = Project::get();
$totalProjects = $projects->count();
$updatedProjects = [];
Log::info($totalProjects);

3
app/Console/Kernel.php

@ -15,7 +15,8 @@ class Kernel extends ConsoleKernel
protected $commands = [
Commands\ScheduleHealth::class,
Commands\CalculateSCurve::class,
Commands\CalculateProgressGantt::class
Commands\CalculateProgressGantt::class,
Commands\ActualProgressProject::class
];
/**

2
app/Http/Controllers/ProjectController.php

@ -292,7 +292,7 @@ class ProjectController extends Controller
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
Artisan::call('calculate:ActualProgressProject');
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}

Loading…
Cancel
Save