Skip to content

Commit

Permalink
Merge pull request #191 from horstoeko/Issue_189
Browse files Browse the repository at this point in the history
Issue 189
  • Loading branch information
horstoeko authored Nov 27, 2024
2 parents 90f7072 + 0ef5615 commit b79c5c7
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/ZugferdDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,14 +860,14 @@ public function addDocumentProductEndUserContact(?string $contactpersonname, ?st
/**
* Ship-To
*
* @param string $name __BT-70, From BASIC WL__ The name of the party to whom the goods are being delivered or for whom the services are being performed. Must be used if the recipient of the goods or services is not the same as the buyer.
* @param string|null $name __BT-70, From BASIC WL__ The name of the party to whom the goods are being delivered or for whom the services are being performed. Must be used if the recipient of the goods or services is not the same as the buyer.
* @param string|null $id __BT-71, From BASIC WL__ An identifier for the place where the goods are delivered or where the services are provided. Multiple IDs can be assigned or specified. They can be differentiated by using different identification schemes. If no scheme is given, it should be known to the buyer and seller, e.g. a previously exchanged identifier assigned by the buyer or seller.
* @param string|null $description __BT-, From __ Further legal information that is relevant for the party
* @return ZugferdDocumentBuilder
*/
public function setDocumentShipTo(?string $name, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
public function setDocumentShipTo(?string $name = null, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
{
$shipToTradeParty = $this->getObjectHelper()->getTradeParty($name, $id, $description);
$shipToTradeParty = $this->getObjectHelper()->getTradePartyAllowEmpty($name, $id, $description);
$this->getObjectHelper()->tryCall($this->headerTradeDelivery, "setShipToTradeParty", $shipToTradeParty);
return $this;
}
Expand Down Expand Up @@ -989,14 +989,14 @@ public function addDocumentShipToContact(?string $contactpersonname, ?string $co
/**
* Detailed information on the different end recipient
*
* @param string $name __BT-X-164, From EXTENDED__ Name or company name of the different end recipient
* @param string|null $name __BT-X-164, From EXTENDED__ Name or company name of the different end recipient
* @param string|null $id __BT-X-162, From EXTENDED__ Identification of the different end recipient. Multiple IDs can be assigned or specified. They can be differentiated by using different identification schemes.
* @param string|null $description __BT-, From __ Further legal information that is relevant for the different end recipient
* @return ZugferdDocumentBuilder
*/
public function setDocumentUltimateShipTo(string $name, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
public function setDocumentUltimateShipTo(?string $name = null, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
{
$shipToTradeParty = $this->getObjectHelper()->getTradeParty($name, $id, $description);
$shipToTradeParty = $this->getObjectHelper()->getTradePartyAllowEmpty($name, $id, $description);
$this->getObjectHelper()->tryCall($this->headerTradeDelivery, "setUltimateShipToTradeParty", $shipToTradeParty);
return $this;
}
Expand Down Expand Up @@ -1118,14 +1118,14 @@ public function addDocumentUltimateShipToContact(?string $contactpersonname, ?st
/**
* Set detailed information of the deviating consignor party
*
* @param string $name __BT-X-183, From EXTENDED__ The name of the party
* @param string|null $name __BT-X-183, From EXTENDED__ The name of the party
* @param string|null $id __BT-X-181, From EXTENDED__ An identifier for the party. Multiple IDs can be assigned or specified. They can be differentiated by using different identification schemes. If no scheme is given, it should be known to the buyer and seller, e.g. a previously exchanged identifier assigned by the buyer or seller.
* @param string|null $description __BT-, From __ Further legal information that is relevant for the party
* @return ZugferdDocumentBuilder
*/
public function setDocumentShipFrom(string $name, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
public function setDocumentShipFrom(?string $name = null, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
{
$shipToTradeParty = $this->getObjectHelper()->getTradeParty($name, $id, $description);
$shipToTradeParty = $this->getObjectHelper()->getTradePartyAllowEmpty($name, $id, $description);
$this->getObjectHelper()->tryCall($this->headerTradeDelivery, "setShipFromTradeParty", $shipToTradeParty);
return $this;
}
Expand Down Expand Up @@ -2667,15 +2667,15 @@ public function setDocumentPositionQuantity(float $billedQuantity, string $bille
/**
* Set detailed information on the different ship-to party at position level
*
* @param string $name __BT-X-50, From EXTENDED__ The name of the party to whom the goods are being delivered or for whom the services are being performed. Must be used if the recipient of the goods or services is not the same as the buyer.
* @param string|null $name __BT-X-50, From EXTENDED__ The name of the party to whom the goods are being delivered or for whom the services are being performed. Must be used if the recipient of the goods or services is not the same as the buyer.
* @param string|null $id __BT-X-48, From EXTENDED__ An identifier for the place where the goods are delivered or where the services are provided. Multiple IDs can be assigned or specified. They can be differentiated by using different identification schemes. If no scheme is given, it should be known to the buyer and seller, e.g. a previously exchanged identifier assigned by the buyer or seller.
* @param string|null $description __BT-, From __ Further legal information that is relevant for the party (Obsolete)
* @return ZugferdDocumentBuilder
*/
public function setDocumentPositionShipTo(string $name, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
public function setDocumentPositionShipTo(?string $name = null, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
{
$positiondelivery = $this->getObjectHelper()->tryCallAndReturn($this->currentPosition, "getSpecifiedLineTradeDelivery");
$shipToTradeParty = $this->getObjectHelper()->getTradeParty($name, $id, $description);
$shipToTradeParty = $this->getObjectHelper()->getTradePartyAllowEmpty($name, $id, $description);
$this->getObjectHelper()->tryCall($positiondelivery, "setShipToTradeParty", $shipToTradeParty);
return $this;
}
Expand Down Expand Up @@ -2790,15 +2790,15 @@ public function addDocumentPositionShipToContact(?string $contactpersonname, ?st
/**
* Detailed information on the different end recipient on position level
*
* @param string $name __BT-X-69, From EXTENDED__ The name of the party to whom the goods are being delivered or for whom the services are being performed. Must be used if the recipient of the goods or services is not the same as the buyer.
* @param string|null $name __BT-X-69, From EXTENDED__ The name of the party to whom the goods are being delivered or for whom the services are being performed. Must be used if the recipient of the goods or services is not the same as the buyer.
* @param string|null $id __BT-X-67, From EXTENDED__ An identifier for the party Multiple IDs can be assigned or specified. They can be differentiated by using different identification schemes. If no scheme is given, it should be known to the buyer and seller, e.g. a previously exchanged identifier assigned by the buyer or seller.
* @param string|null $description __BT-, From __ Further legal information that is relevant for the party (Obsolete)
* @return ZugferdDocumentBuilder
*/
public function setDocumentPositionUltimateShipTo(string $name, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
public function setDocumentPositionUltimateShipTo(?string $name = null, ?string $id = null, ?string $description = null): ZugferdDocumentBuilder
{
$positiondelivery = $this->getObjectHelper()->tryCallAndReturn($this->currentPosition, "getSpecifiedLineTradeDelivery");
$shipToTradeParty = $this->getObjectHelper()->getTradeParty($name, $id, $description);
$shipToTradeParty = $this->getObjectHelper()->getTradePartyAllowEmpty($name, $id, $description);
$this->getObjectHelper()->tryCall($positiondelivery, "setUltimateShipToTradeParty", $shipToTradeParty);
return $this;
}
Expand Down
15 changes: 14 additions & 1 deletion src/ZugferdObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public function getCrossIndustryInvoice()
}

/**
* Tradeparty type^^
* Tradeparty type
*
* @param string|null $name
* @param string|null $ID
Expand All @@ -611,6 +611,19 @@ public function getTradeParty(?string $name = null, ?string $ID = null, ?string
return null;
}

return $this->getTradePartyAllowEmpty($name, $ID, $description);
}

/**
* Tradeparty type (allow all nulls)
*
* @param string|null $name
* @param string|null $ID
* @param string|null $description
* @return object|null
*/
public function getTradePartyAllowEmpty(?string $name = null, ?string $ID = null, ?string $description = null): ?object
{
$tradeParty = $this->createClassInstance('ram\TradePartyType');

$this->tryCall($tradeParty, "addToID", $this->getIdType($ID));
Expand Down
23 changes: 23 additions & 0 deletions tests/testcases/BuilderEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,29 @@ public function testAddDocumentProductEndUserContact(): void
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:ProductEndUserTradeParty/ram:DefinedTradeContact/ram:EmailURIUniversalCommunication/ram:URIID', 1);
}

public function testSetDocumentShipToAllEmpty(): void
{
(self::$document)->setDocumentShipTo();

$this->disableRenderXmlContent();
$this->assertXPathExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:Name');
}

public function testAddDocumentShipTolAllEmptyId(): void
{
$this->assertXPathExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:Name');

(self::$document)->addDocumentShipTolId('549911');

$this->disableRenderXmlContent();
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID', 0, "549911");
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID', 1);
}

public function testSetDocumentShipTo(): void
{
(self::$document)->setDocumentShipTo("Kunden AG Mitte", "549910");
Expand Down
23 changes: 23 additions & 0 deletions tests/testcases/BuilderExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,29 @@ public function testAddDocumentProductEndUserContact(): void
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:ProductEndUserTradeParty/ram:DefinedTradeContact/ram:EmailURIUniversalCommunication/ram:URIID', 2);
}

public function testSetDocumentShipToAllEmpty(): void
{
(self::$document)->setDocumentShipTo();

$this->disableRenderXmlContent();
$this->assertXPathExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:Name');
}

public function testAddDocumentShipTolAllEmptyId(): void
{
$this->assertXPathExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:Name');

(self::$document)->addDocumentShipTolId('549911');

$this->disableRenderXmlContent();
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID', 0, "549911");
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID', 1);
}

public function testSetDocumentShipTo(): void
{
(self::$document)->setDocumentShipTo("Kunden AG Mitte", "549910");
Expand Down
23 changes: 23 additions & 0 deletions tests/testcases/BuilderMinimumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,29 @@ public function testAddDocumentProductEndUserContact(): void
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:ProductEndUserTradeParty/ram:DefinedTradeContact/ram:EmailURIUniversalCommunication/ram:URIID', 1);
}

public function testSetDocumentShipToAllEmpty(): void
{
(self::$document)->setDocumentShipTo();

$this->disableRenderXmlContent();
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:Name');
}

public function testAddDocumentShipTolAllEmptyId(): void
{
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:Name');

(self::$document)->addDocumentShipTolId('549911');

$this->disableRenderXmlContent();
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:ID');
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty/ram:Name');
}

public function testSetDocumentShipTo(): void
{
(self::$document)->setDocumentShipTo("Kunden AG Mitte", "549910");
Expand Down
28 changes: 28 additions & 0 deletions tests/testcases/ObjectHelperEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,34 @@ public function testGetTradePartyNullValues(): void
$this->assertNull($tradeparty);
}

public function testGetTradePartyAllValuesWithAllowEmpty(): void
{
/**
* @var \horstoeko\zugferd\entities\en16931\ram\TradePartyType
*/
$tradeparty = self::$objectHelper->getTradePartyAllowEmpty("name", "id", "description");
$this->assertEquals("name", $tradeparty->getName());
$this->assertIsArray($tradeparty->getID());
$this->assertArrayHasKey(0, $tradeparty->getID());
$this->assertEquals("id", $tradeparty->getID()[0]);
$this->assertEquals("description", $tradeparty->getDescription());
}

public function testGetTradePartyNullValuesWithAllowEmpty(): void
{
/**
* @var \horstoeko\zugferd\entities\en16931\ram\TradePartyType
*/
$tradeparty = self::$objectHelper->getTradePartyAllowEmpty(null, null, null);
$this->assertNotNull($tradeparty);
$this->assertNull($tradeparty->getName());
$this->assertEquals("", $tradeparty->getName());
$this->assertIsArray($tradeparty->getID());
$this->assertArrayNotHasKey(0, $tradeparty->getID());
$this->assertNull($tradeparty->getDescription());
$this->assertEquals("", $tradeparty->getDescription());
}

public function testGetTradeAddressAllValues(): void
{
/**
Expand Down
28 changes: 28 additions & 0 deletions tests/testcases/ObjectHelperExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,34 @@ public function testGetTradePartyNullValues(): void
$this->assertNull($tradeparty);
}

public function testGetTradePartyAllValuesWithAllowEmpty(): void
{
/**
* @var \horstoeko\zugferd\entities\extended\ram\TradePartyType
*/
$tradeparty = self::$objectHelper->getTradePartyAllowEmpty("name", "id", "description");
$this->assertEquals("name", $tradeparty->getName());
$this->assertIsArray($tradeparty->getID());
$this->assertArrayHasKey(0, $tradeparty->getID());
$this->assertEquals("id", $tradeparty->getID()[0]);
$this->assertEquals("description", $tradeparty->getDescription());
}

public function testGetTradePartyNullValuesWithAllowEmpty(): void
{
/**
* @var \horstoeko\zugferd\entities\extended\ram\TradePartyType
*/
$tradeparty = self::$objectHelper->getTradePartyAllowEmpty(null, null, null);
$this->assertNotNull($tradeparty);
$this->assertNull($tradeparty->getName());
$this->assertEquals("", $tradeparty->getName());
$this->assertIsArray($tradeparty->getID());
$this->assertArrayNotHasKey(0, $tradeparty->getID());
$this->assertNull($tradeparty->getDescription());
$this->assertEquals("", $tradeparty->getDescription());
}

public function testGetTradeAddressAllValues(): void
{
/**
Expand Down
4 changes: 4 additions & 0 deletions tests/testcases/PdfReaderEn16931AllowanceChargeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,13 @@ function () {
public function testDocumentShipToGeneral(): void
{
self::$document->getDocumentShipTo($shiptoname, $shiptoids, $shiptodescription);
$this->assertNotNull($shiptoname);
$this->assertIsString($shiptoname);
$this->assertEquals("", $shiptoname);
$this->assertIsArray($shiptoids);
$this->assertEmpty($shiptoids);
$this->assertNotNull($shiptodescription);
$this->assertIsString($shiptodescription);
$this->assertEquals("", $shiptodescription);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/testcases/PdfReaderEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,13 @@ function () {
public function testDocumentShipToGeneral(): void
{
self::$document->getDocumentShipTo($shiptoname, $shiptoids, $shiptodescription);
$this->assertNotNull($shiptoname);
$this->assertIsString($shiptoname);
$this->assertEquals("", $shiptoname);
$this->assertIsArray($shiptoids);
$this->assertEmpty($shiptoids);
$this->assertNotNull($shiptodescription);
$this->assertIsString($shiptodescription);
$this->assertEquals("", $shiptodescription);
}

Expand Down
Loading

0 comments on commit b79c5c7

Please sign in to comment.