Added entities and properties for some future features.

This commit is contained in:
Jan Böhmer 2019-08-12 15:47:57 +02:00
parent bcdba8b3e0
commit 7826e3d2ad
49 changed files with 1477 additions and 362 deletions

View file

@ -0,0 +1,131 @@
<?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
*
*/
namespace App\Entity\PriceInformations;
use App\Entity\Base\StructuralDBElement;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity describes a currency that can be used for price informations.
* @package App\Entity
* @UniqueEntity("iso_code")
* @ORM\Entity()
* @ORM\Table(name="currencies")
*/
class Currency extends StructuralDBElement
{
/**
* @var string The 3 letter ISO code of the currency.
* @ORM\Column(type="string", unique=true, nullable=true)
* @Assert\Currency()
*/
protected $iso_code;
/**
* @var float|null The exchange rate between this currency and the base currency
* (how many base units the current currency is worth)
* @ORM\Column(type="decimal", precision=11, scale=5)
* @Assert\Positive()
*/
protected $exchange_rate;
/**
* Returns the 3 letter ISO code of this currency
* @return string
*/
public function getIsoCode(): string
{
return $this->iso_code;
}
/**
* @param string $iso_code
* @return Currency
*/
public function setIsoCode(string $iso_code): Currency
{
$this->iso_code = $iso_code;
return $this;
}
/**
* Returns the inverse exchange rate (how many of the current currency the base unit is worth)
* @return float|null
*/
public function getInverseExchangeRate(): ?float
{
$tmp = $this->getExchangeRate();
if ($tmp == null) {
return null;
}
return 1 / $tmp;
}
/**
* Returns The exchange rate between this currency and the base currency
* (how many base units the current currency is worth)
* @return float|null
*/
public function getExchangeRate(): ?float
{
return $this->exchange_rate;
}
/**
* @param float|null $exchange_rate
* @return Currency
*/
public function setExchangeRate(?float $exchange_rate): Currency
{
$this->exchange_rate = $exchange_rate;
return $this;
}
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
*
* @return string The ID as a string;
*
*/
public function getIDString(): string
{
return 'C' . $this->getID();
}
}

View file

@ -0,0 +1,327 @@
<?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);
/**
* 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
*/
namespace App\Entity\PriceInformations;
use App\Entity\Base\DBElement;
use App\Entity\Parts\Part;
use App\Entity\Parts\Supplier;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use Exception;
/**
* Class Orderdetail.
*
* @ORM\Table("`orderdetails`")
* @ORM\Entity()
*/
class Orderdetail extends DBElement
{
/**
* @var Part
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="orderdetails")
* @ORM\JoinColumn(name="part_id", referencedColumnName="id")
*/
protected $part;
/**
* @var Supplier
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="orderdetails")
* @ORM\JoinColumn(name="id_supplier", referencedColumnName="id")
*/
protected $supplier;
/**
* @ORM\OneToMany(targetEntity="Pricedetail", mappedBy="orderdetail")
*/
protected $pricedetails;
/**
* @var string
* @ORM\Column(type="string")
*/
protected $supplierpartnr;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
protected $obsolete;
/**
* @var string
* @ORM\Column(type="string")
*/
protected $supplier_product_url;
/**
* @var \DateTime The date when this element was created.
* @ORM\Column(type="datetimetz", name="datetime_added")
*/
protected $addedDate;
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
*
* @return string The ID as a string;
*/
public function getIDString(): string
{
return 'O'.sprintf('%06d', $this->getID());
}
/********************************************************************************
*
* Getters
*
*********************************************************************************/
/**
* Get the part.
*
* @return Part the part of this orderdetails
*/
public function getPart(): Part
{
return $this->part;
}
/**
* Get the supplier.
*
* @return Supplier the supplier of this orderdetails
*/
public function getSupplier(): Supplier
{
return $this->supplier;
}
/**
* Get the supplier part-nr.
*
* @return string the part-nr.
*/
public function getSupplierPartNr(): string
{
return $this->supplierpartnr;
}
/**
* Get if this orderdetails is obsolete.
*
* "Orderdetails is obsolete" means that the part with that supplier-part-nr
* is no longer available from the supplier of that orderdetails.
*
* @return bool * true if this part is obsolete at that supplier
* * false if this part isn't obsolete at that supplier
*/
public function getObsolete(): bool
{
return (bool) $this->obsolete;
}
/**
* Returns the date/time when the element was created.
* Returns null if the element was not yet saved to DB yet.
*
* @return \DateTime|null The creation time of the part.
*/
public function getAddedDate(): ?\DateTime
{
return $this->addedDate;
}
/**
* 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
*
* @return string the link to the article
*/
public function getSupplierProductUrl(bool $no_automatic_url = false): string
{
if ($no_automatic_url || '' !== $this->supplier_product_url) {
return $this->supplier_product_url;
}
return $this->getSupplier()->getAutoProductUrl($this->supplierpartnr); // maybe an automatic url is available...
}
/**
* Get all pricedetails.
*
* @return Pricedetail[] all pricedetails as a one-dimensional array of Pricedetails objects,
* sorted by minimum discount quantity
*
* @throws Exception if there was an error
*/
public function getPricedetails(): PersistentCollection
{
return $this->pricedetails;
}
/**
* 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
*
* @return float float: the price as a float number (if "$as_money_string == false")
*
* @throws Exception if there are no pricedetails for the choosed quantity
* (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!)
* @throws Exception if there was an error
*/
public function getPrice(int $quantity = 1, $multiplier = null) : ?float
{
if (($quantity == 0) && ($multiplier === null)) {
return 0.0;
}
$all_pricedetails = $this->getPricedetails();
if (count($all_pricedetails) == 0) {
return null;
}
$correct_pricedetails = null;
foreach ($all_pricedetails as $pricedetails) {
// choose the correct pricedetails for the choosed quantity ($quantity)
if ($quantity < $pricedetails->getMinDiscountQuantity()) {
break;
}
$correct_pricedetails = $pricedetails;
}
if ($correct_pricedetails == null) {
return null;
}
if ($multiplier === null) {
$multiplier = $quantity;
}
return $correct_pricedetails->getPricePerUnit($multiplier);
}
/********************************************************************************
*
* Setters
*
*********************************************************************************/
/**
* Set the supplier ID.
*
* @param int $new_supplier_id the ID of the new supplier
*/
public function setSupplierId(int $new_supplier_id): self
{
throw new \Exception('Not implemented yet!');
//TODO;
return $this;
}
/**
* Set the supplier part-nr.
*
* @param string $new_supplierpartnr the new supplier-part-nr
*/
public function setSupplierpartnr(string $new_supplierpartnr): self
{
$this->supplierpartnr = $new_supplierpartnr;
return $this;
}
/**
* Set if the part is obsolete at the supplier of that orderdetails.
*
* @param bool $new_obsolete true means that this part is obsolete
*/
public function setObsolete(bool $new_obsolete): self
{
$this->obsolete = $new_obsolete;
return $this;
}
/**
* 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.
*/
public function setSupplierProductUrl(string $new_url)
{
$this->supplier_product_url = $new_url;
return $this;
}
}

View file

@ -0,0 +1,305 @@
<?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);
/**
* 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
*/
namespace App\Entity\PriceInformations;
use App\Entity\Base\DBElement;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Pricedetail.
*
* @ORM\Entity()
* @ORM\Table("`pricedetails`")
* @UniqueEntity(fields={"orderdetail", "min_discount_quantity"})
*/
class Pricedetail extends DBElement
{
/**
* @var Orderdetail
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails")
* @ORM\JoinColumn(name="orderdetails_id", referencedColumnName="id")
*/
protected $orderdetail;
/**
* @var float The price related to the detail. (Given in the selected currency)
* @ORM\Column(type="decimal", precision=11, scale=5)
* @Assert\Positive()
*/
protected $price;
/**
* @var ?Currency The currency used for the current price information.
* If this is null, the global base unit is assumed.
* @ORM\ManyToOne(targetEntity="Currency")
* @ORM\JoinColumn(name="id_currency", referencedColumnName="id", nullable=true)
*/
protected $currency;
/**
* @var int
* @ORM\Column(type="integer")
* @Assert\Positive()
*/
protected $price_related_quantity;
/**
* @var int
* @ORM\Column(type="integer")
*/
protected $min_discount_quantity;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
protected $manual_input;
/**
* @ORM\Column(type="datetimetz")
*/
protected $last_modified;
/********************************************************************************
*
* Getters
*
*********************************************************************************/
/**
* Get the orderdetails of this pricedetails.
*
* @return Orderdetail the orderdetails object
*/
public function getOrderdetails(): Orderdetail
{
return $this->orderdetail;
}
/**
* Returns the price associated with this pricedetail.
* It is given in current currency and for the price related quantity.
* @return float
*/
public function getPrice() : float
{
return (float) $this->price;
}
/**
* Get the price for a single unit in the currency associated with this price detail.
*
* @param int $multiplier The returned price (float or string) will be multiplied
* with this multiplier.
*
* You will get the price for $multiplier parts. If you want the price which is stored
* in the database, you have to pass the "price_related_quantity" count as $multiplier.
*
* @return float the price as a float number
*/
public function getPricePerUnit(int $multiplier = 1) : float
{
return ($this->price * $multiplier) / $this->price_related_quantity;
}
/**
* Get the price related quantity.
*
* This is the quantity, for which the price is valid.
*
* @return int the price related quantity
*
* @see Pricedetail::setPriceRelatedQuantity()
*/
public function getPriceRelatedQuantity(): int
{
return $this->price_related_quantity;
}
/**
* Get the minimum discount quantity.
*
* "Minimum discount quantity" means the minimum order quantity for which the price
* of this orderdetails is valid.
*
* @return int the minimum discount quantity
*
* @see Pricedetail::setMinDiscountQuantity()
*/
public function getMinDiscountQuantity(): int
{
return $this->min_discount_quantity;
}
/**
* Returns the currency associated with this price information.
* Returns null, if no specific currency is selected and the global base currency should be assumed.
* @return Currency|null
*/
public function getCurrency(): ?Currency
{
return $this->currency;
}
/********************************************************************************
*
* Setters
*
*********************************************************************************/
/**
* Sets the currency associated with the price informations.
* Set to null, to use the global base currency.
* @param Currency|null $currency
* @return Pricedetail
*/
public function setCurrency(?Currency $currency): Pricedetail
{
$this->currency = $currency;
}
/**
* Set the price.
*
* @param float $new_price the new price as a float number
*
* * This is the price for "price_related_quantity" parts!!
* * Example: if "price_related_quantity" is '10',
* you have to set here the price for 10 parts!
*
* @return self
*/
public function setPrice(float $new_price): Pricedetail
{
//Assert::natural($new_price, 'The new price must be positive! Got %s!');
$this->price = $new_price;
return $this;
}
/**
* Set the price related quantity.
*
* This is the quantity, for which the price is valid.
*
* Example:
* If 100pcs costs 20$, you have to set the price to 20$ and the price related
* quantity to 100. The single price (20$/100 = 0.2$) will be calculated automatically.
*
* @param int $new_price_related_quantity the price related quantity
*
* @return self
*/
public function setPriceRelatedQuantity(int $new_price_related_quantity): self
{
//Assert::greaterThan($new_price_related_quantity, 0,
// 'The new price related quantity must be greater zero! Got %s.');
$this->price_related_quantity = $new_price_related_quantity;
return $this;
}
/**
* Set the minimum discount quantity.
*
* "Minimum discount quantity" means the minimum order quantity for which the price
* of this orderdetails is valid. This way, you're able to use different prices
* for different order quantities (quantity discount!).
*
* Example:
* - 1-9pcs costs 10$: set price to 10$/pcs and minimum discount quantity to 1
* - 10-99pcs costs 9$: set price to 9$/pcs and minimum discount quantity to 10
* - 100pcs or more costs 8$: set price/pcs to 8$ and minimum discount quantity to 100
*
* (Each of this examples would be an own Pricedetails-object.
* So the orderdetails would have three Pricedetails for one supplier.)
*
* @param int $new_min_discount_quantity the minimum discount quantity
*
* @return self
*/
public function setMinDiscountQuantity(int $new_min_discount_quantity): self
{
//Assert::greaterThan($new_min_discount_quantity, 0,
// 'The new minimum discount quantity must be greater zero! Got %s.');
$this->min_discount_quantity = $new_min_discount_quantity;
return $this;
}
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
*
* @return string The ID as a string;
*/
public function getIDString(): string
{
return 'PD'.sprintf('%06d', $this->getID());
}
}