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