Browse Source

logger progress

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
deea3080d0
  1. 21
      app/Models/Activity.php
  2. 19
      app/Models/ActivityProgressLog.php

21
app/Models/Activity.php

@ -3,6 +3,7 @@
namespace App\Models;
use App\Models\AssignMaterial;
use App\Models\ActivityProgressLog;
use App\Models\AssignTools;
use App\Models\ReportActivityMaterial;
use Illuminate\Database\Eloquent\Model;
@ -50,11 +51,17 @@ 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->persentase_bobot){
$data->updatePersentaseProgress();
$data->updateCostActual();
}
});
static::deleted(function($data) {
@ -63,8 +70,10 @@ class Activity extends Model
$data->updateBobot(true);
$data->updateCostPlanning();
if($data->persentase_bobot){
$data->updatePersentaseProgress();
$data->updateCostActual();
}
});
}
@ -138,6 +147,18 @@ class Activity extends Model
}
}
private function logPersentaseProgress()
{
ActivityProgressLog::create([
'version_gantt_id' => $this->version_gantt_id,
'activity_id' => request()->id,
'old_percentage' => $this->persentase_progress,
'new_percentage' => request()->persentase_progress,
'variance' => $this->persentase_progress - request()->persentase_progress,
'created_by'=> "system"
]);
}
public function getJobsDoneAttribute()
{
if(!ReportActivityMaterial::where('activity_id', $this->id)->first())

19
app/Models/ActivityProgressLog.php

@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ActivityProgressLog extends Model
{
protected $table = 'm_activity_progress_log';
const CREATED_AT = 'created_at';
const UPDATED_AT = null;
protected $fillable = [
'version_gantt_id', 'activity_id', 'old_percentage', 'new_percentage', 'variance',
'created_at', 'created_by'
];
}
Loading…
Cancel
Save