2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Setting;
|
|
|
|
|
|
|
|
use App\Models\Model;
|
|
|
|
|
|
|
|
class Category extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'categories';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attributes that should be mass-assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sortable columns.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $sortable = ['name', 'type', 'enabled'];
|
|
|
|
|
2018-04-23 22:17:20 +03:00
|
|
|
public function bills()
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2018-04-23 22:17:20 +03:00
|
|
|
return $this->hasMany('App\Models\Expense\Bill');
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
2018-04-23 22:17:20 +03:00
|
|
|
public function invoices()
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2018-04-23 22:17:20 +03:00
|
|
|
return $this->hasMany('App\Models\Income\Invoice');
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-23 22:17:20 +03:00
|
|
|
public function payments()
|
|
|
|
{
|
|
|
|
return $this->hasMany('App\Models\Expense\Payment');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function revenues()
|
|
|
|
{
|
|
|
|
return $this->hasMany('App\Models\Income\Revenue');
|
|
|
|
}
|
|
|
|
|
2017-09-14 22:21:00 +03:00
|
|
|
/**
|
|
|
|
* Scope to only include categories of a given type.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
|
|
* @param mixed $type
|
|
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
|
|
*/
|
|
|
|
public function scopeType($query, $type)
|
|
|
|
{
|
|
|
|
return $query->where('type', $type);
|
|
|
|
}
|
2017-12-05 15:56:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scope transfer category.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
|
|
*/
|
|
|
|
public function scopeTransfer($query)
|
|
|
|
{
|
|
|
|
return $query->where('type', 'other')->pluck('id')->first();
|
|
|
|
}
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|