mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Added an price field to allow defining the price of non-part BOM entries
This commit is contained in:
parent
f62937096f
commit
0e020dab74
7 changed files with 161 additions and 39 deletions
|
@ -25,6 +25,10 @@ namespace App\Entity\ProjectSystem;
|
|||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Validator\Constraints\BigDecimal\BigDecimalPositive;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
@ -86,6 +90,29 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
*/
|
||||
protected ?Part $part = null;
|
||||
|
||||
/**
|
||||
* @var BigDecimal The price of this non-part BOM entry
|
||||
* @ORM\Column(type="big_decimal", precision=11, scale=5, nullable=true)
|
||||
* @Assert\AtLeastOneOf({
|
||||
* @BigDecimalPositive(),
|
||||
* @Assert\IsNull()
|
||||
* })
|
||||
*/
|
||||
protected ?BigDecimal $price;
|
||||
|
||||
/**
|
||||
* @var ?Currency The currency for the price of this non-part BOM entry
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency")
|
||||
* @ORM\JoinColumn(nullable=true)
|
||||
* @Selectable()
|
||||
*/
|
||||
protected ?Currency $price_currency = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->price = BigDecimal::zero()->toScale(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
|
@ -196,6 +223,44 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price of this BOM entry, if existing.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
* @return BigDecimal|null
|
||||
*/
|
||||
public function getPrice(): ?BigDecimal
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the price of this BOM entry.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
* @param BigDecimal|null $price
|
||||
*/
|
||||
public function setPrice(?BigDecimal $price): void
|
||||
{
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Currency|null
|
||||
*/
|
||||
public function getPriceCurrency(): ?Currency
|
||||
{
|
||||
return $this->price_currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Currency|null $price_currency
|
||||
*/
|
||||
public function setPriceCurrency(?Currency $price_currency): void
|
||||
{
|
||||
$this->price_currency = $price_currency;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Assert\Callback
|
||||
*/
|
||||
|
@ -231,6 +296,13 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
->addViolation();
|
||||
}
|
||||
|
||||
//Prices are only only allowed on non-part BOM entries
|
||||
if ($this->part !== null && $this->price !== null) {
|
||||
$context->buildViolation('project.bom_entry.price_not_allowed_on_parts')
|
||||
->atPath('price')
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
//Check that the part is not the build representation part of this device or one of its parents
|
||||
if ($this->part && $this->part->getBuiltProject() !== null) {
|
||||
//Get the associated project
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue