Browse Source

update type data and boot function

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

89
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,58 +64,60 @@ 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();
}); });
static::updated(function($data) { static::updated(function($data) {
$data->updateBobot(); $data->updateBobot();
$data->updateCostPlanning(); $data->updateCostPlanning();
if($data->bobot_planning){ if($data->bobot_planning){
$data->updatePersentaseProgress(); $data->updatePersentaseProgress();
} }
$data->updateCostActual(); $data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) { // if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader(); // $data->updateStartEndDateHeader();
// } // }
}); });
static::deleted(function($data) { static::deleted(function($data) {
if (isset($data->parent_id)) { if (isset($data->parent_id)) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0) { if(Activity::where("parent_id", $data->parent_id)->count() == 0) {
$activity = Activity::find($data->parent_id); $activity = Activity::find($data->parent_id);
if ($activity) { if ($activity) {
$activity->update(["type_activity"=>"task"]); $activity->update(["type_activity"=>"task"]);
} }
} }
} }
$data->updateBobot(true); $data->updateBobot(true);
$data->updateCostPlanning(); $data->updateCostPlanning();
if($data->bobot_planning){ if($data->bobot_planning){
$data->updatePersentaseProgress(); $data->updatePersentaseProgress();
} }
$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],
->whereNull('parent_id') ['proyek_id', $this->proyek_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