|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
use App\Models\HierarchyFtth; |
|
|
|
|
use App\Models\VersionGantt; |
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
|
|
|
|
|
class HierarchyFtthController extends Controller |
|
|
|
|
{ |
|
|
|
@ -106,18 +107,26 @@ class HierarchyFtthController extends Controller
|
|
|
|
|
->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'); |
|
|
|
|
$ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); |
|
|
|
|
|
|
|
|
|
$ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); |
|
|
|
|
if($ftth){ |
|
|
|
|
$round = $gantts/$ganttCount; |
|
|
|
|
$ftth->progress = round($round, 2); |
|
|
|
|
try { |
|
|
|
|
$ftth->save(); |
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
// Log the error or handle it in some other way |
|
|
|
|
Log::error($e->getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($ftthIds as $ftthId) { |
|
|
|
|
$gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress'); |
|
|
|
|
$ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); |
|
|
|
|
|
|
|
|
|
$ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); |
|
|
|
|
$round = $gantts/$ganttCount; |
|
|
|
|
$ftth->progress = round($round, 2); |
|
|
|
|
$ftth->save(); |
|
|
|
|
|
|
|
|
|
if($ftth->parent_id){ |
|
|
|
|
$this->countParent($ftth); |
|
|
|
|
if($ftth->parent_id){ |
|
|
|
|
$this->countParent($ftth); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -126,11 +135,18 @@ class HierarchyFtthController extends Controller
|
|
|
|
|
$parent = HierarchyFtth::find($ftth->parent_id); |
|
|
|
|
$children = HierarchyFtth::where('parent_id', $ftth->parent_id)->sum('progress'); |
|
|
|
|
$childrenCount = HierarchyFtth::where('parent_id', $ftth->parent_id)->count(); |
|
|
|
|
$round = $children/$childrenCount; |
|
|
|
|
$parent->progress = round($round, 2); |
|
|
|
|
$parent->save(); |
|
|
|
|
if($parent->parent_id) { |
|
|
|
|
$this->countParent($parent); |
|
|
|
|
if($parent){ |
|
|
|
|
$round = $children/$childrenCount; |
|
|
|
|
$parent->progress = round($round, 2); |
|
|
|
|
try { |
|
|
|
|
$parent->save(); |
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
// Log the error or handle it in some other way |
|
|
|
|
Log::error($e->getMessage()); |
|
|
|
|
} |
|
|
|
|
if($parent->parent_id) { |
|
|
|
|
$this->countParent($parent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|