Browse Source

Merge pull request 'staging upload 23-04-11' (#27) from staging into master

Reviewed-on: ordo/adw-backend#27
pull/3/head
ibnu 2 years ago
parent
commit
5233171870
  1. 34
      app/Http/Controllers/HierarchyFtthController.php
  2. 23
      app/Http/Controllers/VersionGanttController.php
  3. 2
      app/Models/HierarchyFtth.php

34
app/Http/Controllers/HierarchyFtthController.php

@ -100,9 +100,43 @@ class HierarchyFtthController extends Controller
], 500);
}
}
public function countProgress($project_id) {
$ftthIds = VersionGantt::select('hierarchy_ftth_id')
->where('proyek_id', $project_id)
->groupBy('hierarchy_ftth_id')
->get();
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);
}
}
}
public function countParent($ftth){
$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);
}
}
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){

23
app/Http/Controllers/VersionGanttController.php

@ -83,20 +83,9 @@ class VersionGanttController extends Controller
$dataBuilder = $this->setUpPayload($payload, 'm_version_gantt');
$builder = $dataBuilder['builder'];
// $countBuilder = $dataBuilder['count'];
$progress = $this->ganttProgress($request->columns[0]["name"], $request->columns[0]["value"]);
$this->ganttProgress($request->columns[0]["name"], $request->columns[0]["value"]);
$dataGet = $builder->get();
// Loop through $dataGet collection
foreach ($dataGet as $item) {
// Loop through $progress collection
foreach ($progress as $progressItem) {
// Check if both have the same id
if ($item->id == $progressItem->id) {
// Set the progress of $item to the corresponding progress of $progressItem
$item->progress = $progressItem->persentase_progress;
break;
}
}
}
// $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet], 200);
}
@ -108,8 +97,12 @@ class VersionGanttController extends Controller
->where('m_activity.type_activity', "project")
->where('m_activity.parent_id', null)
->get();
return $progress;
foreach($progress as $item) {
if($item->persentase_progress){
$item->progress = $item->persentase_progress;
$item->save();
}
}
}
public function list()

2
app/Models/HierarchyFtth.php

@ -12,6 +12,6 @@ class HierarchyFtth extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'parent_id', 'project_id', 'created_at', 'updated_at'
'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress'
];
}

Loading…
Cancel
Save