2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Setting;
|
|
|
|
|
|
|
|
use App\Models\Model;
|
|
|
|
|
|
|
|
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-01-08 11:53:13 +03:00
|
|
|
return $this->hasMany('App\Models\Expense\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-01-08 11:53:13 +03:00
|
|
|
return $this->hasMany('App\Models\Income\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 . ' (';
|
|
|
|
|
|
|
|
if (setting('general.percent_position', 'after') == 'after') {
|
|
|
|
$title .= $this->rate . '%';
|
|
|
|
} else {
|
|
|
|
$title .= '%' . $this->rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title .= ')';
|
|
|
|
|
|
|
|
return $title;
|
|
|
|
}
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|