akaunting/app/Models/Purchase/BillItemTax.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2018-10-22 16:57:35 +03:00
<?php
2019-12-31 15:49:09 +03:00
namespace App\Models\Purchase;
2018-10-22 16:57:35 +03:00
2019-11-16 10:21:14 +03:00
use App\Abstracts\Model;
2018-10-22 16:57:35 +03:00
use App\Traits\Currencies;
2020-01-20 23:50:29 +03:00
use Znck\Eloquent\Traits\BelongsToThrough;
2018-10-22 16:57:35 +03:00
class BillItemTax extends Model
{
2020-01-20 23:50:29 +03:00
use Currencies, BelongsToThrough;
2018-10-22 16:57:35 +03: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 15:49:09 +03:00
return $this->belongsTo('App\Models\Purchase\Bill');
2018-10-22 16:57:35 +03:00
}
2020-01-20 23:50:29 +03:00
public function item()
{
2020-02-25 16:21:04 +03:00
return $this->belongsToThrough('App\Models\Common\Item', 'App\Models\Purchase\BillItem', 'bill_item_id')->withDefault(['name' => trans('general.na')]);
2020-01-20 23:50:29 +03:00
}
2018-10-22 16:57:35 +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 16:57:35 +03:00
}
/**
* Convert amount to double.
*
* @param string $value
* @return void
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = (double) $value;
}
}