Part-DB.Part-DB-server/src/Entity/Parts/Part.php

874 lines
24 KiB
PHP
Raw Normal View History

<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
2019-03-05 14:37:41 +01:00
2019-02-23 22:41:13 +01:00
/**
2019-03-05 14:37:41 +01:00
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/.
2019-03-05 14:37:41 +01:00
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2019-02-23 22:41:13 +01:00
*/
namespace App\Entity\Parts;
2019-02-23 22:41:13 +01:00
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Devices\Device;
use App\Entity\PriceInformations\Orderdetail;
use App\Security\Annotations\ColumnSecurity;
use App\Validator\Constraints\Selectable;
2019-02-23 22:41:13 +01:00
use Doctrine\ORM\Mapping as ORM;
2019-08-15 22:34:37 +02:00
use Doctrine\ORM\PersistentCollection;
use Symfony\Component\Validator\Constraints as Assert;
2019-02-23 22:41:13 +01:00
/**
* Class Part.
2019-02-23 22:41:13 +01:00
*
* @ORM\Entity(repositoryClass="App\Repository\PartRepository")
* @ORM\Table("`parts`")
2019-02-23 22:41:13 +01:00
*/
class Part extends AttachmentContainingDBElement
{
public const INSTOCK_UNKNOWN = -2;
2019-02-23 22:41:13 +01:00
/**
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element")
*/
protected $attachments;
2019-02-23 22:41:13 +01:00
/**
* @var Category
* @ORM\ManyToOne(targetEntity="Category", inversedBy="parts")
* @ORM\JoinColumn(name="id_category", referencedColumnName="id")
* @Selectable()
2019-02-23 22:41:13 +01:00
*/
protected $category;
/**
* @var Footprint|null
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="parts")
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id")
*
* @ColumnSecurity(prefix="footprint", type="object")
* @Selectable()
2019-02-23 22:41:13 +01:00
*/
protected $footprint;
/**
* @var Manufacturer|null
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="parts")
* @ORM\JoinColumn(name="id_manufacturer", referencedColumnName="id")
*
* @ColumnSecurity(prefix="manufacturer", type="object")
* @Selectable()
2019-02-23 22:41:13 +01:00
*/
protected $manufacturer;
/**
* @var Attachment
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\Attachment")
* @ORM\JoinColumn(name="id_master_picture_attachement", referencedColumnName="id")
*
* @ColumnSecurity(prefix="attachments", type="object")
2019-02-23 22:41:13 +01:00
*/
protected $master_picture_attachment;
/**
* @var Orderdetail[]
* @ORM\OneToMany(targetEntity="App\Entity\PriceInformations\Orderdetail", mappedBy="part")
*
* @ColumnSecurity(prefix="orderdetails", type="object")
2019-02-23 22:41:13 +01:00
*/
protected $orderdetails;
/**
* @var Orderdetail
* @ORM\OneToOne(targetEntity="App\Entity\PriceInformations\Orderdetail")
2019-02-23 22:41:13 +01:00
* @ORM\JoinColumn(name="order_orderdetails_id", referencedColumnName="id")
*
* @ColumnSecurity(prefix="order", type="object")
2019-02-23 22:41:13 +01:00
*/
protected $order_orderdetail;
//TODO
protected $devices;
/**
* @ColumnSecurity(type="datetime")
* @ORM\Column(type="datetimetz", name="datetime_added")
*/
protected $addedDate;
/**
* @var \DateTime The date when this element was modified the last time.
* @ORM\Column(type="datetimetz", name="last_modified")
* @ColumnSecurity(type="datetime")
*/
protected $lastModified;
2019-02-23 22:41:13 +01:00
/**********************
* Propertys
***********************/
/**
* @var string
* @ORM\Column(type="string")
*
* @ColumnSecurity(prefix="name")
*/
protected $name;
/**
* @var string
* @ORM\Column(type="text")
*
* @ColumnSecurity(prefix="description")
2019-02-23 22:41:13 +01:00
*/
2019-03-20 22:53:06 +01:00
protected $description = '';
2019-02-23 22:41:13 +01:00
/**
* @var ?PartLot[]
* @ORM\OneToMany(targetEntity="PartLot", mappedBy="part")
2019-02-23 22:41:13 +01:00
*/
protected $partLots;
2019-02-23 22:41:13 +01:00
/**
* @var float
* @ORM\Column(type="float")
* @Assert\PositiveOrZero()
2019-08-15 22:34:37 +02:00
*
* @ColumnSecurity(prefix="mininstock", type="integer")
*/
2019-08-16 22:54:23 +02:00
protected $minamount = 0;
2019-02-23 22:41:13 +01:00
/**
* @var string
* @ORM\Column(type="text")
* @ColumnSecurity(prefix="comment")
2019-02-23 22:41:13 +01:00
*/
2019-03-20 22:53:06 +01:00
protected $comment = '';
2019-02-23 22:41:13 +01:00
/**
* @var bool
* @ORM\Column(type="boolean")
*/
protected $visible = true;
2019-02-23 22:41:13 +01:00
/**
* @var bool
* @ORM\Column(type="boolean")
* @ColumnSecurity(type="boolean")
2019-02-23 22:41:13 +01:00
*/
protected $favorite = false;
2019-02-23 22:41:13 +01:00
/**
* @var int
* @ORM\Column(type="integer")
* @ColumnSecurity(prefix="order", type="integer")
2019-02-23 22:41:13 +01:00
*/
protected $order_quantity = 0;
2019-02-23 22:41:13 +01:00
/**
* @var bool
* @ORM\Column(type="boolean")
* @ColumnSecurity(prefix="order", type="boolean")
2019-02-23 22:41:13 +01:00
*/
protected $manual_order = false;
2019-02-23 22:41:13 +01:00
/**
* @var string
* @ORM\Column(type="string")
* @ColumnSecurity(prefix="manufacturer", type="string", placeholder="")
2019-02-23 22:41:13 +01:00
*/
2019-03-20 22:53:06 +01:00
protected $manufacturer_product_url = '';
2019-02-23 22:41:13 +01:00
/**
* @var string
* @ORM\Column(type="string")
* @ColumnSecurity(prefix="manufacturer", type="string", placeholder="")
*/
protected $manufacturer_product_number;
/**
* @var bool Determines if this part entry needs review (for example, because it is work in progress)
* @ORM\Column(type="boolean")
*/
protected $needs_review = false;
/**
2019-08-15 22:34:37 +02:00
* @var ?MeasurementUnit The unit in which the part's amount is measured.
* @ORM\ManyToOne(targetEntity="MeasurementUnit")
* @ORM\JoinColumn(name="id_part_unit", referencedColumnName="id", nullable=true)
*/
protected $partUnit;
/**
* @var string A comma seperated list of tags, assocciated with the part.
* @ORM\Column(type="text")
*/
protected $tags;
/**
* @var float|null How much a single part unit weighs in gramms.
* @ORM\Column(type="float", nullable=true)
2019-08-16 16:43:31 +02:00
* @Assert\Positive()
*/
protected $mass;
2019-02-23 22:41:13 +01:00
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
*
2019-02-23 22:41:13 +01:00
* @return string The ID as a string;
*/
public function getIDString(): string
{
2019-08-15 22:34:37 +02:00
return 'P' . sprintf('%06d', $this->getID());
2019-02-23 22:41:13 +01:00
}
/*********************************************************************************
* Getters
********************************************************************************/
/**
* Get the description string like it is saved in the database.
* This can contain BBCode, it is not parsed yet.
2019-02-23 22:41:13 +01:00
*
* @return string the description
2019-02-23 22:41:13 +01:00
*/
public function getDescription(): string
2019-02-23 22:41:13 +01:00
{
return htmlspecialchars($this->description);
2019-02-23 22:41:13 +01:00
}
/**
* Get the count of parts which must be in stock at least.
2019-02-23 22:41:13 +01:00
*
* @return int count of parts which must be in stock at least
2019-02-23 22:41:13 +01:00
*/
2019-08-16 22:54:23 +02:00
public function getMinAmount(): float
2019-02-23 22:41:13 +01:00
{
2019-08-16 22:54:23 +02:00
return $this->minamount;
2019-02-23 22:41:13 +01:00
}
/**
* Get the comment associated with this part.
2019-02-23 22:41:13 +01:00
*
* @return string The raw/unparsed comment
2019-02-23 22:41:13 +01:00
*/
public function getComment(): string
2019-02-23 22:41:13 +01:00
{
return htmlspecialchars($this->comment);
2019-02-23 22:41:13 +01:00
}
/**
* Get if this part is obsolete.
2019-02-23 22:41:13 +01:00
*
* A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete".
2019-02-23 22:41:13 +01:00
* If a part has no orderdetails, the part isn't marked as obsolete.
*
* @return bool true, if this part is obsolete. false, if this part isn't obsolete
2019-02-23 22:41:13 +01:00
*/
public function isObsolete(): bool
2019-02-23 22:41:13 +01:00
{
$all_orderdetails = $this->getOrderdetails();
if (0 === count($all_orderdetails)) {
2019-02-23 22:41:13 +01:00
return false;
}
foreach ($all_orderdetails as $orderdetails) {
if (!$orderdetails->getObsolete()) {
2019-02-23 22:41:13 +01:00
return false;
}
}
return true;
}
/**
* Get if this part is visible.
2019-02-23 22:41:13 +01:00
*
* @return bool true if this part is visible
* false if this part isn't visible
2019-02-23 22:41:13 +01:00
*/
public function isVisible(): bool
2019-02-23 22:41:13 +01:00
{
return $this->visible;
2019-02-23 22:41:13 +01:00
}
/**
* Get if this part is a favorite.
*
* @return bool * true if this part is a favorite
* * false if this part is not a favorite.
2019-02-23 22:41:13 +01:00
*/
public function isFavorite(): bool
2019-02-23 22:41:13 +01:00
{
return $this->favorite;
2019-02-23 22:41:13 +01:00
}
/**
* Get the selected order orderdetails of this part.
* @return Orderdetail the selected order orderdetails
2019-02-23 22:41:13 +01:00
*/
public function getOrderOrderdetails(): ?Orderdetail
2019-02-23 22:41:13 +01:00
{
return $this->order_orderdetail;
}
/**
* Get the order quantity of this part.
2019-02-23 22:41:13 +01:00
*
* @return int the order quantity
2019-02-23 22:41:13 +01:00
*/
public function getOrderQuantity(): int
2019-02-23 22:41:13 +01:00
{
return $this->order_quantity;
2019-02-23 22:41:13 +01:00
}
/**
* Check if this part is marked for manual ordering.
2019-02-23 22:41:13 +01:00
*
* @return bool the "manual_order" attribute
2019-02-23 22:41:13 +01:00
*/
public function isMarkedForManualOrder(): bool
2019-02-23 22:41:13 +01:00
{
return $this->manual_order;
2019-02-23 22:41:13 +01:00
}
/**
* Get the link to the website of the article on the manufacturers website
* When no this part has no explicit url set, then it is tried to generate one from the Manufacturer of this part
* automatically.
2019-02-23 22:41:13 +01:00
*
* @param
*
* @return string the link to the article
2019-02-23 22:41:13 +01:00
*/
public function getManufacturerProductUrl(): string
2019-02-23 22:41:13 +01:00
{
if ('' !== $this->manufacturer_product_url) {
2019-02-23 22:41:13 +01:00
return $this->manufacturer_product_url;
}
if (null !== $this->getManufacturer()) {
2019-02-23 22:41:13 +01:00
return $this->getManufacturer()->getAutoProductUrl($this->name);
2019-03-20 22:53:06 +01:00
}
return ''; // no url is available
2019-02-23 22:41:13 +01:00
}
/**
* Similar to getManufacturerProductUrl, but here only the database value is returned.
*
* @return string The manufacturer url saved in DB for this part.
*/
2019-08-15 22:34:37 +02:00
public function getCustomProductURL(): string
{
return $this->manufacturer_product_url;
}
2019-02-23 22:41:13 +01:00
/**
* Get the category of this part.
2019-02-23 22:41:13 +01:00
*
* There is always a category, for each part!
*
* @return Category the category of this part
2019-02-23 22:41:13 +01:00
*/
public function getCategory(): Category
2019-02-23 22:41:13 +01:00
{
return $this->category;
}
/**
* Get the footprint of this part (if there is one).
2019-02-23 22:41:13 +01:00
*
* @return Footprint the footprint of this part (if there is one)
2019-02-23 22:41:13 +01:00
*/
public function getFootprint(): ?Footprint
2019-02-23 22:41:13 +01:00
{
return $this->footprint;
}
/**
* Get the manufacturer of this part (if there is one).
2019-02-23 22:41:13 +01:00
*
* @return Manufacturer the manufacturer of this part (if there is one)
2019-02-23 22:41:13 +01:00
*/
public function getManufacturer(): ?Manufacturer
2019-02-23 22:41:13 +01:00
{
return $this->manufacturer;
}
/**
* Get the master picture "Attachement"-object of this part (if there is one).
2019-02-23 22:41:13 +01:00
*
* @return Attachment the master picture Attachement of this part (if there is one)
2019-02-23 22:41:13 +01:00
*/
public function getMasterPictureAttachement(): ?Attachment
2019-02-23 22:41:13 +01:00
{
2019-03-12 19:39:02 +01:00
return $this->master_picture_attachment;
2019-02-23 22:41:13 +01:00
}
/**
* Get all orderdetails of this part.
2019-02-23 22:41:13 +01:00
*
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned
2019-02-23 22:41:13 +01:00
*
* @return Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects
* (empty array if there are no ones)
* * the array is sorted by the suppliers names / minimum order quantity
2019-02-23 22:41:13 +01:00
*
*/
2019-08-15 22:34:37 +02:00
public function getOrderdetails(bool $hide_obsolete = false) : PersistentCollection
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
//If needed hide the obsolete entries
2019-02-23 22:41:13 +01:00
if ($hide_obsolete) {
$orderdetails = $this->orderdetails;
foreach ($orderdetails as $key => $details) {
if ($details->getObsolete()) {
unset($orderdetails[$key]);
}
}
2019-02-23 22:41:13 +01:00
return $orderdetails;
}
2019-08-15 22:34:37 +02:00
return $this->orderdetails;
2019-02-23 22:41:13 +01:00
}
/**
* Get all devices which uses this part.
2019-02-23 22:41:13 +01:00
*
* @return Device[] * all devices which uses this part as a one-dimensional array of Device objects
* (empty array if there are no ones)
* * the array is sorted by the devices names
2019-02-23 22:41:13 +01:00
*
*/
public function getDevices(): array
2019-02-23 22:41:13 +01:00
{
return $this->devices;
}
/**
* Get all prices of this part.
2019-02-23 22:41:13 +01:00
*
* This method simply gets the prices of the orderdetails and prepare them.\n
* In the returned array/string there is a price for every supplier.
* @param int $quantity this is the quantity to choose the correct priceinformation
* @param int|null $multiplier * This is the multiplier which will be applied to every single price
* * If you pass NULL, the number from $quantity will be used
* @param bool $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned
2019-02-23 22:41:13 +01:00
*
* @return float[] all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true")
2019-02-23 22:41:13 +01:00
*
* @throws \Exception if there was an error
2019-02-23 22:41:13 +01:00
*/
public function getPrices(int $quantity = 1, $multiplier = null, bool $hide_obsolete = false) : array
2019-02-23 22:41:13 +01:00
{
$prices = array();
foreach ($this->getOrderdetails($hide_obsolete) as $details) {
$prices[] = $details->getPrice($quantity, $multiplier);
2019-02-23 22:41:13 +01:00
}
return $prices;
2019-02-23 22:41:13 +01:00
}
/**
* Get the average price of all orderdetails.
2019-02-23 22:41:13 +01:00
*
* With the $multiplier you're able to multiply the price before it will be returned.
* This is useful if you want to have the price as a string with currency, but multiplied with a factor.
*
* @param int $quantity this is the quantity to choose the correct priceinformations
* @param int|null $multiplier * This is the multiplier which will be applied to every single price
* * If you pass NULL, the number from $quantity will be used
2019-02-23 22:41:13 +01:00
*
* @return float price (if "$as_money_string == false")
2019-02-23 22:41:13 +01:00
*
* @throws \Exception if there was an error
2019-02-23 22:41:13 +01:00
*/
public function getAveragePrice(int $quantity = 1, $multiplier = null) : ?float
2019-02-23 22:41:13 +01:00
{
$prices = $this->getPrices($quantity, $multiplier, true);
2019-08-15 22:34:37 +02:00
//Findout out
2019-02-23 22:41:13 +01:00
$average_price = null;
$count = 0;
2019-08-15 22:34:37 +02:00
foreach ($this->getOrderdetails() as $orderdetail) {
$price = $orderdetail->getPrice(1, null);
if (null !== $price) {
2019-02-23 22:41:13 +01:00
$average_price += $price;
++$count;
2019-02-23 22:41:13 +01:00
}
}
if ($count > 0) {
$average_price /= $count;
}
return $average_price;
2019-02-23 22:41:13 +01:00
}
/**
2019-08-15 22:34:37 +02:00
* Checks if this part is marked, for that it needs further review.
* @return bool
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function isNeedsReview(): bool
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
return $this->needs_review;
2019-02-23 22:41:13 +01:00
}
/**
2019-08-15 22:34:37 +02:00
* Sets the "needs review" status of this part.
* @param bool $needs_review
* @return Part
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function setNeedsReview(bool $needs_review): Part
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
$this->needs_review = $needs_review;
return $this;
}
2019-02-23 22:41:13 +01:00
2019-08-15 22:34:37 +02:00
/**
* Get all part lots where this part is stored.
* @return PartLot[]|PersistentCollection
*/
public function getPartLots() : PersistentCollection
{
return $this->partLots;
}
2019-02-23 22:41:13 +01:00
2019-08-15 22:34:37 +02:00
/**
* Returns the assigned manufacturer product number (MPN) for this part.
* @return string
*/
public function getManufacturerProductNumber(): string
{
return $this->manufacturer_product_number;
2019-02-23 22:41:13 +01:00
}
/**
2019-08-15 22:34:37 +02:00
* Sets the manufacturer product number (MPN) for this part.
* @param string $manufacturer_product_number
* @return Part
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function setManufacturerProductNumber(string $manufacturer_product_number): Part
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
$this->manufacturer_product_number = $manufacturer_product_number;
return $this;
2019-02-23 22:41:13 +01:00
}
2019-08-15 22:34:37 +02:00
/**
* Gets the measurement unit in which the part's amount should be measured.
* Returns null if no specific unit was that. That means the parts are measured simply in quantity numbers.
* @return ?MeasurementUnit
*/
public function getPartUnit(): ?MeasurementUnit
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
return $this->partUnit;
}
2019-02-23 22:41:13 +01:00
/**
2019-08-15 22:34:37 +02:00
* Sets the measurement unit in which the part's amount should be measured.
* Set to null, if the part should be measured in quantities.
* @param ?MeasurementUnit $partUnit
* @return Part
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function setPartUnit(?MeasurementUnit $partUnit): Part
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
$this->partUnit = $partUnit;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
2019-08-15 22:34:37 +02:00
* Gets a comma separated list, of tags, that are assigned to this part
* @return string
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function getTags(): string
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
return $this->tags;
2019-02-23 22:41:13 +01:00
}
/**
2019-08-15 22:34:37 +02:00
* Sets a comma separated list of tags, that are assigned to this part.
* @param string $tags
* @return Part
*/
2019-08-15 22:34:37 +02:00
public function setTags(string $tags): Part
{
2019-08-15 22:34:37 +02:00
$this->tags = $tags;
2019-03-20 22:53:06 +01:00
return $this;
}
2019-02-23 22:41:13 +01:00
/**
2019-08-15 22:34:37 +02:00
* Returns the mass of a single part unit.
* Returns null, if the mass is unknown/not set yet
* @return float|null
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function getMass(): ?float
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
return $this->mass;
}
2019-08-15 22:34:37 +02:00
/**
* Sets the mass of a single part unit.
* Sett to null, if the mass is unknown.
* @param float|null $mass
* @return Part
*/
public function setMass(?float $mass): Part
{
$this->mass = $mass;
return $this;
2019-02-23 22:41:13 +01:00
}
2019-08-16 22:54:23 +02:00
/**
* Checks if this part uses the float amount .
* This setting is based on the part unit (see MeasurementUnit->isInteger()).
* @return bool True if the float amount field should be used. False if the integer instock field should be used.
*/
public function useFloatAmount(): bool
{
if ($this->partUnit instanceof MeasurementUnit) {
return $this->partUnit->isInteger();
}
//When no part unit is set, treat it as part count, and so use the integer value.
return false;
}
/**
* Returns the summed amount of this part (over all part lots)
* @return float
*/
public function getAmountSum() : float
{
//TODO: Find a method to do this natively in SQL, the current method could be a bit slow
$sum = 0;
foreach($this->getPartLots() as $lot) {
//Dont use the instock value, if it is unkown
if ($lot->isInstockUnknown()) {
continue;
}
$sum += $lot->getAmount();
}
if(!$this->useFloatAmount()) {
return $sum;
}
return round($sum);
}
2019-08-15 22:34:37 +02:00
/********************************************************************************
*
* Setters
*
*********************************************************************************/
2019-02-23 22:41:13 +01:00
/**
2019-08-15 22:34:37 +02:00
* Set the description.
*
2019-08-15 22:34:37 +02:00
* @param string $new_description the new description
*
* @return self
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function setDescription(?string $new_description): self
2019-02-23 22:41:13 +01:00
{
2019-08-15 22:34:37 +02:00
$this->description = $new_description;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
2019-08-16 22:54:23 +02:00
* Set the minimum amount of parts that have to be instock.
* See getPartUnit() for the associated unit.
*
* @param int $new_mininstock the new count of parts which should be in stock at least
2019-02-23 22:41:13 +01:00
*
* @return self
2019-02-23 22:41:13 +01:00
*/
public function setMinAmount(float $new_minamount): self
2019-02-23 22:41:13 +01:00
{
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.');
2019-08-16 22:54:23 +02:00
$this->minamount = $new_minamount;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
* Set the comment.
2019-02-23 22:41:13 +01:00
*
* @param string $new_comment the new comment
2019-02-23 22:41:13 +01:00
*
* @return self
2019-02-23 22:41:13 +01:00
*/
public function setComment(string $new_comment): self
2019-02-23 22:41:13 +01:00
{
$this->comment = $new_comment;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
* Set the "manual_order" attribute.
2019-02-23 22:41:13 +01:00
*
* @param bool $new_manual_order the new "manual_order" attribute
* @param int $new_order_quantity the new order quantity
* @param int|null $new_order_orderdetails_id * the ID of the new order orderdetails
* * or Zero for "no order orderdetails"
* * or NULL for automatic order orderdetails
* (if the part has exactly one orderdetails,
* set this orderdetails as order orderdetails.
* Otherwise, set "no order orderdetails")
2019-02-23 22:41:13 +01:00
*
* @return self
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, ?Orderdetail $new_order_orderdetail = null): Part
2019-02-23 22:41:13 +01:00
{
//Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!');
2019-02-23 22:41:13 +01:00
$this->manual_order = $new_manual_order;
2019-02-23 22:41:13 +01:00
//TODO;
2019-08-15 22:34:37 +02:00
$this->order_orderdetail = $new_order_orderdetail;
2019-02-23 22:41:13 +01:00
$this->order_quantity = $new_order_quantity;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
* Set the category of this Part.
2019-02-23 22:41:13 +01:00
*
* Every part must have a valid category (in contrast to the
2019-02-23 22:41:13 +01:00
* attributes "footprint", "storelocation", ...)!
*
* @param Category $category The new category of this part
2019-02-23 22:41:13 +01:00
*
* @return self
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function setCategory(Category $category): Part
2019-02-23 22:41:13 +01:00
{
$this->category = $category;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
* Set the new Footprint of this Part.
2019-02-23 22:41:13 +01:00
*
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have
* a footprint.
*
* @return self
2019-02-23 22:41:13 +01:00
*/
2019-08-15 22:34:37 +02:00
public function setFootprint(?Footprint $new_footprint): Part
2019-02-23 22:41:13 +01:00
{
$this->footprint = $new_footprint;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
* Sets the new manufacturer of this part.
2019-02-23 22:41:13 +01:00
*
* @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should
* not have a manufacturer.
*
* @return Part
2019-02-23 22:41:13 +01:00
*/
public function setManufacturer(?Manufacturer $new_manufacturer): self
2019-02-23 22:41:13 +01:00
{
$this->manufacturer = $new_manufacturer;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
* Set the favorite status for this part.
*
2019-02-23 22:41:13 +01:00
* @param $new_favorite_status bool The new favorite status, that should be applied on this part.
* Set this to true, when the part should be a favorite.
*
* @return self
2019-02-23 22:41:13 +01:00
*/
public function setFavorite(bool $new_favorite_status): self
2019-02-23 22:41:13 +01:00
{
$this->favorite = $new_favorite_status;
return $this;
2019-02-23 22:41:13 +01:00
}
/**
* Sets the URL to the manufacturer site about this Part. Set to "" if this part should use the automatically URL based on its manufacturer.
*
2019-02-23 22:41:13 +01:00
* @param string $new_url The new url
*
* @return self
2019-02-23 22:41:13 +01:00
*/
public function setManufacturerProductURL(string $new_url): self
2019-02-23 22:41:13 +01:00
{
$this->manufacturer_product_url = $new_url;
return $this;
2019-02-23 22:41:13 +01:00
}
}