Order::setDimensions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (c) 2017 Salah Alkhwlani <[email protected]>
5
 *
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Yemenifree\PickServices\Model;
11
12
use Carbon\Carbon;
13
use Yemenifree\PickServices\Base\Model;
14
15
class Order extends Model
16
{
17
    /**
18
     * items types.
19
     */
20
    const ITEM_FOOD = 'food';
21
    const ITEM_CLOTHING = 'clothing';
22
    const ITEM_HOUSEHOLD = 'household';
23
    const ITEM_ELECTRONICS = 'electronics';
24
    const ITEM_HEALTH_CARE = 'health care';
25
    const ITEM_MAKEUP = 'makeup';
26
    const ITEM_OTHERS = 'other';
27
28
    /**
29
     * Payment types.
30
     */
31
    const PAYMENT_PRE_PAID = 'Pre-paid';
32
    const PAYMENT_COD = 'COD';
33
34
    /**
35
     * Services types.
36
     */
37
    const SERVICE_ON_DEMAND = 'on-demand';
38
    const SERVICE_ECONOMY = 'economy';
39
    const SERVICE_SHIPPING = 'shipping';
40
41
    /**
42
     * @var array
43
     */
44
    protected $rules = [
45
        'price' => 'present|numeric',
46
        'service_type' => 'in:on-demand,economy,shipping',
47
        'payment_type' => 'required|in:Pre-paid,COD',
48
        'items' => 'required|in:food,clothing,household,electronics,health care,makeup,other',
49
        'receiver_name' => 'required',
50
        'receiver_phone' => 'required',
51
        'pickup_time' => 'required',
52
        'pickup_location' => 'required',
53
    ];
54
55
    protected $fields = [
56
        'delivery_notes', 'items', 'price', 'payment_type', 'service_type',
57
        'receiver_name', 'receiver_phone', 'pickup_time', 'dropoff_time',
58
        'dropoff_location', 'pickup_location', 'addons', 'dimensions',
59
    ];
60
61
    /** @var string */
62
    protected $delivery_notes = '';
63
    /** @var string */
64
    protected $items = '';
65
    /** @var int (optional) */
66
    protected $price = 0;
67
    /**
68
     * Payment type.
69
     *
70
     * COD to charge customer the service cost fees and item price.
71
     * PRE_PAID to not charge customer any fees.
72
     * ONLY_SENDER_FEES to charge the sender the service fees and not charge the customer anything.
73
     * ONLY_RECEIVER_FEES to charge customer service cost fees only and not item price.
74
     *
75
     * @var string
76
     */
77
    protected $payment_type;
78
    /**
79
     * on-demand => توصيل فوري 34 ريال/طلب
80
     * economy =>   توصيل اقتصادي 24 ريال/طلب
81
     * shipping => شحن29 ريال/طلب.
82
     *
83
     * @var string
84
     */
85
    protected $service_type = '';
86
    /** @var string */
87
    protected $receiver_name = '';
88
    /** @var string */
89
    protected $receiver_phone = '';
90
91
    /** @var Carbon */
92
    protected $pickup_time = '';
93
    /** @var Carbon */
94
    protected $dropoff_time = '';
95
    /** @var array */
96
    protected $dropoff_location = '';
97
    /** @var array */
98
    protected $pickup_location = '';
99
100
    /** @var array */
101
    protected $addons = [];
102
    /** @var array */
103
    protected $dimensions = [];
104
105
    /**
106
     * @return string
107
     */
108
    public function getDeliveryNotes(): string
109
    {
110
        return $this->delivery_notes;
111
    }
112
113
    /**
114
     * @param string $delivery_notes
115
     *
116
     * @return Order
117
     */
118
    public function setDeliveryNotes(string $delivery_notes): Order
119
    {
120
        $this->delivery_notes = $delivery_notes;
121
122
        return $this;
123
    }
124
125
    /**
126
     * @return string
127
     */
128
    public function getDimensions(): string
129
    {
130
        return \json_encode($this->dimensions);
131
    }
132
133
    /**
134
     * @param int $width
135
     * @param int $length
136
     * @param int $weight
137
     * @param int $height
138
     *
139
     * @return Order
140
     */
141
    public function setDimensions(int $width, int $length, int $weight, int $height): Order
142
    {
143
        $this->dimensions = ['width' => $width, 'length' => $length, 'weight' => $weight, 'height' => $height];
144
145
        return $this;
146
    }
147
148
    /**
149
     * @return int
150
     */
151
    public function getPrice(): int
152
    {
153
        return $this->price;
154
    }
155
156
    /**
157
     * @param int $price
158
     *
159
     * @return Order
160
     */
161
    public function setPrice(int $price): Order
162
    {
163
        $this->price = $price;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @return string
170
     */
171
    public function getReceiverName(): string
172
    {
173
        return $this->receiver_name;
174
    }
175
176
    /**
177
     * @param string $receiver_name
178
     *
179
     * @return Order
180
     */
181
    public function setReceiverName(string $receiver_name): Order
182
    {
183
        $this->receiver_name = $receiver_name;
184
185
        return $this;
186
    }
187
188
    /**
189
     * @return string
190
     */
191
    public function getReceiverPhone(): string
192
    {
193
        return $this->receiver_phone;
194
    }
195
196
    /**
197
     * @param string $receiver_phone
198
     *
199
     * @return Order
200
     */
201
    public function setReceiverPhone(string $receiver_phone): Order
202
    {
203
        $this->receiver_phone = $receiver_phone;
204
205
        return $this;
206
    }
207
208
    /**
209
     * @return string
210
     */
211
    public function getServiceType(): string
212
    {
213
        return $this->service_type;
214
    }
215
216
    /**
217
     * @param string $service_type
218
     *
219
     * @return Order
220
     */
221
    public function setServiceType(string $service_type): Order
222
    {
223
        $this->service_type = $service_type;
224
225
        return $this;
226
    }
227
228
    /**
229
     * @return string
230
     */
231
    public function getPaymentType(): string
232
    {
233
        return $this->payment_type;
234
    }
235
236
    /**
237
     * @param string $payment_type
238
     *
239
     * @return Order
240
     */
241
    public function setPaymentType(string $payment_type): Order
242
    {
243
        $this->payment_type = $payment_type;
244
245
        return $this;
246
    }
247
248
    /**
249
     * @return string
250
     */
251
    public function getItems(): string
252
    {
253
        return $this->items;
254
    }
255
256
    /**
257
     * @param string $items
258
     *
259
     * @return Order
260
     */
261
    public function setItems(string $items): Order
262
    {
263
        $this->items = $items;
264
265
        return $this;
266
    }
267
268
    /**
269
     * @return string
270
     */
271
    public function getPickupTime(): string
272
    {
273
        return $this->pickup_time ? $this->pickup_time->format('Y-m-d h:i A') : '';
274
    }
275
276
    /**
277
     * @param Carbon $pickup_time
278
     *
279
     * @return Order
280
     */
281
    public function setPickupTime(Carbon $pickup_time): self
282
    {
283
        $this->pickup_time = $pickup_time;
284
285
        return $this;
286
    }
287
288
    /**
289
     * @return string
290
     */
291
    public function getDropoffTime(): string
292
    {
293
        return $this->dropoff_time ? $this->dropoff_time->format('Y-m-d h:i A') : '';
294
    }
295
296
    /**
297
     * @param Carbon $dropoff_time
298
     *
299
     * @return Order
300
     */
301
    public function setDropoffTime(Carbon $dropoff_time): Order
302
    {
303
        $this->dropoff_time = $dropoff_time;
304
305
        return $this;
306
    }
307
308
    /**
309
     * @return string
310
     */
311
    public function getDropoffLocation(): string
312
    {
313
        return \implode(',', (array) $this->dropoff_location);
314
    }
315
316
    /**
317
     * @param float $lat
318
     * @param float $lng
319
     *
320
     * @return Order
321
     */
322
    public function setDropoffLocation(float $lat, float $lng): Order
323
    {
324
        $this->dropoff_location = [$lat, $lng];
325
326
        return $this;
327
    }
328
329
    /**
330
     * @return string
331
     */
332
    public function getPickupLocation(): string
333
    {
334
        return \implode(',', (array) $this->pickup_location);
335
    }
336
337
    /**
338
     * @param float $lat
339
     * @param float $lng
340
     *
341
     * @return Order
342
     */
343
    public function setPickupLocation(float $lat, float $lng): Order
344
    {
345
        $this->pickup_location = [$lat, $lng];
346
347
        return $this;
348
    }
349
350
    /**
351
     * add insurance addons to order.
352
     *
353
     * @return Order
354
     */
355
    public function addInsuranceService(): Order
356
    {
357
        $this->addons[] = 'insurance';
358
359
        return $this;
360
    }
361
362
    /**
363
     * add packaging addons to order.
364
     *
365
     * @return Order
366
     */
367
    public function addPackagingService(): Order
368
    {
369
        $this->addons[] = 'packaging';
370
371
        return $this;
372
    }
373
374
    /**
375
     * add container addons to order.
376
     *
377
     * @return Order
378
     */
379
    public function addContainerService(): Order
380
    {
381
        $this->addons[] = 'container';
382
383
        return $this;
384
    }
385
386
    /**
387
     * @return string
388
     */
389
    public function getAddons(): string
390
    {
391
        return \implode(',', \array_unique((array) $this->addons));
392
    }
393
}
394