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();
$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'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) {
$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'){
$reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){
@ -434,19 +438,25 @@ class ProjectController extends Controller
}
$activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early
$activity->actual_start = $reports[$i]['min_date'];
$activity->save();
}
foreach($activities as $activity) {
$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");
$dayOffs = VersionGantt::where('id', $activity->version_gantt_id)->first()->config_dayoff;
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$diff = date_diff($startDate, $endDate);
$duration = $diff->days + 1;
$daysRemaining = $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
$duration--;
}
$daysRemaining--; // Decrease the remaining days by one
}
$activity->duration = $duration;
$activity->actual_start = $reports[$i]['min_date'];
$activity->save();
}

Loading…
Cancel
Save