2018-10-22 15:53:56 +03:00
|
|
|
<?php
|
|
|
|
|
2019-12-31 15:49:09 +03:00
|
|
|
namespace App\Models\Sale;
|
2018-10-22 15:53:56 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Abstracts\Model;
|
2018-10-22 15:53:56 +03:00
|
|
|
use App\Traits\Currencies;
|
2020-01-20 22:58:49 +03:00
|
|
|
use Znck\Eloquent\Traits\BelongsToThrough;
|
2018-10-22 15:53:56 +03:00
|
|
|
|
|
|
|
class InvoiceItemTax extends Model
|
|
|
|
{
|
2020-01-20 22:58:49 +03:00
|
|
|
use Currencies, BelongsToThrough;
|
2018-10-22 15:53:56 +03:00
|
|
|
|
|
|
|
protected $table = 'invoice_item_taxes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attributes that should be mass-assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = ['company_id', 'invoice_id', 'invoice_item_id', 'tax_id', 'name', 'amount'];
|
|
|
|
|
|
|
|
public function invoice()
|
|
|
|
{
|
2019-12-31 15:49:09 +03:00
|
|
|
return $this->belongsTo('App\Models\Sale\Invoice');
|
2018-10-22 15:53:56 +03:00
|
|
|
}
|
|
|
|
|
2020-01-20 22:58:49 +03:00
|
|
|
public function item()
|
|
|
|
{
|
|
|
|
return $this->belongsToThrough('App\Models\Common\Item', 'App\Models\Sale\InvoiceItem', 'invoice_item_id')->withDefault(['name' => trans('general.na')]);
|
|
|
|
}
|
|
|
|
|
2018-10-22 15:53:56 +03:00
|
|
|
public function tax()
|
|
|
|
{
|
2020-02-25 16:21:04 +03:00
|
|
|
return $this->belongsTo('App\Models\Setting\Tax')->withDefault(['name' => trans('general.na'), 'rate' => 0]);
|
2018-10-22 15:53:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert amount to double.
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setAmountAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['amount'] = (double) $value;
|
|
|
|
}
|
|
|
|
}
|