2019-03-20 23:16:07 +01:00
|
|
|
<?php
|
2019-08-12 15:47:57 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
namespace App\Entity\PriceInformations;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
use App\Entity\Base\DBElement;
|
2019-08-29 13:06:04 +02:00
|
|
|
use App\Entity\Base\TimestampTrait;
|
2019-08-12 15:47:57 +02:00
|
|
|
use App\Entity\Parts\Part;
|
|
|
|
use App\Entity\Parts\Supplier;
|
2019-08-30 14:25:05 +02:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
2019-02-23 22:41:13 +01:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-08-02 12:17:56 +02:00
|
|
|
use Doctrine\ORM\PersistentCollection;
|
|
|
|
use Exception;
|
2019-08-30 14:25:05 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
2019-08-29 13:06:04 +02:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Class Orderdetail.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-08-06 13:18:29 +02:00
|
|
|
* @ORM\Table("`orderdetails`")
|
2019-02-23 22:41:13 +01:00
|
|
|
* @ORM\Entity()
|
2019-08-29 13:06:04 +02:00
|
|
|
* @ORM\HasLifecycleCallbacks()
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
class Orderdetail extends DBElement
|
|
|
|
{
|
2019-08-29 13:06:04 +02:00
|
|
|
use TimestampTrait;
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
|
|
|
* @var Part
|
2019-08-12 15:47:57 +02:00
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="orderdetails")
|
2019-02-23 22:41:13 +01:00
|
|
|
* @ORM\JoinColumn(name="part_id", referencedColumnName="id")
|
2019-08-30 14:25:05 +02:00
|
|
|
* @Assert\NotNull()
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $part;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Supplier
|
2019-08-12 15:47:57 +02:00
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="orderdetails")
|
2019-02-23 22:41:13 +01:00
|
|
|
* @ORM\JoinColumn(name="id_supplier", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
protected $supplier;
|
|
|
|
|
|
|
|
/**
|
2019-08-30 14:25:05 +02:00
|
|
|
* @ORM\OneToMany(targetEntity="Pricedetail", mappedBy="orderdetail", cascade={"persist", "remove"}, orphanRemoval=true)
|
|
|
|
* @Assert\Valid()
|
2019-08-31 12:07:16 +02:00
|
|
|
* @ORM\OrderBy({"min_discount_quantity" = "ASC"})
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $pricedetails;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
* @ORM\Column(type="string")
|
|
|
|
*/
|
2019-08-29 13:06:04 +02:00
|
|
|
protected $supplierpartnr = "";
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
* @ORM\Column(type="boolean")
|
|
|
|
*/
|
2019-08-29 13:06:04 +02:00
|
|
|
protected $obsolete = false;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
* @ORM\Column(type="string")
|
2019-08-29 13:06:04 +02:00
|
|
|
* @Assert\Url()
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-08-29 13:06:04 +02:00
|
|
|
protected $supplier_product_url = "";
|
2019-08-02 12:17:56 +02:00
|
|
|
|
2019-08-30 14:25:05 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->pricedetails = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
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 'O'.sprintf('%06d', $this->getID());
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
*
|
|
|
|
* Getters
|
|
|
|
*
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Part the part of this orderdetails
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getPart(): Part
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->part;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the supplier.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Supplier the supplier of this orderdetails
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-08-29 13:06:04 +02:00
|
|
|
public function getSupplier(): ?Supplier
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->supplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the supplier part-nr.
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return string the part-nr.
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getSupplierPartNr(): string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->supplierpartnr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get if this orderdetails is obsolete.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* "Orderdetails is obsolete" means that the part with that supplier-part-nr
|
|
|
|
* is no longer available from the supplier of that orderdetails.
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return bool * true if this part is obsolete at that supplier
|
|
|
|
* * false if this part isn't obsolete at that supplier
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getObsolete(): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return (bool) $this->obsolete;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the link to the website of the article on the suppliers website.
|
|
|
|
*
|
|
|
|
* @param $no_automatic_url bool Set this to true, if you only want to get the local set product URL for this Orderdetail
|
|
|
|
* and not a automatic generated one, based from the Supplier
|
|
|
|
*
|
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 getSupplierProductUrl(bool $no_automatic_url = false): string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-08-02 12:17:56 +02:00
|
|
|
if ($no_automatic_url || '' !== $this->supplier_product_url) {
|
|
|
|
return $this->supplier_product_url;
|
2019-03-20 22:53:06 +01:00
|
|
|
}
|
|
|
|
|
2019-08-31 13:43:41 +02:00
|
|
|
if ($this->supplier === null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-03-20 22:53:06 +01:00
|
|
|
return $this->getSupplier()->getAutoProductUrl($this->supplierpartnr); // maybe an automatic url is available...
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get all pricedetails.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-08-02 12:17:56 +02:00
|
|
|
* @return Pricedetail[] all pricedetails as a one-dimensional array of Pricedetails objects,
|
2019-03-20 23:16:07 +01:00
|
|
|
* sorted by minimum discount quantity
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* @throws Exception if there was an error
|
|
|
|
*/
|
2019-08-30 14:25:05 +02:00
|
|
|
public function getPricedetails(): Collection
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->pricedetails;
|
|
|
|
}
|
|
|
|
|
2019-08-30 14:25:05 +02:00
|
|
|
/**
|
|
|
|
* Adds an pricedetail to this orderdetail
|
|
|
|
* @param Pricedetail $pricedetail The pricedetail to add
|
|
|
|
* @return Orderdetail
|
|
|
|
*/
|
|
|
|
public function addPricedetail(Pricedetail $pricedetail) : Orderdetail
|
|
|
|
{
|
|
|
|
$pricedetail->setOrderdetail($this);
|
|
|
|
$this->pricedetails->add($pricedetail);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes an pricedetail from this orderdetail
|
|
|
|
* @param Pricedetail $pricedetail
|
|
|
|
* @return Orderdetail
|
|
|
|
*/
|
|
|
|
public function removePricedetail(Pricedetail $pricedetail) : Orderdetail
|
|
|
|
{
|
|
|
|
$this->pricedetails->removeElement($pricedetail);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the price for a specific quantity.
|
|
|
|
* @param int $quantity this is the quantity to choose the correct pricedetails
|
|
|
|
* @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-08-02 15:10:29 +02:00
|
|
|
* @return float float: the price as a float number (if "$as_money_string == false")
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* @throws Exception if there are no pricedetails for the choosed quantity
|
2019-03-20 23:16:07 +01:00
|
|
|
* (for example, there are only one pricedetails with the minimum discount quantity '10',
|
|
|
|
* but the choosed quantity is '5' --> the price for 5 parts is not defined!)
|
2019-02-23 22:41:13 +01:00
|
|
|
* @throws Exception if there was an error
|
|
|
|
*/
|
2019-08-02 15:10:29 +02:00
|
|
|
public function getPrice(int $quantity = 1, $multiplier = null) : ?float
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-08-02 15:10:29 +02:00
|
|
|
|
2019-08-20 18:39:57 +02:00
|
|
|
if (($quantity === 0) && ($multiplier === null)) {
|
2019-08-02 15:10:29 +02:00
|
|
|
return 0.0;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$all_pricedetails = $this->getPricedetails();
|
|
|
|
|
|
|
|
if (count($all_pricedetails) == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:10:29 +02:00
|
|
|
|
|
|
|
$correct_pricedetails = null;
|
2019-02-23 22:41:13 +01:00
|
|
|
foreach ($all_pricedetails as $pricedetails) {
|
|
|
|
// choose the correct pricedetails for the choosed quantity ($quantity)
|
|
|
|
if ($quantity < $pricedetails->getMinDiscountQuantity()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$correct_pricedetails = $pricedetails;
|
|
|
|
}
|
|
|
|
|
2019-08-20 18:39:57 +02:00
|
|
|
if ($correct_pricedetails === null) {
|
2019-08-02 15:10:29 +02:00
|
|
|
return null;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($multiplier === null) {
|
|
|
|
$multiplier = $quantity;
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:10:29 +02:00
|
|
|
return $correct_pricedetails->getPricePerUnit($multiplier);
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
*
|
|
|
|
* Setters
|
|
|
|
*
|
|
|
|
*********************************************************************************/
|
|
|
|
|
2019-08-30 14:25:05 +02:00
|
|
|
/**
|
|
|
|
* Sets a new part with which this orderdetail is associated
|
|
|
|
* @param Part $part
|
|
|
|
*/
|
|
|
|
public function setPart(Part $part)
|
|
|
|
{
|
|
|
|
$this->part = $part;
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
2019-08-20 18:39:57 +02:00
|
|
|
* Sets the new supplier associated with this orderdetail.
|
|
|
|
* @param Supplier $new_supplier
|
|
|
|
* @return Orderdetail
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-08-20 18:39:57 +02:00
|
|
|
public function setSupplier(Supplier $new_supplier) : Orderdetail
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-08-20 18:39:57 +02:00
|
|
|
$this->supplier = $new_supplier;
|
2019-02-24 12:54:11 +01:00
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the supplier part-nr.
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param string $new_supplierpartnr the new supplier-part-nr
|
2019-08-20 18:39:57 +02:00
|
|
|
* @return Orderdetail
|
|
|
|
* @return Orderdetail
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setSupplierpartnr(string $new_supplierpartnr): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->supplierpartnr = $new_supplierpartnr;
|
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 if the part is obsolete at the supplier of that orderdetails.
|
|
|
|
* @param bool $new_obsolete true means that this part is obsolete
|
2019-08-20 18:39:57 +02:00
|
|
|
* @return Orderdetail
|
|
|
|
* @return Orderdetail
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setObsolete(bool $new_obsolete): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->obsolete = $new_obsolete;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the custom product supplier URL for this order detail.
|
|
|
|
* Set this to "", if the function getSupplierProductURL should return the automatic generated URL.
|
|
|
|
* @param $new_url string The new URL for the supplier URL.
|
2019-08-20 18:39:57 +02:00
|
|
|
* @return Orderdetail
|
|
|
|
* @return Orderdetail
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
public function setSupplierProductUrl(string $new_url)
|
|
|
|
{
|
2019-08-30 14:25:05 +02:00
|
|
|
//Only change the internal URL if it is not the auto generated one
|
|
|
|
if ($new_url == $this->supplier->getAutoProductUrl($this->getSupplierPartNr())) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2019-02-24 12:54:11 +01:00
|
|
|
$this->supplier_product_url = $new_url;
|
|
|
|
|
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|