|
|
@ -38,39 +38,7 @@ class Activity extends Model |
|
|
|
parent::boot(); |
|
|
|
parent::boot(); |
|
|
|
|
|
|
|
|
|
|
|
static::updated(function($data) { |
|
|
|
static::updated(function($data) { |
|
|
|
|
|
|
|
$data->updateBobot(); |
|
|
|
// update bobot |
|
|
|
|
|
|
|
if(Activity::where('version_gantt_id', $data->version_gantt_id)->where("proyek_id", $data->proyek_id)->where('type_activity', 'header')->count() == 0) |
|
|
|
|
|
|
|
$totalCost = Activity::select( |
|
|
|
|
|
|
|
DB::raw('sum(cast(rencana_biaya as double precision))') |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
->where("proyek_id", $data->proyek_id) |
|
|
|
|
|
|
|
->where("version_gantt_id", $data->version_gantt_id) |
|
|
|
|
|
|
|
->whereNull("parent_id") |
|
|
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rootActivity = Activity::where('version_gantt_id', $data->version_gantt_id) |
|
|
|
|
|
|
|
->where("proyek_id", $data->proyek_id) |
|
|
|
|
|
|
|
->where('type_activity', 'header') |
|
|
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) |
|
|
|
|
|
|
|
->where("proyek_id", $data->proyek_id) |
|
|
|
|
|
|
|
->where("version_gantt_id", $data->version_gantt_id) |
|
|
|
|
|
|
|
->where("parent_id", $rootActivity->id) |
|
|
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($totalCost->sum > 0){ |
|
|
|
|
|
|
|
$activities = Activity::where("proyek_id", $data->proyek_id)->where("version_gantt_id", $data->version_gantt_id)->get(); |
|
|
|
|
|
|
|
foreach ($activities as $activity) { |
|
|
|
|
|
|
|
$activity->update([ |
|
|
|
|
|
|
|
"bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100, |
|
|
|
|
|
|
|
"updated_by" => auth()->user() ? auth()->user()->name : "system", |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data->updateCostPlanning(); |
|
|
|
$data->updateCostPlanning(); |
|
|
|
$data->updatePersentaseProgress(); |
|
|
|
$data->updatePersentaseProgress(); |
|
|
|
$data->updateCostActual(); |
|
|
|
$data->updateCostActual(); |
|
|
@ -87,6 +55,40 @@ class Activity extends Model |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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( |
|
|
|
|
|
|
|
DB::raw('sum(cast(rencana_biaya as double precision))') |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
->where("proyek_id", $this->proyek_id) |
|
|
|
|
|
|
|
->where("version_gantt_id", $this->version_gantt_id) |
|
|
|
|
|
|
|
->whereNull("parent_id") |
|
|
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id) |
|
|
|
|
|
|
|
->where("proyek_id", $this->proyek_id) |
|
|
|
|
|
|
|
->where('type_activity', 'header') |
|
|
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) |
|
|
|
|
|
|
|
->where("proyek_id", $this->proyek_id) |
|
|
|
|
|
|
|
->where("version_gantt_id", $this->version_gantt_id) |
|
|
|
|
|
|
|
->where("parent_id", $rootActivity->id) |
|
|
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($totalCost->sum > 0){ |
|
|
|
|
|
|
|
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); |
|
|
|
|
|
|
|
foreach ($activities as $activity) { |
|
|
|
|
|
|
|
$activity->update([ |
|
|
|
|
|
|
|
"bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100, |
|
|
|
|
|
|
|
"updated_by" => auth()->user() ? auth()->user()->name : "system", |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function updateCostActual() |
|
|
|
private function updateCostActual() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual"); |
|
|
|
$actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual"); |
|
|
|