Skip to content

Commit

Permalink
Merge pull request #33 from horstoeko/Issue_32
Browse files Browse the repository at this point in the history
Added Fix and a Test for Issue #32
  • Loading branch information
horstoeko authored Mar 24, 2024
2 parents eb570a0 + 6e1d4d0 commit 05f58ad
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
</testsuite>
<testsuite name="issues">
<file>../tests/testcases/issues/Issue10Test.php</file>
<file>../tests/testcases/issues/Issue18Test.php</file>
<file>../tests/testcases/issues/Issue32Test.php</file>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
Expand Down
2 changes: 1 addition & 1 deletion src/quick/ZugferdQuickDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public function doAddTradeLineItem(string $lineId, string $productName, float $u
$allowanceAmount = $allowanceChargeAmountIsAllowance === true ? abs($allowanceChargeAmount) : 0.0;
$chargeAmount = $allowanceChargeAmountIsAllowance === false ? abs($allowanceChargeAmount) : 0.0;
$allowanceChargeAmount = abs($allowanceChargeAmount);
$lineTotalAmount = $unitPrice * $quantity + $chargeAmount - $allowanceAmount;
$lineTotalAmount = round($unitPrice * $quantity + $chargeAmount - $allowanceAmount, 2);

$this->addNewPosition($lineId);
$this->setDocumentPositionProductDetails($productName);
Expand Down
57 changes: 57 additions & 0 deletions tests/testcases/issues/Issue32Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace horstoeko\zugferd\tests\testcases\issues;

use \horstoeko\zugferd\tests\TestCase;
use \horstoeko\zugferd\codelists\ZugferdUnitCodes;
use \horstoeko\zugferd\tests\traits\HandlesXmlTests;
use \horstoeko\zugferd\quick\ZugferdQuickDescriptorXRechnung3;
use horstoeko\zugferd\codelists\ZugferdTextSubjectCodeQualifiers;

class Issue32Test extends TestCase
{
use HandlesXmlTests;

/**
* @inheritDoc
*/
public static function setUpBeforeClass(): void
{
self::$document = ZugferdQuickDescriptorXRechnung3::doCreateNew();
}

/**
* @return void
* @issue #32
*/
public function testIssue(): void
{
self::$document
->doCreateInvoice("471102", \DateTime::createFromFormat("Ymd", "20180305"), "EUR")
->doSetPaymentTerms("Zahlbar sofort", new \DateTime('+3 days'))
->doSetPaymentMeansForCreditTransfer(true, "DE12500105170648489890")
->doAddNote('Rechnung gemäß Bestellung vom 01.03.2018.')
->doAddNote('Lieferant GmbH' . PHP_EOL . 'Lieferantenstraße 20' . PHP_EOL . '80333 München' . PHP_EOL . 'Deutschland' . PHP_EOL . 'Geschäftsführer: Hans Muster' . PHP_EOL . 'Handelsregisternummer: H A 123' . PHP_EOL . PHP_EOL, ZugferdTextSubjectCodeQualifiers::UNTDID_4451_REG)
->doSetBuyer("Kunden AG Mitte", "69876", "Frankfurt", "Lieferantenstraße 20", "DE", "34676-342323")
->doSetBuyerContact("Hans Miller")
->doSetBuyerElectronicCommunication("[email protected]")
->doSetSeller("Lieferant GmbH", "80333", "München", "Lieferantenstraße 20", "DE", null, "4000001123452", "0088")
->doAddSellerTaxRegistration("FC", "201/113/40209")
->doAddSellerTaxRegistration("VA", "DE123456789")
->doSetSellerContact("Horst Meier", null, "[email protected]", "+49-0000-8888888")
->doSetSellerElectronicCommunication("[email protected]")
->doAddTradeLineItem(1, "PositionText", 31.67, 61.64, ZugferdUnitCodes::REC20_PIECE, 0.0, '', 'S', 'VAT', 19);

$this->disableRenderXmlContent();
$this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:Name', "Kunden AG Mitte");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:LineTotalAmount', 0, "1952.14");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:ChargeTotalAmount', 0, "0.0");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:AllowanceTotalAmount', 0, "0.0");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxBasisTotalAmount', 0, "1952.14");
$this->assertXPathValueWithIndexAndAttribute('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount', 0, "370.91", "currencyID", "EUR");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:RoundingAmount', 0, "0.0");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:GrandTotalAmount', 0, "2323.05");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TotalPrepaidAmount', 0, "0.0");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:DuePayableAmount', 0, "2323.05");
}
}
2 changes: 1 addition & 1 deletion tests/traits/HandlesXmlTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
trait HandlesXmlTests
{
/**
* @var ZugferdDocumentBuilder
* @var \horstoeko\zugferd\ZugferdDocumentBuilder|\horstoeko\zugferd\quick\ZugferdQuickDescriptor
*/
protected static $document;

Expand Down

0 comments on commit 05f58ad

Please sign in to comment.