1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Loevgaard\DandomainFoundation\Entity; |
6
|
|
|
|
7
|
|
|
use Brick\Math\BigDecimal; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
use Loevgaard\DandomainFoundation; |
10
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\OrderLineInterface; |
|
|
|
|
11
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\OrderLineTrait; |
|
|
|
|
12
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\ProductInterface; |
|
|
|
|
13
|
|
|
use Money\Money; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @ORM\Entity() |
17
|
|
|
* @ORM\Table(name="ldf_order_lines") |
18
|
|
|
*/ |
19
|
|
|
class OrderLine extends AbstractEntity implements OrderLineInterface |
20
|
|
|
{ |
21
|
|
|
use OrderLineTrait; |
22
|
|
|
|
23
|
|
|
protected $hydrateConversions = [ |
24
|
|
|
'id' => 'externalId', |
25
|
|
|
'productId' => 'productNumber', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
* |
31
|
|
|
* @ORM\Id |
32
|
|
|
* @ORM\GeneratedValue |
33
|
|
|
* @ORM\Column(type="integer") |
34
|
|
|
**/ |
35
|
|
|
protected $id; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var int |
39
|
|
|
* |
40
|
|
|
* @ORM\Column(type="integer", unique=true) |
41
|
|
|
*/ |
42
|
|
|
protected $externalId; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string|null |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(nullable=true, type="string", length=191) |
48
|
|
|
*/ |
49
|
|
|
protected $fileUrl; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string|null |
53
|
|
|
* |
54
|
|
|
* @ORM\Column(nullable=true, type="string", length=191) |
55
|
|
|
*/ |
56
|
|
|
protected $productNumber; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string|null |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(nullable=true, type="text") |
62
|
|
|
*/ |
63
|
|
|
protected $productName; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var int|null |
67
|
|
|
* |
68
|
|
|
* @ORM\Column(nullable=true, type="integer") |
69
|
|
|
*/ |
70
|
|
|
protected $quantity; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* This number is excl vat. |
74
|
|
|
* |
75
|
|
|
* @var int|null |
76
|
|
|
* |
77
|
|
|
* @ORM\Column(nullable=true, type="integer") |
78
|
|
|
*/ |
79
|
|
|
protected $unitPrice; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* This number is excl vat. |
83
|
|
|
* |
84
|
|
|
* @var int|null |
85
|
|
|
* |
86
|
|
|
* @ORM\Column(nullable=true, type="integer") |
87
|
|
|
*/ |
88
|
|
|
protected $totalPrice; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var float|null |
92
|
|
|
* |
93
|
|
|
* @ORM\Column(nullable=true, type="decimal", precision=5, scale=2) |
94
|
|
|
*/ |
95
|
|
|
protected $vatPct; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var string|null |
99
|
|
|
* |
100
|
|
|
* @ORM\Column(nullable=true, type="string", length=191) |
101
|
|
|
*/ |
102
|
|
|
protected $variant; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var string|null |
106
|
|
|
* |
107
|
|
|
* @ORM\Column(nullable=true, type="text") |
108
|
|
|
*/ |
109
|
|
|
protected $xmlParams; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var Order |
113
|
|
|
* |
114
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE", nullable=false) |
115
|
|
|
* @ORM\ManyToOne(inversedBy="orderLines", targetEntity="Order") |
116
|
|
|
*/ |
117
|
|
|
protected $order; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var ProductInterface|null |
121
|
|
|
* |
122
|
|
|
* @ORM\JoinColumn(onDelete="SET NULL") |
123
|
|
|
* @ORM\ManyToOne(targetEntity="Product", cascade={"persist"}) |
124
|
|
|
*/ |
125
|
|
|
protected $product; |
126
|
|
|
|
127
|
|
|
// @todo implement withVat and withoutVat methods |
128
|
|
|
|
129
|
6 |
|
public function hydrate(array $data, bool $useConversions = false, $scalarsOnly = true) |
130
|
|
|
{ |
131
|
6 |
|
if (is_null($this->order)) { |
132
|
3 |
|
throw new \RuntimeException('Cannot hydrate order line without an associated order'); |
133
|
|
|
} |
134
|
|
|
|
135
|
3 |
|
if (isset($data['unitPrice'])) { |
136
|
3 |
|
$data['unitPrice'] = DandomainFoundation\createMoneyFromFloat($this->getCurrencyCode(), $data['unitPrice']); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
3 |
|
if (isset($data['totalPrice'])) { |
140
|
3 |
|
$data['totalPrice'] = DandomainFoundation\createMoneyFromFloat($this->getCurrencyCode(), $data['totalPrice']); |
141
|
|
|
} |
142
|
|
|
|
143
|
3 |
|
parent::hydrate($data, $useConversions, $scalarsOnly); |
144
|
3 |
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* This method copies properties from $orderLine onto this order line. |
148
|
|
|
* |
149
|
|
|
* @param OrderLineInterface $orderLine |
150
|
|
|
*/ |
151
|
|
|
public function copyProperties(OrderLineInterface $orderLine): void |
152
|
|
|
{ |
153
|
|
|
$this->setExternalId($orderLine->getExternalId()); |
154
|
|
|
$this->setFileUrl($orderLine->getFileUrl()); |
155
|
|
|
$this->setProductNumber($orderLine->getProductNumber()); |
156
|
|
|
$this->setProductName($orderLine->getProductName()); |
157
|
|
|
$this->setQuantity($orderLine->getQuantity()); |
158
|
|
|
$this->setUnitPrice($orderLine->getUnitPrice()); |
159
|
|
|
$this->setTotalPrice($orderLine->getTotalPrice()); |
160
|
|
|
$this->setVatPct($orderLine->getVatPct()); |
161
|
|
|
$this->setVariant($orderLine->getVariant()); |
162
|
|
|
$this->setXmlParams($orderLine->getXmlParams()); |
163
|
|
|
$this->setOrder($orderLine->getOrder()); |
164
|
|
|
$this->setProduct($orderLine->getProduct()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/* |
168
|
2 |
|
* Helper methods |
169
|
|
|
*/ |
170
|
3 |
|
public function getUnitPriceInclVat(): ?Money |
171
|
2 |
|
{ |
172
|
1 |
|
$unitPrice = $this->getUnitPrice(); |
173
|
1 |
|
if (!$unitPrice) { |
174
|
|
|
return null; |
175
|
2 |
|
} |
176
|
|
|
|
177
|
3 |
|
$multiplier = BigDecimal::of('100')->plus($this->vatPct)->exactlyDividedBy('100'); |
|
|
|
|
178
|
|
|
|
179
|
1 |
|
return $unitPrice->multiply((string) $multiplier); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function getUnitPriceExclVat(): ?Money |
183
|
|
|
{ |
184
|
|
|
return $this->getUnitPrice(); |
185
|
2 |
|
} |
186
|
|
|
|
187
|
3 |
|
public function getTotalPriceInclVat(): ?Money |
188
|
2 |
|
{ |
189
|
1 |
|
$totalPrice = $this->getTotalPrice(); |
190
|
1 |
|
if (!$totalPrice) { |
191
|
|
|
return null; |
192
|
2 |
|
} |
193
|
|
|
|
194
|
3 |
|
$multiplier = BigDecimal::of('100')->plus($this->vatPct)->exactlyDividedBy('100'); |
195
|
|
|
|
196
|
1 |
|
return $totalPrice->multiply((string) $multiplier); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function getTotalPriceExclVat(): ?Money |
200
|
|
|
{ |
201
|
|
|
return $this->getTotalPrice(); |
202
|
4 |
|
} |
203
|
|
|
|
204
|
4 |
|
/** |
205
|
|
|
* @return int |
206
|
|
|
*/ |
207
|
2 |
|
public function getId(): int |
208
|
|
|
{ |
209
|
2 |
|
return (int) $this->id; |
210
|
2 |
|
} |
211
|
|
|
|
212
|
2 |
|
/** |
213
|
|
|
* @param int $id |
214
|
2 |
|
* |
215
|
|
|
* @return OrderLineInterface |
216
|
|
|
*/ |
217
|
15 |
|
public function setId(int $id) |
218
|
|
|
{ |
219
|
15 |
|
$this->id = $id; |
220
|
|
|
|
221
|
1 |
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
12 |
|
* @return int |
226
|
|
|
*/ |
227
|
19 |
|
public function getExternalId(): int |
228
|
|
|
{ |
229
|
19 |
|
return (int) $this->externalId; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param int $externalId |
234
|
|
|
* |
235
|
2 |
|
* @return OrderLineInterface |
236
|
|
|
*/ |
237
|
8 |
|
public function setExternalId(int $externalId) |
238
|
|
|
{ |
239
|
6 |
|
$this->externalId = $externalId; |
240
|
|
|
|
241
|
6 |
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
2 |
|
* @return null|string |
246
|
|
|
*/ |
247
|
3 |
|
public function getFileUrl() |
248
|
|
|
{ |
249
|
3 |
|
return $this->fileUrl; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @param null|string $fileUrl |
254
|
|
|
* |
255
|
2 |
|
* @return OrderLineInterface |
256
|
|
|
*/ |
257
|
3 |
|
public function setFileUrl($fileUrl) |
258
|
|
|
{ |
259
|
1 |
|
$this->fileUrl = $fileUrl; |
260
|
|
|
|
261
|
1 |
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
2 |
|
* @return string|null |
266
|
|
|
*/ |
267
|
3 |
|
public function getProductNumber() |
268
|
|
|
{ |
269
|
3 |
|
return $this->productNumber; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param string|null $productNumber |
274
|
|
|
* |
275
|
2 |
|
* @return OrderLineInterface |
276
|
|
|
*/ |
277
|
3 |
|
public function setProductNumber($productNumber) |
278
|
|
|
{ |
279
|
1 |
|
$this->productNumber = $productNumber; |
280
|
|
|
|
281
|
1 |
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
2 |
|
* @return null|string |
286
|
|
|
*/ |
287
|
3 |
|
public function getProductName() |
288
|
|
|
{ |
289
|
3 |
|
return $this->productName; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @param null|string $productName |
294
|
|
|
* |
295
|
2 |
|
* @return OrderLineInterface |
296
|
|
|
*/ |
297
|
3 |
|
public function setProductName($productName) |
298
|
|
|
{ |
299
|
1 |
|
$this->productName = $productName; |
300
|
|
|
|
301
|
1 |
|
return $this; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
2 |
|
* @return int|null |
306
|
|
|
*/ |
307
|
3 |
|
public function getQuantity() |
308
|
|
|
{ |
309
|
3 |
|
return $this->quantity; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @param int|null $quantity |
314
|
|
|
* |
315
|
2 |
|
* @return OrderLineInterface |
316
|
|
|
*/ |
317
|
3 |
|
public function setQuantity($quantity) |
318
|
|
|
{ |
319
|
1 |
|
$this->quantity = $quantity; |
320
|
|
|
|
321
|
1 |
|
return $this; |
322
|
|
|
} |
323
|
4 |
|
|
324
|
|
|
/** |
325
|
4 |
|
* @return Money|null |
326
|
|
|
*/ |
327
|
5 |
|
public function getTotalPrice() |
328
|
|
|
{ |
329
|
1 |
|
return DandomainFoundation\createMoney($this->getCurrencyCode(), (int) $this->totalPrice); |
|
|
|
|
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
2 |
|
* @param Money|null $totalPrice |
334
|
|
|
* |
335
|
2 |
|
* @return OrderLineInterface |
336
|
|
|
*/ |
337
|
2 |
|
public function setTotalPrice(Money $totalPrice = null) |
338
|
|
|
{ |
339
|
2 |
|
$this->totalPrice = $totalPrice ? $totalPrice->getAmount() : $totalPrice; |
|
|
|
|
340
|
|
|
|
341
|
6 |
|
return $this; |
342
|
|
|
} |
343
|
4 |
|
|
344
|
|
|
/** |
345
|
4 |
|
* @return Money|null |
346
|
|
|
*/ |
347
|
1 |
|
public function getUnitPrice() |
348
|
2 |
|
{ |
349
|
1 |
|
return DandomainFoundation\createMoney($this->getCurrencyCode(), (int) $this->unitPrice); |
|
|
|
|
350
|
2 |
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param Money|null $unitPrice |
354
|
|
|
* |
355
|
|
|
* @return OrderLineInterface |
356
|
|
|
*/ |
357
|
2 |
|
public function setUnitPrice(Money $unitPrice = null) |
358
|
6 |
|
{ |
359
|
2 |
|
$this->unitPrice = $unitPrice ? $unitPrice->getAmount() : $unitPrice; |
|
|
|
|
360
|
6 |
|
|
361
|
2 |
|
return $this; |
362
|
6 |
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @return float |
366
|
|
|
*/ |
367
|
1 |
|
public function getVatPct() : float |
368
|
2 |
|
{ |
369
|
1 |
|
return (float)$this->vatPct; |
370
|
2 |
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @param float|null $vatPct |
374
|
|
|
* |
375
|
|
|
* @return OrderLineInterface |
376
|
|
|
*/ |
377
|
3 |
|
public function setVatPct($vatPct) |
378
|
2 |
|
{ |
379
|
3 |
|
$this->vatPct = $vatPct; |
380
|
2 |
|
|
381
|
3 |
|
return $this; |
382
|
2 |
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @return null|string |
386
|
|
|
*/ |
387
|
1 |
|
public function getVariant() |
388
|
|
|
{ |
389
|
1 |
|
return $this->variant; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @param null|string $variant |
394
|
|
|
* |
395
|
|
|
* @return OrderLineInterface |
396
|
|
|
*/ |
397
|
1 |
|
public function setVariant($variant) |
398
|
2 |
|
{ |
399
|
1 |
|
$this->variant = $variant; |
400
|
2 |
|
|
401
|
1 |
|
return $this; |
402
|
2 |
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* @return null|string |
406
|
|
|
*/ |
407
|
|
|
public function getXmlParams() |
408
|
8 |
|
{ |
409
|
|
|
return $this->xmlParams; |
410
|
8 |
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param null|string $xmlParams |
414
|
|
|
* |
415
|
|
|
* @return OrderLineInterface |
416
|
16 |
|
*/ |
417
|
1 |
|
public function setXmlParams($xmlParams) |
418
|
16 |
|
{ |
419
|
1 |
|
$this->xmlParams = $xmlParams; |
420
|
16 |
|
|
421
|
1 |
|
return $this; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* @return Order |
426
|
2 |
|
*/ |
427
|
4 |
|
public function getOrder(): ?Order |
428
|
2 |
|
{ |
429
|
4 |
|
return $this->order; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @param Order|null $order |
434
|
2 |
|
* |
435
|
|
|
* @return OrderLineInterface |
436
|
2 |
|
*/ |
437
|
8 |
|
public function setOrder(?Order $order) |
438
|
2 |
|
{ |
439
|
8 |
|
$this->order = $order; |
440
|
|
|
|
441
|
14 |
|
return $this; |
442
|
|
|
} |
443
|
6 |
|
|
444
|
|
|
/** |
445
|
|
|
* @return ProductInterface|null |
446
|
|
|
*/ |
447
|
1 |
|
public function getProduct() |
448
|
|
|
{ |
449
|
1 |
|
return $this->product; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @param ProductInterface|null $product |
454
|
|
|
* |
455
|
|
|
* @return OrderLineInterface |
456
|
|
|
*/ |
457
|
1 |
|
public function setProduct(ProductInterface $product = null) |
458
|
|
|
{ |
459
|
1 |
|
$this->product = $product; |
460
|
|
|
|
461
|
1 |
|
return $this; |
462
|
|
|
} |
463
|
|
|
|
464
|
3 |
|
protected function getCurrencyCode(): string |
465
|
|
|
{ |
466
|
3 |
|
return $this->getOrder()->getCurrency()->getIsoCodeAlpha(); |
467
|
|
|
} |
468
|
|
|
} |
469
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths