1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* part-db version 0.1 |
5
|
|
|
* Copyright (C) 2005 Christoph Lechner |
6
|
|
|
* http://www.cl-projects.de/ |
7
|
|
|
* |
8
|
|
|
* part-db version 0.2+ |
9
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
10
|
|
|
* http://code.google.com/p/part-db/ |
11
|
|
|
* |
12
|
|
|
* Part-DB Version 0.4+ |
13
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
14
|
|
|
* https://github.com/jbtronics |
15
|
|
|
* |
16
|
|
|
* This program is free software; you can redistribute it and/or |
17
|
|
|
* modify it under the terms of the GNU General Public License |
18
|
|
|
* as published by the Free Software Foundation; either version 2 |
19
|
|
|
* of the License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU General Public License |
27
|
|
|
* along with this program; if not, write to the Free Software |
28
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
declare(strict_types=1); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* part-db version 0.1 |
36
|
|
|
* Copyright (C) 2005 Christoph Lechner |
37
|
|
|
* http://www.cl-projects.de/. |
38
|
|
|
* |
39
|
|
|
* part-db version 0.2+ |
40
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
41
|
|
|
* http://code.google.com/p/part-db/ |
42
|
|
|
* |
43
|
|
|
* Part-DB Version 0.4+ |
44
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
45
|
|
|
* https://github.com/jbtronics |
46
|
|
|
* |
47
|
|
|
* This program is free software; you can redistribute it and/or |
48
|
|
|
* modify it under the terms of the GNU General Public License |
49
|
|
|
* as published by the Free Software Foundation; either version 2 |
50
|
|
|
* of the License, or (at your option) any later version. |
51
|
|
|
* |
52
|
|
|
* This program is distributed in the hope that it will be useful, |
53
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
54
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
55
|
|
|
* GNU General Public License for more details. |
56
|
|
|
* |
57
|
|
|
* You should have received a copy of the GNU General Public License |
58
|
|
|
* along with this program; if not, write to the Free Software |
59
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
60
|
|
|
*/ |
61
|
|
|
|
62
|
|
|
namespace App\Entity\Parts; |
63
|
|
|
|
64
|
|
|
use App\Entity\Attachments\Attachment; |
65
|
|
|
use App\Entity\Attachments\AttachmentContainingDBElement; |
66
|
|
|
use App\Entity\Devices\Device; |
67
|
|
|
use App\Entity\PriceInformations\Orderdetail; |
68
|
|
|
use App\Security\Annotations\ColumnSecurity; |
69
|
|
|
use App\Validator\Constraints\Selectable; |
70
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
71
|
|
|
use Doctrine\Common\Collections\Collection; |
72
|
|
|
use Doctrine\ORM\Mapping as ORM; |
73
|
|
|
|
74
|
|
|
use Doctrine\ORM\PersistentCollection; |
75
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Class Part. |
79
|
|
|
* |
80
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\PartRepository") |
81
|
|
|
* @ORM\Table("`parts`") |
82
|
|
|
*/ |
83
|
|
|
class Part extends AttachmentContainingDBElement |
84
|
|
|
{ |
85
|
|
|
public const INSTOCK_UNKNOWN = -2; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element") |
89
|
|
|
*/ |
90
|
|
|
protected $attachments; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var Category |
94
|
|
|
* @ORM\ManyToOne(targetEntity="Category", inversedBy="parts") |
95
|
|
|
* @ORM\JoinColumn(name="id_category", referencedColumnName="id") |
96
|
|
|
* @Selectable() |
97
|
|
|
*/ |
98
|
|
|
protected $category; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var Footprint|null |
102
|
|
|
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="parts") |
103
|
|
|
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id") |
104
|
|
|
* |
105
|
|
|
* @ColumnSecurity(prefix="footprint", type="object") |
106
|
|
|
* @Selectable() |
107
|
|
|
*/ |
108
|
|
|
protected $footprint; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var Manufacturer|null |
112
|
|
|
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="parts") |
113
|
|
|
* @ORM\JoinColumn(name="id_manufacturer", referencedColumnName="id") |
114
|
|
|
* |
115
|
|
|
* @ColumnSecurity(prefix="manufacturer", type="object") |
116
|
|
|
* @Selectable() |
117
|
|
|
*/ |
118
|
|
|
protected $manufacturer; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var Attachment |
122
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\Attachment") |
123
|
|
|
* @ORM\JoinColumn(name="id_master_picture_attachement", referencedColumnName="id") |
124
|
|
|
* |
125
|
|
|
* @ColumnSecurity(prefix="attachments", type="object") |
126
|
|
|
*/ |
127
|
|
|
protected $master_picture_attachment; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var Orderdetail[] |
131
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\PriceInformations\Orderdetail", mappedBy="part") |
132
|
|
|
* |
133
|
|
|
* @ColumnSecurity(prefix="orderdetails", type="object") |
134
|
|
|
*/ |
135
|
|
|
protected $orderdetails; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @var Orderdetail |
139
|
|
|
* @ORM\OneToOne(targetEntity="App\Entity\PriceInformations\Orderdetail") |
140
|
|
|
* @ORM\JoinColumn(name="order_orderdetails_id", referencedColumnName="id") |
141
|
|
|
* |
142
|
|
|
* @ColumnSecurity(prefix="order", type="object") |
143
|
|
|
*/ |
144
|
|
|
protected $order_orderdetail; |
145
|
|
|
|
146
|
|
|
//TODO |
147
|
|
|
protected $devices; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @ColumnSecurity(type="datetime") |
151
|
|
|
* @ORM\Column(type="datetimetz", name="datetime_added") |
152
|
|
|
*/ |
153
|
|
|
protected $addedDate; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @var \DateTime The date when this element was modified the last time. |
157
|
|
|
* @ORM\Column(type="datetimetz", name="last_modified") |
158
|
|
|
* @ColumnSecurity(type="datetime") |
159
|
|
|
*/ |
160
|
|
|
protected $lastModified; |
161
|
|
|
|
162
|
|
|
/********************** |
163
|
|
|
* Propertys |
164
|
|
|
***********************/ |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @var string |
168
|
|
|
* @ORM\Column(type="string") |
169
|
|
|
* |
170
|
|
|
* @ColumnSecurity(prefix="name") |
171
|
|
|
*/ |
172
|
|
|
protected $name = ''; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @var string |
176
|
|
|
* @ORM\Column(type="text") |
177
|
|
|
* |
178
|
|
|
* @ColumnSecurity(prefix="description") |
179
|
|
|
*/ |
180
|
|
|
protected $description = ''; |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @var ?PartLot[] |
184
|
|
|
* @ORM\OneToMany(targetEntity="PartLot", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=true) |
185
|
|
|
* @Assert\Valid() |
186
|
|
|
*/ |
187
|
|
|
protected $partLots; |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @var float |
191
|
|
|
* @ORM\Column(type="float") |
192
|
|
|
* @Assert\PositiveOrZero() |
193
|
|
|
* |
194
|
|
|
* @ColumnSecurity(prefix="mininstock", type="integer") |
195
|
|
|
*/ |
196
|
|
|
protected $minamount = 0; |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @var string |
200
|
|
|
* @ORM\Column(type="text") |
201
|
|
|
* @ColumnSecurity(prefix="comment") |
202
|
|
|
*/ |
203
|
|
|
protected $comment = ''; |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @var bool |
207
|
|
|
* @ORM\Column(type="boolean") |
208
|
|
|
*/ |
209
|
|
|
protected $visible = true; |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @var bool |
213
|
|
|
* @ORM\Column(type="boolean") |
214
|
|
|
* @ColumnSecurity(type="boolean") |
215
|
|
|
*/ |
216
|
|
|
protected $favorite = false; |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @var int |
220
|
|
|
* @ORM\Column(type="integer") |
221
|
|
|
* @ColumnSecurity(prefix="order", type="integer") |
222
|
|
|
*/ |
223
|
|
|
protected $order_quantity = 0; |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @var bool |
227
|
|
|
* @ORM\Column(type="boolean") |
228
|
|
|
* @ColumnSecurity(prefix="order", type="boolean") |
229
|
|
|
*/ |
230
|
|
|
protected $manual_order = false; |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @var string |
234
|
|
|
* @ORM\Column(type="string") |
235
|
|
|
* @ColumnSecurity(prefix="manufacturer", type="string", placeholder="") |
236
|
|
|
*/ |
237
|
|
|
protected $manufacturer_product_url = ''; |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @var string |
241
|
|
|
* @ORM\Column(type="string") |
242
|
|
|
* @ColumnSecurity(prefix="manufacturer", type="string", placeholder="") |
243
|
|
|
*/ |
244
|
|
|
protected $manufacturer_product_number = ''; |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @var bool Determines if this part entry needs review (for example, because it is work in progress) |
248
|
|
|
* @ORM\Column(type="boolean") |
249
|
|
|
*/ |
250
|
|
|
protected $needs_review = false; |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @var ?MeasurementUnit The unit in which the part's amount is measured. |
254
|
|
|
* @ORM\ManyToOne(targetEntity="MeasurementUnit") |
255
|
|
|
* @ORM\JoinColumn(name="id_part_unit", referencedColumnName="id", nullable=true) |
256
|
|
|
*/ |
257
|
|
|
protected $partUnit; |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @var string A comma seperated list of tags, assocciated with the part. |
261
|
|
|
* @ORM\Column(type="text") |
262
|
|
|
*/ |
263
|
|
|
protected $tags = ''; |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @var float|null How much a single part unit weighs in gramms. |
267
|
|
|
* @ORM\Column(type="float", nullable=true) |
268
|
|
|
* @Assert\Positive() |
269
|
|
|
*/ |
270
|
|
|
protected $mass; |
271
|
|
|
|
272
|
|
|
public function __construct() |
273
|
|
|
{ |
274
|
|
|
parent::__construct(); |
275
|
|
|
$this->partLots = new ArrayCollection(); |
|
|
|
|
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Returns the ID as an string, defined by the element class. |
280
|
|
|
* This should have a form like P000014, for a part with ID 14. |
281
|
|
|
* |
282
|
|
|
* @return string The ID as a string; |
283
|
|
|
*/ |
284
|
|
|
public function getIDString(): string |
285
|
|
|
{ |
286
|
|
|
return 'P' . sprintf('%06d', $this->getID()); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/********************************************************************************* |
290
|
|
|
* Getters |
291
|
|
|
********************************************************************************/ |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Get the description string like it is saved in the database. |
295
|
|
|
* This can contain BBCode, it is not parsed yet. |
296
|
|
|
* |
297
|
|
|
* @return string the description |
298
|
|
|
*/ |
299
|
|
|
public function getDescription(): string |
300
|
|
|
{ |
301
|
|
|
return htmlspecialchars($this->description); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Get the count of parts which must be in stock at least. |
306
|
|
|
* |
307
|
|
|
* @return int count of parts which must be in stock at least |
308
|
|
|
*/ |
309
|
|
|
public function getMinAmount(): float |
310
|
|
|
{ |
311
|
|
|
return $this->minamount; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Get the comment associated with this part. |
316
|
|
|
* |
317
|
|
|
* @return string The raw/unparsed comment |
318
|
|
|
*/ |
319
|
|
|
public function getComment(): string |
320
|
|
|
{ |
321
|
|
|
return htmlspecialchars($this->comment); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Get if this part is obsolete. |
326
|
|
|
* |
327
|
|
|
* A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete". |
328
|
|
|
* If a part has no orderdetails, the part isn't marked as obsolete. |
329
|
|
|
* |
330
|
|
|
* @return bool true, if this part is obsolete. false, if this part isn't obsolete |
331
|
|
|
*/ |
332
|
|
|
public function isObsolete(): bool |
333
|
|
|
{ |
334
|
|
|
$all_orderdetails = $this->getOrderdetails(); |
335
|
|
|
|
336
|
|
|
if (0 === count($all_orderdetails)) { |
337
|
|
|
return false; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
foreach ($all_orderdetails as $orderdetails) { |
341
|
|
|
if (!$orderdetails->getObsolete()) { |
342
|
|
|
return false; |
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
return true; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Get if this part is visible. |
351
|
|
|
* |
352
|
|
|
* @return bool true if this part is visible |
353
|
|
|
* false if this part isn't visible |
354
|
|
|
*/ |
355
|
|
|
public function isVisible(): bool |
356
|
|
|
{ |
357
|
|
|
return $this->visible; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Get if this part is a favorite. |
362
|
|
|
* |
363
|
|
|
* @return bool * true if this part is a favorite |
364
|
|
|
* * false if this part is not a favorite. |
365
|
|
|
*/ |
366
|
|
|
public function isFavorite(): bool |
367
|
|
|
{ |
368
|
|
|
return $this->favorite; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Get the selected order orderdetails of this part. |
373
|
|
|
* @return Orderdetail the selected order orderdetails |
374
|
|
|
*/ |
375
|
|
|
public function getOrderOrderdetails(): ?Orderdetail |
376
|
|
|
{ |
377
|
|
|
return $this->order_orderdetail; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Get the order quantity of this part. |
382
|
|
|
* |
383
|
|
|
* @return int the order quantity |
384
|
|
|
*/ |
385
|
|
|
public function getOrderQuantity(): int |
386
|
|
|
{ |
387
|
|
|
return $this->order_quantity; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Check if this part is marked for manual ordering. |
392
|
|
|
* |
393
|
|
|
* @return bool the "manual_order" attribute |
394
|
|
|
*/ |
395
|
|
|
public function isMarkedForManualOrder(): bool |
396
|
|
|
{ |
397
|
|
|
return $this->manual_order; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Get the link to the website of the article on the manufacturers website |
402
|
|
|
* When no this part has no explicit url set, then it is tried to generate one from the Manufacturer of this part |
403
|
|
|
* automatically. |
404
|
|
|
* |
405
|
|
|
* @param |
406
|
|
|
* |
407
|
|
|
* @return string the link to the article |
408
|
|
|
*/ |
409
|
|
|
public function getManufacturerProductUrl(): string |
410
|
|
|
{ |
411
|
|
|
if ('' !== $this->manufacturer_product_url) { |
412
|
|
|
return $this->manufacturer_product_url; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
if (null !== $this->getManufacturer()) { |
416
|
|
|
return $this->getManufacturer()->getAutoProductUrl($this->name); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
return ''; // no url is available |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Similar to getManufacturerProductUrl, but here only the database value is returned. |
424
|
|
|
* |
425
|
|
|
* @return string The manufacturer url saved in DB for this part. |
426
|
|
|
*/ |
427
|
|
|
public function getCustomProductURL(): string |
428
|
|
|
{ |
429
|
|
|
return $this->manufacturer_product_url; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Get the category of this part. |
434
|
|
|
* |
435
|
|
|
* There is always a category, for each part! |
436
|
|
|
* |
437
|
|
|
* @return Category the category of this part |
438
|
|
|
*/ |
439
|
|
|
public function getCategory(): Category |
440
|
|
|
{ |
441
|
|
|
return $this->category; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Get the footprint of this part (if there is one). |
446
|
|
|
* |
447
|
|
|
* @return Footprint the footprint of this part (if there is one) |
448
|
|
|
*/ |
449
|
|
|
public function getFootprint(): ?Footprint |
450
|
|
|
{ |
451
|
|
|
return $this->footprint; |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Get the manufacturer of this part (if there is one). |
456
|
|
|
* |
457
|
|
|
* @return Manufacturer the manufacturer of this part (if there is one) |
458
|
|
|
*/ |
459
|
|
|
public function getManufacturer(): ?Manufacturer |
460
|
|
|
{ |
461
|
|
|
return $this->manufacturer; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Get the master picture "Attachement"-object of this part (if there is one). |
466
|
|
|
* |
467
|
|
|
* @return Attachment the master picture Attachement of this part (if there is one) |
468
|
|
|
*/ |
469
|
|
|
public function getMasterPictureAttachement(): ?Attachment |
470
|
|
|
{ |
471
|
|
|
return $this->master_picture_attachment; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* Get all orderdetails of this part. |
476
|
|
|
* |
477
|
|
|
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned |
478
|
|
|
* |
479
|
|
|
* @return Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects |
480
|
|
|
* (empty array if there are no ones) |
481
|
|
|
* * the array is sorted by the suppliers names / minimum order quantity |
482
|
|
|
* |
483
|
|
|
*/ |
484
|
|
|
public function getOrderdetails(bool $hide_obsolete = false) : Collection |
485
|
|
|
{ |
486
|
|
|
//If needed hide the obsolete entries |
487
|
|
|
if ($hide_obsolete) { |
488
|
|
|
$orderdetails = $this->orderdetails; |
489
|
|
|
foreach ($orderdetails as $key => $details) { |
490
|
|
|
if ($details->getObsolete()) { |
491
|
|
|
unset($orderdetails[$key]); |
492
|
|
|
} |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
return $orderdetails; |
|
|
|
|
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
return $this->orderdetails; |
|
|
|
|
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* Get all devices which uses this part. |
503
|
|
|
* |
504
|
|
|
* @return Device[] * all devices which uses this part as a one-dimensional array of Device objects |
505
|
|
|
* (empty array if there are no ones) |
506
|
|
|
* * the array is sorted by the devices names |
507
|
|
|
* |
508
|
|
|
*/ |
509
|
|
|
public function getDevices(): array |
510
|
|
|
{ |
511
|
|
|
return $this->devices; |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* Get all prices of this part. |
516
|
|
|
* |
517
|
|
|
* This method simply gets the prices of the orderdetails and prepare them.\n |
518
|
|
|
* In the returned array/string there is a price for every supplier. |
519
|
|
|
* @param int $quantity this is the quantity to choose the correct priceinformation |
520
|
|
|
* @param int|null $multiplier * This is the multiplier which will be applied to every single price |
521
|
|
|
* * If you pass NULL, the number from $quantity will be used |
522
|
|
|
* @param bool $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned |
523
|
|
|
* |
524
|
|
|
* @return float[] all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true") |
525
|
|
|
* |
526
|
|
|
* @throws \Exception if there was an error |
527
|
|
|
*/ |
528
|
|
|
public function getPrices(int $quantity = 1, $multiplier = null, bool $hide_obsolete = false) : array |
529
|
|
|
{ |
530
|
|
|
$prices = array(); |
531
|
|
|
|
532
|
|
|
foreach ($this->getOrderdetails($hide_obsolete) as $details) { |
533
|
|
|
$prices[] = $details->getPrice($quantity, $multiplier); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
return $prices; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* Get the average price of all orderdetails. |
541
|
|
|
* |
542
|
|
|
* With the $multiplier you're able to multiply the price before it will be returned. |
543
|
|
|
* This is useful if you want to have the price as a string with currency, but multiplied with a factor. |
544
|
|
|
* |
545
|
|
|
* @param int $quantity this is the quantity to choose the correct priceinformations |
546
|
|
|
* @param int|null $multiplier * This is the multiplier which will be applied to every single price |
547
|
|
|
* * If you pass NULL, the number from $quantity will be used |
548
|
|
|
* |
549
|
|
|
* @return float price (if "$as_money_string == false") |
550
|
|
|
* |
551
|
|
|
* @throws \Exception if there was an error |
552
|
|
|
*/ |
553
|
|
|
public function getAveragePrice(int $quantity = 1, $multiplier = null) : ?float |
554
|
|
|
{ |
555
|
|
|
$prices = $this->getPrices($quantity, $multiplier, true); |
|
|
|
|
556
|
|
|
//Findout out |
557
|
|
|
|
558
|
|
|
$average_price = null; |
559
|
|
|
|
560
|
|
|
$count = 0; |
561
|
|
|
foreach ($this->getOrderdetails() as $orderdetail) { |
562
|
|
|
$price = $orderdetail->getPrice(1, null); |
563
|
|
|
if (null !== $price) { |
564
|
|
|
$average_price += $price; |
565
|
|
|
++$count; |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
if ($count > 0) { |
570
|
|
|
$average_price /= $count; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
return $average_price; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* Checks if this part is marked, for that it needs further review. |
578
|
|
|
* @return bool |
579
|
|
|
*/ |
580
|
|
|
public function isNeedsReview(): bool |
581
|
|
|
{ |
582
|
|
|
return $this->needs_review; |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
/** |
586
|
|
|
* Sets the "needs review" status of this part. |
587
|
|
|
* @param bool $needs_review |
588
|
|
|
* @return Part |
589
|
|
|
*/ |
590
|
|
|
public function setNeedsReview(bool $needs_review): Part |
591
|
|
|
{ |
592
|
|
|
$this->needs_review = $needs_review; |
593
|
|
|
return $this; |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* Get all part lots where this part is stored. |
598
|
|
|
* @return PartLot[]|Collection |
599
|
|
|
*/ |
600
|
|
|
public function getPartLots() : Collection |
601
|
|
|
{ |
602
|
|
|
return $this->partLots; |
|
|
|
|
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
public function addPartLot(PartLot $lot): Part |
606
|
|
|
{ |
607
|
|
|
$lot->setPart($this); |
608
|
|
|
$this->partLots->add($lot); |
|
|
|
|
609
|
|
|
return $this; |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
public function removePartLot(PartLot $lot): Part |
613
|
|
|
{ |
614
|
|
|
$this->partLots->removeElement($lot); |
615
|
|
|
return $this; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* Returns the assigned manufacturer product number (MPN) for this part. |
620
|
|
|
* @return string |
621
|
|
|
*/ |
622
|
|
|
public function getManufacturerProductNumber(): string |
623
|
|
|
{ |
624
|
|
|
return $this->manufacturer_product_number; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* Sets the manufacturer product number (MPN) for this part. |
629
|
|
|
* @param string $manufacturer_product_number |
630
|
|
|
* @return Part |
631
|
|
|
*/ |
632
|
|
|
public function setManufacturerProductNumber(string $manufacturer_product_number): Part |
633
|
|
|
{ |
634
|
|
|
$this->manufacturer_product_number = $manufacturer_product_number; |
635
|
|
|
return $this; |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
/** |
639
|
|
|
* Gets the measurement unit in which the part's amount should be measured. |
640
|
|
|
* Returns null if no specific unit was that. That means the parts are measured simply in quantity numbers. |
641
|
|
|
* @return ?MeasurementUnit |
642
|
|
|
*/ |
643
|
|
|
public function getPartUnit(): ?MeasurementUnit |
644
|
|
|
{ |
645
|
|
|
return $this->partUnit; |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* Sets the measurement unit in which the part's amount should be measured. |
650
|
|
|
* Set to null, if the part should be measured in quantities. |
651
|
|
|
* @param ?MeasurementUnit $partUnit |
652
|
|
|
* @return Part |
653
|
|
|
*/ |
654
|
|
|
public function setPartUnit(?MeasurementUnit $partUnit): Part |
655
|
|
|
{ |
656
|
|
|
$this->partUnit = $partUnit; |
657
|
|
|
return $this; |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* Gets a comma separated list, of tags, that are assigned to this part |
662
|
|
|
* @return string |
663
|
|
|
*/ |
664
|
|
|
public function getTags(): string |
665
|
|
|
{ |
666
|
|
|
return $this->tags; |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* Sets a comma separated list of tags, that are assigned to this part. |
671
|
|
|
* @param string $tags |
672
|
|
|
* @return Part |
673
|
|
|
*/ |
674
|
|
|
public function setTags(string $tags): Part |
675
|
|
|
{ |
676
|
|
|
$this->tags = $tags; |
677
|
|
|
return $this; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* Returns the mass of a single part unit. |
682
|
|
|
* Returns null, if the mass is unknown/not set yet |
683
|
|
|
* @return float|null |
684
|
|
|
*/ |
685
|
|
|
public function getMass(): ?float |
686
|
|
|
{ |
687
|
|
|
return $this->mass; |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* Sets the mass of a single part unit. |
692
|
|
|
* Sett to null, if the mass is unknown. |
693
|
|
|
* @param float|null $mass |
694
|
|
|
* @return Part |
695
|
|
|
*/ |
696
|
|
|
public function setMass(?float $mass): Part |
697
|
|
|
{ |
698
|
|
|
$this->mass = $mass; |
699
|
|
|
return $this; |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
/** |
703
|
|
|
* Checks if this part uses the float amount . |
704
|
|
|
* This setting is based on the part unit (see MeasurementUnit->isInteger()). |
705
|
|
|
* @return bool True if the float amount field should be used. False if the integer instock field should be used. |
706
|
|
|
*/ |
707
|
|
|
public function useFloatAmount(): bool |
708
|
|
|
{ |
709
|
|
|
if ($this->partUnit instanceof MeasurementUnit) { |
710
|
|
|
return $this->partUnit->isInteger(); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
//When no part unit is set, treat it as part count, and so use the integer value. |
714
|
|
|
return false; |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
/** |
718
|
|
|
* Returns the summed amount of this part (over all part lots) |
719
|
|
|
* @return float |
720
|
|
|
*/ |
721
|
|
|
public function getAmountSum() : float |
722
|
|
|
{ |
723
|
|
|
//TODO: Find a method to do this natively in SQL, the current method could be a bit slow |
724
|
|
|
$sum = 0; |
725
|
|
|
foreach($this->getPartLots() as $lot) { |
726
|
|
|
//Dont use the instock value, if it is unkown |
727
|
|
|
if ($lot->isInstockUnknown()) { |
728
|
|
|
continue; |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
$sum += $lot->getAmount(); |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
if(!$this->useFloatAmount()) { |
735
|
|
|
return $sum; |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
return round($sum); |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
/******************************************************************************** |
742
|
|
|
* |
743
|
|
|
* Setters |
744
|
|
|
* |
745
|
|
|
*********************************************************************************/ |
746
|
|
|
|
747
|
|
|
/** |
748
|
|
|
* Set the description. |
749
|
|
|
* |
750
|
|
|
* @param string $new_description the new description |
751
|
|
|
* |
752
|
|
|
* @return self |
753
|
|
|
*/ |
754
|
|
|
public function setDescription(?string $new_description): self |
755
|
|
|
{ |
756
|
|
|
$this->description = $new_description; |
757
|
|
|
|
758
|
|
|
return $this; |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
/** |
762
|
|
|
* Set the minimum amount of parts that have to be instock. |
763
|
|
|
* See getPartUnit() for the associated unit. |
764
|
|
|
* |
765
|
|
|
* @param int $new_mininstock the new count of parts which should be in stock at least |
766
|
|
|
* |
767
|
|
|
* @return self |
768
|
|
|
*/ |
769
|
|
|
public function setMinAmount(float $new_minamount): self |
770
|
|
|
{ |
771
|
|
|
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.'); |
772
|
|
|
|
773
|
|
|
$this->minamount = $new_minamount; |
774
|
|
|
|
775
|
|
|
return $this; |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
/** |
779
|
|
|
* Set the comment. |
780
|
|
|
* |
781
|
|
|
* @param string $new_comment the new comment |
782
|
|
|
* |
783
|
|
|
* @return self |
784
|
|
|
*/ |
785
|
|
|
public function setComment(string $new_comment): self |
786
|
|
|
{ |
787
|
|
|
$this->comment = $new_comment; |
788
|
|
|
|
789
|
|
|
return $this; |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
/** |
793
|
|
|
* Set the "manual_order" attribute. |
794
|
|
|
* |
795
|
|
|
* @param bool $new_manual_order the new "manual_order" attribute |
796
|
|
|
* @param int $new_order_quantity the new order quantity |
797
|
|
|
* @param int|null $new_order_orderdetails_id * the ID of the new order orderdetails |
798
|
|
|
* * or Zero for "no order orderdetails" |
799
|
|
|
* * or NULL for automatic order orderdetails |
800
|
|
|
* (if the part has exactly one orderdetails, |
801
|
|
|
* set this orderdetails as order orderdetails. |
802
|
|
|
* Otherwise, set "no order orderdetails") |
803
|
|
|
* |
804
|
|
|
* @return self |
805
|
|
|
*/ |
806
|
|
|
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, ?Orderdetail $new_order_orderdetail = null): Part |
807
|
|
|
{ |
808
|
|
|
//Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!'); |
809
|
|
|
|
810
|
|
|
$this->manual_order = $new_manual_order; |
811
|
|
|
|
812
|
|
|
//TODO; |
813
|
|
|
$this->order_orderdetail = $new_order_orderdetail; |
814
|
|
|
$this->order_quantity = $new_order_quantity; |
815
|
|
|
|
816
|
|
|
return $this; |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
/** |
820
|
|
|
* Set the category of this Part. |
821
|
|
|
* |
822
|
|
|
* Every part must have a valid category (in contrast to the |
823
|
|
|
* attributes "footprint", "storelocation", ...)! |
824
|
|
|
* |
825
|
|
|
* @param Category $category The new category of this part |
826
|
|
|
* |
827
|
|
|
* @return self |
828
|
|
|
*/ |
829
|
|
|
public function setCategory(Category $category): Part |
830
|
|
|
{ |
831
|
|
|
$this->category = $category; |
832
|
|
|
|
833
|
|
|
return $this; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
/** |
837
|
|
|
* Set the new Footprint of this Part. |
838
|
|
|
* |
839
|
|
|
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have |
840
|
|
|
* a footprint. |
841
|
|
|
* |
842
|
|
|
* @return self |
843
|
|
|
*/ |
844
|
|
|
public function setFootprint(?Footprint $new_footprint): Part |
845
|
|
|
{ |
846
|
|
|
$this->footprint = $new_footprint; |
847
|
|
|
|
848
|
|
|
return $this; |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
/** |
852
|
|
|
* Sets the new manufacturer of this part. |
853
|
|
|
* |
854
|
|
|
* @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should |
855
|
|
|
* not have a manufacturer. |
856
|
|
|
* |
857
|
|
|
* @return Part |
858
|
|
|
*/ |
859
|
|
|
public function setManufacturer(?Manufacturer $new_manufacturer): self |
860
|
|
|
{ |
861
|
|
|
$this->manufacturer = $new_manufacturer; |
862
|
|
|
|
863
|
|
|
return $this; |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
/** |
867
|
|
|
* Set the favorite status for this part. |
868
|
|
|
* |
869
|
|
|
* @param $new_favorite_status bool The new favorite status, that should be applied on this part. |
870
|
|
|
* Set this to true, when the part should be a favorite. |
871
|
|
|
* |
872
|
|
|
* @return self |
873
|
|
|
*/ |
874
|
|
|
public function setFavorite(bool $new_favorite_status): self |
875
|
|
|
{ |
876
|
|
|
$this->favorite = $new_favorite_status; |
877
|
|
|
|
878
|
|
|
return $this; |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
/** |
882
|
|
|
* Sets the URL to the manufacturer site about this Part. Set to "" if this part should use the automatically URL based on its manufacturer. |
883
|
|
|
* |
884
|
|
|
* @param string $new_url The new url |
885
|
|
|
* |
886
|
|
|
* @return self |
887
|
|
|
*/ |
888
|
|
|
public function setManufacturerProductURL(string $new_url): self |
889
|
|
|
{ |
890
|
|
|
$this->manufacturer_product_url = $new_url; |
891
|
|
|
|
892
|
|
|
return $this; |
893
|
|
|
} |
894
|
|
|
} |
895
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..