Browse Source

update for calculate progress

pull/1/head
ibnu 11 months ago
parent
commit
16e73335bb
  1. 29
      app/Console/Commands/CalculateProgressGantt.php
  2. 20
      app/Helpers/MasterFunctionsHelper.php
  3. 5
      app/Http/Controllers/ActivityController.php
  4. 65
      app/Http/Controllers/HierarchyFtthController.php

29
app/Console/Commands/CalculateProgressGantt.php

@ -0,0 +1,29 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Project;
class CalculateProgressGantt extends Command
{
protected $signature = 'calculate:progressgantt {project_id}';
protected $description = 'Calculate Progress Gantt';
public function handle()
{
$project_id = $this->argument('project_id');
$project = Project::find($project_id);
$project->calculation_status = true;
$project->save();
$data = MasterFunctionsHelper::CalculateSCurve($project_id);
$project->scurve = json_encode($data);
$project->calculation_status = true;
$project->save();
}
}

20
app/Helpers/MasterFunctionsHelper.php

@ -609,24 +609,8 @@ class MasterFunctionsHelper
$progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning;
}
}
if($keyActualM->status_activity == 'done'){
// if($keyActualM->count_report > 1){
// $progressActualWeek = $keyActualM->bobot_planning/$keyActualM->count_report;
// }else{
$progressActualWeek = $keyActualM->bobot_planning / $keyActualM->count_report;
// }
// if($progressActualWeek > $keyActualM->bobot_planning){
// $progressActualWeek = $keyActualM->bobot_planning;
// }else if($keyActualM->qty_actual == 0){
// $progressActualWeek = $keyActualM->bobot_planning;
// }else if($keyActualM->qty_plan == $keyActualM->sum_qty_actual){
// $progressActualWeek = $keyActualM->bobot_planning;
// }else {
// $progressActualWeek = $progressActualWeek;
// }
// $progressActualWeek = $progressActualWeek > $keyActualM->bobot_planning ? $keyActualM->bobot_planning : $progressActualWeek;
// jika report lebih dari 1 x, maka harusnya di bagi sabanyak jumlah report,
// contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping
if($keyActualM->status_activity == 'done'){
$progressActualWeek = $keyActualM->bobot_planning / $keyActualM->count_report;
}
else{
$progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek;

5
app/Http/Controllers/ActivityController.php

@ -1156,4 +1156,9 @@ class ActivityController extends Controller
}
return response()->json(['status' => 'success', 'data' => $request, 'message' => 'Update successful!', 'code' => 200], 200);
}
// public function recalculateProject($by, $id){
// // query get activity
// $cekActivity =
// }
}

65
app/Http/Controllers/HierarchyFtthController.php

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
use App\Models\VersionGantt;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Artisan;
class HierarchyFtthController extends Controller
{
@ -103,35 +104,40 @@ class HierarchyFtthController extends Controller
}
public function countProgress($project_id) {
$ftthIds = VersionGantt::select('hierarchy_ftth_id')
->where('proyek_id', $project_id)
->groupBy('hierarchy_ftth_id')
->get();
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) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
if($ftth->parent_id){
$this->countParent($ftth);
}
}
}
}
// $ftthIds = VersionGantt::select('hierarchy_ftth_id')
// ->where('proyek_id', $project_id)
// ->groupBy('hierarchy_ftth_id')
// ->get();
// 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) {
// // Log the error or handle it in some other way
// Log::error($e->getMessage());
// }
// if($ftth->parent_id){
// $this->countParent($ftth);
// }
// }
// }
// }
// calculate ke curva berdasarkan site
Artisan::call('calculate:progressgantt', [
'project_id' => $project_id
]);
}
public function countParent($ftth){
@ -180,6 +186,7 @@ class HierarchyFtthController extends Controller
public function getTreeByProject($project_id)
{
$this->countProgress(intval($project_id));
$data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
$finalData = [];
foreach($data as $objRow){

Loading…
Cancel
Save