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;
|
2020-10-14 17:07:59 +03:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
class Tax extends Model
|
|
|
|
{
|
2020-10-14 17:07:59 +03:00
|
|
|
use HasFactory;
|
|
|
|
|
2017-09-14 22:21:00 +03:00
|
|
|
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
|
|
|
|
2020-01-20 22:58:49 +03:00
|
|
|
public function scopeName($query, $name)
|
|
|
|
{
|
|
|
|
return $query->where('name', '=', $name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeRate($query, $rate)
|
|
|
|
{
|
|
|
|
return $query->where('rate', '=', $rate);
|
|
|
|
}
|
|
|
|
|
2020-07-22 15:11:31 +03:00
|
|
|
public function scopeNotRate($query, $rate)
|
|
|
|
{
|
|
|
|
return $query->where('rate', '<>', $rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeType($query, $types)
|
|
|
|
{
|
|
|
|
if (empty($types)) {
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query->whereIn($this->table . '.type', (array) $types);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeFixed($query)
|
|
|
|
{
|
|
|
|
return $query->where($this->table . '.type', '=', 'fixed');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeNormal($query)
|
|
|
|
{
|
|
|
|
return $query->where($this->table . '.type', '=', 'normal');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeInclusive($query)
|
|
|
|
{
|
|
|
|
return $query->where($this->table . '.type', '=', 'inclusive');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeCompound($query)
|
|
|
|
{
|
|
|
|
return $query->where($this->table . '.type', '=', 'compound');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeWithholding($query)
|
|
|
|
{
|
|
|
|
return $query->where($this->table . '.type', '=', 'withholding');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeNotWithholding($query)
|
|
|
|
{
|
|
|
|
return $query->where($this->table . '.type', '<>', 'withholding');
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2020-10-14 17:07:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new factory instance for the model.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
|
|
|
*/
|
|
|
|
protected static function newFactory()
|
|
|
|
{
|
|
|
|
return \Database\Factories\Tax::new();
|
|
|
|
}
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|