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 Symfony\Component\Validator\Constraints as Assert; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Class Part. |
78
|
|
|
* |
79
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\PartRepository") |
80
|
|
|
* @ORM\Table("`parts`") |
81
|
|
|
*/ |
82
|
|
|
class Part extends AttachmentContainingDBElement |
83
|
|
|
{ |
84
|
|
|
public const INSTOCK_UNKNOWN = -2; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
88
|
|
|
* @Assert\Valid() |
89
|
|
|
*/ |
90
|
|
|
protected $attachments; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var Category |
94
|
|
|
* @ORM\ManyToOne(targetEntity="Category", inversedBy="parts") |
95
|
|
|
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false) |
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", cascade={"persist", "remove"}, orphanRemoval=true) |
132
|
|
|
* @Assert\Valid() |
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="datetime", name="datetime_added", options={"default"="CURRENT_TIMESTAMP"}) |
152
|
|
|
*/ |
153
|
|
|
protected $addedDate; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @var \DateTime The date when this element was modified the last time. |
157
|
|
|
* @ColumnSecurity(type="datetime") |
158
|
|
|
* @ORM\Column(type="datetime", name="last_modified", options={"default"="CURRENT_TIMESTAMP"}) |
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 string |
248
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
249
|
|
|
* @Assert\Choice({"announced", "active", "nrfnd", "eol", "discontinued", ""}) |
250
|
|
|
*/ |
251
|
|
|
protected $manufacturing_status = ""; |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @var bool Determines if this part entry needs review (for example, because it is work in progress) |
255
|
|
|
* @ORM\Column(type="boolean") |
256
|
|
|
*/ |
257
|
|
|
protected $needs_review = false; |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @var ?MeasurementUnit The unit in which the part's amount is measured. |
261
|
|
|
* @ORM\ManyToOne(targetEntity="MeasurementUnit") |
262
|
|
|
* @ORM\JoinColumn(name="id_part_unit", referencedColumnName="id", nullable=true) |
263
|
|
|
*/ |
264
|
|
|
protected $partUnit; |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @var string A comma seperated list of tags, assocciated with the part. |
268
|
|
|
* @ORM\Column(type="text") |
269
|
|
|
*/ |
270
|
|
|
protected $tags = ''; |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @var float|null How much a single part unit weighs in gramms. |
274
|
|
|
* @ORM\Column(type="float", nullable=true) |
275
|
|
|
* @Assert\PositiveOrZero() |
276
|
|
|
*/ |
277
|
|
|
protected $mass; |
278
|
|
|
|
279
|
|
|
public function __construct() |
280
|
|
|
{ |
281
|
|
|
parent::__construct(); |
282
|
|
|
$this->partLots = new ArrayCollection(); |
|
|
|
|
283
|
|
|
$this->orderdetails = new ArrayCollection(); |
|
|
|
|
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Returns the ID as an string, defined by the element class. |
288
|
|
|
* This should have a form like P000014, for a part with ID 14. |
289
|
|
|
* |
290
|
|
|
* @return string The ID as a string; |
291
|
|
|
*/ |
292
|
|
|
public function getIDString(): string |
293
|
|
|
{ |
294
|
|
|
return 'P' . sprintf('%06d', $this->getID()); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/********************************************************************************* |
298
|
|
|
* Getters |
299
|
|
|
********************************************************************************/ |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Get the description string like it is saved in the database. |
303
|
|
|
* This can contain BBCode, it is not parsed yet. |
304
|
|
|
* |
305
|
|
|
* @return string the description |
306
|
|
|
*/ |
307
|
|
|
public function getDescription(): string |
308
|
|
|
{ |
309
|
|
|
return htmlspecialchars($this->description); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Get the count of parts which must be in stock at least. |
314
|
|
|
* If a integer-based part unit is selected, the value will be rounded to integers |
315
|
|
|
* |
316
|
|
|
* @return float count of parts which must be in stock at least |
317
|
|
|
*/ |
318
|
|
|
public function getMinAmount(): float |
319
|
|
|
{ |
320
|
|
|
if ($this->useFloatAmount()) { |
321
|
|
|
return $this->minamount; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
return round($this->minamount); |
325
|
|
|
|
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Get the comment associated with this part. |
330
|
|
|
* |
331
|
|
|
* @return string The raw/unparsed comment |
332
|
|
|
*/ |
333
|
|
|
public function getComment(): string |
334
|
|
|
{ |
335
|
|
|
return htmlspecialchars($this->comment); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Get if this part is obsolete. |
340
|
|
|
* |
341
|
|
|
* A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete". |
342
|
|
|
* If a part has no orderdetails, the part isn't marked as obsolete. |
343
|
|
|
* |
344
|
|
|
* @return bool true, if this part is obsolete. false, if this part isn't obsolete |
345
|
|
|
*/ |
346
|
|
|
public function isObsolete(): bool |
347
|
|
|
{ |
348
|
|
|
$all_orderdetails = $this->getOrderdetails(); |
349
|
|
|
|
350
|
|
|
if (0 === count($all_orderdetails)) { |
351
|
|
|
return false; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
foreach ($all_orderdetails as $orderdetails) { |
355
|
|
|
if (!$orderdetails->getObsolete()) { |
356
|
|
|
return false; |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
return true; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Get if this part is visible. |
365
|
|
|
* |
366
|
|
|
* @return bool true if this part is visible |
367
|
|
|
* false if this part isn't visible |
368
|
|
|
*/ |
369
|
|
|
public function isVisible(): bool |
370
|
|
|
{ |
371
|
|
|
return $this->visible; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Get if this part is a favorite. |
376
|
|
|
* |
377
|
|
|
* @return bool * true if this part is a favorite |
378
|
|
|
* * false if this part is not a favorite. |
379
|
|
|
*/ |
380
|
|
|
public function isFavorite(): bool |
381
|
|
|
{ |
382
|
|
|
return $this->favorite; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Get the selected order orderdetails of this part. |
387
|
|
|
* @return Orderdetail the selected order orderdetails |
388
|
|
|
*/ |
389
|
|
|
public function getOrderOrderdetails(): ?Orderdetail |
390
|
|
|
{ |
391
|
|
|
return $this->order_orderdetail; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Get the order quantity of this part. |
396
|
|
|
* |
397
|
|
|
* @return int the order quantity |
398
|
|
|
*/ |
399
|
|
|
public function getOrderQuantity(): int |
400
|
|
|
{ |
401
|
|
|
return $this->order_quantity; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* Check if this part is marked for manual ordering. |
406
|
|
|
* |
407
|
|
|
* @return bool the "manual_order" attribute |
408
|
|
|
*/ |
409
|
|
|
public function isMarkedForManualOrder(): bool |
410
|
|
|
{ |
411
|
|
|
return $this->manual_order; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Get the link to the website of the article on the manufacturers website |
416
|
|
|
* When no this part has no explicit url set, then it is tried to generate one from the Manufacturer of this part |
417
|
|
|
* automatically. |
418
|
|
|
* |
419
|
|
|
* @param |
420
|
|
|
* |
421
|
|
|
* @return string the link to the article |
422
|
|
|
*/ |
423
|
|
|
public function getManufacturerProductUrl(): string |
424
|
|
|
{ |
425
|
|
|
if ('' !== $this->manufacturer_product_url) { |
426
|
|
|
return $this->manufacturer_product_url; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
if (null !== $this->getManufacturer()) { |
430
|
|
|
return $this->getManufacturer()->getAutoProductUrl($this->name); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
return ''; // no url is available |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Similar to getManufacturerProductUrl, but here only the database value is returned. |
438
|
|
|
* |
439
|
|
|
* @return string The manufacturer url saved in DB for this part. |
440
|
|
|
*/ |
441
|
|
|
public function getCustomProductURL(): string |
442
|
|
|
{ |
443
|
|
|
return $this->manufacturer_product_url; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Returns the manufacturing/production status for this part. |
448
|
|
|
* The status can be one of the following: |
449
|
|
|
* (Similar to https://designspark.zendesk.com/hc/en-us/articles/213584805-What-are-the-Lifecycle-Status-definitions-) |
450
|
|
|
* * "": Status unknown |
451
|
|
|
* * "announced": Part has been announced, but is not in production yet |
452
|
|
|
* * "active": Part is in production and will be for the forseeable future |
453
|
|
|
* * "nrfnd": Not recommended for new designs. |
454
|
|
|
* * "eol": Part will become discontinued soon |
455
|
|
|
* * "discontinued": Part is obsolete/discontinued by the manufacturer |
456
|
|
|
* @return string |
457
|
|
|
*/ |
458
|
|
|
public function getManufacturingStatus(): ?string |
459
|
|
|
{ |
460
|
|
|
return $this->manufacturing_status; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Sets the manufacturing status for this part |
465
|
|
|
* See getManufacturingStatus() for valid values. |
466
|
|
|
* @param string $manufacturing_status |
467
|
|
|
* @return Part |
468
|
|
|
*/ |
469
|
|
|
public function setManufacturingStatus(string $manufacturing_status): Part |
470
|
|
|
{ |
471
|
|
|
$this->manufacturing_status = $manufacturing_status; |
472
|
|
|
return $this; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
|
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Get the category of this part. |
479
|
|
|
* |
480
|
|
|
* There is always a category, for each part! |
481
|
|
|
* |
482
|
|
|
* @return Category the category of this part |
483
|
|
|
*/ |
484
|
|
|
public function getCategory(): Category |
485
|
|
|
{ |
486
|
|
|
return $this->category; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* Get the footprint of this part (if there is one). |
491
|
|
|
* |
492
|
|
|
* @return Footprint the footprint of this part (if there is one) |
493
|
|
|
*/ |
494
|
|
|
public function getFootprint(): ?Footprint |
495
|
|
|
{ |
496
|
|
|
return $this->footprint; |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* Get the manufacturer of this part (if there is one). |
501
|
|
|
* |
502
|
|
|
* @return Manufacturer the manufacturer of this part (if there is one) |
503
|
|
|
*/ |
504
|
|
|
public function getManufacturer(): ?Manufacturer |
505
|
|
|
{ |
506
|
|
|
return $this->manufacturer; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
/** |
510
|
|
|
* Get the master picture "Attachement"-object of this part (if there is one). |
511
|
|
|
* |
512
|
|
|
* @return Attachment the master picture Attachement of this part (if there is one) |
513
|
|
|
*/ |
514
|
|
|
public function getMasterPictureAttachement(): ?Attachment |
515
|
|
|
{ |
516
|
|
|
return $this->master_picture_attachment; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Get all orderdetails of this part. |
521
|
|
|
* |
522
|
|
|
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned |
523
|
|
|
* |
524
|
|
|
* @return Collection|Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects |
525
|
|
|
* (empty array if there are no ones) |
526
|
|
|
* * the array is sorted by the suppliers names / minimum order quantity |
527
|
|
|
* |
528
|
|
|
*/ |
529
|
|
|
public function getOrderdetails(bool $hide_obsolete = false) : Collection |
530
|
|
|
{ |
531
|
|
|
//If needed hide the obsolete entries |
532
|
|
|
if ($hide_obsolete) { |
533
|
|
|
$orderdetails = $this->orderdetails; |
534
|
|
|
foreach ($orderdetails as $key => $details) { |
535
|
|
|
if ($details->getObsolete()) { |
536
|
|
|
unset($orderdetails[$key]); |
537
|
|
|
} |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
return $orderdetails; |
|
|
|
|
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
return $this->orderdetails; |
|
|
|
|
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
public function addOrderdetail(Orderdetail $orderdetail) : Part |
547
|
|
|
{ |
548
|
|
|
$orderdetail->setPart($this); |
549
|
|
|
$this->orderdetails->add($orderdetail); |
550
|
|
|
return $this; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
public function removeOrderdetail(Orderdetail $orderdetail) : Part |
554
|
|
|
{ |
555
|
|
|
$this->orderdetails->removeElement($orderdetail); |
556
|
|
|
return $this; |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* Get all devices which uses this part. |
561
|
|
|
* |
562
|
|
|
* @return Device[] * all devices which uses this part as a one-dimensional array of Device objects |
563
|
|
|
* (empty array if there are no ones) |
564
|
|
|
* * the array is sorted by the devices names |
565
|
|
|
* |
566
|
|
|
*/ |
567
|
|
|
public function getDevices(): array |
568
|
|
|
{ |
569
|
|
|
return $this->devices; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* Checks if this part is marked, for that it needs further review. |
574
|
|
|
* @return bool |
575
|
|
|
*/ |
576
|
|
|
public function isNeedsReview(): bool |
577
|
|
|
{ |
578
|
|
|
return $this->needs_review; |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* Sets the "needs review" status of this part. |
583
|
|
|
* @param bool $needs_review |
584
|
|
|
* @return Part |
585
|
|
|
*/ |
586
|
|
|
public function setNeedsReview(bool $needs_review): Part |
587
|
|
|
{ |
588
|
|
|
$this->needs_review = $needs_review; |
589
|
|
|
return $this; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* Get all part lots where this part is stored. |
594
|
|
|
* @return PartLot[]|Collection |
595
|
|
|
*/ |
596
|
|
|
public function getPartLots() : Collection |
597
|
|
|
{ |
598
|
|
|
return $this->partLots; |
|
|
|
|
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
public function addPartLot(PartLot $lot): Part |
602
|
|
|
{ |
603
|
|
|
$lot->setPart($this); |
604
|
|
|
$this->partLots->add($lot); |
|
|
|
|
605
|
|
|
return $this; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
public function removePartLot(PartLot $lot): Part |
609
|
|
|
{ |
610
|
|
|
$this->partLots->removeElement($lot); |
611
|
|
|
return $this; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* Returns the assigned manufacturer product number (MPN) for this part. |
616
|
|
|
* @return string |
617
|
|
|
*/ |
618
|
|
|
public function getManufacturerProductNumber(): string |
619
|
|
|
{ |
620
|
|
|
return $this->manufacturer_product_number; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* Sets the manufacturer product number (MPN) for this part. |
625
|
|
|
* @param string $manufacturer_product_number |
626
|
|
|
* @return Part |
627
|
|
|
*/ |
628
|
|
|
public function setManufacturerProductNumber(string $manufacturer_product_number): Part |
629
|
|
|
{ |
630
|
|
|
$this->manufacturer_product_number = $manufacturer_product_number; |
631
|
|
|
return $this; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
/** |
635
|
|
|
* Gets the measurement unit in which the part's amount should be measured. |
636
|
|
|
* Returns null if no specific unit was that. That means the parts are measured simply in quantity numbers. |
637
|
|
|
* @return MeasurementUnit|null |
638
|
|
|
*/ |
639
|
|
|
public function getPartUnit(): ?MeasurementUnit |
640
|
|
|
{ |
641
|
|
|
return $this->partUnit; |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
/** |
645
|
|
|
* Sets the measurement unit in which the part's amount should be measured. |
646
|
|
|
* Set to null, if the part should be measured in quantities. |
647
|
|
|
* @param MeasurementUnit|null $partUnit |
648
|
|
|
* @return Part |
649
|
|
|
*/ |
650
|
|
|
public function setPartUnit(?MeasurementUnit $partUnit): Part |
651
|
|
|
{ |
652
|
|
|
$this->partUnit = $partUnit; |
653
|
|
|
return $this; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* Gets a comma separated list, of tags, that are assigned to this part |
658
|
|
|
* @return string |
659
|
|
|
*/ |
660
|
|
|
public function getTags(): string |
661
|
|
|
{ |
662
|
|
|
return $this->tags; |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
/** |
666
|
|
|
* Sets a comma separated list of tags, that are assigned to this part. |
667
|
|
|
* @param string $tags |
668
|
|
|
* @return Part |
669
|
|
|
*/ |
670
|
|
|
public function setTags(string $tags): Part |
671
|
|
|
{ |
672
|
|
|
$this->tags = $tags; |
673
|
|
|
return $this; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
/** |
677
|
|
|
* Returns the mass of a single part unit. |
678
|
|
|
* Returns null, if the mass is unknown/not set yet |
679
|
|
|
* @return float|null |
680
|
|
|
*/ |
681
|
|
|
public function getMass(): ?float |
682
|
|
|
{ |
683
|
|
|
return $this->mass; |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
/** |
687
|
|
|
* Sets the mass of a single part unit. |
688
|
|
|
* Sett to null, if the mass is unknown. |
689
|
|
|
* @param float|null $mass |
690
|
|
|
* @return Part |
691
|
|
|
*/ |
692
|
|
|
public function setMass(?float $mass): Part |
693
|
|
|
{ |
694
|
|
|
$this->mass = $mass; |
695
|
|
|
return $this; |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* Checks if this part uses the float amount . |
700
|
|
|
* This setting is based on the part unit (see MeasurementUnit->isInteger()). |
701
|
|
|
* @return bool True if the float amount field should be used. False if the integer instock field should be used. |
702
|
|
|
*/ |
703
|
|
|
public function useFloatAmount(): bool |
704
|
|
|
{ |
705
|
|
|
if ($this->partUnit instanceof MeasurementUnit) { |
706
|
|
|
return !$this->partUnit->isInteger(); |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
//When no part unit is set, treat it as part count, and so use the integer value. |
710
|
|
|
return false; |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
/** |
714
|
|
|
* Returns the summed amount of this part (over all part lots) |
715
|
|
|
* @return float |
716
|
|
|
*/ |
717
|
|
|
public function getAmountSum() : float |
718
|
|
|
{ |
719
|
|
|
//TODO: Find a method to do this natively in SQL, the current method could be a bit slow |
720
|
|
|
$sum = 0; |
721
|
|
|
foreach ($this->getPartLots() as $lot) { |
722
|
|
|
//Dont use the instock value, if it is unkown |
723
|
|
|
if ($lot->isInstockUnknown()) { |
724
|
|
|
continue; |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
$sum += $lot->getAmount(); |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
if ($this->useFloatAmount()) { |
731
|
|
|
return $sum; |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
return round($sum); |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/******************************************************************************** |
738
|
|
|
* |
739
|
|
|
* Setters |
740
|
|
|
* |
741
|
|
|
*********************************************************************************/ |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Set the description. |
745
|
|
|
* |
746
|
|
|
* @param string $new_description the new description |
747
|
|
|
* |
748
|
|
|
* @return self |
749
|
|
|
*/ |
750
|
|
|
public function setDescription(?string $new_description): self |
751
|
|
|
{ |
752
|
|
|
$this->description = $new_description; |
753
|
|
|
|
754
|
|
|
return $this; |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
/** |
758
|
|
|
* Set the minimum amount of parts that have to be instock. |
759
|
|
|
* See getPartUnit() for the associated unit. |
760
|
|
|
* |
761
|
|
|
* @param int $new_minamount the new count of parts which should be in stock at least |
762
|
|
|
* |
763
|
|
|
* @return self |
764
|
|
|
*/ |
765
|
|
|
public function setMinAmount(float $new_minamount): self |
766
|
|
|
{ |
767
|
|
|
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.'); |
768
|
|
|
|
769
|
|
|
$this->minamount = $new_minamount; |
770
|
|
|
|
771
|
|
|
return $this; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* Set the comment. |
776
|
|
|
* |
777
|
|
|
* @param string $new_comment the new comment |
778
|
|
|
* |
779
|
|
|
* @return self |
780
|
|
|
*/ |
781
|
|
|
public function setComment(string $new_comment): self |
782
|
|
|
{ |
783
|
|
|
$this->comment = $new_comment; |
784
|
|
|
|
785
|
|
|
return $this; |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
/** |
789
|
|
|
* Set the "manual_order" attribute. |
790
|
|
|
* |
791
|
|
|
* @param bool $new_manual_order the new "manual_order" attribute |
792
|
|
|
* @param int $new_order_quantity the new order quantity |
793
|
|
|
* @param int|null $new_order_orderdetails_id * the ID of the new order orderdetails |
794
|
|
|
* * or Zero for "no order orderdetails" |
795
|
|
|
* * or NULL for automatic order orderdetails |
796
|
|
|
* (if the part has exactly one orderdetails, |
797
|
|
|
* set this orderdetails as order orderdetails. |
798
|
|
|
* Otherwise, set "no order orderdetails") |
799
|
|
|
* |
800
|
|
|
* @return self |
801
|
|
|
*/ |
802
|
|
|
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, ?Orderdetail $new_order_orderdetail = null): Part |
803
|
|
|
{ |
804
|
|
|
//Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!'); |
805
|
|
|
|
806
|
|
|
$this->manual_order = $new_manual_order; |
807
|
|
|
|
808
|
|
|
//TODO; |
809
|
|
|
$this->order_orderdetail = $new_order_orderdetail; |
810
|
|
|
$this->order_quantity = $new_order_quantity; |
811
|
|
|
|
812
|
|
|
return $this; |
813
|
|
|
} |
814
|
|
|
|
815
|
|
|
/** |
816
|
|
|
* Set the category of this Part. |
817
|
|
|
* |
818
|
|
|
* Every part must have a valid category (in contrast to the |
819
|
|
|
* attributes "footprint", "storelocation", ...)! |
820
|
|
|
* |
821
|
|
|
* @param Category $category The new category of this part |
822
|
|
|
* |
823
|
|
|
* @return self |
824
|
|
|
*/ |
825
|
|
|
public function setCategory(Category $category): Part |
826
|
|
|
{ |
827
|
|
|
$this->category = $category; |
828
|
|
|
|
829
|
|
|
return $this; |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
/** |
833
|
|
|
* Set the new Footprint of this Part. |
834
|
|
|
* |
835
|
|
|
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have |
836
|
|
|
* a footprint. |
837
|
|
|
* |
838
|
|
|
* @return self |
839
|
|
|
*/ |
840
|
|
|
public function setFootprint(?Footprint $new_footprint): Part |
841
|
|
|
{ |
842
|
|
|
$this->footprint = $new_footprint; |
843
|
|
|
|
844
|
|
|
return $this; |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
/** |
848
|
|
|
* Sets the new manufacturer of this part. |
849
|
|
|
* |
850
|
|
|
* @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should |
851
|
|
|
* not have a manufacturer. |
852
|
|
|
* |
853
|
|
|
* @return Part |
854
|
|
|
*/ |
855
|
|
|
public function setManufacturer(?Manufacturer $new_manufacturer): self |
856
|
|
|
{ |
857
|
|
|
$this->manufacturer = $new_manufacturer; |
858
|
|
|
|
859
|
|
|
return $this; |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
/** |
863
|
|
|
* Set the favorite status for this part. |
864
|
|
|
* |
865
|
|
|
* @param $new_favorite_status bool The new favorite status, that should be applied on this part. |
866
|
|
|
* Set this to true, when the part should be a favorite. |
867
|
|
|
* |
868
|
|
|
* @return self |
869
|
|
|
*/ |
870
|
|
|
public function setFavorite(bool $new_favorite_status): self |
871
|
|
|
{ |
872
|
|
|
$this->favorite = $new_favorite_status; |
873
|
|
|
|
874
|
|
|
return $this; |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
/** |
878
|
|
|
* Sets the URL to the manufacturer site about this Part. Set to "" if this part should use the automatically URL based on its manufacturer. |
879
|
|
|
* |
880
|
|
|
* @param string $new_url The new url |
881
|
|
|
* |
882
|
|
|
* @return self |
883
|
|
|
*/ |
884
|
|
|
public function setManufacturerProductURL(string $new_url): self |
885
|
|
|
{ |
886
|
|
|
$this->manufacturer_product_url = $new_url; |
887
|
|
|
|
888
|
|
|
return $this; |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
|
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..