Add discount per item feature to the bills

This commit is contained in:
Burak Çakırel
2020-03-24 00:16:11 +03:00
parent e2148ef9a7
commit 6903a44bce
17 changed files with 159 additions and 150 deletions

View File

@ -18,7 +18,18 @@ class BillItem extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'bill_id', 'item_id', 'name', 'quantity', 'price', 'total', 'tax'];
protected $fillable = [
'company_id',
'bill_id',
'item_id',
'name',
'quantity',
'price',
'total',
'tax',
'discount_rate',
'discount_type',
];
/**
* Clonable relationships.
@ -84,6 +95,22 @@ class BillItem extends Model
$this->attributes['tax'] = (double) $value;
}
/**
* Get the formatted discount.
*
* @return string
*/
public function getDiscountRateAttribute($value)
{
if (setting('localisation.percent_position', 'after') === 'after') {
$text = ($this->discount_type === 'normal') ? $value . '%' : $value;
} else {
$text = ($this->discount_type === 'normal') ? '%' . $value : $value;
}
return $text;
}
/**
* Convert tax to Array.
*