mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 18:34:32 +02:00
Added an PHP CS fixer config file and applied it to files.
We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
parent
89258bc102
commit
e557bdedd5
210 changed files with 2099 additions and 2742 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
|
@ -17,14 +17,11 @@
|
|||
* 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\Attachments\CurrencyAttachment;
|
||||
use App\Entity\Attachments\SupplierAttachment;
|
||||
use App\Entity\Base\StructuralDBElement;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -33,14 +30,13 @@ 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
|
||||
{
|
||||
|
||||
public const PRICE_SCALE = 5;
|
||||
|
||||
/**
|
||||
|
@ -58,7 +54,7 @@ class Currency extends StructuralDBElement
|
|||
|
||||
/**
|
||||
* @var string|null The exchange rate between this currency and the base currency
|
||||
* (how many base units the current currency is worth)
|
||||
* (how many base units the current currency is worth)
|
||||
* @ORM\Column(type="decimal", precision=11, scale=5, nullable=true)
|
||||
* @Assert\Positive()
|
||||
*/
|
||||
|
@ -76,7 +72,8 @@ class Currency extends StructuralDBElement
|
|||
protected $parent;
|
||||
|
||||
/**
|
||||
* Returns the 3 letter ISO code of this currency
|
||||
* Returns the 3 letter ISO code of this currency.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIsoCode(): ?string
|
||||
|
@ -86,23 +83,26 @@ class Currency extends StructuralDBElement
|
|||
|
||||
/**
|
||||
* @param string $iso_code
|
||||
*
|
||||
* @return Currency
|
||||
*/
|
||||
public function setIsoCode(?string $iso_code): Currency
|
||||
public function setIsoCode(?string $iso_code): self
|
||||
{
|
||||
$this->iso_code = $iso_code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the inverse exchange rate (how many of the current currency the base unit is worth)
|
||||
* Returns the inverse exchange rate (how many of the current currency the base unit is worth).
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getInverseExchangeRate(): ?string
|
||||
{
|
||||
$tmp = $this->getExchangeRate();
|
||||
|
||||
if ($tmp === null || $tmp === "0") {
|
||||
if (null === $tmp || '0' === $tmp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,8 @@ class Currency extends StructuralDBElement
|
|||
|
||||
/**
|
||||
* Returns The exchange rate between this currency and the base currency
|
||||
* (how many base units the current currency is worth)
|
||||
* (how many base units the current currency is worth).
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getExchangeRate(): ?string
|
||||
|
@ -120,25 +121,23 @@ class Currency extends StructuralDBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string|null $exchange_rate
|
||||
* @return Currency
|
||||
*/
|
||||
public function setExchangeRate(?string $exchange_rate): Currency
|
||||
public function setExchangeRate(?string $exchange_rate): self
|
||||
{
|
||||
$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();
|
||||
return 'C'.$this->getID();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
|
@ -17,7 +17,6 @@
|
|||
* 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);
|
||||
|
@ -193,7 +192,7 @@ class Orderdetail extends DBElement
|
|||
return $this->supplier_product_url;
|
||||
}
|
||||
|
||||
if ($this->getSupplier() === null) {
|
||||
if (null === $this->getSupplier()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -204,7 +203,7 @@ class Orderdetail extends DBElement
|
|||
* Get all pricedetails.
|
||||
*
|
||||
* @return Pricedetail[]|Collection all pricedetails as a one-dimensional array of Pricedetails objects,
|
||||
* sorted by minimum discount quantity
|
||||
* sorted by minimum discount quantity
|
||||
*/
|
||||
public function getPricedetails(): Collection
|
||||
{
|
||||
|
@ -212,36 +211,41 @@ class Orderdetail extends DBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds an pricedetail to this orderdetail
|
||||
* Adds an pricedetail to this orderdetail.
|
||||
*
|
||||
* @param Pricedetail $pricedetail The pricedetail to add
|
||||
*
|
||||
* @return Orderdetail
|
||||
*/
|
||||
public function addPricedetail(Pricedetail $pricedetail) : Orderdetail
|
||||
public function addPricedetail(Pricedetail $pricedetail): self
|
||||
{
|
||||
$pricedetail->setOrderdetail($this);
|
||||
$this->pricedetails->add($pricedetail);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an pricedetail from this orderdetail
|
||||
* @param Pricedetail $pricedetail
|
||||
* Removes an pricedetail from this orderdetail.
|
||||
*
|
||||
* @return Orderdetail
|
||||
*/
|
||||
public function removePricedetail(Pricedetail $pricedetail) : Orderdetail
|
||||
public function removePricedetail(Pricedetail $pricedetail): self
|
||||
{
|
||||
$this->pricedetails->removeElement($pricedetail);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the pricedetail that is correct for the desired amount (the one with the greatest discount value with a
|
||||
* minimum order amount of the wished quantity)
|
||||
* @param float $quantity this is the quantity to choose the correct pricedetails
|
||||
* minimum order amount of the wished quantity).
|
||||
*
|
||||
* @param float $quantity this is the quantity to choose the correct pricedetails
|
||||
*
|
||||
* @return Pricedetail|null: the price as a bcmath string. Null if there are no orderdetails for the given quantity
|
||||
*/
|
||||
public function findPriceForQty(float $quantity = 1) : ?Pricedetail
|
||||
public function findPriceForQty(float $quantity = 1): ?Pricedetail
|
||||
{
|
||||
if ($quantity <= 0) {
|
||||
return null;
|
||||
|
@ -269,30 +273,34 @@ class Orderdetail extends DBElement
|
|||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets a new part with which this orderdetail is associated
|
||||
* @param Part $part
|
||||
* Sets a new part with which this orderdetail is associated.
|
||||
*
|
||||
* @return Orderdetail
|
||||
*/
|
||||
public function setPart(Part $part) : Orderdetail
|
||||
public function setPart(Part $part): self
|
||||
{
|
||||
$this->part = $part;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new supplier associated with this orderdetail.
|
||||
* @param Supplier $new_supplier
|
||||
*
|
||||
* @return Orderdetail
|
||||
*/
|
||||
public function setSupplier(Supplier $new_supplier) : Orderdetail
|
||||
public function setSupplier(Supplier $new_supplier): self
|
||||
{
|
||||
$this->supplier = $new_supplier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the supplier part-nr.
|
||||
*
|
||||
* @param string $new_supplierpartnr the new supplier-part-nr
|
||||
*
|
||||
* @return Orderdetail
|
||||
* @return Orderdetail
|
||||
*/
|
||||
|
@ -305,7 +313,9 @@ class Orderdetail extends DBElement
|
|||
|
||||
/**
|
||||
* Set if the part is obsolete at the supplier of that orderdetails.
|
||||
*
|
||||
* @param bool $new_obsolete true means that this part is obsolete
|
||||
*
|
||||
* @return Orderdetail
|
||||
* @return Orderdetail
|
||||
*/
|
||||
|
@ -319,10 +329,12 @@ class Orderdetail extends DBElement
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return Orderdetail
|
||||
*/
|
||||
public function setSupplierProductUrl(string $new_url) : Orderdetail
|
||||
public function setSupplierProductUrl(string $new_url): self
|
||||
{
|
||||
//Only change the internal URL if it is not the auto generated one
|
||||
if ($new_url === $this->supplier->getAutoProductUrl($this->getSupplierPartNr())) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
|
@ -17,7 +17,6 @@
|
|||
* 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);
|
||||
|
@ -69,7 +68,6 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
*/
|
||||
class Pricedetail extends DBElement
|
||||
{
|
||||
|
||||
public const PRICE_PRECISION = 5;
|
||||
|
||||
use TimestampTrait;
|
||||
|
@ -91,7 +89,7 @@ class Pricedetail extends DBElement
|
|||
|
||||
/**
|
||||
* @var ?Currency The currency used for the current price information.
|
||||
* If this is null, the global base unit is assumed.
|
||||
* If this is null, the global base unit is assumed.
|
||||
* @ORM\ManyToOne(targetEntity="Currency")
|
||||
* @ORM\JoinColumn(name="id_currency", referencedColumnName="id", nullable=true)
|
||||
* @Selectable()
|
||||
|
@ -142,9 +140,10 @@ class Pricedetail extends DBElement
|
|||
/**
|
||||
* Returns the price associated with this pricedetail.
|
||||
* It is given in current currency and for the price related quantity.
|
||||
*
|
||||
* @return string The price as string, like returned raw from DB.
|
||||
*/
|
||||
public function getPrice() : string
|
||||
public function getPrice(): string
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
@ -152,18 +151,19 @@ class Pricedetail extends DBElement
|
|||
/**
|
||||
* Get the price for a single unit in the currency associated with this price detail.
|
||||
*
|
||||
* @param float|string $multiplier The returned price (float or string) will be multiplied
|
||||
* with this multiplier.
|
||||
* @param float|string $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 string the price as a bcmath string
|
||||
* @return string the price as a bcmath string
|
||||
*/
|
||||
public function getPricePerUnit($multiplier = 1.0) : string
|
||||
public function getPricePerUnit($multiplier = 1.0): string
|
||||
{
|
||||
$multiplier = (string) $multiplier;
|
||||
$tmp = bcmul($this->price, $multiplier, static::PRICE_PRECISION);
|
||||
|
||||
return bcdiv($tmp, (string) $this->price_related_quantity, static::PRICE_PRECISION);
|
||||
//return ($this->price * $multiplier) / $this->price_related_quantity;
|
||||
}
|
||||
|
@ -180,10 +180,12 @@ class Pricedetail extends DBElement
|
|||
*/
|
||||
public function getPriceRelatedQuantity(): float
|
||||
{
|
||||
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
|
||||
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
|
||||
$tmp = round($this->price_related_quantity);
|
||||
|
||||
return $tmp < 1 ? 1 : $tmp;
|
||||
}
|
||||
|
||||
return $this->price_related_quantity;
|
||||
}
|
||||
|
||||
|
@ -203,6 +205,7 @@ class Pricedetail extends DBElement
|
|||
{
|
||||
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
|
||||
$tmp = round($this->min_discount_quantity);
|
||||
|
||||
return $tmp < 1 ? 1 : $tmp;
|
||||
}
|
||||
|
||||
|
@ -212,6 +215,7 @@ class Pricedetail extends DBElement
|
|||
/**
|
||||
* 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
|
||||
|
@ -227,24 +231,26 @@ class Pricedetail extends DBElement
|
|||
|
||||
/**
|
||||
* Sets the orderdetail to which this pricedetail belongs to.
|
||||
* @param Orderdetail $orderdetail
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrderdetail(Orderdetail $orderdetail) : self
|
||||
public function setOrderdetail(Orderdetail $orderdetail): self
|
||||
{
|
||||
$this->orderdetail = $orderdetail;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
public function setCurrency(?Currency $currency): self
|
||||
{
|
||||
$this->currency = $currency;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -259,7 +265,7 @@ class Pricedetail extends DBElement
|
|||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setPrice(string $new_price): Pricedetail
|
||||
public function setPrice(string $new_price): self
|
||||
{
|
||||
//Assert::natural($new_price, 'The new price must be positive! Got %s!');
|
||||
|
||||
|
@ -322,6 +328,6 @@ class Pricedetail extends DBElement
|
|||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'PD' . sprintf('%06d', $this->getID());
|
||||
return 'PD'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue