Add discount per item for invoice

This commit is contained in:
Burak Çakırel
2020-03-21 04:42:45 +03:00
parent 307e93c53c
commit a1ccfc8b22
15 changed files with 235 additions and 60 deletions

View File

@ -17,7 +17,18 @@ class InvoiceItem extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'quantity', 'price', 'total', 'tax'];
protected $fillable = [
'company_id',
'invoice_id',
'item_id',
'name',
'quantity',
'price',
'total',
'tax',
'discount_rate',
'discount_type',
];
/**
* Clonable relationships.
@ -83,6 +94,22 @@ class InvoiceItem 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.
*