Browse Source

Remove weight pro rate

pull/3/head
Wahyu Ramadhan 2 years ago
parent
commit
9ae2f37029
  1. 90
      app/Http/Controllers/ActivityController.php

90
app/Http/Controllers/ActivityController.php

@ -351,51 +351,51 @@ class ActivityController extends Controller
$activityStack = []; $activityStack = [];
$hasWeight = false; // $hasWeight = false;
//
foreach ($data['activities'] as $key => $value) { // foreach ($data['activities'] as $key => $value) {
if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){ // if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){
$hasWeight = true; // $hasWeight = true;
break; // break;
} // }
} // }
//
if(!$hasWeight){ // if(!$hasWeight){
foreach ($data['activities'] as $key => $value) { // foreach ($data['activities'] as $key => $value) {
if($key == 0){ // if($key == 0){
$data['activities'][$key]['weight'] = 100; // $data['activities'][$key]['weight'] = 100;
} else { // } else {
$parentWeight = 0; // $parentWeight = 0;
$siblingsCount = 1; // $siblingsCount = 1;
//
$i = $key; // $i = $key;
while($i > 0){ // while($i > 0){
if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){ // if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){
$parentWeight = $data['activities'][$i - 1]['weight']; // $parentWeight = $data['activities'][$i - 1]['weight'];
break; // break;
} // }
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ // if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
$siblingsCount++; // $siblingsCount++;
} // }
$i--; // $i--;
} // }
//
$i = $key+1; // $i = $key+1;
while($i < count($data['activities'])){ // while($i < count($data['activities'])){
if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){ // if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){
break; // break;
} // }
// Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']); // // Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']);
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){ // if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
$siblingsCount++; // $siblingsCount++;
} // }
$i++; // $i++;
} // }
//
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount; // $data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
} // }
}; // };
} // }
$projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first(); $projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first();
foreach ($data['activities'] as $i => $activity_row) { foreach ($data['activities'] as $i => $activity_row) {
$startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek); $startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek);

Loading…
Cancel
Save