Add discount per item for invoice
This commit is contained in:
@ -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.
|
||||
*
|
||||
|
42
app/Models/Sale/InvoiceItemDiscount.php
Normal file
42
app/Models/Sale/InvoiceItemDiscount.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sale;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
use App\Traits\Currencies;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
class InvoiceItemDiscount extends Model
|
||||
{
|
||||
use Currencies, BelongsToThrough;
|
||||
|
||||
protected $table = 'invoice_item_discounts';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'invoice_item_id', 'rate', 'type', 'name', 'amount'];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Sale\Invoice');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsToThrough('App\Models\Common\Item', 'App\Models\Sale\InvoiceItem', 'invoice_item_id')->withDefault(['name' => trans('general.na')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert rate to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setRateAttribute($value)
|
||||
{
|
||||
$this->attributes['rate'] = (double) $value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user