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

@ -62,76 +62,17 @@ class OrderdetailTest extends TestCase
$this->assertSame($price5, $orderdetail->findPriceForQty(10000));
}
public function testGetPricesIncludesVAT(): void
public function testGetSetPricesIncludesVAT(): void
{
$orderdetail = new Orderdetail();
//By default, the pricesIncludesVAT property should be null for empty orderdetails
$this->assertNull($orderdetail->getPricesIncludesVAT());
$price0 = (new Pricedetail())->setMinDiscountQuantity(0.23);
$price1 = (new Pricedetail())->setMinDiscountQuantity(1);
$price5 = (new Pricedetail())->setMinDiscountQuantity(5.3);
$orderdetail->addPricedetail($price0)->addPricedetail($price1)->addPricedetail($price5);
//With empty pricedetails, the pricesIncludesVAT property should still be null
$this->assertNull($orderdetail->getPricesIncludesVAT());
//If all of the pricedetails have the same value for includesVAT, the pricesIncludesVAT property should return this value
$price0->setIncludesVAT(true);
$price1->setIncludesVAT(true);
$price5->setIncludesVAT(true);
$this->assertTrue($orderdetail->getPricesIncludesVAT());
$price0->setIncludesVAT(false);
$price1->setIncludesVAT(false);
$price5->setIncludesVAT(false);
$this->assertFalse($orderdetail->getPricesIncludesVAT());
//If the pricedetails have different values for includesVAT, the pricesIncludesVAT property should return null
$price0->setIncludesVAT(true);
$price1->setIncludesVAT(false);
$price5->setIncludesVAT(true);
$this->assertNull($orderdetail->getPricesIncludesVAT());
//If the pricedetails have different values for includesVAT, the pricesIncludesVAT property should return null, even if one of them is null
$price0->setIncludesVAT(null);
$price1->setIncludesVAT(false);
$price5->setIncludesVAT(false);
$this->assertNull($orderdetail->getPricesIncludesVAT());
}
public function testSetPricesIncludesVAT(): void
{
$orderdetail = new Orderdetail();
$price0 = (new Pricedetail())->setMinDiscountQuantity(0.23);
$price1 = (new Pricedetail())->setMinDiscountQuantity(1);
$price5 = (new Pricedetail())->setMinDiscountQuantity(5.3);
$orderdetail->addPricedetail($price0)->addPricedetail($price1)->addPricedetail($price5);
$this->assertNull($orderdetail->getPricesIncludesVAT());
$orderdetail->setPricesIncludesVAT(true);
$this->assertTrue($orderdetail->getPricesIncludesVAT());
//Ensure that the pricesIncludesVAT property is correctly propagated to the pricedetails
foreach ($orderdetail->getPricedetails() as $pricedetail) {
$this->assertTrue($pricedetail->getIncludesVAT());
}
$orderdetail->setPricesIncludesVAT(false);
$this->assertFalse($orderdetail->getPricesIncludesVAT());
//Ensure that the pricesIncludesVAT property is correctly propagated to the pricedetails
foreach ($orderdetail->getPricedetails() as $pricedetail) {
$this->assertFalse($pricedetail->getIncludesVAT());
}
$orderdetail->setPricesIncludesVAT(null);
$this->assertNull($orderdetail->getPricesIncludesVAT());
//Ensure that the pricesIncludesVAT property is correctly propagated to the pricedetails
foreach ($orderdetail->getPricedetails() as $pricedetail) {
$this->assertNull($pricedetail->getIncludesVAT());
}
}
}

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
*/
namespace App\Tests\Services\InfoProviderSystem\DTOs;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use PHPUnit\Framework\TestCase;
@ -33,4 +34,40 @@ class PurchaseInfoDTOTest extends TestCase
$this->expectExceptionMessage('The prices array must only contain PriceDTO instances');
new PurchaseInfoDTO('test', 'test', [new \stdClass()]);
}
public function testPricesIncludesVATHandling(): void
{
$pricesTrue = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: true),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: true),
];
$pricesFalse = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: false),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: false),
];
$pricesMixed = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: true),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: false),
];
$pricesNull = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: null),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: null),
];
//If the prices_include_vat parameter is given, use it:
$dto = new PurchaseInfoDTO('test', 'test', $pricesMixed, prices_include_vat: true);
$this->assertTrue($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesMixed, prices_include_vat: false);
$this->assertFalse($dto->prices_include_vat);
//If the prices_include_vat parameter is not given, try to deduct it from the prices:
$dto = new PurchaseInfoDTO('test', 'test', $pricesTrue);
$this->assertTrue($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesFalse);
$this->assertFalse($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesMixed);
$this->assertNull($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesNull);
$this->assertNull($dto->prices_include_vat);
}
}

View file

@ -94,15 +94,12 @@ class DTOtoEntityConverterTest extends WebTestCase
minimum_discount_amount: 5,
price: "10.0",
currency_iso_code: 'EUR',
includes_tax: true,
);
$entity = $this->service->convertPrice($dto);
//For base currencies, the currency field is null
$this->assertNull($entity->getCurrency());
$this->assertTrue($entity->getIncludesVat());
}
public function testConvertPurchaseInfo(): void
@ -117,6 +114,7 @@ class DTOtoEntityConverterTest extends WebTestCase
order_number: 'TestOrderNumber',
prices: $prices,
product_url: 'https://example.com',
prices_include_vat: true,
);
$entity = $this->service->convertPurchaseInfo($dto);
@ -124,6 +122,7 @@ class DTOtoEntityConverterTest extends WebTestCase
$this->assertSame($dto->distributor_name, $entity->getSupplier()->getName());
$this->assertSame($dto->order_number, $entity->getSupplierPartNr());
$this->assertEquals($dto->product_url, $entity->getSupplierProductUrl());
$this->assertTrue($dto->prices_include_vat);
}
public function testConvertFileWithName(): void