Browse Source

hierarchy & gantt cascade delete

pull/3/head
wahyu 1 year ago
parent
commit
86588d4892
  1. 12
      app/Models/Activity.php
  2. 16
      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) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0)
Activity::find($data->parent_id)->update(["type_activity"=>"task"]);
if (isset($data->parent_id)) {
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->updateCostPlanning();
@ -100,7 +106,7 @@ class Activity extends Model
->whereNull('parent_id')
->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();
foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id)

16
app/Models/HierarchyFtth.php

@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\VersionGantt;
class HierarchyFtth extends Model
{
@ -14,15 +15,20 @@ class HierarchyFtth extends Model
protected $fillable = [
'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning'
];
public static function boot() {
parent::boot();
static::deleted(function($data) {
$ftths = HierarchyFtth::where('parent_id', $data->id)->get();
foreach ($ftths as $ftth) {
$ftth->delete();
}
$ftths = HierarchyFtth::where('parent_id', $data->id)->get();
foreach ($ftths as $ftth) {
$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) {
$data->updateActDuration();
});
static::deleted(function ($data) {
$activities = Activity::where('version_gantt_id', $data->id)->get();
foreach ($activities as $activity) {
$activity->delete();
}
});
}

Loading…
Cancel
Save