diff --git a/src/ZugferdDocumentBuilder.php b/src/ZugferdDocumentBuilder.php index 0846c2ea..d4f6be05 100644 --- a/src/ZugferdDocumentBuilder.php +++ b/src/ZugferdDocumentBuilder.php @@ -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 * @@ -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 * diff --git a/tests/testcases/BuilderEn16931Test.php b/tests/testcases/BuilderEn16931Test.php index a8047282..6633e1b0 100644 --- a/tests/testcases/BuilderEn16931Test.php +++ b/tests/testcases/BuilderEn16931Test.php @@ -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 */ @@ -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 */ diff --git a/tests/testcases/BuilderExtendedTest.php b/tests/testcases/BuilderExtendedTest.php index e9e93808..fd335e23 100644 --- a/tests/testcases/BuilderExtendedTest.php +++ b/tests/testcases/BuilderExtendedTest.php @@ -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 */ @@ -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 */ diff --git a/tests/testcases/BuilderMinimumTest.php b/tests/testcases/BuilderMinimumTest.php index a04c0634..ee202546 100644 --- a/tests/testcases/BuilderMinimumTest.php +++ b/tests/testcases/BuilderMinimumTest.php @@ -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 */ @@ -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 */