Skip to content

Commit

Permalink
Added methods "addDocumentSellerId" and "addDocumentBuyerId" for addi…
Browse files Browse the repository at this point in the history
…ngs additional ids (not global ids) for seller and buyer (#90)
  • Loading branch information
HorstOeko committed Jun 14, 2024
1 parent 127f1de commit deba063
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ZugferdDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,19 @@ public function setDocumentSeller(string $name, ?string $id = null, ?string $des
return $this;
}

/**
* Add an id to the document seller
*
* @param string|null $id __BT-29, From BASIC WL__ An identifier of the seller. In many systems, seller identification is key information. Multiple seller 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, buyer-assigned identifier of the seller
* @return ZugferdDocumentBuilder
*/
public function addDocumentSellerId(string $id): ZugferdDocumentBuilder
{
$sellerTradeParty = $this->getObjectHelper()->tryCallAndReturn($this->headerTradeAgreement, "getSellerTradeParty");
$this->getObjectHelper()->tryCall($sellerTradeParty, "addToID", $this->getObjectHelper()->getIdType($id));
return $this;
}

/**
* Add a global id for the seller
*
Expand Down Expand Up @@ -556,6 +569,19 @@ public function setDocumentBuyer(string $name, ?string $id = null, ?string $desc
return $this;
}

/**
* Add an id to the document buyer
*
* @param string|null $id __BT-46, From BASIC WL__ An identifier of the buyer. In many systems, buyer identification is key information. Multiple buyer 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 buyer, e.g. a previously exchanged, seller-assigned identifier of the buyer
* @return ZugferdDocumentBuilder
*/
public function addDocumentBuyerId(string $id): ZugferdDocumentBuilder
{
$buyerTradeParty = $this->getObjectHelper()->tryCallAndReturn($this->headerTradeAgreement, "getBuyerTradeParty");
$this->getObjectHelper()->tryCall($buyerTradeParty, "addToID", $this->getObjectHelper()->getIdType($id));
return $this;
}

/**
* Add a global id for the buyer
*
Expand Down
30 changes: 30 additions & 0 deletions tests/testcases/BuilderEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ public function testSetDocumentSeller(): void
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:Name');
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentSellerId
*/
public function testAddDocumentSellerId(): void
{
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 0, "5499103");
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 1);

(self::$document)->addDocumentSellerId('5499104');

$this->disableRenderXmlContent();
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 0, "5499103");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 1, "5499104");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentSellerGlobalId
*/
Expand Down Expand Up @@ -334,6 +349,21 @@ public function testSetDocumentBuyer(): void
$this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:Name', "Kunden AG Mitte");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentBuyerId
*/
public function testAddDocumentBuyerId(): void
{
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 0, "549910");
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 1);

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

$this->disableRenderXmlContent();
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 0, "549910");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 1, "549911");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentBuyerGlobalId
*/
Expand Down
30 changes: 30 additions & 0 deletions tests/testcases/BuilderExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ public function testSetDocumentSeller(): void
$this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:Name', "Lieferant GmbH");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentSellerId
*/
public function testAddDocumentSellerId(): void
{
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 0, "549910");
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 1);

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

$this->disableRenderXmlContent();
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 0, "549910");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 1, "549911");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentSellerGlobalId
*/
Expand Down Expand Up @@ -328,6 +343,21 @@ public function testSetDocumentBuyer(): void
$this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:Name', "Kunden AG Mitte");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentBuyerId
*/
public function testAddDocumentBuyerId(): void
{
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 0, "549910");
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 1);

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

$this->disableRenderXmlContent();
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 0, "549910");
$this->assertXPathValueWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 1, "549911");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentBuyerGlobalId
*/
Expand Down
30 changes: 30 additions & 0 deletions tests/testcases/BuilderMinimumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ public function testSetDocumentSeller(): void
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:Name');
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentSellerId
*/
public function testAddDocumentSellerId(): void
{
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 0);
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 1);

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

$this->disableRenderXmlContent();
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 0);
$this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:SellerTradeParty/ram:ID', 1);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentSellerGlobalId
*/
Expand Down Expand Up @@ -337,6 +352,21 @@ public function testSetDocumentBuyer(): void
$this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:Name', "Kunden AG Mitte");
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentBuyerId
*/
public function testAddDocumentBuyerId(): void
{
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 0);
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 1);

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

$this->disableRenderXmlContent();
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 0);
$this->assertXPathNotExistsWithIndex('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:ID', 1);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::addDocumentBuyerGlobalId
*/
Expand Down

0 comments on commit deba063

Please sign in to comment.