Blame view

app/Models/Setting/Currency.php 3.09 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  <?php
  
  namespace App\Models\Setting;
  
  use App\Models\Model;
  
  class Currency extends Model
  {
  
      protected $table = 'currencies';
  
      /**
       * Attributes that should be mass-assignable.
       *
       * @var array
       */
      protected $fillable = ['company_id', 'name', 'code', 'rate', 'enabled', 'precision', 'symbol', 'symbol_first', 'decimal_mark', 'thousands_separator'];
  
      /**
       * Sortable columns.
       *
       * @var array
       */
      public $sortable = ['name', 'code', 'rate', 'enabled'];
  
      public function accounts()
      {
          return $this->hasMany('App\Models\Banking\Account', 'currency_code', 'code');
      }
  
      public function customers()
      {
          return $this->hasMany('App\Models\Income\Customer', 'currency_code', 'code');
      }
  
      public function invoices()
      {
          return $this->hasMany('App\Models\Income\Invoice', 'currency_code', 'code');
      }
  
      public function invoice_payments()
      {
          return $this->hasMany('App\Models\Income\InvoicePayment', 'currency_code', 'code');
      }
  
      public function revenues()
      {
          return $this->hasMany('App\Models\Income\Revenue', 'currency_code', 'code');
      }
  
      public function bills()
      {
          return $this->hasMany('App\Models\Expense\Bill', 'currency_code', 'code');
      }
  
      public function bill_payments()
      {
          return $this->hasMany('App\Models\Expense\BillPayment', 'currency_code', 'code');
      }
  
      public function payments()
      {
          return $this->hasMany('App\Models\Expense\Payment', 'currency_code', 'code');
      }
  
      /**
       * Convert rate to double.
       *
       * @param  string  $value
       * @return void
       */
      public function setRateAttribute($value)
      {
          $this->attributes['rate'] = (double) $value;
      }
  
      /**
       * Get the current precision.
       *
       * @return string
       */
      public function getPrecisionAttribute($value)
      {
          if (empty($value)) {
              return config('money.' . $this->code . '.precision');
          }
  
          return $value;
      }
  
      /**
       * Get the current symbol.
       *
       * @return string
       */
      public function getSymbolAttribute($value)
      {
          if (empty($value)) {
              return config('money.' . $this->code . '.symbol');
          }
  
          return $value;
      }
  
      /**
       * Get the current symbol_first.
       *
       * @return string
       */
      public function getSymbolFirstAttribute($value)
      {
          if (empty($value)) {
              return config('money.' . $this->code . '.symbol_first');
          }
  
          return $value;
      }
  
      /**
       * Get the current decimal_mark.
       *
       * @return string
       */
      public function getDecimalMarkAttribute($value)
      {
          if (empty($value)) {
              return config('money.' . $this->code . '.decimal_mark');
          }
  
          return $value;
      }
  
      /**
       * Get the current thousands_separator.
       *
       * @return string
       */
      public function getThousandsSeparatorAttribute($value)
      {
          if (empty($value)) {
              return config('money.' . $this->code . '.thousands_separator');
          }
  
          return $value;
      }
  }