1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models\Concerns\Denomination; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Storage; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @property string $code |
9
|
|
|
* @property string $name |
10
|
|
|
* @property float $value |
11
|
|
|
* @property \App\Enum\DenominationType $type |
12
|
|
|
* @property int $quantity_per_bundle |
13
|
|
|
* @property int $minimum_order_bundle |
14
|
|
|
* @property int $maximum_order_bundle |
15
|
|
|
* @property int $minimum_order_quantity |
16
|
|
|
* @property int $maximum_order_quantity |
17
|
|
|
* @property bool $can_order_custom_quantity |
18
|
|
|
* @property bool $is_visible |
19
|
|
|
* @property string $image |
20
|
|
|
* @property-read array $range_order_bundle |
21
|
|
|
* @property-read float $value_per_bundle |
22
|
|
|
* @property-read float $minimum_order_value |
23
|
|
|
* @property-read float $maximum_order_value |
24
|
|
|
* @property-read string $value_rupiah |
25
|
|
|
* @property-read string $type_badge |
26
|
|
|
* @property-read string $can_order_custom_quantity_badge |
27
|
|
|
* @property-read string $is_visible_badge |
28
|
|
|
* |
29
|
|
|
* @see \App\Models\Denomination |
30
|
|
|
*/ |
31
|
|
|
trait Attribute |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Return "minimum_order_quantity" attribute value. |
35
|
|
|
* |
36
|
|
|
* @param mixed $value |
37
|
|
|
* @return int |
38
|
|
|
*/ |
39
|
2 |
|
public function getMinimumOrderQuantityAttribute($value): int |
40
|
|
|
{ |
41
|
2 |
|
if ($this->can_order_custom_quantity) { |
42
|
1 |
|
return $this->castAttribute('minimum_order_quantity', $value); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
return $this->countMinimumOrderQuantityAttribute(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Return "maximum_order_quantity" attribute value. |
50
|
|
|
* |
51
|
|
|
* @param mixed $value |
52
|
|
|
* @return int |
53
|
|
|
*/ |
54
|
2 |
|
public function getMaximumOrderQuantityAttribute($value): int |
55
|
|
|
{ |
56
|
2 |
|
if ($this->can_order_custom_quantity) { |
57
|
1 |
|
return $this->castAttribute('maximum_order_quantity', $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
return $this->countMaximumOrderQuantityAttribute(); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Return "image" attribute value. |
65
|
|
|
* |
66
|
|
|
* @param mixed $value |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
2 |
|
public function getImageAttribute($value): string |
70
|
|
|
{ |
71
|
2 |
|
if (is_null($value)) { |
72
|
1 |
|
return asset('img/dummy.png'); |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
return Storage::url(static::IMAGE_PATH . '/' . $value); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Return "range_order_bundle" attribute value. |
80
|
|
|
* |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
2 |
|
public function getRangeOrderBundleAttribute(): array |
84
|
|
|
{ |
85
|
2 |
|
return range($this->minimum_order_bundle, $this->maximum_order_bundle); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Return "value_per_bundle" attribute value. |
90
|
|
|
* |
91
|
|
|
* @return float |
92
|
|
|
*/ |
93
|
|
|
public function getValuePerBundleAttribute(): float |
94
|
|
|
{ |
95
|
|
|
return $this->value * $this->quantity_per_bundle; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Return "minimum_order_value" attribute value. |
100
|
|
|
* |
101
|
|
|
* @return float |
102
|
|
|
*/ |
103
|
|
|
public function getMinimumOrderValueAttribute(): float |
104
|
|
|
{ |
105
|
|
|
return $this->value_per_bundle * $this->minimum_order_bundle; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Return "maximum_order_value" attribute value. |
110
|
|
|
* |
111
|
|
|
* @return float |
112
|
|
|
*/ |
113
|
|
|
public function getMaximumOrderValueAttribute(): float |
114
|
|
|
{ |
115
|
|
|
return $this->value_per_bundle * $this->maximum_order_bundle; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Return "value_rupiah" attribute value. |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getValueRupiahAttribute(): string |
124
|
|
|
{ |
125
|
|
|
return format_rupiah($this->value); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Return "type_badge" attribute value. |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getTypeBadgeAttribute(): string |
134
|
|
|
{ |
135
|
|
|
return sprintf(<<<'html' |
136
|
|
|
<span class="badge badge-%s"> |
137
|
|
|
<i class="fa fa-%s"></i> %s |
138
|
|
|
</span> |
139
|
|
|
html, |
140
|
|
|
$this->type->isCoin() ? 'danger' : 'success', |
|
|
|
|
141
|
|
|
$this->type->isCoin() ? 'coins' : 'money-bill', |
142
|
|
|
$this->type->label |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Return "can_order_custom_quantity_badge" attribute value. |
148
|
|
|
* |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
|
|
public function getCanOrderCustomQuantityBadgeAttribute(): string |
152
|
|
|
{ |
153
|
|
|
return sprintf(<<<'html' |
154
|
|
|
<span class="badge badge-%s"> |
155
|
|
|
<i class="fa fa-%s"></i> %s |
156
|
|
|
</span> |
157
|
|
|
html, |
158
|
|
|
$this->can_order_custom_quantity ? 'success' : 'danger', |
159
|
|
|
$this->can_order_custom_quantity ? 'check-circle' : 'times-circle', |
160
|
|
|
$this->can_order_custom_quantity ? trans('Yes') : trans('No') |
|
|
|
|
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Return "is_visible_badge" attribute value. |
166
|
|
|
* |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
|
|
public function getIsVisibleBadgeAttribute(): string |
170
|
|
|
{ |
171
|
|
|
return sprintf(<<<'html' |
172
|
|
|
<span class="badge badge-%s"> |
173
|
|
|
<i class="fa fa-%s"></i> %s |
174
|
|
|
</span> |
175
|
|
|
html, |
176
|
|
|
$this->is_visible ? 'success' : 'danger', |
177
|
|
|
$this->is_visible ? 'check-circle' : 'times-circle', |
178
|
|
|
$this->is_visible ? trans('Yes') : trans('No') |
|
|
|
|
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|