77 lines
1.6 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Models\Setting;
2019-11-16 10:21:14 +03:00
use App\Abstracts\Model;
2017-09-14 22:21:00 +03:00
class Tax extends Model
{
protected $table = 'taxes';
2018-04-16 19:01:29 +03:00
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['title'];
2017-09-14 22:21:00 +03:00
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
2018-11-06 17:55:31 +03:00
protected $fillable = ['company_id', 'name', 'rate', 'type', 'enabled'];
2017-09-14 22:21:00 +03:00
/**
* Sortable columns.
*
* @var array
*/
public $sortable = ['name', 'rate', 'enabled'];
public function items()
{
2018-06-10 02:48:51 +03:00
return $this->hasMany('App\Models\Common\Item');
2017-09-14 22:21:00 +03:00
}
2017-10-16 01:06:49 +03:00
public function bill_items()
2017-09-14 22:21:00 +03:00
{
2019-12-31 15:49:09 +03:00
return $this->hasMany('App\Models\Purchase\BillItemTax');
2017-09-14 22:21:00 +03:00
}
2017-10-16 01:06:49 +03:00
public function invoice_items()
2017-09-14 22:21:00 +03:00
{
2019-12-31 15:49:09 +03:00
return $this->hasMany('App\Models\Sale\InvoiceItemTax');
2017-09-14 22:21:00 +03:00
}
2017-10-21 14:23:57 +03:00
/**
* Convert rate to double.
*
* @param string $value
* @return void
*/
public function setRateAttribute($value)
{
$this->attributes['rate'] = (double) $value;
}
2018-04-16 19:01:29 +03:00
/**
* Get the name including rate.
*
* @return string
*/
public function getTitleAttribute()
{
$title = $this->name . ' (';
2019-11-16 10:21:14 +03:00
if (setting('localisation.percent_position', 'after') == 'after') {
$title .= $this->getAttribute('type') == 'fixed' ? $this->rate : $this->rate . '%';
2018-04-16 19:01:29 +03:00
} else {
2019-11-16 10:21:14 +03:00
$title .= $this->getAttribute('type') == 'fixed' ? $this->rate : '%' . $this->rate;
2018-04-16 19:01:29 +03:00
}
$title .= ')';
return $title;
}
2017-09-14 22:21:00 +03:00
}