mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 21:09:35 +00:00
Moved VAT include info from pricedetail to orderdetail level
That makes implementing the form easier
This commit is contained in:
parent
4740b6d19e
commit
586375d921
9 changed files with 88 additions and 125 deletions
|
|
@ -148,6 +148,13 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
|
|||
#[ORM\JoinColumn(name: 'id_supplier')]
|
||||
protected ?Supplier $supplier = null;
|
||||
|
||||
/**
|
||||
* @var bool|null Whether the prices includes VAT or not. Null means, that it is not specified, if the prices includes VAT or not.
|
||||
*/
|
||||
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
|
||||
#[Groups(['extended', 'full', 'import', 'orderdetail:read', 'orderdetail:write'])]
|
||||
protected ?bool $prices_includes_vat = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pricedetails = new ArrayCollection();
|
||||
|
|
@ -390,45 +397,23 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if the prices of this orderdetail include VAT. This is determined by checking the pricedetails of this
|
||||
* orderdetail. If there are no pricedetails or if the pricedetails have conflicting values, null is returned.
|
||||
* Checks if the prices of this orderdetail include VAT. Null means, that it is not specified, if the prices includes
|
||||
* VAT or not.
|
||||
* @return bool|null
|
||||
*/
|
||||
#[Groups(['orderdetail:read'])]
|
||||
#[SerializedName('prices_include_vat')]
|
||||
public function getPricesIncludesVAT(): ?bool
|
||||
{
|
||||
$value = null;
|
||||
//We determine that via the pricedetails
|
||||
foreach ($this->getPricedetails() as $pricedetail) {
|
||||
/** @var Pricedetail $pricedetail */
|
||||
if ($pricedetail->getIncludesVat() === null) {
|
||||
return null; // If any pricedetail doesn't specify this, we can't determine it
|
||||
}
|
||||
|
||||
if ($value === null) {
|
||||
$value = $pricedetail->getIncludesVat(); // Set initial value
|
||||
} elseif ($value !== $pricedetail->getIncludesVat()) {
|
||||
return null; // If there are conflicting values, we can't determine it
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
return $this->prices_includes_vat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the prices of this orderdetail include VAT. This is set for all pricedetails of this orderdetail.
|
||||
* Sets whether the prices of this orderdetail include VAT.
|
||||
* @param bool|null $includesVat
|
||||
* @return $this
|
||||
*/
|
||||
#[Groups(['orderdetail:write'])]
|
||||
#[SerializedName('prices_include_vat')]
|
||||
public function setPricesIncludesVAT(?bool $includesVat): self
|
||||
{
|
||||
foreach ($this->getPricedetails() as $pricedetail) {
|
||||
/** @var Pricedetail $pricedetail */
|
||||
$pricedetail->setIncludesVat($includesVat);
|
||||
}
|
||||
$this->prices_includes_vat = $includesVat;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,12 +121,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
#[Groups(['pricedetail:read:standalone', 'pricedetail:write'])]
|
||||
protected ?Orderdetail $orderdetail = null;
|
||||
|
||||
/**
|
||||
* @var bool|null Whether the price includes VAT or not. Null means, that it is not specified, if the price includes VAT or not.
|
||||
*/
|
||||
#[ORM\Column(name: "include_vat", type: Types::BOOLEAN, nullable: true)]
|
||||
#[Groups(['extended', 'full', 'import', 'pricedetail:read', 'pricedetail:write'])]
|
||||
protected ?bool $includes_vat = null;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
|
@ -277,7 +272,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
*/
|
||||
public function getIncludesVat(): ?bool
|
||||
{
|
||||
return $this->includes_vat;
|
||||
return $this->orderdetail?->getPricesIncludesVAT();
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
|
|
@ -376,15 +371,4 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the price includes VAT or not. Null means, that it is not specified, if the price includes VAT or not.
|
||||
* @param bool|null $includes_vat
|
||||
* @return $this
|
||||
*/
|
||||
public function setIncludesVat(?bool $includes_vat): self
|
||||
{
|
||||
$this->includes_vat = $includes_vat;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue