|
|
|
@ -3,6 +3,8 @@
|
|
|
|
|
namespace App\Models; |
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
use App\Models\Activity; |
|
|
|
|
use App\Models\AssignMaterial; |
|
|
|
|
|
|
|
|
|
class ReportActivityMaterial extends Model |
|
|
|
|
{ |
|
|
|
@ -15,4 +17,29 @@ class ReportActivityMaterial extends Model
|
|
|
|
|
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id', |
|
|
|
|
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
public static function boot() { |
|
|
|
|
parent::boot(); |
|
|
|
|
|
|
|
|
|
static::created(function($data) { |
|
|
|
|
|
|
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
|
$assignedMaterial = AssignMaterial::find($data->assign_material_id); |
|
|
|
|
|
|
|
|
|
$activity->biaya_actual += floatval($assignedMaterial->budget) * floatval($data->qty); |
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
static::deleted(function($data) { |
|
|
|
|
|
|
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
|
$assignedMaterial = AssignMaterial::find($data->assign_material_id); |
|
|
|
|
|
|
|
|
|
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); |
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|