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