This commit is contained in:
denisdulici
2019-01-07 18:38:34 +03:00
parent 4632eb0856
commit a844b7a721
15 changed files with 117 additions and 78 deletions

View File

@ -17,7 +17,7 @@ class InvoiceItem extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax', 'tax_id'];
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax'];
public function invoice()
{
@ -29,16 +29,11 @@ class InvoiceItem extends Model
return $this->belongsTo('App\Models\Common\Item');
}
public function itemTaxes()
public function taxes()
{
return $this->hasMany('App\Models\Income\InvoiceItemTax', 'invoice_item_id', 'id');
}
public function tax()
{
return $this->belongsTo('App\Models\Setting\Tax');
}
/**
* Convert price to double.
*
@ -71,23 +66,4 @@ class InvoiceItem extends Model
{
$this->attributes['tax'] = (double) $value;
}
/**
* Convert tax to double.
*
* @param string $value
* @return void
*/
public function getTaxIdAttribute($value)
{
$tax_ids = [];
if (!empty($value)) {
$tax_ids[] = $value;
return $tax_ids;
}
return $this->itemTaxes->pluck('tax_id');
}
}