Browse Source

Fix user to activity & ftth count progress

pull/3/head
Wahyu Ramadhan 1 year ago
parent
commit
c64c329ae3
  1. 18
      app/Http/Controllers/HierarchyFtthController.php
  2. 8
      app/Http/Controllers/UserToActivityController.php

18
app/Http/Controllers/HierarchyFtthController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\HierarchyFtth; use App\Models\HierarchyFtth;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use Illuminate\Support\Facades\Log;
class HierarchyFtthController extends Controller class HierarchyFtthController extends Controller
{ {
@ -106,33 +107,48 @@ class HierarchyFtthController extends Controller
->where('proyek_id', $project_id) ->where('proyek_id', $project_id)
->groupBy('hierarchy_ftth_id') ->groupBy('hierarchy_ftth_id')
->get(); ->get();
if($ftthIds){
foreach ($ftthIds as $ftthId) { foreach ($ftthIds as $ftthId) {
$gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress'); $gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress');
$ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count(); $ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count();
$ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id); $ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id);
if($ftth){
$round = $gantts/$ganttCount; $round = $gantts/$ganttCount;
$ftth->progress = round($round, 2); $ftth->progress = round($round, 2);
try {
$ftth->save(); $ftth->save();
} catch (\Exception $e) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
if($ftth->parent_id){ if($ftth->parent_id){
$this->countParent($ftth); $this->countParent($ftth);
} }
} }
} }
}
}
public function countParent($ftth){ public function countParent($ftth){
$parent = HierarchyFtth::find($ftth->parent_id); $parent = HierarchyFtth::find($ftth->parent_id);
$children = HierarchyFtth::where('parent_id', $ftth->parent_id)->sum('progress'); $children = HierarchyFtth::where('parent_id', $ftth->parent_id)->sum('progress');
$childrenCount = HierarchyFtth::where('parent_id', $ftth->parent_id)->count(); $childrenCount = HierarchyFtth::where('parent_id', $ftth->parent_id)->count();
if($parent){
$round = $children/$childrenCount; $round = $children/$childrenCount;
$parent->progress = round($round, 2); $parent->progress = round($round, 2);
try {
$parent->save(); $parent->save();
} catch (\Exception $e) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
if($parent->parent_id) { if($parent->parent_id) {
$this->countParent($parent); $this->countParent($parent);
} }
} }
}
public function getTreeByProject($project_id) public function getTreeByProject($project_id)
{ {

8
app/Http/Controllers/UserToActivityController.php

@ -27,10 +27,10 @@ class UserToActivityController extends Controller
public function addMultiple(Request $request){ public function addMultiple(Request $request){
$users_id = $request->user_id; $users_id = $request->user_id;
$data = UserToActivity::where("activity_id", $request->activity_id); // $data = UserToActivity::where("activity_id", $request->activity_id);
if($data){ // if($data){
$data->delete(); // $data->delete();
} // }
if(is_array($users_id) && count($users_id) > 0){ if(is_array($users_id) && count($users_id) > 0){
$countRes = 0; $countRes = 0;

Loading…
Cancel
Save