discount
This commit is contained in:
@@ -21,7 +21,7 @@ class Invoice extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['attachment'];
|
||||
protected $appends = ['attachment', 'discount'];
|
||||
|
||||
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
|
||||
|
||||
@@ -164,4 +164,26 @@ class Invoice extends Model
|
||||
|
||||
return $this->getMedia('attachment')->last();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the discount percentage.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDiscountAttribute()
|
||||
{
|
||||
$discount = 0;
|
||||
|
||||
foreach ($this->totals as $total) {
|
||||
if ($total->code != 'discount') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$discount = number_format((($total->amount * 100) / $this->amount), 0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user