diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 23ef012..35615b2 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -348,6 +348,7 @@ class ActivityController extends Controller Activity::where('version_gantt_id', $data['ganttId'])->delete(); $projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id; + $dayOffs = VersionGantt::find($data['ganttId'])->first()->config_dayoff; $activityStack = []; @@ -400,7 +401,23 @@ 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'); + // $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->setTime(23, 59, 59); $input['name'] = $activity_row['name']; $input['proyek_id'] = $projectId; @@ -494,6 +511,27 @@ 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, diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 29ab815..1b98d03 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -36,6 +36,11 @@ class Activity extends Model public function getStartDateAttribute($value) { + if ($value instanceof \DateTime) { + return Carbon::instance($value) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } return Carbon::createFromTimestamp(strtotime($value)) ->timezone(env('APP_TIMEZONE')) ->toDateTimeString(); @@ -43,6 +48,11 @@ class Activity extends Model public function getEndDateAttribute($value) { + if ($value instanceof \DateTime) { + return Carbon::instance($value) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } return Carbon::createFromTimestamp(strtotime($value)) ->timezone(env('APP_TIMEZONE')) ->toDateTimeString();