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