Browse Source

update type data and boot function

pull/1/head
wahyuun 10 months ago
parent
commit
7e74b4434a
  1. 19
      app/Models/Activity.php

19
app/Models/Activity.php

@ -33,6 +33,9 @@ class Activity extends Model
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense' 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense'
]; ];
protected $casts = [
'rencana_biaya' => 'double'
];
public function getStartDateAttribute($value) public function getStartDateAttribute($value)
{ {
@ -61,7 +64,7 @@ class Activity extends Model
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
DB::transaction(function() {
static::updating(function($data) { static::updating(function($data) {
$data->logPersentaseProgress(); $data->logPersentaseProgress();
}); });
@ -96,23 +99,25 @@ class Activity extends Model
$data->updateCostActual(); $data->updateCostActual();
$data->updateStartEndDateHeader(); $data->updateStartEndDateHeader();
}); });
},5);
} }
private function updateBobot($isDelete = false) private function updateBobot($isDelete = false)
{ {
$root = Activity::where('version_gantt_id', $this->version_gantt_id) $root = Activity::where([
->where("proyek_id", $this->proyek_id) ['version_gantt_id', $this->version_gantt_id],
['proyek_id', $this->proyek_id]
])
->whereNull('parent_id') ->whereNull('parent_id')
->first(); ->first();
if(isset($root) && $root->rencana_biaya > 0){ if(isset($root) && doubleval($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],['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)
continue; continue;
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100; $activity->bobot_planning = ( doubleval($activity->rencana_biaya) / doubleval($root->rencana_biaya)) * 100;
$activity->updated_by = auth()->user() ? auth()->user()->name : "system"; $activity->updated_by = auth()->user() ? auth()->user()->name : "system";
$activity->saveQuietly(); $activity->saveQuietly();

Loading…
Cancel
Save