Browse Source

Remove duration modifiers

pull/3/head
Wahyu Ramadhan 2 years ago
parent
commit
e39192b54d
  1. 39
      app/Http/Controllers/ActivityController.php

39
app/Http/Controllers/ActivityController.php

@ -401,23 +401,7 @@ class ActivityController extends Controller
foreach ($data['activities'] as $i => $activity_row) {
$startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek);
$endDate = clone $startDate;
// $endDate->modify('+'.$activity_row['duration'].' days');
$daysRemaining = $activity_row['duration'];
// Loop until the remaining days become zero
while ($daysRemaining > 0) {
$endDate->modify('+1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int)$endDate->format('w');
if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) {
continue; // Skip the day off and continue to the next day
}
$daysRemaining--; // Decrease the remaining days by one
}
Log::info('create ', [$activity_row['duration'], $startDate, $endDate]);
$endDate->modify('+'.$activity_row['duration'].' days');
$endDate->setTime(23, 59, 59);
$input['name'] = $activity_row['name'];
$input['proyek_id'] = $projectId;
@ -511,27 +495,6 @@ class ActivityController extends Controller
$predecessorFinishDate = new \DateTime($predecessorActivity->end_date);
$interval = $predecessorFinishDate->diff(new \DateTime($activity->start_date));
$diff = $interval->days;
unset($activity->level);
$successorStartDate = $predecessorFinishDate;
$successorEndDate = clone $successorStartDate;
$daysRemaining = $activity->duration;
// Loop until the remaining days become zero
while ($daysRemaining > 1) {
$successorEndDate->modify('+1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int)$successorEndDate->format('w');
if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) {
continue; // Skip the day off and continue to the next day
}
$daysRemaining--; // Decrease the remaining days by one
}
Log::info('update ', [$activity->id, $activity->duration, $successorStartDate, $successorEndDate]);
$activity->start_date = $successorStartDate;
$activity->end_date = $successorEndDate;
$activity->save();
Link::create([
'created_by' => $this->currentName,

Loading…
Cancel
Save