| Total Complexity | 75 |
| Total Lines | 1081 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Part often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Part, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 50 | class Part extends AttachmentContainingDBElement |
||
| 51 | { |
||
| 52 | public const INSTOCK_UNKNOWN = -2; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var Category |
||
| 56 | * @ORM\ManyToOne(targetEntity="Category", inversedBy="parts") |
||
| 57 | * @ORM\JoinColumn(name="id_category", referencedColumnName="id") |
||
| 58 | */ |
||
| 59 | protected $category; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var Footprint|null |
||
| 63 | * @ORM\ManyToOne(targetEntity="Footprint", inversedBy="parts") |
||
| 64 | * @ORM\JoinColumn(name="id_footprint", referencedColumnName="id") |
||
| 65 | * |
||
| 66 | * @ColumnSecurity(prefix="footprint", type="object") |
||
| 67 | */ |
||
| 68 | protected $footprint; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var Storelocation|null |
||
| 72 | * @ORM\ManyToOne(targetEntity="Storelocation", inversedBy="parts") |
||
| 73 | * @ORM\JoinColumn(name="id_storelocation", referencedColumnName="id") |
||
| 74 | * |
||
| 75 | * @ColumnSecurity(prefix="storelocation", type="object") |
||
| 76 | */ |
||
| 77 | protected $storelocation; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var Manufacturer|null |
||
| 81 | * @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="parts") |
||
| 82 | * @ORM\JoinColumn(name="id_manufacturer", referencedColumnName="id") |
||
| 83 | * |
||
| 84 | * @ColumnSecurity(prefix="manufacturer", type="object") |
||
| 85 | */ |
||
| 86 | protected $manufacturer; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var Attachment |
||
| 90 | * @ORM\ManyToOne(targetEntity="Attachment") |
||
| 91 | * @ORM\JoinColumn(name="id_master_picture_attachement", referencedColumnName="id") |
||
| 92 | * |
||
| 93 | * @ColumnSecurity(prefix="attachments", type="object") |
||
| 94 | */ |
||
| 95 | protected $master_picture_attachment; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var |
||
| 99 | * @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="part") |
||
| 100 | * |
||
| 101 | * @ColumnSecurity(prefix="orderdetails", type="object") |
||
| 102 | */ |
||
| 103 | protected $orderdetails; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var Orderdetail |
||
| 107 | * @ORM\OneToOne(targetEntity="Orderdetail") |
||
| 108 | * @ORM\JoinColumn(name="order_orderdetails_id", referencedColumnName="id") |
||
| 109 | * |
||
| 110 | * @ColumnSecurity(prefix="order", type="object") |
||
| 111 | */ |
||
| 112 | protected $order_orderdetail; |
||
| 113 | |||
| 114 | //TODO |
||
| 115 | protected $devices; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @ColumnSecurity(type="datetime") |
||
| 119 | * @ORM\Column(type="datetimetz", name="datetime_added") |
||
| 120 | */ |
||
| 121 | protected $addedDate; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var \DateTime The date when this element was modified the last time. |
||
| 125 | * @ORM\Column(type="datetimetz", name="last_modified") |
||
| 126 | * @ColumnSecurity(type="datetime") |
||
| 127 | */ |
||
| 128 | protected $lastModified; |
||
| 129 | |||
| 130 | |||
| 131 | /********************** |
||
| 132 | * Propertys |
||
| 133 | ***********************/ |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @var string |
||
| 137 | * @ORM\Column(type="string") |
||
| 138 | * |
||
| 139 | * @ColumnSecurity(prefix="name") |
||
| 140 | */ |
||
| 141 | protected $name; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var string |
||
| 145 | * @ORM\Column(type="string") |
||
| 146 | * |
||
| 147 | * @ColumnSecurity(prefix="description") |
||
| 148 | */ |
||
| 149 | protected $description = ''; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var int |
||
| 153 | * @ORM\Column(type="integer") |
||
| 154 | * @Assert\GreaterThanOrEqual(0) |
||
| 155 | * |
||
| 156 | * @ColumnSecurity(prefix="instock", type="integer") |
||
| 157 | */ |
||
| 158 | protected $instock = 0; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @var int |
||
| 162 | * @ORM\Column(type="integer") |
||
| 163 | * @Assert\GreaterThanOrEqual(0) |
||
| 164 | * |
||
| 165 | * @ColumnSecurity(prefix="mininstock", type="integer") |
||
| 166 | */ |
||
| 167 | protected $mininstock = 0; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @var string |
||
| 171 | * @ORM\Column(type="string") |
||
| 172 | * @ColumnSecurity(prefix="comment") |
||
| 173 | */ |
||
| 174 | protected $comment = ''; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @var bool |
||
| 178 | * @ORM\Column(type="boolean") |
||
| 179 | */ |
||
| 180 | protected $visible = true; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @var bool |
||
| 184 | * @ORM\Column(type="boolean") |
||
| 185 | * @ColumnSecurity(type="boolean") |
||
| 186 | */ |
||
| 187 | protected $favorite = false; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @var int |
||
| 191 | * @ORM\Column(type="integer") |
||
| 192 | * @ColumnSecurity(prefix="order", type="integer") |
||
| 193 | */ |
||
| 194 | protected $order_quantity = 0; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @var bool |
||
| 198 | * @ORM\Column(type="boolean") |
||
| 199 | * @ColumnSecurity(prefix="order", type="boolean") |
||
| 200 | */ |
||
| 201 | protected $manual_order = false; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @var string |
||
| 205 | * @ORM\Column(type="string") |
||
| 206 | *@ColumnSecurity(prefix="manufacturer", type="string", placeholder="") |
||
| 207 | */ |
||
| 208 | protected $manufacturer_product_url = ''; |
||
| 209 | |||
| 210 | |||
| 211 | /** |
||
| 212 | * Returns the ID as an string, defined by the element class. |
||
| 213 | * This should have a form like P000014, for a part with ID 14. |
||
| 214 | * @return string The ID as a string; |
||
| 215 | */ |
||
| 216 | public function getIDString(): string |
||
| 217 | { |
||
| 218 | return 'P' . sprintf('%06d', $this->getID()); |
||
| 219 | } |
||
| 220 | |||
| 221 | |||
| 222 | /********************************************************************************* |
||
| 223 | * Getters |
||
| 224 | ********************************************************************************/ |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Get the description string like it is saved in the database. |
||
| 228 | * This can contain BBCode, it is not parsed yet. |
||
| 229 | * |
||
| 230 | * @return string the description |
||
| 231 | */ |
||
| 232 | public function getDescription() : string |
||
| 233 | { |
||
| 234 | return htmlspecialchars($this->description); |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Get the count of parts which are in stock. |
||
| 239 | * When the instock is unkown, then Part::INSTOCK_UNKNOWN is returned. |
||
| 240 | * |
||
| 241 | * @return int count of parts which are in stock |
||
| 242 | */ |
||
| 243 | public function getInstock() : int |
||
| 244 | { |
||
| 245 | return $this->instock; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Check if the value of the Instock is unknown. |
||
| 250 | * @return bool True, if the value of the instock is unknown. |
||
| 251 | */ |
||
| 252 | public function isInstockUnknown() : bool |
||
| 253 | { |
||
| 254 | return $this->instock <= static::INSTOCK_UNKNOWN; |
||
| 255 | }/** @noinspection ReturnTypeCanBeDeclaredInspection */ |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Get the count of parts which must be in stock at least |
||
| 259 | * |
||
| 260 | * @return integer count of parts which must be in stock at least |
||
| 261 | */ |
||
| 262 | public function getMinInstock() : int |
||
| 263 | { |
||
| 264 | return $this->mininstock; |
||
| 265 | } |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Get the comment associated with this part. |
||
| 269 | * |
||
| 270 | * @return string The raw/unparsed comment |
||
| 271 | */ |
||
| 272 | public function getComment() : string |
||
| 273 | { |
||
| 274 | |||
| 275 | return htmlspecialchars($this->comment); |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Get if this part is obsolete |
||
| 280 | * |
||
| 281 | * A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete". |
||
| 282 | * If a part has no orderdetails, the part isn't marked as obsolete. |
||
| 283 | * |
||
| 284 | * @return boolean true, if this part is obsolete. false, if this part isn't obsolete |
||
| 285 | */ |
||
| 286 | public function isObsolete() : bool |
||
| 287 | { |
||
| 288 | $all_orderdetails = $this->getOrderdetails(); |
||
| 289 | |||
| 290 | if (count($all_orderdetails) === 0) { |
||
| 291 | return false; |
||
| 292 | } |
||
| 293 | |||
| 294 | foreach ($all_orderdetails as $orderdetails) { |
||
| 295 | if (! $orderdetails->getObsolete()) { |
||
| 296 | return false; |
||
| 297 | } |
||
| 298 | } |
||
| 299 | |||
| 300 | return true; |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Get if this part is visible |
||
| 305 | * |
||
| 306 | * @return boolean true if this part is visible |
||
| 307 | * false if this part isn't visible |
||
| 308 | */ |
||
| 309 | public function isVisible() : bool |
||
| 310 | { |
||
| 311 | return $this->visible; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Get if this part is a favorite. |
||
| 316 | * |
||
| 317 | * @return bool * true if this part is a favorite |
||
| 318 | * * false if this part is not a favorite. |
||
| 319 | */ |
||
| 320 | public function isFavorite() : bool |
||
| 321 | { |
||
| 322 | return $this->favorite; |
||
| 323 | } |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Get the selected order orderdetails of this part |
||
| 327 | * |
||
| 328 | * @return Orderdetail the selected order orderdetails |
||
| 329 | * @return NULL if there is no order supplier selected |
||
| 330 | * @throws Exception |
||
| 331 | */ |
||
| 332 | public function getOrderOrderdetails() : ?Orderdetail |
||
| 333 | { |
||
| 334 | //TODO |
||
| 335 | /* |
||
| 336 | if ($this->order_orderdetails->getObsolete()) { |
||
| 337 | $this->setOrderOrderdetailsID(null); |
||
| 338 | $this->order_orderdetails = null; |
||
| 339 | }*/ |
||
| 340 | |||
| 341 | return $this->order_orderdetail; |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Get the order quantity of this part |
||
| 346 | * |
||
| 347 | * @return integer the order quantity |
||
| 348 | */ |
||
| 349 | public function getOrderQuantity() : int |
||
| 350 | { |
||
| 351 | return $this->order_quantity; |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Get the minimum quantity which should be ordered |
||
| 356 | * |
||
| 357 | * @param boolean $with_devices * if true, all parts from devices which are marked as "to order" will be included in the calculation |
||
| 358 | * * if false, only max(mininstock - instock, 0) will be returned |
||
| 359 | * |
||
| 360 | * @return integer the minimum order quantity |
||
| 361 | * @throws Exception |
||
| 362 | */ |
||
| 363 | public function getMinOrderQuantity(bool $with_devices = true) : int |
||
|
|
|||
| 364 | { |
||
| 365 | //TODO |
||
| 366 | throw new \Exception('Not implemented yet...'); |
||
| 367 | |||
| 368 | /** |
||
| 369 | if ($with_devices) { |
||
| 370 | $count_must_order = 0; // for devices with "order_only_missing_parts == false" |
||
| 371 | $count_should_order = 0; // for devices with "order_only_missing_parts == true" |
||
| 372 | $deviceparts = DevicePart::getOrderDeviceParts($this->database, $this->current_user, $this->log, $this->getID()); |
||
| 373 | foreach ($deviceparts as $devicepart) { |
||
| 374 | /** @var $devicepart DevicePart */ |
||
| 375 | /** @var $device Device */ /** |
||
| 376 | $device = $devicepart->getDevice(); |
||
| 377 | if ($device->getOrderOnlyMissingParts()) { |
||
| 378 | $count_should_order += $device->getOrderQuantity() * $devicepart->getMountQuantity(); |
||
| 379 | } else { |
||
| 380 | $count_must_order += $device->getOrderQuantity() * $devicepart->getMountQuantity(); |
||
| 381 | } |
||
| 382 | } |
||
| 383 | |||
| 384 | return $count_must_order + max(0, $this->getMinInstock() - $this->getInstock() + $count_should_order); |
||
| 385 | } else { |
||
| 386 | return max(0, $this->getMinInstock() - $this->getInstock()); |
||
| 387 | } **/ |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Check if this part is marked for manual ordering |
||
| 392 | * |
||
| 393 | * @return boolean the "manual_order" attribute |
||
| 394 | */ |
||
| 395 | public function isMarkedForManualOrder() : bool |
||
| 396 | { |
||
| 397 | return $this->manual_order; |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Check if the part is automatically marked for Ordering, because the instock value is smaller than the min instock value. |
||
| 402 | * This is called automatic ordering |
||
| 403 | * @return bool True, if the part should be ordered. |
||
| 404 | */ |
||
| 405 | public function isAutoOrdered() : bool |
||
| 406 | { |
||
| 407 | //Parts with negative instock never gets ordered. |
||
| 408 | if ($this->getInstock() < 0) { |
||
| 409 | return false; |
||
| 410 | } |
||
| 411 | |||
| 412 | return $this->getInstock() < $this->getMinInstock(); |
||
| 413 | } |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Get the link to the website of the article on the manufacturers website |
||
| 417 | * When no this part has no explicit url set, then it is tried to generate one from the Manufacturer of this part |
||
| 418 | * automatically. |
||
| 419 | * |
||
| 420 | * @param |
||
| 421 | * |
||
| 422 | * @return string the link to the article |
||
| 423 | */ |
||
| 424 | public function getManufacturerProductUrl() : string |
||
| 425 | { |
||
| 426 | if ($this->manufacturer_product_url !== '') { |
||
| 427 | return $this->manufacturer_product_url; |
||
| 428 | } |
||
| 429 | |||
| 430 | if ($this->getManufacturer() !== null) { |
||
| 431 | return $this->getManufacturer()->getAutoProductUrl($this->name); |
||
| 432 | } |
||
| 433 | |||
| 434 | return ''; // no url is available |
||
| 435 | } |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Similar to getManufacturerProductUrl, but here only the database value is returned. |
||
| 439 | * @return string The manufacturer url saved in DB for this part. |
||
| 440 | */ |
||
| 441 | public function getOwnProductURL() : string |
||
| 442 | { |
||
| 443 | return $this->manufacturer_product_url; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Get the category of this part |
||
| 448 | * |
||
| 449 | * There is always a category, for each part! |
||
| 450 | * |
||
| 451 | * @return Category the category of this part |
||
| 452 | */ |
||
| 453 | public function getCategory() : Category |
||
| 454 | { |
||
| 455 | return $this->category; |
||
| 456 | } |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Get the footprint of this part (if there is one) |
||
| 460 | * |
||
| 461 | * @return Footprint the footprint of this part (if there is one) |
||
| 462 | * @return NULL if this part has no footprint |
||
| 463 | */ |
||
| 464 | public function getFootprint() : ?Footprint |
||
| 467 | } |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Get the storelocation of this part (if there is one) |
||
| 471 | * |
||
| 472 | * @return Storelocation the storelocation of this part (if there is one) |
||
| 473 | * @return NULL if this part has no storelocation |
||
| 474 | */ |
||
| 475 | public function getStorelocation() : ?Storelocation |
||
| 476 | { |
||
| 477 | return $this->storelocation; |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Get the manufacturer of this part (if there is one) |
||
| 482 | * |
||
| 483 | * @return Manufacturer the manufacturer of this part (if there is one) |
||
| 484 | * @return NULL if this part has no manufacturer |
||
| 485 | */ |
||
| 486 | public function getManufacturer() : ?Manufacturer |
||
| 487 | { |
||
| 488 | return $this->manufacturer; |
||
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Get the master picture "Attachement"-object of this part (if there is one) |
||
| 493 | * |
||
| 494 | * @return Attachment the master picture Attachement of this part (if there is one) |
||
| 495 | * @return NULL if this part has no master picture |
||
| 496 | */ |
||
| 497 | public function getMasterPictureAttachement() : ?Attachment |
||
| 498 | { |
||
| 499 | return $this->master_picture_attachment; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Get all orderdetails of this part |
||
| 504 | * |
||
| 505 | * @param boolean $hide_obsolete If true, obsolete orderdetails will NOT be returned |
||
| 506 | * |
||
| 507 | * @return Orderdetails[] * all orderdetails as a one-dimensional array of Orderdetails objects |
||
| 508 | * (empty array if there are no ones) |
||
| 509 | * * the array is sorted by the suppliers names / minimum order quantity |
||
| 510 | * |
||
| 511 | * @throws Exception if there was an error |
||
| 512 | */ |
||
| 513 | public function getOrderdetails(bool $hide_obsolete = false) |
||
| 514 | { |
||
| 515 | if ($hide_obsolete) { |
||
| 516 | $orderdetails = $this->orderdetails; |
||
| 517 | foreach ($orderdetails as $key => $details) { |
||
| 518 | if ($details->getObsolete()) { |
||
| 519 | unset($orderdetails[$key]); |
||
| 520 | } |
||
| 521 | } |
||
| 522 | return $orderdetails; |
||
| 523 | } else { |
||
| 524 | return $this->orderdetails; |
||
| 525 | } |
||
| 526 | } |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Get all devices which uses this part |
||
| 530 | * |
||
| 531 | * @return Device[] * all devices which uses this part as a one-dimensional array of Device objects |
||
| 532 | * (empty array if there are no ones) |
||
| 533 | * * the array is sorted by the devices names |
||
| 534 | * |
||
| 535 | * @throws Exception if there was an error |
||
| 536 | */ |
||
| 537 | public function getDevices() : array |
||
| 538 | { |
||
| 539 | return $this->devices; |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Get all suppliers of this part |
||
| 544 | * |
||
| 545 | * This method simply gets the suppliers of the orderdetails and prepare them.\n |
||
| 546 | * You can get the suppliers as an array or as a string with individual delimeter. |
||
| 547 | * |
||
| 548 | * @param boolean $object_array * if true, this method returns an array of Supplier objects |
||
| 549 | * * if false, this method returns an array of strings |
||
| 550 | * @param string|NULL $delimeter * if this is a string and "$object_array == false", |
||
| 551 | * this method returns a string with all |
||
| 552 | * supplier names, delimeted by "$delimeter" |
||
| 553 | * @param boolean $full_paths * if true and "$object_array = false", the returned |
||
| 554 | * suppliernames are full paths (path + name) |
||
| 555 | * * if true and "$object_array = false", the returned |
||
| 556 | * suppliernames are only the names (without path) |
||
| 557 | * @param boolean $hide_obsolete If true, suppliers from obsolete orderdetails will NOT be returned |
||
| 558 | * |
||
| 559 | * @return array all suppliers as a one-dimensional array of Supplier objects |
||
| 560 | * (if "$object_array == true") |
||
| 561 | * @return array all supplier-names as a one-dimensional array of strings |
||
| 562 | * ("if $object_array == false" and "$delimeter == NULL") |
||
| 563 | * @return string a sting of all supplier names, delimeted by $delimeter |
||
| 564 | * ("if $object_array == false" and $delimeter is a string) |
||
| 565 | * |
||
| 566 | * @throws Exception if there was an error |
||
| 567 | */ |
||
| 568 | public function getSuppliers(bool $object_array = true, $delimeter = null, bool $full_paths = false, bool $hide_obsolete = false) |
||
| 594 | } |
||
| 595 | } |
||
| 596 | } |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Get all supplier-part-Nrs |
||
| 600 | * |
||
| 601 | * This method simply gets the suppliers-part-Nrs of the orderdetails and prepare them.\n |
||
| 602 | * You can get the numbers as an array or as a string with individual delimeter. |
||
| 603 | * |
||
| 604 | * @param string|NULL $delimeter * if this is a string, this method returns a delimeted string |
||
| 605 | * * otherwise, this method returns an array of strings |
||
| 606 | * @param boolean $hide_obsolete If true, supplierpartnrs from obsolete orderdetails will NOT be returned |
||
| 607 | * |
||
| 608 | * @return array all supplierpartnrs as an array of strings (if "$delimeter == NULL") |
||
| 609 | * @return string all supplierpartnrs as a string, delimeted ba $delimeter (if $delimeter is a string) |
||
| 610 | * |
||
| 611 | * @throws Exception if there was an error |
||
| 612 | */ |
||
| 613 | public function getSupplierPartNrs($delimeter = null, bool $hide_obsolete = false) |
||
| 614 | { |
||
| 615 | $supplierpartnrs = array(); |
||
| 616 | |||
| 617 | foreach ($this->getOrderdetails($hide_obsolete) as $details) { |
||
| 618 | $supplierpartnrs[] = $details->getSupplierPartNr(); |
||
| 619 | } |
||
| 620 | |||
| 621 | if (\is_string($delimeter)) { |
||
| 622 | return implode($delimeter, $supplierpartnrs); |
||
| 623 | } else { |
||
| 624 | return $supplierpartnrs; |
||
| 625 | } |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Get all prices of this part |
||
| 630 | * |
||
| 631 | * This method simply gets the prices of the orderdetails and prepare them.\n |
||
| 632 | * In the returned array/string there is a price for every supplier. |
||
| 633 | * |
||
| 634 | * @param boolean $float_array * if true, the returned array is an array of floats |
||
| 635 | * * if false, the returned array is an array of strings |
||
| 636 | * @param string|NULL $delimeter if this is a string, this method returns a delimeted string |
||
| 637 | * instead of an array. |
||
| 638 | * @param integer $quantity this is the quantity to choose the correct priceinformation |
||
| 639 | * @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price |
||
| 640 | * * If you pass NULL, the number from $quantity will be used |
||
| 641 | * @param boolean $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned |
||
| 642 | * |
||
| 643 | * @return array all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true") |
||
| 644 | * @return array all prices as an array of strings (if "$delimeter == NULL" & "$float_array == false") |
||
| 645 | * @return string all prices as a string, delimeted by $delimeter (if $delimeter is a string) |
||
| 646 | * |
||
| 647 | * If there are orderdetails without prices, for these orderdetails there |
||
| 648 | * will be a "NULL" in the returned float array (or a "-" in the string array)!! |
||
| 649 | * (This is needed for the HTML output, if there are all orderdetails and prices listed.) |
||
| 650 | * |
||
| 651 | * @throws Exception if there was an error |
||
| 652 | */ |
||
| 653 | public function getPrices(bool $float_array = false, $delimeter = null, int $quantity = 1, $multiplier = null, bool $hide_obsolete = false) |
||
| 665 | } |
||
| 666 | } |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Get the average price of all orderdetails |
||
| 670 | * |
||
| 671 | * With the $multiplier you're able to multiply the price before it will be returned. |
||
| 672 | * This is useful if you want to have the price as a string with currency, but multiplied with a factor. |
||
| 673 | * |
||
| 674 | * @param boolean $as_money_string * if true, the retruned value will be a string incl. currency, |
||
| 675 | * ready to print it out. See float_to_money_string(). |
||
| 676 | * * if false, the returned value is a float |
||
| 677 | * @param integer $quantity this is the quantity to choose the correct priceinformations |
||
| 678 | * @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price |
||
| 679 | * * If you pass NULL, the number from $quantity will be used |
||
| 680 | * |
||
| 681 | * @return float price (if "$as_money_string == false") |
||
| 682 | * @return NULL if there are no prices for this part and "$as_money_string == false" |
||
| 683 | * @return string price with currency (if "$as_money_string == true") |
||
| 684 | * |
||
| 685 | * @throws Exception if there was an error |
||
| 686 | */ |
||
| 687 | public function getAveragePrice(bool $as_money_string = false, int $quantity = 1, $multiplier = null) |
||
| 688 | { |
||
| 689 | $prices = $this->getPrices(true, null, $quantity, $multiplier, true); |
||
| 690 | $average_price = null; |
||
| 691 | |||
| 692 | $count = 0; |
||
| 693 | foreach ($prices as $price) { |
||
| 694 | if ($price !== null) { |
||
| 695 | $average_price += $price; |
||
| 696 | $count++; |
||
| 697 | } |
||
| 698 | } |
||
| 699 | |||
| 700 | if ($count > 0) { |
||
| 701 | $average_price /= $count; |
||
| 702 | } |
||
| 703 | |||
| 704 | if ($as_money_string) { |
||
| 705 | return floatToMoneyString($average_price); |
||
| 706 | } else { |
||
| 707 | return $average_price; |
||
| 708 | } |
||
| 709 | } |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Get the filename of the master picture (absolute path from filesystem root) |
||
| 713 | * |
||
| 714 | * @param boolean $use_footprint_filename * if true, and this part has no picture, this method |
||
| 715 | * will return the filename of its footprint (if available) |
||
| 716 | * * if false, and this part has no picture, |
||
| 717 | * this method will return NULL |
||
| 718 | * |
||
| 719 | * @return string the whole path + filename from filesystem root as a UNIX path (with slashes) |
||
| 720 | * @return NULL if there is no picture |
||
| 721 | * |
||
| 722 | * @throws \Exception if there was an error |
||
| 723 | */ |
||
| 724 | public function getMasterPictureFilename(bool $use_footprint_filename = false) : ?string |
||
| 725 | { |
||
| 726 | $master_picture = $this->getMasterPictureAttachement(); // returns an Attachement-object |
||
| 727 | |||
| 728 | if ($master_picture !== null) { |
||
| 729 | return $master_picture->getFilename(); |
||
| 730 | } |
||
| 731 | |||
| 732 | if ($use_footprint_filename) { |
||
| 733 | $footprint = $this->getFootprint(); |
||
| 734 | if ($footprint !== null) { |
||
| 735 | return $footprint->getFilename(); |
||
| 736 | } |
||
| 737 | } |
||
| 738 | |||
| 739 | return null; |
||
| 740 | } |
||
| 741 | |||
| 742 | /** |
||
| 743 | * Parses the selected fields and extract Properties of the part. |
||
| 744 | * @param bool $use_description Use the description field for parsing |
||
| 745 | * @param bool $use_comment Use the comment field for parsing |
||
| 746 | * @param bool $use_name Use the name field for parsing |
||
| 747 | * @param bool $force_output Properties are parsed even if properties are disabled. |
||
| 748 | * @return array A array of PartProperty objects. |
||
| 749 | * @return array If Properties are disabled or nothing was detected, then an empty array is returned. |
||
| 750 | * @throws Exception |
||
| 751 | */ |
||
| 752 | public function getProperties(bool $use_description = true, bool $use_comment = true, bool $use_name = true, bool $force_output = false) : array |
||
| 756 | /* |
||
| 757 | global $config; |
||
| 758 | |||
| 759 | if ($config['properties']['active'] || $force_output) { |
||
| 760 | if ($this->getCategory()->getDisableProperties(true)) { |
||
| 761 | return array(); |
||
| 762 | } |
||
| 763 | |||
| 764 | $name = array(); |
||
| 765 | $desc = array(); |
||
| 766 | $comm = array(); |
||
| 767 | |||
| 768 | if ($use_name === true) { |
||
| 769 | $name = $this->getCategory()->getPartnameRegexObj()->getProperties($this->getName()); |
||
| 770 | } |
||
| 771 | if ($use_description === true) { |
||
| 772 | $desc = PartProperty::parseDescription($this->getDescription()); |
||
| 773 | } |
||
| 774 | if ($use_comment === true) { |
||
| 775 | $comm = PartProperty::parseDescription($this->getComment(false)); |
||
| 776 | } |
||
| 777 | |||
| 778 | return array_merge($name, $desc, $comm); |
||
| 779 | } else { |
||
| 780 | return array(); |
||
| 781 | }*/ |
||
| 782 | } |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Returns a loop (array) of the array representations of the properties of this part. |
||
| 786 | * @param bool $use_description Use the description field for parsing |
||
| 787 | * @param bool $use_comment Use the comment field for parsing |
||
| 788 | * @return array A array of arrays with the name and value of the properties. |
||
| 789 | */ |
||
| 790 | public function getPropertiesLoop(bool $use_description = true, bool $use_comment = true, bool $use_name = true) : array |
||
| 800 | } |
||
| 801 | |||
| 802 | /* |
||
| 803 | public function hasValidName() : bool |
||
| 804 | { |
||
| 805 | return self::isValidName($this->getName(), $this->getCategory()); |
||
| 806 | } */ |
||
| 807 | |||
| 808 | /******************************************************************************** |
||
| 809 | * |
||
| 810 | * Setters |
||
| 811 | * |
||
| 812 | *********************************************************************************/ |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Set the description |
||
| 816 | * |
||
| 817 | * @param string $new_description the new description |
||
| 818 | * |
||
| 819 | * @return self |
||
| 820 | */ |
||
| 821 | public function setDescription(?string $new_description) : self |
||
| 822 | { |
||
| 823 | $this->description = $new_description; |
||
| 824 | return $this; |
||
| 825 | } |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Set the count of parts which are in stock |
||
| 829 | * |
||
| 830 | * @param integer $new_instock the new count of parts which are in stock |
||
| 831 | * |
||
| 832 | * @return self |
||
| 833 | */ |
||
| 834 | public function setInstock(int $new_instock, $comment = null) : self |
||
| 835 | { |
||
| 836 | //Assert::natural($new_instock, 'New instock must be positive. Got: %s'); |
||
| 837 | |||
| 838 | $old_instock = $this->getInstock(); |
||
| 839 | $this->instock = $new_instock; |
||
| 840 | //TODO |
||
| 841 | /* |
||
| 842 | InstockChangedEntry::add( |
||
| 843 | $this->database, |
||
| 844 | $this->current_user, |
||
| 845 | $this->log, |
||
| 846 | $this, |
||
| 847 | $old_instock, |
||
| 848 | $new_instock, |
||
| 849 | $comment |
||
| 850 | );*/ |
||
| 851 | |||
| 852 | return $this; |
||
| 853 | } |
||
| 854 | |||
| 855 | /** |
||
| 856 | * Sets the unknown status of this part. |
||
| 857 | * When the instock is currently unknown and you pass false, then the instock is set to zero. |
||
| 858 | * If the instock is not unknown and you pass false, nothing is changed. |
||
| 859 | * |
||
| 860 | * @param bool $new_unknown Set this to true if the instock should be marked as unknown. |
||
| 861 | * @return Part |
||
| 862 | */ |
||
| 863 | public function setInstockUnknown(bool $new_unknown) : self |
||
| 864 | { |
||
| 865 | if($new_unknown === true) { |
||
| 866 | $this->instock = self::INSTOCK_UNKNOWN; |
||
| 867 | } else if ($this->isInstockUnknown()) { |
||
| 868 | $this->setInstock(0); |
||
| 869 | } |
||
| 870 | |||
| 871 | return $this; |
||
| 872 | |||
| 873 | } |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Withdrawal the given number of parts. |
||
| 877 | * @param $count int The number of parts which should be withdrawan. |
||
| 878 | * @param $comment string A comment that should be associated with the withdrawal. |
||
| 879 | * |
||
| 880 | * @return self |
||
| 881 | */ |
||
| 882 | public function withdrawalParts(int $count, $comment = null) : self |
||
| 883 | { |
||
| 884 | //Assert::greaterThan($count,0, 'Count of withdrawn parts must be greater 0! Got %s!'); |
||
| 885 | //Assert::greaterThan($count, $this->instock, 'You can not withdraw more parts, than there are existing!'); |
||
| 886 | |||
| 887 | $old_instock = $this->getInstock(); |
||
| 888 | $new_instock = $old_instock - $count; |
||
| 889 | |||
| 890 | //TODO |
||
| 891 | /* |
||
| 892 | InstockChangedEntry::add( |
||
| 893 | $this->database, |
||
| 894 | $this->current_user, |
||
| 895 | $this->log, |
||
| 896 | $this, |
||
| 897 | $old_instock, |
||
| 898 | $new_instock, |
||
| 899 | $comment |
||
| 900 | );*/ |
||
| 901 | |||
| 902 | $this->instock = $new_instock; |
||
| 903 | |||
| 904 | return $this; |
||
| 905 | } |
||
| 906 | |||
| 907 | /** |
||
| 908 | * Add the given number of parts. |
||
| 909 | * @param $count int The number of parts which should be withdrawan. |
||
| 910 | * @param $comment string A comment that should be associated with the withdrawal. |
||
| 911 | * |
||
| 912 | * @return self |
||
| 913 | */ |
||
| 914 | public function addParts(int $count, string $comment = null) : self |
||
| 915 | { |
||
| 916 | //Assert::greaterThan($count, 0, 'Count of added parts must be greater zero! Got %s.'); |
||
| 917 | |||
| 918 | //TODO |
||
| 919 | |||
| 920 | $old_instock = $this->getInstock(); |
||
| 921 | $new_instock = $old_instock + $count; |
||
| 922 | |||
| 923 | //TODO |
||
| 924 | /* |
||
| 925 | InstockChangedEntry::add( |
||
| 926 | $this->database, |
||
| 927 | $this->current_user, |
||
| 928 | $this->log, |
||
| 929 | $this, |
||
| 930 | $old_instock, |
||
| 931 | $new_instock, |
||
| 932 | $comment |
||
| 933 | );*/ |
||
| 934 | |||
| 935 | $this->instock = $new_instock; |
||
| 936 | |||
| 937 | return $this; |
||
| 938 | } |
||
| 939 | |||
| 940 | /** |
||
| 941 | * Set the count of parts which should be in stock at least |
||
| 942 | * |
||
| 943 | * @param integer $new_mininstock the new count of parts which should be in stock at least |
||
| 944 | * @return self |
||
| 945 | */ |
||
| 946 | public function setMinInstock(int $new_mininstock) : self |
||
| 947 | { |
||
| 948 | //Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.'); |
||
| 949 | |||
| 950 | $this->mininstock = $new_mininstock; |
||
| 951 | return $this; |
||
| 952 | } |
||
| 953 | |||
| 954 | /** |
||
| 955 | * Set the comment |
||
| 956 | * |
||
| 957 | * @param string $new_comment the new comment |
||
| 958 | * |
||
| 959 | * @return self |
||
| 960 | */ |
||
| 961 | public function setComment(string $new_comment) : self |
||
| 962 | { |
||
| 963 | $this->comment = $new_comment; |
||
| 964 | |||
| 965 | return $this; |
||
| 966 | } |
||
| 967 | |||
| 968 | /** |
||
| 969 | * Set the "manual_order" attribute |
||
| 970 | * |
||
| 971 | * @param boolean $new_manual_order the new "manual_order" attribute |
||
| 972 | * @param integer $new_order_quantity the new order quantity |
||
| 973 | * @param integer|NULL $new_order_orderdetails_id * the ID of the new order orderdetails |
||
| 974 | * * or Zero for "no order orderdetails" |
||
| 975 | * * or NULL for automatic order orderdetails |
||
| 976 | * (if the part has exactly one orderdetails, |
||
| 977 | * set this orderdetails as order orderdetails. |
||
| 978 | * Otherwise, set "no order orderdetails") |
||
| 979 | * |
||
| 980 | * @return self |
||
| 981 | */ |
||
| 982 | public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null) : self |
||
| 983 | { |
||
| 984 | //Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!'); |
||
| 985 | |||
| 986 | |||
| 987 | $this->manual_order = $new_manual_order; |
||
| 988 | |||
| 989 | //TODO; |
||
| 990 | /* $this->order_orderdetail = $new_order_orderdetails_id; */ |
||
| 991 | $this->order_quantity = $new_order_quantity; |
||
| 992 | |||
| 993 | return $this; |
||
| 994 | } |
||
| 995 | |||
| 996 | /** |
||
| 997 | * Set the ID of the order orderdetails |
||
| 998 | * |
||
| 999 | * @param integer|NULL $new_order_orderdetails_id * the new order orderdetails ID |
||
| 1000 | * * Or, to remove the orderdetails, pass a NULL |
||
| 1001 | * |
||
| 1002 | * @return self |
||
| 1003 | */ |
||
| 1004 | public function setOrderOrderdetailsID($new_order_orderdetails_id) : self |
||
| 1005 | { |
||
| 1006 | //TODO |
||
| 1007 | throw new \Exception('Not implemented yet...'); |
||
| 1008 | |||
| 1009 | return $this; |
||
| 1010 | } |
||
| 1011 | |||
| 1012 | /** |
||
| 1013 | * Set the order quantity |
||
| 1014 | * |
||
| 1015 | * @param integer $new_order_quantity the new order quantity |
||
| 1016 | * |
||
| 1017 | * @return self |
||
| 1018 | */ |
||
| 1019 | public function setOrderQuantity(int $new_order_quantity) : self |
||
| 1020 | { |
||
| 1021 | //Assert::greaterThan($new_order_quantity,0, 'The new order quantity must be greater zero. Got %s!'); |
||
| 1022 | |||
| 1023 | $this->order_quantity = $new_order_quantity; |
||
| 1024 | |||
| 1025 | return $this; |
||
| 1026 | } |
||
| 1027 | |||
| 1028 | /** |
||
| 1029 | * Set the category of this Part |
||
| 1030 | * |
||
| 1031 | * Every part must have a valid category (in contrast to the |
||
| 1032 | * attributes "footprint", "storelocation", ...)! |
||
| 1033 | * |
||
| 1034 | * @param Category $category The new category of this part |
||
| 1035 | * |
||
| 1036 | * @return self |
||
| 1037 | */ |
||
| 1038 | public function setCategory(Category $category) : self |
||
| 1043 | } |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Set the new Footprint of this Part. |
||
| 1047 | * |
||
| 1048 | * @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have |
||
| 1049 | * a footprint. |
||
| 1050 | * @return self |
||
| 1051 | */ |
||
| 1052 | public function setFootprint(?Footprint $new_footprint) : self |
||
| 1053 | { |
||
| 1054 | $this->footprint = $new_footprint; |
||
| 1055 | |||
| 1056 | return $this; |
||
| 1057 | } |
||
| 1058 | |||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * Set the new store location of this part. |
||
| 1062 | * |
||
| 1063 | * @param Storelocation|null $new_storelocation The new Storelocation of this part. Set to null, if this part should |
||
| 1064 | * not have a storelocation. |
||
| 1065 | * @return Part |
||
| 1066 | */ |
||
| 1067 | public function setStorelocation(?Storelocation $new_storelocation) : self |
||
| 1068 | { |
||
| 1069 | $this->storelocation = $new_storelocation; |
||
| 1070 | |||
| 1071 | return $this; |
||
| 1072 | } |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Sets the new manufacturer of this part. |
||
| 1076 | * |
||
| 1077 | * @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should |
||
| 1078 | * not have a manufacturer. |
||
| 1079 | * @return Part |
||
| 1080 | */ |
||
| 1081 | public function setManufacturer(?Manufacturer $new_manufacturer) : self |
||
| 1082 | { |
||
| 1083 | $this->manufacturer = $new_manufacturer; |
||
| 1084 | |||
| 1085 | return $this; |
||
| 1086 | } |
||
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Set the favorite status for this part. |
||
| 1090 | * @param $new_favorite_status bool The new favorite status, that should be applied on this part. |
||
| 1091 | * Set this to true, when the part should be a favorite. |
||
| 1092 | * |
||
| 1093 | * @return self |
||
| 1094 | */ |
||
| 1095 | public function setFavorite(bool $new_favorite_status) : self |
||
| 1096 | { |
||
| 1097 | $this->favorite = $new_favorite_status; |
||
| 1098 | |||
| 1099 | return $this; |
||
| 1100 | } |
||
| 1101 | |||
| 1102 | /** |
||
| 1103 | * Sets the URL to the manufacturer site about this Part. Set to "" if this part should use the automatically URL based on its manufacturer. |
||
| 1104 | * @param string $new_url The new url |
||
| 1105 | * @return self |
||
| 1106 | */ |
||
| 1107 | public function setManufacturerProductURL(string $new_url) : self |
||
| 1112 | } |
||
| 1113 | |||
| 1114 | /** |
||
| 1115 | * Set the ID of the master picture Attachement |
||
| 1116 | * |
||
| 1117 | * @param integer|NULL $new_master_picture_attachement_id * the ID of the Attachement object of the master picture |
||
| 1118 | * * NULL means "no master picture" |
||
| 1119 | * |
||
| 1120 | * @throws Exception if the new ID is not valid |
||
| 1121 | * @throws Exception if there was an error |
||
| 1122 | * |
||
| 1123 | * @return self |
||
| 1124 | */ |
||
| 1125 | public function setMasterPictureAttachementID($new_master_picture_attachement_id) : self |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | |||
| 1134 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.