akaunting/app/Models/Purchase/BillItemTax.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2018-10-22 13:57:35 +00:00
<?php
2019-12-31 12:49:09 +00:00
namespace App\Models\Purchase;
2018-10-22 13:57:35 +00:00
2019-11-16 07:21:14 +00:00
use App\Abstracts\Model;
2018-10-22 13:57:35 +00:00
use App\Traits\Currencies;
2020-01-20 20:50:29 +00:00
use Znck\Eloquent\Traits\BelongsToThrough;
2018-10-22 13:57:35 +00:00
class BillItemTax extends Model
{
2020-01-20 20:50:29 +00:00
use Currencies, BelongsToThrough;
2018-10-22 13:57:35 +00:00
protected $table = 'bill_item_taxes';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'bill_id', 'bill_item_id', 'tax_id', 'name', 'amount'];
public function bill()
{
2019-12-31 12:49:09 +00:00
return $this->belongsTo('App\Models\Purchase\Bill');
2018-10-22 13:57:35 +00:00
}
2020-01-20 20:50:29 +00:00
public function item()
{
2020-02-25 13:21:04 +00:00
return $this->belongsToThrough('App\Models\Common\Item', 'App\Models\Purchase\BillItem', 'bill_item_id')->withDefault(['name' => trans('general.na')]);
2020-01-20 20:50:29 +00:00
}
2018-10-22 13:57:35 +00:00
public function tax()
{
2020-02-25 13:21:04 +00:00
return $this->belongsTo('App\Models\Setting\Tax')->withDefault(['name' => trans('general.na'), 'rate' => 0]);
2018-10-22 13:57:35 +00:00
}
/**
* Convert amount to double.
*
* @param string $value
* @return void
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = (double) $value;
}
}