Browse Source

hierarchy & gantt cascade delete

pull/3/head
wahyu 1 year ago
parent
commit
86588d4892
  1. 12
      app/Models/Activity.php
  2. 14
      app/Models/HierarchyFtth.php
  3. 7
      app/Models/VersionGantt.php

12
app/Models/Activity.php

@ -79,8 +79,14 @@ class Activity extends Model
}); });
static::deleted(function($data) { static::deleted(function($data) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0) if (isset($data->parent_id)) {
Activity::find($data->parent_id)->update(["type_activity"=>"task"]); if(Activity::where("parent_id", $data->parent_id)->count() == 0) {
$activity = Activity::find($data->parent_id);
if ($activity) {
$activity->update(["type_activity"=>"task"]);
}
}
}
$data->updateBobot(true); $data->updateBobot(true);
$data->updateCostPlanning(); $data->updateCostPlanning();
@ -100,7 +106,7 @@ class Activity extends Model
->whereNull('parent_id') ->whereNull('parent_id')
->first(); ->first();
if($root->rencana_biaya > 0){ if(isset($root) && $root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
foreach ($activities as $activity) { foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id) if($isDelete && $activity->id == $this->id)

14
app/Models/HierarchyFtth.php

@ -3,6 +3,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\VersionGantt;
class HierarchyFtth extends Model class HierarchyFtth extends Model
{ {
@ -19,10 +20,15 @@ class HierarchyFtth extends Model
parent::boot(); parent::boot();
static::deleted(function($data) { static::deleted(function($data) {
$ftths = HierarchyFtth::where('parent_id', $data->id)->get(); $ftths = HierarchyFtth::where('parent_id', $data->id)->get();
foreach ($ftths as $ftth) { foreach ($ftths as $ftth) {
$ftth->delete(); $ftth->delete();
} }
$gantts = VersionGantt::where('hierarchy_ftth_id', $data->id)->get();
foreach ($gantts as $gantt) {
$gantt->delete();
}
}); });
} }
} }

7
app/Models/VersionGantt.php

@ -38,6 +38,13 @@ class VersionGantt extends Model
static::updated(function($data) { static::updated(function($data) {
$data->updateActDuration(); $data->updateActDuration();
});
static::deleted(function ($data) {
$activities = Activity::where('version_gantt_id', $data->id)->get();
foreach ($activities as $activity) {
$activity->delete();
}
}); });
} }

Loading…
Cancel
Save