Browse Source

Fix backend duration

pull/3/head
Wahyu Ramadhan 1 year ago
parent
commit
24234e3f86
  1. 17
      app/Http/Controllers/ActivityController.php

17
app/Http/Controllers/ActivityController.php

@ -401,7 +401,21 @@ 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('-1 day');
$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
}
$endDate->setTime(23, 59, 59);
$input['name'] = $activity_row['name'];
$input['proyek_id'] = $projectId;
@ -744,6 +758,7 @@ class ActivityController extends Controller
$data = $request->all();
foreach ($data as $value) {
$activity = Activity::find($value['id']);
$activity->duration = $value['duration'];
$activity->start_date = $value['start_date'];
$activity->end_date = $value['end_date'];
$activity->save();

Loading…
Cancel
Save