|
|
@ -3,6 +3,8 @@ |
|
|
|
namespace App\Models; |
|
|
|
namespace App\Models; |
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
|
|
|
use App\Models\RequestMaterial; |
|
|
|
|
|
|
|
use App\Models\Activity; |
|
|
|
|
|
|
|
|
|
|
|
class AssignMaterial extends Model |
|
|
|
class AssignMaterial extends Model |
|
|
|
{ |
|
|
|
{ |
|
|
@ -14,4 +16,22 @@ class AssignMaterial extends Model |
|
|
|
protected $fillable = [ |
|
|
|
protected $fillable = [ |
|
|
|
'proyek_id', 'activity_id', 'material_id', 'qty_planning', 'budget', 'plan_date','created_at', 'created_by', 'updated_at', 'updated_by' |
|
|
|
'proyek_id', 'activity_id', 'material_id', 'qty_planning', 'budget', 'plan_date','created_at', 'created_by', 'updated_at', 'updated_by' |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function boot() { |
|
|
|
|
|
|
|
parent::boot(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static::created(function($data) { |
|
|
|
|
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
|
|
|
|
$material = RequestMaterial::where("id", $data->material_id)->first(); |
|
|
|
|
|
|
|
$activity->rencana_biaya += $activity->rencana_biaya + ($material->price * $data->qty_planning); |
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static::deleted(function($data) { |
|
|
|
|
|
|
|
$activity = Activity::where('id', $data->activity_id)->first(); |
|
|
|
|
|
|
|
$activity->rencana_biaya -= $data->budget * $data->qty_planning; |
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|