Browse Source

fix sync report

pull/3/head
wahyu 1 year ago
parent
commit
4f3f4aa71d
  1. 44
      app/Http/Controllers/ProjectController.php

44
app/Http/Controllers/ProjectController.php

@ -416,17 +416,21 @@ class ProjectController extends Controller
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport);
} }
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->save();
} }
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) { for ($i=0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']); $activity = Activity::find($reports[$i]['activity_id']);
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
}
if($reports[$i]['status'] != 'done'){ if($reports[$i]['status'] != 'done'){
$reports[$i]['max_date']->modify('-1 day'); $reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){ }else if($reports[$i]['status'] == 'done'){
@ -434,19 +438,25 @@ class ProjectController extends Controller
} }
$activity->start_date = $reports[$i]['min_date']; //same early $activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early
$activity->actual_start = $reports[$i]['min_date']; $dayOffs = VersionGantt::where('id', $activity->version_gantt_id)->first()->config_dayoff;
$activity->save(); $startDate = new DateTime($activity->start_date);
} $endDate = new DateTime($activity->end_date);
$diff = date_diff($startDate, $endDate);
foreach($activities as $activity) { $duration = $diff->days + 1;
$successor = Link::where('t_activity_id', $activity->id)->first(); $daysRemaining = $duration;
if ($successor) { // Loop until the remaining days become zero
$predecessor = Activity::find($successor->s_activity_id); while ($daysRemaining > 0) {
$activity->start_date = $predecessor->end_date; $endDate->modify('-1 day');
$end_date = new DateTime($activity->start_date); // Check if the current day is a day off (Sunday or Saturday)
$end_date->modify("+" . $activity->duration . " days"); $currentDayOfWeek = (int) $endDate->format('w');
$activity->end_date = $end_date->format("Y-m-d H:i:sO"); if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
// continue; // Skip the day off and continue to the next day
$duration--;
}
$daysRemaining--; // Decrease the remaining days by one
} }
$activity->duration = $duration;
$activity->actual_start = $reports[$i]['min_date'];
$activity->save(); $activity->save();
} }

Loading…
Cancel
Save