This commit is contained in:
denisdulici
2018-04-17 16:40:52 +03:00
parent cfda5585a4
commit 18a3a3f6cb
19 changed files with 344 additions and 88 deletions

View File

@ -15,6 +15,13 @@ class Bill extends Model
protected $table = 'bills';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['attachment', 'discount'];
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
/**
@ -155,4 +162,26 @@ class Bill 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;
}
}