Hoan thien core finance v2
This commit is contained in:
@@ -33,6 +33,11 @@ class Contract extends Model
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function paymentTemplate()
|
||||
{
|
||||
return $this->belongsTo(PaymentTemplate::class);
|
||||
}
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->belongsToMany(Customer::class, 'contract_customers')
|
||||
@@ -73,6 +78,19 @@ class Contract extends Model
|
||||
return $this->hasMany(PaymentFine::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Giá trị sau chiết khấu.
|
||||
*/
|
||||
public function getFinalValueAttribute(): float
|
||||
{
|
||||
$result = \App\Services\DiscountEngine::calculate(
|
||||
(float) $this->total_value,
|
||||
$this->discount_details
|
||||
);
|
||||
|
||||
return $result['final_value'];
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saving(function ($contract) {
|
||||
|
||||
Reference in New Issue
Block a user