1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use App\Enum\DenominationType; |
6
|
|
|
use App\Infrastructure\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
8
|
|
|
|
9
|
|
|
class Denomination extends Model |
10
|
|
|
{ |
11
|
|
|
use HasFactory, |
|
|
|
|
12
|
|
|
Concerns\Denomination\Attribute, |
13
|
|
|
Concerns\Denomination\Event, |
14
|
|
|
Concerns\Denomination\Relation; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Filepath value for image. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
const IMAGE_PATH = 'denomination'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
|
|
protected $fillable = [ |
27
|
|
|
'key', |
28
|
|
|
'name', |
29
|
|
|
'value', |
30
|
|
|
'type', |
31
|
|
|
'quantity_per_bundle', |
32
|
|
|
'minimum_order_bundle', |
33
|
|
|
'maximum_order_bundle', |
34
|
|
|
'minimum_order_quantity', |
35
|
|
|
'maximum_order_quantity', |
36
|
|
|
'can_order_custom_quantity', |
37
|
|
|
'is_visible', |
38
|
|
|
'image', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
*/ |
44
|
|
|
protected $casts = [ |
45
|
|
|
'value' => 'float', |
46
|
|
|
'type' => DenominationType::class, |
47
|
|
|
'quantity_per_bundle' => 'integer', |
48
|
|
|
'minimum_order_bundle' => 'integer', |
49
|
|
|
'maximum_order_bundle' => 'integer', |
50
|
|
|
'minimum_order_quantity' => 'integer', |
51
|
|
|
'maximum_order_quantity' => 'integer', |
52
|
|
|
'can_order_custom_quantity' => 'boolean', |
53
|
|
|
'is_visible' => 'boolean', |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Determine whether the given value is between the minimum and maximum order bundle. |
58
|
|
|
* |
59
|
|
|
* @param int $value |
60
|
|
|
* @param bool $equal |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public function isBetweenOrderBundle(int $value, bool $equal = true): bool |
64
|
|
|
{ |
65
|
|
|
if ($equal) { |
66
|
|
|
return |
67
|
|
|
$value >= $this->minimum_order_bundle && |
68
|
|
|
$value <= $this->maximum_order_bundle; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return |
72
|
|
|
$value > $this->minimum_order_bundle && |
73
|
|
|
$value < $this->maximum_order_bundle; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Determine whether the given value is between the minimum and maximum order quantity. |
78
|
|
|
* |
79
|
|
|
* @param int $value |
80
|
|
|
* @param bool $equal |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function isBetweenOrderQuantity(int $value, bool $equal = true): bool |
84
|
|
|
{ |
85
|
|
|
if ($equal) { |
86
|
|
|
return |
87
|
|
|
$value >= $this->minimum_order_quantity && |
88
|
|
|
$value <= $this->maximum_order_quantity; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return |
92
|
|
|
$value > $this->minimum_order_quantity && |
93
|
|
|
$value < $this->maximum_order_quantity; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Count value of "minimum_order_quantity" attribute. |
98
|
|
|
* |
99
|
|
|
* @return int |
100
|
|
|
*/ |
101
|
8 |
|
public function countMinimumOrderQuantityAttribute(): int |
102
|
|
|
{ |
103
|
8 |
|
return $this->quantity_per_bundle * $this->minimum_order_bundle; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Count value of "maximum_order_quantity" attribute. |
108
|
|
|
* |
109
|
|
|
* @return int |
110
|
|
|
*/ |
111
|
8 |
|
public function countMaximumOrderQuantityAttribute(): int |
112
|
|
|
{ |
113
|
8 |
|
return $this->quantity_per_bundle * $this->maximum_order_bundle; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|