wahyu
1 year ago
1 changed files with 46 additions and 46 deletions
@ -1,46 +1,46 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Models; |
namespace App\Models; |
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model; |
use Illuminate\Database\Eloquent\Model; |
||||||
use App\Models\RequestMaterial; |
use App\Models\RequestMaterial; |
||||||
use App\Models\Activity; |
use App\Models\Activity; |
||||||
use App\Models\ReportActivityMaterial; |
use App\Models\ReportActivityMaterial; |
||||||
|
|
||||||
class AssignMaterial extends Model |
class AssignMaterial extends Model |
||||||
{ |
{ |
||||||
protected $table = 'assign_material_to_activity'; |
protected $table = 'assign_material_to_activity'; |
||||||
|
|
||||||
const CREATED_AT = 'created_at'; |
const CREATED_AT = 'created_at'; |
||||||
const UPDATED_AT = 'updated_at'; |
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
protected $fillable = [ |
protected $fillable = [ |
||||||
'proyek_id', 'activity_id', 'material_id', 'qty_planning', |
'proyek_id', 'activity_id', 'material_id', 'qty_planning', |
||||||
'budget', 'plan_date', 'status_activity', 'type', |
'budget', 'plan_date', 'status_activity', 'type', |
||||||
'created_at', 'created_by', 'updated_at', 'updated_by' |
'created_at', 'created_by', 'updated_at', 'updated_by' |
||||||
]; |
]; |
||||||
|
|
||||||
protected $casts = [ |
protected $casts = [ |
||||||
'id' => 'integer', |
'id' => 'integer', |
||||||
'budget' => 'string', |
'budget' => 'string', |
||||||
]; |
]; |
||||||
|
|
||||||
public static function boot() { |
public static function boot() { |
||||||
parent::boot(); |
parent::boot(); |
||||||
|
|
||||||
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 += floatval($material->price) * floatval($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) { |
||||||
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); |
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); |
||||||
$activity = Activity::where('id', $data->activity_id)->first(); |
$activity = Activity::where('id', $data->activity_id)->first(); |
||||||
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); |
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); |
||||||
$activity->save(); |
$activity->save(); |
||||||
}); |
}); |
||||||
|
|
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue