|
|
@ -38,30 +38,47 @@ class Activity extends Model |
|
|
|
parent::boot(); |
|
|
|
parent::boot(); |
|
|
|
|
|
|
|
|
|
|
|
static::updated(function($data) { |
|
|
|
static::updated(function($data) { |
|
|
|
|
|
|
|
$data->updateBobot(); |
|
|
|
|
|
|
|
$data->updateCostPlanning(); |
|
|
|
|
|
|
|
$data->updatePersentaseProgress(); |
|
|
|
|
|
|
|
$data->updateCostActual(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static::deleted(function($data) { |
|
|
|
|
|
|
|
if(Activity::where("parent_id", $data->parent_id)->count() == 0) |
|
|
|
|
|
|
|
Activity::find($data->parent_id)->update(["type_activity"=>"task"]); |
|
|
|
|
|
|
|
|
|
|
|
// update bobot |
|
|
|
$data->updateCostPlanning(); |
|
|
|
if(Activity::where('version_gantt_id', $data->version_gantt_id)->where("proyek_id", $data->proyek_id)->where('type_activity', 'header')->count() == 0) |
|
|
|
$data->updatePersentaseProgress(); |
|
|
|
|
|
|
|
$data->updateCostActual(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function updateBobot() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) |
|
|
|
$totalCost = Activity::select( |
|
|
|
$totalCost = Activity::select( |
|
|
|
DB::raw('sum(cast(rencana_biaya as double precision))') |
|
|
|
DB::raw('sum(cast(rencana_biaya as double precision))') |
|
|
|
) |
|
|
|
) |
|
|
|
->where("proyek_id", $data->proyek_id) |
|
|
|
->where("proyek_id", $this->proyek_id) |
|
|
|
->where("version_gantt_id", $data->version_gantt_id) |
|
|
|
->where("version_gantt_id", $this->version_gantt_id) |
|
|
|
->whereNull("parent_id") |
|
|
|
->whereNull("parent_id") |
|
|
|
->first(); |
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
$rootActivity = Activity::where('version_gantt_id', $data->version_gantt_id) |
|
|
|
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) |
|
|
|
->where("proyek_id", $data->proyek_id) |
|
|
|
->where("proyek_id", $this->proyek_id) |
|
|
|
->where('type_activity', 'header') |
|
|
|
->where('type_activity', 'header') |
|
|
|
->first(); |
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) |
|
|
|
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) |
|
|
|
->where("proyek_id", $data->proyek_id) |
|
|
|
->where("proyek_id", $this->proyek_id) |
|
|
|
->where("version_gantt_id", $data->version_gantt_id) |
|
|
|
->where("version_gantt_id", $this->version_gantt_id) |
|
|
|
->where("parent_id", $rootActivity->id) |
|
|
|
->where("parent_id", $rootActivity->id) |
|
|
|
->first(); |
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
if($totalCost->sum > 0){ |
|
|
|
if($totalCost->sum > 0){ |
|
|
|
$activities = Activity::where("proyek_id", $data->proyek_id)->where("version_gantt_id", $data->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) { |
|
|
|
$activity->update([ |
|
|
|
$activity->update([ |
|
|
|
"bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100, |
|
|
|
"bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100, |
|
|
@ -70,21 +87,6 @@ class Activity extends Model |
|
|
|
$activity->save(); |
|
|
|
$activity->save(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$data->updateCostPlanning(); |
|
|
|
|
|
|
|
$data->updatePersentaseProgress(); |
|
|
|
|
|
|
|
$data->updateCostActual(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static::deleted(function($data) { |
|
|
|
|
|
|
|
if(Activity::where("parent_id", $data->parent_id)->count() == 0) |
|
|
|
|
|
|
|
Activity::find($data->parent_id)->update(["type_activity"=>"task"]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data->updateCostPlanning(); |
|
|
|
|
|
|
|
$data->updatePersentaseProgress(); |
|
|
|
|
|
|
|
$data->updateCostActual(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function updateCostActual() |
|
|
|
private function updateCostActual() |
|
|
|