From 47730d3d01c1229f22d75193d68bc43ea16bcdb7 Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Fri, 5 Apr 2024 05:38:38 +0200 Subject: [PATCH] Added method "setDocumentBusinessProcess" to ZugferdDocumentBuilder for setting the BusinessProcessSpecifiedDocumentContextParameter-Element --- src/ZugferdDocumentBuilder.php | 23 +++++++++++++++++++++++ tests/testcases/BuilderEn16931Test.php | 17 +++++++++++++++++ tests/testcases/BuilderExtendedTest.php | 17 +++++++++++++++++ tests/testcases/BuilderMinimumTest.php | 17 +++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/src/ZugferdDocumentBuilder.php b/src/ZugferdDocumentBuilder.php index 1250fc14..006ea5fe 100644 --- a/src/ZugferdDocumentBuilder.php +++ b/src/ZugferdDocumentBuilder.php @@ -213,6 +213,29 @@ public function setDocumentInformation(string $documentno, string $documenttypec return $this; } + /** + * Set grouping of business process information + * + * @param string $id + * Identifies the context of a business process where the transaction is taking place, thus allowing the buyer to + * process the invoice in an appropriate manner. + * __Note__: These data make it possible to define the purpose of the settlement (invoice of the authorised person, + * contractual partner, subcontractor, settlement document for a building contract etc.). + * @return ZugferdDocumentBuilder + */ + public function setDocumentBusinessProcess(string $id): ZugferdDocumentBuilder + { + if ($this->getObjectHelper()->isNullOrEmpty($id)) { + return $this; + } + + $busProcessCtxParameter = $this->getObjectHelper()->createClassInstance('ram\DocumentContextParameterType'); + $this->getObjectHelper()->tryCall($busProcessCtxParameter, 'setID', $this->getObjectHelper()->getIdType($id)); + $this->getObjectHelper()->tryCall($this->getInvoiceObject()->getExchangedDocumentContext(), 'setBusinessProcessSpecifiedDocumentContextParameter', $busProcessCtxParameter); + + return $this; + } + /** * Set general payment information * diff --git a/tests/testcases/BuilderEn16931Test.php b/tests/testcases/BuilderEn16931Test.php index c961e024..a8047282 100644 --- a/tests/testcases/BuilderEn16931Test.php +++ b/tests/testcases/BuilderEn16931Test.php @@ -73,6 +73,23 @@ public function testSetDocumentInformation(): void $this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode', "EUR"); } + /** + * @covers \horstoeko\zugferd\ZugferdDocumentBuilder::setDocumentBusinessProcess + */ + public function testSetDocumentBusinessProcess(): void + { + $this->disableRenderXmlContent(); + $this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID'); + + (self::$document)->setDocumentBusinessProcess(""); + $this->disableRenderXmlContent(); + $this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID'); + + (self::$document)->setDocumentBusinessProcess("GENERAL INVOICE"); + $this->disableRenderXmlContent(); + $this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID', "GENERAL INVOICE"); + } + /** * @covers \horstoeko\zugferd\ZugferdDocumentBuilder::setDocumentGeneralPaymentInformation */ diff --git a/tests/testcases/BuilderExtendedTest.php b/tests/testcases/BuilderExtendedTest.php index c6f272ef..e9e93808 100644 --- a/tests/testcases/BuilderExtendedTest.php +++ b/tests/testcases/BuilderExtendedTest.php @@ -72,6 +72,23 @@ public function testSetDocumentInformation(): void $this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode', "EUR"); } + /** + * @covers \horstoeko\zugferd\ZugferdDocumentBuilder::setDocumentBusinessProcess + */ + public function testSetDocumentBusinessProcess(): void + { + $this->disableRenderXmlContent(); + $this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID'); + + (self::$document)->setDocumentBusinessProcess(""); + $this->disableRenderXmlContent(); + $this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID'); + + (self::$document)->setDocumentBusinessProcess("GENERAL INVOICE"); + $this->disableRenderXmlContent(); + $this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID', "GENERAL INVOICE"); + } + /** * @covers \horstoeko\zugferd\ZugferdDocumentBuilder::setDocumentGeneralPaymentInformation */ diff --git a/tests/testcases/BuilderMinimumTest.php b/tests/testcases/BuilderMinimumTest.php index 9daba70c..c8d04711 100644 --- a/tests/testcases/BuilderMinimumTest.php +++ b/tests/testcases/BuilderMinimumTest.php @@ -75,6 +75,23 @@ public function testSetDocumentInformation(): void $this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode', "EUR"); } + /** + * @covers \horstoeko\zugferd\ZugferdDocumentBuilder::setDocumentBusinessProcess + */ + public function testSetDocumentBusinessProcess(): void + { + $this->disableRenderXmlContent(); + $this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID'); + + (self::$document)->setDocumentBusinessProcess(""); + $this->disableRenderXmlContent(); + $this->assertXPathNotExists('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID'); + + (self::$document)->setDocumentBusinessProcess("GENERAL INVOICE"); + $this->disableRenderXmlContent(); + $this->assertXPathValue('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:BusinessProcessSpecifiedDocumentContextParameter/ram:ID', "GENERAL INVOICE"); + } + /** * @covers \horstoeko\zugferd\ZugferdDocumentBuilder::setDocumentGeneralPaymentInformation */