fixed discount percentage #297

This commit is contained in:
denisdulici 2018-04-18 14:34:33 +03:00
parent acf8247c98
commit c37203076c
2 changed files with 12 additions and 16 deletions

View File

@ -170,18 +170,16 @@ class Bill extends Model
*/ */
public function getDiscountAttribute() public function getDiscountAttribute()
{ {
$discount = 0; $percent = 0;
foreach ($this->totals as $total) { $discount = $this->totals()->where('code', 'discount')->value('amount');
if ($total->code != 'discount') {
continue;
}
$discount = number_format((($total->amount * 100) / $this->amount), 0); if ($discount) {
$sub_total = $this->totals()->where('code', 'sub_total')->value('amount');
break; $percent = number_format((($discount * 100) / $sub_total), 0);
} }
return $discount; return $percent;
} }
} }

View File

@ -172,18 +172,16 @@ class Invoice extends Model
*/ */
public function getDiscountAttribute() public function getDiscountAttribute()
{ {
$discount = 0; $percent = 0;
foreach ($this->totals as $total) { $discount = $this->totals()->where('code', 'discount')->value('amount');
if ($total->code != 'discount') {
continue;
}
$discount = number_format((($total->amount * 100) / $this->amount), 0); if ($discount) {
$sub_total = $this->totals()->where('code', 'sub_total')->value('amount');
break; $percent = number_format((($discount * 100) / $sub_total), 0);
} }
return $discount; return $percent;
} }
} }