Browse Source

cast number to float

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
fa2a668936
  1. 10
      app/Models/AssignMaterial.php

10
app/Models/AssignMaterial.php

@ -15,6 +15,12 @@ class AssignMaterial extends Model
protected $fillable = [
'proyek_id', 'activity_id', 'material_id', 'qty_planning', 'budget', 'plan_date','created_at', 'created_by', 'updated_at', 'updated_by'
];
protected $casts = [
'id' => 'integer',
'price' => 'float',
'qty_planning' => 'float',
];
public static function boot() {
@ -23,13 +29,13 @@ class AssignMaterial extends Model
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->rencana_biaya += floatval($material->price) * floatval($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->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save();
});

Loading…
Cancel
Save