Item multiple tax added
This commit is contained in:
@ -26,7 +26,7 @@ class Item extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'description', 'sale_price', 'purchase_price', 'category_id', 'tax_id', 'enabled'];
|
||||
protected $fillable = ['company_id', 'name', 'description', 'sale_price', 'purchase_price', 'category_id', 'enabled'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
@ -46,14 +46,19 @@ class Item extends Model
|
||||
*/
|
||||
protected $sortable = ['name', 'category', 'sale_price', 'purchase_price', 'enabled'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $cloneable_relations = ['taxes'];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Category')->withDefault(['name' => trans('general.na')]);
|
||||
}
|
||||
|
||||
public function tax()
|
||||
public function taxes()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax')->withDefault(['name' => trans('general.na'), 'rate' => 0]);
|
||||
return $this->hasMany('App\Models\Common\ItemTax');
|
||||
}
|
||||
|
||||
public function bill_items()
|
||||
@ -81,6 +86,16 @@ class Item extends Model
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTaxIdsAttribute()
|
||||
{
|
||||
return $this->taxes()->pluck('tax_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope autocomplete.
|
||||
*
|
||||
|
25
app/Models/Common/ItemTax.php
Normal file
25
app/Models/Common/ItemTax.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Common;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
use Bkwld\Cloner\Cloneable;
|
||||
|
||||
class ItemTax extends Model
|
||||
{
|
||||
use Cloneable;
|
||||
|
||||
protected $table = 'item_taxes';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'item_id', 'tax_id'];
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax')->withDefault(['name' => trans('general.na'), 'rate' => 0]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user