Browse Source

calculate s curve by hierarchy id

pull/1/head
wahyu 1 year ago
parent
commit
2703a32aeb
  1. 10
      app/Console/Commands/CalculateProgressGantt.php
  2. 3
      app/Console/Kernel.php
  3. 88
      app/Helpers/MasterFunctionsHelper.php
  4. 2
      app/Http/Controllers/ActivityController.php
  5. 7
      app/Http/Controllers/HierarchyFtthController.php

10
app/Console/Commands/CalculateProgressGantt.php

@ -2,25 +2,27 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\HierarchyFtth;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use App\Models\Project; use App\Models\Project;
class CalculateProgressGantt extends Command class CalculateProgressGantt extends Command
{ {
protected $signature = 'calculate:progressgantt {project_id}'; protected $signature = 'calculate:progressgantt {hierarchy_id}';
protected $description = 'Calculate Progress Gantt'; protected $description = 'Calculate Progress Gantt';
public function handle() public function handle()
{ {
$project_id = $this->argument('project_id'); $hierarchy_id = $this->argument('hierarchy_id');
$project = Project::find($project_id); $hierarchy = HierarchyFtth::findOrFail($hierarchy_id);
$project = Project::find($hierarchy->project_id);
$project->calculation_status = true; $project->calculation_status = true;
$project->save(); $project->save();
$data = MasterFunctionsHelper::CalculateSCurve($project_id); $data = MasterFunctionsHelper::CalculateSCurve(null, $hierarchy_id);
$project->scurve = json_encode($data); $project->scurve = json_encode($data);
$project->calculation_status = true; $project->calculation_status = true;

3
app/Console/Kernel.php

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

88
app/Helpers/MasterFunctionsHelper.php

@ -1306,10 +1306,19 @@ class MasterFunctionsHelper
return $dataFinal; return $dataFinal;
} }
public function calculateSCurve($projectId) public function calculateSCurve($projectId, $hierarchyId = null)
{ {
DB::enableQueryLog(); DB::enableQueryLog();
$hierarchyGantts = [];
if (isset($hierarchyId)) {
$hierarchy = HierarchyFtth::findOrFail($hierarchyId);
$projectId = $hierarchy->project_id;
if (isset($hierarchy)) {
$hierarchyGantts = VersionGantt::where('hierarchy_ftth_id', $hierarchyId)->get()->toArray();
}
}
$dataFinal = []; $dataFinal = [];
$dataPayload = []; $dataPayload = [];
$dataPayload['period'] = 'week'; $dataPayload['period'] = 'week';
@ -1371,17 +1380,43 @@ class MasterFunctionsHelper
//new \Datetime($dt->format("Y-m-d")); //new \Datetime($dt->format("Y-m-d"));
// $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); // $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$tempDate[] = array($dt->format("Y-m-d")); $tempDate[] = array($dt->format("Y-m-d"));
$dataPlanM = [];
$dataActualM = [];
if (count($hierarchyGantts) > 0) {
foreach ($hierarchyGantts as $key => $gantt) {
$dataPlanM[] = DB::table('m_activity')
->where('type_activity', 'task')
->where('bobot_planning', '>', 0)
->where('version_gantt_id', $gantt['id'])
->whereDate('planned_start', '<=', $loopDay)
->whereDate('planned_end', '>=', $loopDay)
->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end')
->get()->toArray();
$dataPlanM = DB::table('m_activity') $dataActualM[] = DB::table('report_activity_material as ram')
->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id')
->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name',
DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'),
DB::raw('(SELECT COUNT(id) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS count_report')
)
->where('ram.report_date', $loopDay)
->where('ma.version_gantt_id', $gantt['id'])
->get()->toArray();
}
} else {
$dataPlanM[] = DB::table('m_activity')
->where('type_activity', 'task') ->where('type_activity', 'task')
->where('bobot_planning', '>', 0) ->where('bobot_planning', '>', 0)
->where('proyek_id', $projectId) ->where('proyek_id', $projectId)
->whereDate('planned_start', '<=', $loopDay) ->whereDate('planned_start', '<=', $loopDay)
->whereDate('planned_end', '>=', $loopDay) ->whereDate('planned_end', '>=', $loopDay)
->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end') ->select('name', 'bobot_planning', 'biaya_actual', 'duration', 'persentase_progress', 'id', 'planned_start', 'planned_end')
->get(); ->get()->toArray();
$dataActualM = DB::table('report_activity_material as ram') $dataActualM[] = DB::table('report_activity_material as ram')
->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id') ->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id')
->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name', ->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name',
DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'), DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
@ -1391,7 +1426,8 @@ class MasterFunctionsHelper
) )
->where('ram.report_date', $loopDay) ->where('ram.report_date', $loopDay)
->where('ma.proyek_id', $projectId) ->where('ma.proyek_id', $projectId)
->get(); ->get()->toArray();
}
$dataActivityPlan = []; $dataActivityPlan = [];
$dataActivityActual = []; $dataActivityActual = [];
@ -1406,14 +1442,15 @@ class MasterFunctionsHelper
$dateWeek[] = [$loopDay]; $dateWeek[] = [$loopDay];
} }
// $progressPlanKomulatifWeek[] += $tmpProgressPlanWeek; // $progressPlanKomulatifWeek[] += $tmpProgressPlanWeek;
if (count($dataPlanM) > 0 && count($dataPlanM[0]) > 0) {
foreach ($dataPlanM as $keyPlanM) { foreach ($dataPlanM as $keyPlanM) {
# hitung untuk persentase progress planning # hitung untuk persentase progress planning
// if($keyPlanM->duration == 0){ // if($keyPlanM->duration == 0){
// $duration = 2; // $duration = 2;
// Tanggal awal // Tanggal awal
$startDate = new DateTime($keyPlanM->planned_start); $startDate = new DateTime($keyPlanM[0]->planned_start);
// Tanggal akhir // Tanggal akhir
$endDate = new DateTime($keyPlanM->planned_end); $endDate = new DateTime($keyPlanM[0]->planned_end);
// Menghitung selisih hari // Menghitung selisih hari
$interval = $startDate->diff($endDate); $interval = $startDate->diff($endDate);
// Mengambil hasil selisih hari // Mengambil hasil selisih hari
@ -1428,33 +1465,35 @@ class MasterFunctionsHelper
// // Mengambil hasil selisih hari // // Mengambil hasil selisih hari
// $duration = $interval->days; // $duration = $interval->days;
// 2023-07-26 // 2023-07-26
$progressPlanWeek = $keyPlanM->bobot_planning / $duration; $progressPlanWeek = $keyPlanM[0]->bobot_planning / $duration;
$dataActivityPlan[] = array( $dataActivityPlan[] = array(
'progressPlanDay' => $progressPlanWeek, 'progressPlanDay' => $progressPlanWeek,
'name' => $keyPlanM->name, 'name' => $keyPlanM[0]->name,
'bobot_p' => $keyPlanM->bobot_planning, 'bobot_p' => $keyPlanM[0]->bobot_planning,
'duration' => $keyPlanM->duration 'duration' => $keyPlanM[0]->duration
); );
$tmpProgressPlanWeek += $progressPlanWeek; $tmpProgressPlanWeek += $progressPlanWeek;
} }
}
// hitung progress actual // hitung progress actual
if (count($dataActualM) > 0 && count($dataActualM[0]) > 0) {
foreach ($dataActualM as $keyActualM) { foreach ($dataActualM as $keyActualM) {
# hitung untuk persentase progress actual # hitung untuk persentase progress actual
// $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100; // $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
// jika total report > dari planning // jika total report > dari planning
if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ if($keyActualM[0]->sum_qty_actual > $keyActualM[0]->qty_plan){
$progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) *$keyActualM->bobot_planning/100; $progressActualWeek = (($keyActualM[0]->qty_actual / $keyActualM[0]->sum_qty_actual) * 100) *$keyActualM[0]->bobot_planning/100;
}else{ }else{
// jika total report < dari planning // jika total report < dari planning
// $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning; // $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
if($keyActualM->qty_actual == 0){ if($keyActualM[0]->qty_actual == 0){
$progressActualWeek = 0; $progressActualWeek = 0;
}else{ }else{
$progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning; $progressActualWeek = ($keyActualM[0]->qty_actual / $keyActualM[0]->qty_plan) * $keyActualM[0]->bobot_planning;
} }
} }
if($keyActualM->status_activity == 'done'){ if($keyActualM[0]->status_activity == 'done'){
// if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ // if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
// } // }
@ -1463,7 +1502,7 @@ class MasterFunctionsHelper
// }else if($keyActualM->qty_actual == 0){ // }else if($keyActualM->qty_actual == 0){
// $progressActualWeek = $keyActualM->bobot_planning; // $progressActualWeek = $keyActualM->bobot_planning;
// }else if($keyActualM->qty_plan == $keyActualM->sum_qty_actual){ // }else if($keyActualM->qty_plan == $keyActualM->sum_qty_actual){
$progressActualWeek = $keyActualM->bobot_planning / $keyActualM->count_report; $progressActualWeek = $keyActualM[0]->bobot_planning / $keyActualM[0]->count_report;
// }else { // }else {
// $progressActualWeek = $progressActualWeek; // $progressActualWeek = $progressActualWeek;
// } // }
@ -1472,20 +1511,21 @@ class MasterFunctionsHelper
// contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping // contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping
} }
else{ else{
$progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek; $progressActualWeek = $progressActualWeek > ($keyActualM[0]->bobot_planning*95)/100 ? ($keyActualM[0]->bobot_planning*95)/100 : $progressActualWeek;
} }
$dataActivityActual[] = array( $dataActivityActual[] = array(
'progressActualDay' => $progressActualWeek, 'progressActualDay' => $progressActualWeek,
'qty_act' => $keyActualM->qty_actual, 'qty_act' => $keyActualM[0]->qty_actual,
'bobot_p' => $keyActualM->bobot_planning, 'bobot_p' => $keyActualM[0]->bobot_planning,
'qty_plan' => $keyActualM->qty_plan, 'qty_plan' => $keyActualM[0]->qty_plan,
'status_activity' => $keyActualM->status_activity, 'status_activity' => $keyActualM[0]->status_activity,
'sum_qty_actual' => $keyActualM->sum_qty_actual, 'sum_qty_actual' => $keyActualM[0]->sum_qty_actual,
'name' => $keyActualM->name 'name' => $keyActualM[0]->name
); );
$tmpProgressActualWeek += $progressActualWeek; $tmpProgressActualWeek += $progressActualWeek;
} }
}
$dataActivityPlanDate[] = array( $dataActivityPlanDate[] = array(
"date" => $loopDay, "date" => $loopDay,

2
app/Http/Controllers/ActivityController.php

@ -322,7 +322,7 @@ class ActivityController extends Controller
$actualEndValues = array_column(array_filter($dataFinal, function($item) { $actualEndValues = array_column(array_filter($dataFinal, function($item) {
return isset($item['actual_end']); return isset($item['actual_end']);
}), 'actual_end'); }), 'actual_end');
$returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null; $returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) && count($actualEndValues) > 0 ? max($actualEndValues) : null;
if (isset($parent)) { if (isset($parent)) {
$parent->actual_end = $returnActualStartOrEnd; $parent->actual_end = $returnActualStartOrEnd;
$parent->save(); $parent->save();

7
app/Http/Controllers/HierarchyFtthController.php

@ -103,7 +103,7 @@ class HierarchyFtthController extends Controller
} }
} }
public function countProgress($project_id) { public function countProgress($hierarchy_id) {
// $ftthIds = VersionGantt::select('hierarchy_ftth_id') // $ftthIds = VersionGantt::select('hierarchy_ftth_id')
// ->where('proyek_id', $project_id) // ->where('proyek_id', $project_id)
// ->groupBy('hierarchy_ftth_id') // ->groupBy('hierarchy_ftth_id')
@ -136,7 +136,7 @@ class HierarchyFtthController extends Controller
// calculate ke curva berdasarkan site // calculate ke curva berdasarkan site
Artisan::call('calculate:progressgantt', [ Artisan::call('calculate:progressgantt', [
'project_id' => $project_id 'hierarchy_id' => $hierarchy_id
]); ]);
} }
@ -185,12 +185,11 @@ class HierarchyFtthController extends Controller
public function getTreeByProject($project_id) public function getTreeByProject($project_id)
{ {
$this->countProgress(intval($project_id));
$data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); $data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
$finalData = []; $finalData = [];
foreach($data as $objRow){ foreach($data as $objRow){
$objRow->key = rand(1, 1000); $objRow->key = rand(1, 1000);
$this->countProgress(intval($objRow->id));
if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) { if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) {
$dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get(); $dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get();
$progress = $this->ganttProgress('hierarchy_ftth_id', $objRow->id); $progress = $this->ganttProgress('hierarchy_ftth_id', $objRow->id);

Loading…
Cancel
Save