Blame view

app/Models/Expense/Vendor.php 1.48 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
73
  <?php
  
  namespace App\Models\Expense;
  
  use App\Models\Model;
  use Bkwld\Cloner\Cloneable;
  use Sofa\Eloquence\Eloquence;
  use App\Traits\Media;
  
  class Vendor extends Model
  {
      use Cloneable, Eloquence, Media;
  
      protected $table = 'vendors';
  
      /**
       * Attributes that should be mass-assignable.
       *
       * @var array
       */
      protected $fillable = ['company_id', 'name', 'email', 'tax_number', 'phone', 'address', 'website', 'currency_code', 'enabled'];
  
      /**
       * Sortable columns.
       *
       * @var array
       */
      public $sortable = ['name', 'email', 'phone', 'enabled'];
  
      /**
       * Searchable rules.
       *
       * @var array
       */
      protected $searchableColumns = [
          'name'    => 10,
          'email'   => 5,
          'phone'   => 2,
          'website' => 2,
          'address' => 1,
      ];
  
      public function bills()
      {
          return $this->hasMany('App\Models\Expense\Bill');
      }
  
      public function payments()
      {
          return $this->hasMany('App\Models\Expense\Payment');
      }
  
      public function currency()
      {
          return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
      }
  
      /**
       * Get the current balance.
       *
       * @return string
       */
      public function getLogoAttribute($value)
      {
          if (!empty($value) && !$this->hasMedia('logo')) {
              return $value;
          } elseif (!$this->hasMedia('logo')) {
              return false;
          }
  
          return $this->getMedia('logo')->last();
      }
  }