|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\Concerns\Denomination; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Storage; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @property string $name |
|
9
|
|
|
* @property float $value |
|
10
|
|
|
* @property \App\Enum\DenominationType $type |
|
11
|
|
|
* @property int $quantity_per_bundle |
|
12
|
|
|
* @property int $minimum_order_bundle |
|
13
|
|
|
* @property int $maximum_order_bundle |
|
14
|
|
|
* @property string $image |
|
15
|
|
|
* @property-read float $value_per_bundle |
|
16
|
|
|
* @property-read float $minimum_order_value |
|
17
|
|
|
* @property-read float $maximum_order_value |
|
18
|
|
|
* @property-read string $value_rupiah |
|
19
|
|
|
* |
|
20
|
|
|
* @see \App\Models\Denomination |
|
21
|
|
|
*/ |
|
22
|
|
|
trait Attribute |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Return "image" attribute value. |
|
26
|
|
|
* |
|
27
|
|
|
* @param mixed $value |
|
28
|
|
|
* @return string|null |
|
29
|
|
|
*/ |
|
30
|
2 |
|
public function getImageAttribute($value): ?string |
|
31
|
|
|
{ |
|
32
|
2 |
|
if (is_null($value)) { |
|
33
|
1 |
|
return asset('img/dummy.png'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
return Storage::url(static::IMAGE_PATH . '/' . $value); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Return "value_per_bundle" attribute value. |
|
41
|
|
|
* |
|
42
|
|
|
* @return float |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getValuePerBundleAttribute(): float |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->value * $this->quantity_per_bundle; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Return "minimum_order_value" attribute value. |
|
51
|
|
|
* |
|
52
|
|
|
* @return float |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getMinimumOrderValueAttribute(): float |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->value_per_bundle * $this->minimum_order_bundle; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Return "maximum_order_value" attribute value. |
|
61
|
|
|
* |
|
62
|
|
|
* @return float |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getMaximumOrderValueAttribute(): float |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->value_per_bundle * $this->maximum_order_bundle; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return "value_rupiah" attribute value. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getValueRupiahAttribute(): string |
|
75
|
|
|
{ |
|
76
|
|
|
return format_rupiah($this->value, 'Rp'); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|