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'
];
protected $casts = [
'rencana_biaya' => 'double'
];
public function getStartDateAttribute($value)
{
@ -61,58 +64,60 @@ class Activity extends Model
public static function boot() {
parent::boot();
static::updating(function($data) {
$data->logPersentaseProgress();
});
static::updated(function($data) {
$data->updateBobot();
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader();
// }
});
static::deleted(function($data) {
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();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
$data->updateStartEndDateHeader();
});
DB::transaction(function() {
static::updating(function($data) {
$data->logPersentaseProgress();
});
static::updated(function($data) {
$data->updateBobot();
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader();
// }
});
static::deleted(function($data) {
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();
if($data->bobot_planning){
$data->updatePersentaseProgress();
}
$data->updateCostActual();
$data->updateStartEndDateHeader();
});
},5);
}
private function updateBobot($isDelete = false)
{
$root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->whereNull('parent_id')
$root = Activity::where([
['version_gantt_id', $this->version_gantt_id],
['proyek_id', $this->proyek_id]
])
->whereNull('parent_id')
->first();
if(isset($root) && $root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
if(isset($root) && doubleval($root->rencana_biaya) > 0){
$activities = Activity::where([['proyek_id', $this->proyek_id],['version_gantt_id', $this->version_gantt_id]])->get();
foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id)
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->saveQuietly();

Loading…
Cancel
Save