Tax.php
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace App\Models\Setting;
use App\Models\Model;
class Tax extends Model
{
protected $table = 'taxes';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['title'];
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'rate', 'enabled'];
/**
* Sortable columns.
*
* @var array
*/
public $sortable = ['name', 'rate', 'enabled'];
public function items()
{
return $this->hasMany('App\Models\Common\Item');
}
public function bill_items()
{
return $this->hasMany('App\Models\Expense\BillItem');
}
public function invoice_items()
{
return $this->hasMany('App\Models\Income\InvoiceItem');
}
/**
* Convert rate to double.
*
* @param string $value
* @return void
*/
public function setRateAttribute($value)
{
$this->attributes['rate'] = (double) $value;
}
/**
* 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;
}
}