Blame view

app/Models/Setting/Category.php 1.51 KB
b7c7a5f6   Alexey Boroda   first commit
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
  <?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'];
  
      public function bills()
      {
          return $this->hasMany('App\Models\Expense\Bill');
      }
  
      public function invoices()
      {
          return $this->hasMany('App\Models\Income\Invoice');
      }
  
      public function items()
      {
          return $this->hasMany('App\Models\Common\Item');
      }
  
      public function payments()
      {
          return $this->hasMany('App\Models\Expense\Payment');
      }
  
      public function revenues()
      {
          return $this->hasMany('App\Models\Income\Revenue');
      }
  
      /**
       * 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);
      }
  
      /**
       * 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();
      }
  }