|
|
|
@ -6,6 +6,7 @@ use App\Models\CommentActivity;
|
|
|
|
|
use App\Models\Link; |
|
|
|
|
use App\Models\Project; |
|
|
|
|
use App\Models\TemplateGantt; |
|
|
|
|
use App\Models\VersionGantt; |
|
|
|
|
use App\Models\UserToActivity; |
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
|
|
|
@ -279,5 +280,110 @@ class ActivityController extends Controller
|
|
|
|
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function import(Request $request) |
|
|
|
|
{ |
|
|
|
|
$data = $request->all(); |
|
|
|
|
|
|
|
|
|
$data['created_by'] = $this->currentName; |
|
|
|
|
|
|
|
|
|
Activity::where('version_gantt_id', $data['ganttId'])->delete(); |
|
|
|
|
|
|
|
|
|
$projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id; |
|
|
|
|
|
|
|
|
|
$activityStack = []; |
|
|
|
|
|
|
|
|
|
foreach ($data['activities'] as $i => $activity_row) { |
|
|
|
|
$startDate = \DateTime::createFromFormat('d-m-y', $activity_row['start_date']); |
|
|
|
|
$endDate = \DateTime::createFromFormat('d-m-y', $activity_row['end_date']); |
|
|
|
|
|
|
|
|
|
$input['name'] = $activity_row['name']; |
|
|
|
|
$input['proyek_id'] = $projectId; |
|
|
|
|
$input['version_gantt_id'] = $data['ganttId']; |
|
|
|
|
$input['parent_id'] = null; |
|
|
|
|
$input['start_date'] = $startDate->format('Y-m-d'); |
|
|
|
|
$input['end_date'] = $endDate->format('Y-m-d'); |
|
|
|
|
$input['duration'] = $activity_row['duration']; |
|
|
|
|
$input['bobot_planning'] = $activity_row['weight']; |
|
|
|
|
$input['persentase_progress'] = 0; |
|
|
|
|
$input['type_activity'] = $i == 0 ? "header" : "task"; |
|
|
|
|
$input['created_by'] = $this->currentName; |
|
|
|
|
|
|
|
|
|
if (!$activity = Activity::create($input)) { |
|
|
|
|
Activity::where('version_gantt_id', $data['ganttId'])->delete(); |
|
|
|
|
return response()->json(['status' => 'error', 'message' => 'Input failed on ' . $activity['name'], 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['activities'][$i]['activity_id'] = $activity->id; |
|
|
|
|
|
|
|
|
|
if ($i == 0) { |
|
|
|
|
$activity->type_activity = "project"; |
|
|
|
|
$activity->save(); |
|
|
|
|
$activity->level = $activity_row['level']; |
|
|
|
|
array_push($activityStack, $activity); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$activity->level = $activity_row['level']; |
|
|
|
|
|
|
|
|
|
if ($lastStack = end($activityStack)) { |
|
|
|
|
$levelLowerThanLastStack = $activity->level < $lastStack->level; |
|
|
|
|
$levelEqualWithLastStack = $activity->level == $lastStack->level; |
|
|
|
|
|
|
|
|
|
if ($levelLowerThanLastStack) { |
|
|
|
|
$lastStackIsNotRight = $levelLowerThanLastStack; |
|
|
|
|
do { |
|
|
|
|
array_pop($activityStack); |
|
|
|
|
$lastStack = end($activityStack); |
|
|
|
|
if ($activity->level > $lastStack->level) |
|
|
|
|
$lastStackIsNotRight = false; |
|
|
|
|
} while ($lastStackIsNotRight); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($levelEqualWithLastStack) { |
|
|
|
|
array_pop($activityStack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$activity->parent_id = $activityStack[count($activityStack) - 1]->id ?? null; |
|
|
|
|
// there should be better way to except / filter attribute level before save because it's cause error |
|
|
|
|
// cant use except() / filter() on $activity collection somehow |
|
|
|
|
unset($activity->level); |
|
|
|
|
$activity->save(); |
|
|
|
|
$activity->level = $activity_row['level']; |
|
|
|
|
|
|
|
|
|
if (@$activityStack[count($activityStack) - 1]->level != $activity->level && $activity->level != $data['activities'][$i - 1]['level']) { |
|
|
|
|
array_push($activityStack, $activity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($activity->level < @$data['activities'][$i + 1]['level']) { |
|
|
|
|
unset($activity->level); |
|
|
|
|
$activity->type_activity = "project"; |
|
|
|
|
$activity->save(); |
|
|
|
|
$activity->level = $activity_row['level']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($activity_row['predecessor'])) { |
|
|
|
|
$key = array_search($activity_row['predecessor'], array_column($data['activities'], 'no')); |
|
|
|
|
|
|
|
|
|
if (!$predecessorActivity = Activity::find($data['activities'][$key]['activity_id'])) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
$predecessorFinishDate = new \DateTime($predecessorActivity->end_date); |
|
|
|
|
$interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date)); |
|
|
|
|
$diff = $interval->days; |
|
|
|
|
|
|
|
|
|
Link::create([ |
|
|
|
|
'created_by' => $this->currentName, |
|
|
|
|
's_activity_id' => $predecessorActivity->id, |
|
|
|
|
't_activity_id' => $activity->id, |
|
|
|
|
'type_link' => 0, |
|
|
|
|
'code_link' => 'FS', |
|
|
|
|
'version_gantt_id' => $data['ganttId'], |
|
|
|
|
'lag' => $diff > 1 ? $diff : null, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|