Browse Source

cast number to float

pull/3/head
Muhammad Sulaiman Yusuf 3 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 = [ 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'
];
protected $casts = [
'id' => 'integer',
'price' => 'float',
'qty_planning' => 'float',
]; ];
public static function boot() { public static function boot() {
@ -23,13 +29,13 @@ class AssignMaterial extends Model
static::created(function($data) { static::created(function($data) {
$activity = Activity::find($data->activity_id); $activity = Activity::find($data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first(); $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(); $activity->save();
}); });
static::deleted(function($data) { static::deleted(function($data) {
$activity = Activity::where('id', $data->activity_id)->first(); $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(); $activity->save();
}); });

Loading…
Cancel
Save