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'
];
protected $casts = [
'rencana_biaya' => 'double'
];
public function getStartDateAttribute($value)
{
@ -61,7 +64,7 @@ class Activity extends Model
public static function boot() {
parent::boot();
DB::transaction(function() {
static::updating(function($data) {
$data->logPersentaseProgress();
});
@ -96,23 +99,25 @@ class Activity extends Model
$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)
$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