1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models\Concerns\Item; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @property int $quantity_per_bundle |
7
|
|
|
* @property int|null $bundle_quantity |
8
|
|
|
* @property int $quantity |
9
|
|
|
* @property bool $is_order_custom_quantity |
10
|
|
|
* @property-read string $denomination_name |
11
|
|
|
* @property-read float $denomination_value |
12
|
|
|
* @property-read float $total |
13
|
|
|
* @property-read string $is_order_custom_quantity_badge |
14
|
|
|
* |
15
|
|
|
* @see \App\Models\Item |
16
|
|
|
*/ |
17
|
|
|
trait Attribute |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Return "quantity" attribute value. |
21
|
|
|
* |
22
|
|
|
* @param mixed $value |
23
|
|
|
* @return int |
24
|
|
|
*/ |
25
|
|
|
public function getQuantityAttribute($value): int |
26
|
|
|
{ |
27
|
|
|
if ($this->is_order_custom_quantity) { |
28
|
|
|
return $this->castAttribute('quantity', $value); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return $this->countQuantityAttribute(); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Return "denomination_name" attribute value. |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function getDenominationNameAttribute(): string |
40
|
|
|
{ |
41
|
|
|
return $this->denomination->name; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Return "denomination_value" attribute value. |
46
|
|
|
* |
47
|
|
|
* @return float |
48
|
|
|
*/ |
49
|
|
|
public function getDenominationValueAttribute(): float |
50
|
|
|
{ |
51
|
|
|
return $this->denomination->value; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Return "total" attribute value. |
56
|
|
|
* |
57
|
|
|
* @return float |
58
|
|
|
*/ |
59
|
|
|
public function getTotalAttribute(): float |
60
|
|
|
{ |
61
|
|
|
return $this->quantity * $this->denomination_value; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Return "is_order_custom_quantity_badge" attribute value. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getIsOrderCustomQuantityBadgeAttribute(): string |
70
|
|
|
{ |
71
|
|
|
return sprintf(<<<'html' |
72
|
|
|
<span class="badge badge-%s"> |
73
|
|
|
<i class="fa fa-%s"></i> %s |
74
|
|
|
</span> |
75
|
|
|
html, |
76
|
|
|
$this->is_order_custom_quantity ? 'success' : 'danger', |
77
|
|
|
$this->is_order_custom_quantity ? 'check-circle' : 'times-circle', |
78
|
|
|
$this->is_order_custom_quantity ? trans('Yes') : trans('No') |
|
|
|
|
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|