1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Inspirum\Balikobot\Definitions; |
6
|
|
|
|
7
|
|
|
use function in_array; |
8
|
|
|
|
9
|
|
|
final class Status |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Ordered |
13
|
|
|
* |
14
|
|
|
* @var float |
15
|
|
|
*/ |
16
|
|
|
public const ORDERED = -1.0; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Picked up at the sender |
20
|
|
|
* |
21
|
|
|
* @var float |
22
|
|
|
*/ |
23
|
|
|
public const PICKED_UP_FROM_SENDER = 2.1; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Transit |
27
|
|
|
* |
28
|
|
|
* @var float |
29
|
|
|
*/ |
30
|
|
|
public const TRANSIT = 2.2; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Ready to pick up |
34
|
|
|
* |
35
|
|
|
* @var float |
36
|
|
|
*/ |
37
|
|
|
public const READY_TO_PICK_UP = 2.3; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Back on the way to the sender |
41
|
|
|
* |
42
|
|
|
* @var float |
43
|
|
|
*/ |
44
|
|
|
public const SEND_BACK_TO_SENDER = 2.4; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Handed over to the final carrier |
48
|
|
|
* |
49
|
|
|
* @var float |
50
|
|
|
*/ |
51
|
|
|
public const HANDED_TO_FINAL_CARRIER = 2.5; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Cancellation by the carrier |
55
|
|
|
* |
56
|
|
|
* @var float |
57
|
|
|
*/ |
58
|
|
|
public const CANCELLATION_BY_CARRIER = 3.1; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Cancellation by the recipient |
62
|
|
|
* |
63
|
|
|
* @var float |
64
|
|
|
*/ |
65
|
|
|
public const CANCELLATION_BY_RECIPIENT = 3.2; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Cancellation by the sender |
69
|
|
|
* |
70
|
|
|
* @var float |
71
|
|
|
*/ |
72
|
|
|
public const CANCELLATION_BY_SENDER = 3.3; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Delivered back to sender |
76
|
|
|
* |
77
|
|
|
* @var float |
78
|
|
|
*/ |
79
|
|
|
public const DELIVERED_BACK_TO_SENDER = 4.0; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Cash on delivery has been credited to the sender's account |
83
|
|
|
* |
84
|
|
|
* @var float |
85
|
|
|
*/ |
86
|
|
|
public const COD_PAID = 5.0; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Carrier error |
90
|
|
|
* |
91
|
|
|
* @var float |
92
|
|
|
*/ |
93
|
|
|
public const ERROR_CARRIER = 0.1; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Error on the part of the recipient |
97
|
|
|
* |
98
|
|
|
* @var float |
99
|
|
|
*/ |
100
|
|
|
public const ERROR_RECIPIENT = 0.2; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Error on the part of the sender |
104
|
|
|
* |
105
|
|
|
* @var float |
106
|
|
|
*/ |
107
|
|
|
public const ERROR_SENDER = 0.3; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Collection of the consignment at the delivery point |
111
|
|
|
* |
112
|
|
|
* @var float |
113
|
|
|
*/ |
114
|
|
|
public const PICKUP_ON_DELIVERY_POINT = 1.1; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Delivered to address |
118
|
|
|
* |
119
|
|
|
* @var float |
120
|
|
|
*/ |
121
|
|
|
public const DELIVERED_TO_ADDRESS = 1.2; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Is package delivered to customer |
125
|
|
|
*/ |
126
|
|
|
public static function isDelivered(float $status): bool |
127
|
|
|
{ |
128
|
|
|
return self::isStatus($status, [ |
129
|
|
|
self::PICKUP_ON_DELIVERY_POINT, |
130
|
|
|
self::DELIVERED_TO_ADDRESS, |
131
|
|
|
]); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Package delivery failed |
136
|
|
|
*/ |
137
|
|
|
public static function isError(float $status): bool |
138
|
|
|
{ |
139
|
|
|
return self::isStatus($status, [ |
140
|
|
|
self::ERROR_CARRIER, |
141
|
|
|
self::ERROR_RECIPIENT, |
142
|
|
|
self::ERROR_SENDER, |
143
|
|
|
]); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Package is being delivered to customer |
148
|
|
|
*/ |
149
|
|
|
public static function isBeingDelivered(float $status): bool |
150
|
|
|
{ |
151
|
|
|
return self::isStatus($status, [ |
152
|
|
|
self::ORDERED, |
153
|
|
|
self::PICKED_UP_FROM_SENDER, |
154
|
|
|
self::TRANSIT, |
155
|
|
|
self::READY_TO_PICK_UP, |
156
|
|
|
self::HANDED_TO_FINAL_CARRIER, |
157
|
|
|
]); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Package delivery processed ended |
162
|
|
|
*/ |
163
|
|
|
public static function isClosed(float $status): bool |
164
|
|
|
{ |
165
|
|
|
return self::isStatus($status, [ |
166
|
|
|
self::DELIVERED_BACK_TO_SENDER, |
167
|
|
|
self::COD_PAID, |
168
|
|
|
self::PICKUP_ON_DELIVERY_POINT, |
169
|
|
|
self::DELIVERED_TO_ADDRESS, |
170
|
|
|
]); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Check if given ID is in any of given statuses |
175
|
|
|
* |
176
|
|
|
* @param array<float> $statuses |
177
|
|
|
*/ |
178
|
|
|
private static function isStatus(float $status, array $statuses): bool |
179
|
|
|
{ |
180
|
|
|
return in_array($status, $statuses, true); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|