Moved VAT include info from pricedetail to orderdetail level

That makes implementing the form easier
This commit is contained in:
Jan Böhmer 2026-02-10 16:53:41 +01:00
parent 4740b6d19e
commit 586375d921
9 changed files with 88 additions and 125 deletions

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -39,7 +39,9 @@ readonly class PriceDTO
public string $price,
/** @var string The currency of the used ISO code of this price detail */
public ?string $currency_iso_code,
/** @var bool If the price includes tax */
/** @var bool If the price includes tax
* @deprecated Use the prices_include_vat property of the PurchaseInfoDTO instead, as this property is not reliable if there are multiple prices with different values for includes_tax
*/
public ?bool $includes_tax = true,
/** @var float the price related quantity */
public ?float $price_related_quantity = 1.0,

View file

@ -29,6 +29,9 @@ namespace App\Services\InfoProviderSystem\DTOs;
*/
readonly class PurchaseInfoDTO
{
/** @var bool|null If the prices contain VAT or not. Null if state is unknown. */
public ?bool $prices_include_vat;
public function __construct(
public string $distributor_name,
public string $order_number,
@ -36,6 +39,7 @@ readonly class PurchaseInfoDTO
public array $prices,
/** @var string|null An url to the product page of the vendor */
public ?string $product_url = null,
?bool $prices_include_vat = null,
)
{
//Ensure that the prices are PriceDTO instances
@ -44,5 +48,17 @@ readonly class PurchaseInfoDTO
throw new \InvalidArgumentException('The prices array must only contain PriceDTO instances');
}
}
//If no prices_include_vat information is given, try to deduct it from the prices
if ($prices_include_vat === null) {
$vatValues = array_unique(array_map(fn(PriceDTO $price) => $price->includes_tax, $this->prices));
if (count($vatValues) === 1) {
$this->prices_include_vat = $vatValues[0]; //Use the value of the prices if they are all the same
} else {
$this->prices_include_vat = null; //If there are different values for the prices, we cannot determine if the prices include VAT or not
}
} else {
$this->prices_include_vat = $prices_include_vat;
}
}
}

View file

@ -100,8 +100,6 @@ final class DTOtoEntityConverter
$entity->setCurrency(null);
}
$entity->setIncludesVat($dto->includes_tax);
return $entity;
}
@ -118,6 +116,8 @@ final class DTOtoEntityConverter
$entity->addPricedetail($this->convertPrice($price));
}
$entity->setPricesIncludesVAT($dto->prices_include_vat);
return $entity;
}