2019-03-20 23:16:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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
|
2019-03-20 23:16:07 +01:00
|
|
|
* 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;
|
|
|
|
|
2019-03-20 19:11:34 +01:00
|
|
|
use App\Security\Annotations\ColumnSecurity;
|
2019-02-23 22:41:13 +01:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-03-13 13:23:12 +01:00
|
|
|
//use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Class Part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-02-23 22:52:48 +01:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\PartRepository")
|
2019-08-06 13:18:29 +02:00
|
|
|
* @ORM\Table("`parts`")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
class Part extends AttachmentContainingDBElement
|
|
|
|
{
|
2019-03-20 23:16:07 +01:00
|
|
|
public const INSTOCK_UNKNOWN = -2;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-08-06 13:18:29 +02:00
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="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")
|
|
|
|
*/
|
|
|
|
protected $category;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Footprint|null
|
|
|
|
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="parts")
|
|
|
|
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id")
|
2019-03-20 22:30:03 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="footprint", type="object")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $footprint;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Storelocation|null
|
|
|
|
* @ORM\ManyToOne(targetEntity="Storelocation", inversedBy="parts")
|
|
|
|
* @ORM\JoinColumn(name="id_storelocation", referencedColumnName="id")
|
2019-03-20 22:30:03 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="storelocation", type="object")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $storelocation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Manufacturer|null
|
|
|
|
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="parts")
|
|
|
|
* @ORM\JoinColumn(name="id_manufacturer", referencedColumnName="id")
|
2019-03-20 22:30:03 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="manufacturer", type="object")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $manufacturer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Attachment
|
|
|
|
* @ORM\ManyToOne(targetEntity="Attachment")
|
2019-02-23 22:52:48 +01:00
|
|
|
* @ORM\JoinColumn(name="id_master_picture_attachement", referencedColumnName="id")
|
2019-03-20 22:30:03 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="attachments", type="object")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $master_picture_attachment;
|
|
|
|
|
|
|
|
/**
|
2019-08-02 12:17:56 +02:00
|
|
|
* @var Orderdetail[]
|
2019-02-23 22:41:13 +01:00
|
|
|
* @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="part")
|
2019-03-20 22:30:03 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="orderdetails", type="object")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $orderdetails;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Orderdetail
|
|
|
|
* @ORM\OneToOne(targetEntity="Orderdetail")
|
|
|
|
* @ORM\JoinColumn(name="order_orderdetails_id", referencedColumnName="id")
|
2019-03-20 22:30:03 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="order", type="object")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $order_orderdetail;
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
protected $devices;
|
|
|
|
|
2019-03-20 22:30:03 +01:00
|
|
|
/**
|
|
|
|
* @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")
|
2019-03-20 19:11:34 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="name")
|
|
|
|
*/
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
2019-08-06 13:18:29 +02:00
|
|
|
* @ORM\Column(type="text")
|
2019-03-20 19:11:34 +01:00
|
|
|
*
|
|
|
|
* @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 int
|
|
|
|
* @ORM\Column(type="integer")
|
2019-03-13 13:23:12 +01:00
|
|
|
* @Assert\GreaterThanOrEqual(0)
|
2019-03-20 19:11:34 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="instock", type="integer")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-13 13:23:12 +01:00
|
|
|
protected $instock = 0;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
* @ORM\Column(type="integer")
|
2019-03-13 13:23:12 +01:00
|
|
|
* @Assert\GreaterThanOrEqual(0)
|
2019-03-20 19:11:34 +01:00
|
|
|
*
|
|
|
|
* @ColumnSecurity(prefix="mininstock", type="integer")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-13 13:23:12 +01:00
|
|
|
protected $mininstock = 0;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
2019-08-06 13:18:29 +02:00
|
|
|
* @ORM\Column(type="text")
|
2019-03-20 19:11:34 +01:00
|
|
|
* @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")
|
|
|
|
*/
|
2019-03-13 13:23:12 +01:00
|
|
|
protected $visible = true;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
* @ORM\Column(type="boolean")
|
2019-03-20 22:30:03 +01:00
|
|
|
* @ColumnSecurity(type="boolean")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-13 13:23:12 +01:00
|
|
|
protected $favorite = false;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
* @ORM\Column(type="integer")
|
2019-03-20 22:30:03 +01:00
|
|
|
* @ColumnSecurity(prefix="order", type="integer")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-13 13:23:12 +01:00
|
|
|
protected $order_quantity = 0;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
* @ORM\Column(type="boolean")
|
2019-03-20 22:30:03 +01:00
|
|
|
* @ColumnSecurity(prefix="order", type="boolean")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-13 13:23:12 +01:00
|
|
|
protected $manual_order = false;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
* @ORM\Column(type="string")
|
2019-03-20 22:30:03 +01:00
|
|
|
*@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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @return string The ID as a string;
|
|
|
|
*/
|
|
|
|
public function getIDString(): string
|
|
|
|
{
|
2019-03-20 23:16:07 +01:00
|
|
|
return 'P'.sprintf('%06d', $this->getID());
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************
|
|
|
|
* Getters
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2019-03-05 17:02:48 +01:00
|
|
|
* 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
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return string the description
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getDescription(): string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-05 17:02:48 +01:00
|
|
|
return htmlspecialchars($this->description);
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-05 17:02:48 +01:00
|
|
|
* Get the count of parts which are in stock.
|
|
|
|
* When the instock is unkown, then Part::INSTOCK_UNKNOWN is returned.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return int count of parts which are in stock
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getInstock(): int
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->instock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the value of the Instock is unknown.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @return bool True, if the value of the instock is unknown.
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function isInstockUnknown(): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->instock <= static::INSTOCK_UNKNOWN;
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @noinspection ReturnTypeCanBeDeclaredInspection */
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the count of parts which must be in stock at least.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return int count of parts which must be in stock at least
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getMinInstock(): int
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->mininstock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-05 17:02:48 +01:00
|
|
|
* Get the comment associated with this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return string The raw/unparsed comment
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getComment(): string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-05 17:02:48 +01:00
|
|
|
return htmlspecialchars($this->comment);
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get if this part is obsolete.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-05 14:15:18 +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.
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return bool true, if this part is obsolete. false, if this part isn't obsolete
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function isObsolete(): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$all_orderdetails = $this->getOrderdetails();
|
|
|
|
|
2019-03-20 23:16:07 +01:00
|
|
|
if (0 === count($all_orderdetails)) {
|
2019-02-23 22:41:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($all_orderdetails as $orderdetails) {
|
2019-03-20 23:16:07 +01:00
|
|
|
if (!$orderdetails->getObsolete()) {
|
2019-02-23 22:41:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get if this part is visible.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +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
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function isVisible(): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-05 17:02:48 +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
|
2019-03-20 23:16:07 +01:00
|
|
|
* * false if this part is not a favorite.
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function isFavorite(): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-05 17:02:48 +01:00
|
|
|
return $this->favorite;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the selected order orderdetails of this part.
|
|
|
|
*
|
|
|
|
* @return Orderdetail the selected order orderdetails
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getOrderOrderdetails(): ?Orderdetail
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
/*
|
|
|
|
if ($this->order_orderdetails->getObsolete()) {
|
|
|
|
$this->setOrderOrderdetailsID(null);
|
|
|
|
$this->order_orderdetails = null;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
return $this->order_orderdetail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the order quantity of this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return int the order quantity
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getOrderQuantity(): int
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-05 17:02:48 +01:00
|
|
|
return $this->order_quantity;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the minimum quantity which should be ordered.
|
|
|
|
*
|
|
|
|
* @param bool $with_devices * if true, all parts from devices which are marked as "to order" will be included in the calculation
|
|
|
|
* * if false, only max(mininstock - instock, 0) will be returned
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return int the minimum order quantity
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getMinOrderQuantity(bool $with_devices = true): int
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
//TODO
|
2019-03-20 22:53:06 +01:00
|
|
|
throw new \Exception('Not implemented yet...');
|
2019-03-20 23:16:07 +01:00
|
|
|
/*
|
2019-02-23 22:41:13 +01:00
|
|
|
if ($with_devices) {
|
2019-03-14 12:56:55 +01:00
|
|
|
$count_must_order = 0; // for devices with "order_only_missing_parts == false"
|
|
|
|
$count_should_order = 0; // for devices with "order_only_missing_parts == true"
|
|
|
|
$deviceparts = DevicePart::getOrderDeviceParts($this->database, $this->current_user, $this->log, $this->getID());
|
|
|
|
foreach ($deviceparts as $devicepart) {
|
|
|
|
/** @var $devicepart DevicePart */
|
2019-03-20 23:16:07 +01:00
|
|
|
/* @var $device Device */ /*
|
2019-03-14 12:56:55 +01:00
|
|
|
$device = $devicepart->getDevice();
|
|
|
|
if ($device->getOrderOnlyMissingParts()) {
|
|
|
|
$count_should_order += $device->getOrderQuantity() * $devicepart->getMountQuantity();
|
|
|
|
} else {
|
|
|
|
$count_must_order += $device->getOrderQuantity() * $devicepart->getMountQuantity();
|
|
|
|
}
|
|
|
|
}
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-03-14 12:56:55 +01:00
|
|
|
return $count_must_order + max(0, $this->getMinInstock() - $this->getInstock() + $count_should_order);
|
|
|
|
} else {
|
|
|
|
return max(0, $this->getMinInstock() - $this->getInstock());
|
|
|
|
} **/
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Check if this part is marked for manual ordering.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return bool the "manual_order" attribute
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function isMarkedForManualOrder(): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-05 17:02:48 +01:00
|
|
|
return $this->manual_order;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the part is automatically marked for Ordering, because the instock value is smaller than the min instock value.
|
2019-03-20 23:16:07 +01:00
|
|
|
* This is called automatic ordering.
|
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @return bool True, if the part should be ordered.
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function isAutoOrdered(): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
//Parts with negative instock never gets ordered.
|
|
|
|
if ($this->getInstock() < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getInstock() < $this->getMinInstock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the link to the website of the article on the manufacturers website
|
2019-03-05 17:02:48 +01:00
|
|
|
* 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
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return string the link to the article
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getManufacturerProductUrl(): string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-20 23:16:07 +01:00
|
|
|
if ('' !== $this->manufacturer_product_url) {
|
2019-02-23 22:41:13 +01:00
|
|
|
return $this->manufacturer_product_url;
|
2019-03-05 17:02:48 +01:00
|
|
|
}
|
|
|
|
|
2019-03-20 23:16:07 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-03-05 17:02:48 +01:00
|
|
|
/**
|
|
|
|
* Similar to getManufacturerProductUrl, but here only the database value is returned.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return string The manufacturer url saved in DB for this part.
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getOwnProductURL(): string
|
2019-03-05 17:02:48 +01:00
|
|
|
{
|
|
|
|
return $this->manufacturer_product_url;
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the category of this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* There is always a category, for each part!
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Category the category of this part
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getCategory(): Category
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->category;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the footprint of this part (if there is one).
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Footprint the footprint of this part (if there is one)
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getFootprint(): ?Footprint
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->footprint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the storelocation of this part (if there is one).
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Storelocation the storelocation of this part (if there is one)
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getStorelocation(): ?Storelocation
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->storelocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the manufacturer of this part (if there is one).
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Manufacturer the manufacturer of this part (if there is one)
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getManufacturer(): ?Manufacturer
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->manufacturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the master picture "Attachement"-object of this part (if there is one).
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Attachment the master picture Attachement of this part (if there is one)
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get all orderdetails of this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-08-02 12:17:56 +02:00
|
|
|
* @return Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects
|
2019-03-20 23:16:07 +01:00
|
|
|
* (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
|
|
|
*
|
|
|
|
* @throws Exception if there was an error
|
|
|
|
*/
|
|
|
|
public function getOrderdetails(bool $hide_obsolete = false)
|
|
|
|
{
|
|
|
|
if ($hide_obsolete) {
|
|
|
|
$orderdetails = $this->orderdetails;
|
|
|
|
foreach ($orderdetails as $key => $details) {
|
|
|
|
if ($details->getObsolete()) {
|
|
|
|
unset($orderdetails[$key]);
|
|
|
|
}
|
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
return $orderdetails;
|
|
|
|
} else {
|
|
|
|
return $this->orderdetails;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get all devices which uses this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +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)
|
2019-03-13 13:23:12 +01:00
|
|
|
* * the array is sorted by the devices names
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* @throws Exception if there was an error
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getDevices(): array
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get all suppliers of this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* This method simply gets the suppliers of the orderdetails and prepare them.\n
|
|
|
|
* You can get the suppliers as an array or as a string with individual delimeter.
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param bool $object_array * if true, this method returns an array of Supplier objects
|
|
|
|
* * if false, this method returns an array of strings
|
|
|
|
* @param string|null $delimeter * if this is a string and "$object_array == false",
|
|
|
|
* this method returns a string with all
|
|
|
|
* supplier names, delimeted by "$delimeter"
|
|
|
|
* @param bool $full_paths * if true and "$object_array = false", the returned
|
|
|
|
* suppliernames are full paths (path + name)
|
|
|
|
* * if true and "$object_array = false", the returned
|
|
|
|
* suppliernames are only the names (without path)
|
|
|
|
* @param bool $hide_obsolete If true, suppliers from obsolete orderdetails will NOT be returned
|
|
|
|
*
|
|
|
|
* @return array all suppliers as a one-dimensional array of Supplier objects
|
|
|
|
* (if "$object_array == true")
|
|
|
|
* @return array all supplier-names as a one-dimensional array of strings
|
|
|
|
* ("if $object_array == false" and "$delimeter == NULL")
|
|
|
|
* @return string a sting of all supplier names, delimeted by $delimeter
|
|
|
|
* ("if $object_array == false" and $delimeter is a string)
|
|
|
|
*
|
|
|
|
* @throws Exception if there was an error
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
public function getSuppliers(bool $object_array = true, $delimeter = null, bool $full_paths = false, bool $hide_obsolete = false)
|
|
|
|
{
|
|
|
|
$suppliers = array();
|
|
|
|
$orderdetails = $this->getOrderdetails($hide_obsolete);
|
|
|
|
|
|
|
|
foreach ($orderdetails as $details) {
|
|
|
|
$suppliers[] = $details->getSupplier();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($object_array) {
|
|
|
|
return $suppliers;
|
|
|
|
} else {
|
|
|
|
$supplier_names = array();
|
|
|
|
foreach ($suppliers as $supplier) {
|
2019-03-20 23:16:07 +01:00
|
|
|
/* @var Supplier $supplier */
|
2019-02-23 22:41:13 +01:00
|
|
|
if ($full_paths) {
|
|
|
|
$supplier_names[] = $supplier->getFullPath();
|
|
|
|
} else {
|
|
|
|
$supplier_names[] = $supplier->getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (\is_string($delimeter)) {
|
|
|
|
return implode($delimeter, $supplier_names);
|
|
|
|
}
|
2019-03-20 23:24:20 +01:00
|
|
|
|
|
|
|
return $supplier_names;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get all supplier-part-Nrs.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* This method simply gets the suppliers-part-Nrs of the orderdetails and prepare them.\n
|
|
|
|
* You can get the numbers as an array or as a string with individual delimeter.
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param string|null $delimeter * if this is a string, this method returns a delimeted string
|
|
|
|
* * otherwise, this method returns an array of strings
|
|
|
|
* @param bool $hide_obsolete If true, supplierpartnrs from obsolete orderdetails will NOT be returned
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return array all supplierpartnrs as an array of strings (if "$delimeter == NULL")
|
|
|
|
* @return string all supplierpartnrs as a string, delimeted ba $delimeter (if $delimeter is a string)
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @throws Exception if there was an error
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
public function getSupplierPartNrs($delimeter = null, bool $hide_obsolete = false)
|
|
|
|
{
|
|
|
|
$supplierpartnrs = array();
|
|
|
|
|
|
|
|
foreach ($this->getOrderdetails($hide_obsolete) as $details) {
|
|
|
|
$supplierpartnrs[] = $details->getSupplierPartNr();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (\is_string($delimeter)) {
|
|
|
|
return implode($delimeter, $supplierpartnrs);
|
|
|
|
} else {
|
|
|
|
return $supplierpartnrs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* 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.
|
2019-08-02 15:10:29 +02:00
|
|
|
* @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
|
2019-03-20 23:16:07 +01:00
|
|
|
* * If you pass NULL, the number from $quantity will be used
|
2019-08-02 15:10:29 +02:00
|
|
|
* @param bool $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-08-02 15:10:29 +02:00
|
|
|
* @return float[] all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true")
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-08-02 15:10:29 +02:00
|
|
|
* @throws \Exception if there was an error
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-08-02 15:10:29 +02: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) {
|
2019-08-02 15:10:29 +02:00
|
|
|
$prices[] = $details->getPrice($quantity, $multiplier);
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
2019-08-02 15:10:29 +02:00
|
|
|
return $prices;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +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.
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @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
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return float price (if "$as_money_string == false")
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-08-02 15:10:29 +02:00
|
|
|
* @throws \Exception if there was an error
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-08-06 17:15:37 +02:00
|
|
|
public function getAveragePrice(int $quantity = 1, $multiplier = null) : ?float
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-08-02 15:10:29 +02:00
|
|
|
$prices = $this->getPrices($quantity, $multiplier, true);
|
2019-02-23 22:41:13 +01:00
|
|
|
$average_price = null;
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
foreach ($prices as $price) {
|
2019-03-20 23:16:07 +01:00
|
|
|
if (null !== $price) {
|
2019-02-23 22:41:13 +01:00
|
|
|
$average_price += $price;
|
2019-03-20 23:16:07 +01:00
|
|
|
++$count;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($count > 0) {
|
|
|
|
$average_price /= $count;
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:10:29 +02:00
|
|
|
return $average_price;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the filename of the master picture (absolute path from filesystem root).
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param bool $use_footprint_filename * if true, and this part has no picture, this method
|
|
|
|
* will return the filename of its footprint (if available)
|
|
|
|
* * if false, and this part has no picture,
|
|
|
|
* this method will return NULL
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return string the whole path + filename from filesystem root as a UNIX path (with slashes)
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-12 19:39:02 +01:00
|
|
|
* @throws \Exception if there was an error
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getMasterPictureFilename(bool $use_footprint_filename = false): ?string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$master_picture = $this->getMasterPictureAttachement(); // returns an Attachement-object
|
|
|
|
|
2019-03-20 23:16:07 +01:00
|
|
|
if (null !== $master_picture) {
|
2019-02-23 22:41:13 +01:00
|
|
|
return $master_picture->getFilename();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($use_footprint_filename) {
|
|
|
|
$footprint = $this->getFootprint();
|
2019-03-20 23:16:07 +01:00
|
|
|
if (null !== $footprint) {
|
2019-02-23 22:41:13 +01:00
|
|
|
return $footprint->getFilename();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the selected fields and extract Properties of the part.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @param bool $use_description Use the description field for parsing
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param bool $use_comment Use the comment field for parsing
|
|
|
|
* @param bool $use_name Use the name field for parsing
|
|
|
|
* @param bool $force_output Properties are parsed even if properties are disabled.
|
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @return array A array of PartProperty objects.
|
|
|
|
* @return array If Properties are disabled or nothing was detected, then an empty array is returned.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getProperties(bool $use_description = true, bool $use_comment = true, bool $use_name = true, bool $force_output = false): array
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
//TODO
|
2019-03-20 22:53:06 +01:00
|
|
|
throw new \Exception('Not implemented yet!');
|
2019-02-23 22:41:13 +01:00
|
|
|
/*
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if ($config['properties']['active'] || $force_output) {
|
|
|
|
if ($this->getCategory()->getDisableProperties(true)) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = array();
|
|
|
|
$desc = array();
|
|
|
|
$comm = array();
|
|
|
|
|
|
|
|
if ($use_name === true) {
|
|
|
|
$name = $this->getCategory()->getPartnameRegexObj()->getProperties($this->getName());
|
|
|
|
}
|
|
|
|
if ($use_description === true) {
|
|
|
|
$desc = PartProperty::parseDescription($this->getDescription());
|
|
|
|
}
|
|
|
|
if ($use_comment === true) {
|
|
|
|
$comm = PartProperty::parseDescription($this->getComment(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_merge($name, $desc, $comm);
|
|
|
|
} else {
|
|
|
|
return array();
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a loop (array) of the array representations of the properties of this part.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @param bool $use_description Use the description field for parsing
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param bool $use_comment Use the comment field for parsing
|
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @return array A array of arrays with the name and value of the properties.
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getPropertiesLoop(bool $use_description = true, bool $use_comment = true, bool $use_name = true): array
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
//TODO
|
2019-03-20 22:53:06 +01:00
|
|
|
throw new \Exception('Not implemented yet!');
|
2019-02-23 22:41:13 +01:00
|
|
|
$arr = array();
|
|
|
|
foreach ($this->getProperties($use_description, $use_comment, $use_name) as $property) {
|
|
|
|
/* @var PartProperty $property */
|
|
|
|
$arr[] = $property->getArray(true);
|
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
public function hasValidName() : bool
|
|
|
|
{
|
|
|
|
return self::isValidName($this->getName(), $this->getCategory());
|
|
|
|
} */
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
*
|
|
|
|
* Setters
|
|
|
|
*
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the description.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param string $new_description the new description
|
2019-03-05 17:02:48 +01:00
|
|
|
*
|
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setDescription(?string $new_description): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->description = $new_description;
|
2019-03-20 23:16:07 +01:00
|
|
|
|
2019-02-24 12:54:11 +01:00
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the count of parts which are in stock.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param int $new_instock the new count of parts which are in stock
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setInstock(int $new_instock, $comment = null): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
//Assert::natural($new_instock, 'New instock must be positive. Got: %s');
|
2019-03-05 17:02:48 +01:00
|
|
|
|
2019-03-20 22:53:06 +01:00
|
|
|
$old_instock = $this->getInstock();
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->instock = $new_instock;
|
|
|
|
//TODO
|
|
|
|
/*
|
|
|
|
InstockChangedEntry::add(
|
|
|
|
$this->database,
|
|
|
|
$this->current_user,
|
|
|
|
$this->log,
|
|
|
|
$this,
|
|
|
|
$old_instock,
|
|
|
|
$new_instock,
|
|
|
|
$comment
|
|
|
|
);*/
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
2019-03-05 17:02:48 +01:00
|
|
|
/**
|
|
|
|
* Sets the unknown status of this part.
|
|
|
|
* When the instock is currently unknown and you pass false, then the instock is set to zero.
|
|
|
|
* If the instock is not unknown and you pass false, nothing is changed.
|
|
|
|
*
|
|
|
|
* @param bool $new_unknown Set this to true if the instock should be marked as unknown.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return Part
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setInstockUnknown(bool $new_unknown): self
|
2019-03-05 17:02:48 +01:00
|
|
|
{
|
2019-03-20 23:16:07 +01:00
|
|
|
if (true === $new_unknown) {
|
2019-03-05 17:02:48 +01:00
|
|
|
$this->instock = self::INSTOCK_UNKNOWN;
|
2019-03-20 23:16:07 +01:00
|
|
|
} elseif ($this->isInstockUnknown()) {
|
2019-03-20 22:53:06 +01:00
|
|
|
$this->setInstock(0);
|
2019-03-05 17:02:48 +01:00
|
|
|
}
|
|
|
|
|
2019-03-20 22:53:06 +01:00
|
|
|
return $this;
|
2019-03-05 17:02:48 +01:00
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
|
|
|
* Withdrawal the given number of parts.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @param $count int The number of parts which should be withdrawan.
|
|
|
|
* @param $comment string A comment that should be associated with the withdrawal.
|
2019-03-05 17:02:48 +01:00
|
|
|
*
|
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function withdrawalParts(int $count, $comment = null): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
//Assert::greaterThan($count,0, 'Count of withdrawn parts must be greater 0! Got %s!');
|
|
|
|
//Assert::greaterThan($count, $this->instock, 'You can not withdraw more parts, than there are existing!');
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-03-05 17:02:48 +01:00
|
|
|
$old_instock = $this->getInstock();
|
2019-02-23 22:41:13 +01:00
|
|
|
$new_instock = $old_instock - $count;
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
/*
|
|
|
|
InstockChangedEntry::add(
|
|
|
|
$this->database,
|
|
|
|
$this->current_user,
|
|
|
|
$this->log,
|
|
|
|
$this,
|
|
|
|
$old_instock,
|
|
|
|
$new_instock,
|
|
|
|
$comment
|
|
|
|
);*/
|
|
|
|
|
|
|
|
$this->instock = $new_instock;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given number of parts.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @param $count int The number of parts which should be withdrawan.
|
|
|
|
* @param $comment string A comment that should be associated with the withdrawal.
|
2019-03-05 17:02:48 +01:00
|
|
|
*
|
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function addParts(int $count, string $comment = null): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
//Assert::greaterThan($count, 0, 'Count of added parts must be greater zero! Got %s.');
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
2019-03-05 17:02:48 +01:00
|
|
|
$old_instock = $this->getInstock();
|
2019-02-23 22:41:13 +01:00
|
|
|
$new_instock = $old_instock + $count;
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
/*
|
|
|
|
InstockChangedEntry::add(
|
|
|
|
$this->database,
|
|
|
|
$this->current_user,
|
|
|
|
$this->log,
|
|
|
|
$this,
|
|
|
|
$old_instock,
|
|
|
|
$new_instock,
|
|
|
|
$comment
|
|
|
|
);*/
|
|
|
|
|
|
|
|
$this->instock = $new_instock;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the count of parts which should be in stock at least.
|
|
|
|
*
|
|
|
|
* @param int $new_mininstock the new count of parts which should be in stock at least
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setMinInstock(int $new_mininstock): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.');
|
2019-02-24 12:54:11 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->mininstock = $new_mininstock;
|
2019-03-20 23:16:07 +01:00
|
|
|
|
2019-02-24 12:54:11 +01:00
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the comment.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param string $new_comment the new comment
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setComment(string $new_comment): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->comment = $new_comment;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the "manual_order" attribute.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +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
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
//Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!');
|
2019-03-05 17:02:48 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->manual_order = $new_manual_order;
|
2019-03-05 17:02:48 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
//TODO;
|
|
|
|
/* $this->order_orderdetail = $new_order_orderdetails_id; */
|
|
|
|
$this->order_quantity = $new_order_quantity;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the ID of the order orderdetails.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param int|null $new_order_orderdetails_id * the new order orderdetails ID
|
|
|
|
* * Or, to remove the orderdetails, pass a NULL
|
2019-03-05 17:02:48 +01:00
|
|
|
*
|
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setOrderOrderdetailsID($new_order_orderdetails_id): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
//TODO
|
2019-03-20 22:53:06 +01:00
|
|
|
throw new \Exception('Not implemented yet...');
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the order quantity.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param int $new_order_quantity the new order quantity
|
2019-03-05 17:02:48 +01:00
|
|
|
*
|
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setOrderQuantity(int $new_order_quantity): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
//Assert::greaterThan($new_order_quantity,0, 'The new order quantity must be greater zero. Got %s!');
|
2019-03-05 17:02:48 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->order_quantity = $new_order_quantity;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the category of this Part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-05 14:15:18 +01:00
|
|
|
* Every part must have a valid category (in contrast to the
|
2019-02-23 22:41:13 +01:00
|
|
|
* attributes "footprint", "storelocation", ...)!
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param Category $category The new category of this part
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setCategory(Category $category): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
$this->category = $category;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 12:56:55 +01:00
|
|
|
* Set the new Footprint of this Part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-14 12:56:55 +01:00
|
|
|
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have
|
2019-03-20 23:16:07 +01:00
|
|
|
* a footprint.
|
|
|
|
*
|
2019-03-14 12:56:55 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setFootprint(?Footprint $new_footprint): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-14 12:56:55 +01:00
|
|
|
$this->footprint = $new_footprint;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 12:56:55 +01:00
|
|
|
* Set the new store location of this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-14 12:56:55 +01:00
|
|
|
* @param Storelocation|null $new_storelocation The new Storelocation of this part. Set to null, if this part should
|
2019-03-20 23:16:07 +01:00
|
|
|
* not have a storelocation.
|
|
|
|
*
|
2019-03-14 12:56:55 +01:00
|
|
|
* @return Part
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setStorelocation(?Storelocation $new_storelocation): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-14 12:56:55 +01:00
|
|
|
$this->storelocation = $new_storelocation;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 12:56:55 +01:00
|
|
|
* Sets the new manufacturer of this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-14 12:56:55 +01:00
|
|
|
* @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should
|
2019-03-20 23:16:07 +01:00
|
|
|
* not have a manufacturer.
|
|
|
|
*
|
2019-03-14 12:56:55 +01:00
|
|
|
* @return Part
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setManufacturer(?Manufacturer $new_manufacturer): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-14 12:56:55 +01:00
|
|
|
$this->manufacturer = $new_manufacturer;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the favorite status for this part.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
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.
|
2019-03-05 17:02:48 +01:00
|
|
|
*
|
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setFavorite(bool $new_favorite_status): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->favorite = $new_favorite_status;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
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-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @param string $new_url The new url
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-03-05 17:02:48 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setManufacturerProductURL(string $new_url): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->manufacturer_product_url = $new_url;
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the ID of the master picture Attachement.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param int|null $new_master_picture_attachement_id * the ID of the Attachement object of the master picture
|
|
|
|
* * NULL means "no master picture"
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* @throws Exception if the new ID is not valid
|
|
|
|
* @throws Exception if there was an error
|
2019-03-05 17:02:48 +01:00
|
|
|
*
|
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setMasterPictureAttachementID($new_master_picture_attachement_id): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
//TODO
|
2019-03-20 22:53:06 +01:00
|
|
|
throw new \Exception('Not implemented yet!');
|
2019-02-24 12:54:11 +01:00
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|