Browse Source

Fix import WIP

pull/3/head
Wahyu Ramadhan 2 years ago
parent
commit
5a7a269069
  1. 40
      app/Http/Controllers/ActivityController.php
  2. 10
      app/Models/Activity.php

40
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,

10
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();

Loading…
Cancel
Save