diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 49bcc1e..7e06d88 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -63,6 +63,9 @@ class Activity extends Model $data->updatePersentaseProgress(); $data->updateCostActual(); } + if($this->start_date != request()->start_date || $this->end_date != request()->end_date) { + $data->updateStartEndDateHeader(); + } }); static::deleted(function($data) { @@ -75,6 +78,9 @@ class Activity extends Model $data->updatePersentaseProgress(); $data->updateCostActual(); } + if($this->start_date != request()->start_date || $this->end_date != request()->end_date) { + $data->updateStartEndDateHeader(); + } }); } @@ -160,6 +166,18 @@ class Activity extends Model ]); } + private function updateStartEndDateHeader() + { + $earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->oldest('start_date')->pluck('start_date')->first(); + $latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->latest('end_date')->pluck('end_date')->first(); + if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) { + $header->update([ + "start_date" => $earliestStartDate, + "end_date" => $latestEndDate + ]); + } + } + public function getJobsDoneAttribute() { if(!ReportActivityMaterial::where('activity_id', $this->id)->first())