Skip to content

Commit

Permalink
#119 Update to ZUGFeRD 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Sep 21, 2024
1 parent e3c0d2b commit d7fe3bd
Show file tree
Hide file tree
Showing 182 changed files with 31,943 additions and 89,982 deletions.
4 changes: 3 additions & 1 deletion build/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
<file>../tests/testcases/ValidatorValidTest.php</file>
<file>../tests/testcases/ValidatorInvalidTest.php</file>
</testsuite>
<!--
<testsuite name="Exporter">
<file>../tests/testcases/JsonExporterTest.php</file>
</testsuite>
-->
<testsuite name="issues">
<file>../tests/testcases/issues/Issue10Test.php</file>
<file>../tests/testcases/issues/Issue18Test.php</file>
Expand All @@ -63,7 +65,7 @@
</include>
<exclude>
<directory suffix=".php">../src/codelists</directory>
<directory suffix=".php">../src/entities</directory>
<!--<directory suffix=".php">../src/entities</directory>-->
<directory suffix=".php">../src/exception</directory>
<file>../src/ZugferdProfiles.php</file>
</exclude>
Expand Down
31 changes: 18 additions & 13 deletions src/ZugferdDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ public function addDocumentAdditionalReferencedDocument(string $issuerassignedid
public function setDocumentInvoiceReferencedDocument(string $issuerassignedid, ?DateTime $issueddate = null): ZugferdDocumentBuilder
{
$invoicerefdoc = $this->getObjectHelper()->getReferencedDocumentType($issuerassignedid, null, null, null, null, null, $issueddate, null);
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "setInvoiceReferencedDocument", $invoicerefdoc);
$this->getObjectHelper()->tryCallIfMethodExists($this->headerTradeSettlement, "addToInvoiceReferencedDocument", "setInvoiceReferencedDocument", [$invoicerefdoc], $invoicerefdoc);
return $this;
}

Expand Down Expand Up @@ -2326,7 +2326,7 @@ public function addDocumentPaymentMean(string $typecode, ?string $information =
$this->getObjectHelper()->tryCall($paymentMeans, "setPayeePartyCreditorFinancialAccount", $payeefinancialaccount);
$this->getObjectHelper()->tryCall($paymentMeans, "setPayeeSpecifiedCreditorFinancialInstitution", $payeefinancialInstitution);

$this->getObjectHelper()->tryCallAll($this->headerTradeSettlement, ["addToSpecifiedTradeSettlementPaymentMeans", "setSpecifiedTradeSettlementPaymentMeans"], $paymentMeans);
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "addToSpecifiedTradeSettlementPaymentMeans", $paymentMeans);

return $this;
}
Expand Down Expand Up @@ -2360,7 +2360,7 @@ public function addDocumentPaymentMeanToCreditTransfer(string $payeeIban, ?strin
$this->getObjectHelper()->tryCall($paymentMeans, "setPayeePartyCreditorFinancialAccount", $payeefinancialaccount);
$this->getObjectHelper()->tryCall($paymentMeans, "setPayeeSpecifiedCreditorFinancialInstitution", $payeefinancialInstitution);

$this->getObjectHelper()->tryCallAll($this->headerTradeSettlement, ["addToSpecifiedTradeSettlementPaymentMeans", "setSpecifiedTradeSettlementPaymentMeans"], $paymentMeans);
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "addToSpecifiedTradeSettlementPaymentMeans", $paymentMeans);

if (!is_null($paymentReference)) {
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "setPaymentReference", $this->getObjectHelper()->getIdType($paymentReference));
Expand All @@ -2386,7 +2386,7 @@ public function addDocumentPaymentMeanToDirectDebit(string $buyerIban, ?string $

$this->getObjectHelper()->tryCall($paymentMeans, "setPayerPartyDebtorFinancialAccount", $buyerfinancialaccount);

$this->getObjectHelper()->tryCallAll($this->headerTradeSettlement, ["addToSpecifiedTradeSettlementPaymentMeans", "setSpecifiedTradeSettlementPaymentMeans"], $paymentMeans);
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "addToSpecifiedTradeSettlementPaymentMeans", $paymentMeans);

if (!is_null($creditorReferenceID)) {
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "setCreditorReferenceID", $this->getObjectHelper()->getIdType($creditorReferenceID));
Expand Down Expand Up @@ -2416,7 +2416,7 @@ public function addDocumentPaymentMeanToPaymentCard(string $cardType, string $ca

$this->getObjectHelper()->tryCall($paymentMeans, "setApplicableTradeSettlementFinancialCard", $financialCard);

$this->getObjectHelper()->tryCallAll($this->headerTradeSettlement, ["addToSpecifiedTradeSettlementPaymentMeans", "setSpecifiedTradeSettlementPaymentMeans"], $paymentMeans);
$this->getObjectHelper()->tryCall($this->headerTradeSettlement, "addToSpecifiedTradeSettlementPaymentMeans", $paymentMeans);

return $this;
}
Expand Down Expand Up @@ -2786,17 +2786,22 @@ public function setDocumentPositionNote(?string $content, ?string $contentCode =
/**
* Adds product details to the last created position (line) in the document
*
* @param string $name __BT-153, From BASIC__ A name of the item (item name)
* @param string|null $description __BT-154, From EN 16931__ A description of the item, the item description makes it possible to describe the item and its properties in more detail than is possible with the item name.
* @param string|null $sellerAssignedID __BT-155, From EN 16931__ An identifier assigned to the item by the seller
* @param string|null $buyerAssignedID __BT-156, From EN 16931__ An identifier assigned to the item by the buyer. The article number of the buyer is a clear, bilaterally agreed identification of the product. It can, for example, be the customer article number or the article number assigned by the manufacturer.
* @param string|null $globalIDType __BT-157-1, From BASIC__ The scheme for $globalID
* @param string|null $globalID __BT-157, From BASIC__ Identification of an article according to the registered scheme (Global identifier of the product, GTIN, ...)
* @param string $name __BT-153, From BASIC__ A name of the item (item name)
* @param string|null $description __BT-154, From EN 16931__ A description of the item, the item description makes it possible to describe the item and its properties in more detail than is possible with the item name.
* @param string|null $sellerAssignedID __BT-155, From EN 16931__ An identifier assigned to the item by the seller
* @param string|null $buyerAssignedID __BT-156, From EN 16931__ An identifier assigned to the item by the buyer. The article number of the buyer is a clear, bilaterally agreed identification of the product. It can, for example, be the customer article number or the article number assigned by the manufacturer.
* @param string|null $globalIDType __BT-157-1, From BASIC__ The scheme for $globalID
* @param string|null $globalID __BT-157, From BASIC__ Identification of an article according to the registered scheme (Global identifier of the product, GTIN, ...)
* @param string|null $industryAssignedID __BT-X-309, From EXTENDED__ ID assigned by the industry to the contained referenced product
* @param string|null $modelID __BT-X-533, From EXTENDED__ A unique model identifier for this product
* @param string|null $batchID __BT-X-534. From EXTENDED__ Identification of the batch (lot) of the product
* @param string|null $brandName __BT-X-535. From EXTENDED__ The brand name, expressed as text, for this product
* @param string|null $modelName __BT-X-536. From EXTENDED__ Model designation of the product
* @return ZugferdDocumentBuilder
*/
public function setDocumentPositionProductDetails(string $name, ?string $description = null, ?string $sellerAssignedID = null, ?string $buyerAssignedID = null, ?string $globalIDType = null, ?string $globalID = null): ZugferdDocumentBuilder
public function setDocumentPositionProductDetails(string $name, ?string $description = null, ?string $sellerAssignedID = null, ?string $buyerAssignedID = null, ?string $globalIDType = null, ?string $globalID = null, ?string $industryAssignedID = null, ?string $modelID = null, ?string $batchID = null, ?string $brandName = null, ?string $modelName = null): ZugferdDocumentBuilder
{
$product = $this->getObjectHelper()->getTradeProductType($name, $description, $sellerAssignedID, $buyerAssignedID, $globalIDType, $globalID);
$product = $this->getObjectHelper()->getTradeProductType($name, $description, $sellerAssignedID, $buyerAssignedID, $globalIDType, $globalID, $industryAssignedID, $modelID, $batchID, $brandName, $modelName);
$this->getObjectHelper()->tryCall($this->currentPosition, "setSpecifiedTradeProduct", $product);
return $this;
}
Expand Down
98 changes: 61 additions & 37 deletions src/ZugferdDocumentReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,44 +382,16 @@ public function getIsTestDocument(?bool &$testdocumentindicator): ZugferdDocumen
public function getDocumentSummation(?float &$grandTotalAmount, ?float &$duePayableAmount, ?float &$lineTotalAmount, ?float &$chargeTotalAmount, ?float &$allowanceTotalAmount, ?float &$taxBasisTotalAmount, ?float &$taxTotalAmount, ?float &$roundingAmount, ?float &$totalPrepaidAmount): ZugferdDocumentReader
{
$invoiceCurrencyCode = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getInvoiceCurrencyCode.value", "");

$grandTotalAmountElement = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getGrandTotalAmount", 0);
if (is_array($grandTotalAmountElement)) {
foreach ($grandTotalAmountElement as $grandTotalAmountElementItem) {
$grandTotalAmountCurrencyCode = $this->getObjectHelper()->tryCallAndReturn($grandTotalAmountElementItem, "getCurrencyID") ?? "";
if ($grandTotalAmountCurrencyCode == $invoiceCurrencyCode || $grandTotalAmountCurrencyCode == "") {
$grandTotalAmount = $this->getObjectHelper()->tryCallAndReturn($grandTotalAmountElementItem, "value") ?? 0;
break;
}
}
} else {
$grandTotalAmount = $this->getObjectHelper()->tryCallAndReturn($grandTotalAmountElement, "value") ?? 0;
}

$taxBasisTotalAmountElement = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getTaxBasisTotalAmount", 0);
if (is_array($taxBasisTotalAmountElement)) {
foreach ($taxBasisTotalAmountElement as $taxBasisTotalAmountElementItem) {
$taxBasisTotalAmountCurrencyCode = $this->getObjectHelper()->tryCallAndReturn($taxBasisTotalAmountElementItem, "getCurrencyID") ?? "";
if ($taxBasisTotalAmountCurrencyCode == $invoiceCurrencyCode || $taxBasisTotalAmountCurrencyCode == "") {
$taxBasisTotalAmount = $this->getObjectHelper()->tryCallAndReturn($taxBasisTotalAmountElementItem, "value") ?? 0;
break;
}
}
} else {
$taxBasisTotalAmount = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getTaxBasisTotalAmount.value", 0);
}

$taxTotalAmountElement = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getTaxTotalAmount", 0);
if (is_array($taxTotalAmountElement)) {
foreach ($taxTotalAmountElement as $taxTotalAmountElementItem) {
$taxTotalAmountCurrencyCode = $this->getObjectHelper()->tryCallAndReturn($taxTotalAmountElementItem, "getCurrencyID") ?? "";
if ($taxTotalAmountCurrencyCode == $invoiceCurrencyCode || $taxTotalAmountCurrencyCode == "") {
$taxTotalAmount = $this->getObjectHelper()->tryCallAndReturn($taxTotalAmountElementItem, "value") ?? 0;
break;
}
$grandTotalAmount = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getGrandTotalAmount.value", 0);
$taxBasisTotalAmount = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getTaxBasisTotalAmount.value", 0);
$taxTotalAmountElement = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getTaxTotalAmount", []);

foreach ($taxTotalAmountElement as $taxTotalAmountElementItem) {
$taxTotalAmountCurrencyCode = $this->getObjectHelper()->tryCallAndReturn($taxTotalAmountElementItem, "getCurrencyID") ?? "";
if ($taxTotalAmountCurrencyCode == $invoiceCurrencyCode || $taxTotalAmountCurrencyCode == "") {
$taxTotalAmount = $this->getObjectHelper()->tryCallAndReturn($taxTotalAmountElementItem, "value") ?? 0;
break;
}
} else {
$taxTotalAmount = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getTaxTotalAmount.value", 0);
}

$duePayableAmount = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getApplicableHeaderTradeSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation.getDuePayableAmount.value", 0);
Expand Down Expand Up @@ -3492,6 +3464,58 @@ public function getDocumentPositionProductDetails(?string &$name, ?string &$desc
return $this;
}

/**
* Get information about the goods and services billed (Enhanced, with Model, Brand, etc.)
*
* @param string|null $name
* A name of the item (item name)
* @param string|null $description
* A description of the item, the item description makes it possible to describe the item and its
* properties in more detail than is possible with the item name.
* @param string|null $sellerAssignedID
* An identifier assigned to the item by the seller
* @param string|null $buyerAssignedID
* An identifier assigned to the item by the buyer. The article number of the buyer is a clear,
* bilaterally agreed identification of the product. It can, for example, be the customer article
* number or the article number assigned by the manufacturer.
* @param string|null $globalIDType
* The scheme for $globalID
* @param string|null $globalID
* Identification of an article according to the registered scheme (Global identifier of the product,
* GTIN, ...)
* @param string|null $industryAssignedID
* D assigned by the industry to the contained referenced product
* @param string|null $modelID
* A unique model identifier for this product
* @param string|null $batchID
* Identification of the batch (lot) of the product
* @param string|null $brandName
* The brand name, expressed as text, for this product
* @param string|null $modelName
* Model designation of the product
* @return ZugferdDocumentReader
*/
public function getDocumentPositionProductDetailsExt(?string &$name, ?string &$description, ?string &$sellerAssignedID, ?string &$buyerAssignedID, ?string &$globalIDType, ?string &$globalID, ?string &$industryAssignedID, ?string &$modelID, ?string &$batchID, ?string &$brandName, ?string &$modelName): ZugferdDocumentReader
{
$tradeLineItem = $this->getInvoiceValueByPath("getSupplyChainTradeTransaction.getIncludedSupplyChainTradeLineItem", []);
$tradeLineItem = $tradeLineItem[$this->positionPointer];

$name = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getName.value", "");
$description = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getDescription.value", "");
$sellerAssignedID = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getSellerAssignedID.value", "");
$buyerAssignedID = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getBuyerAssignedID.value", "");
$globalIDType = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getGlobalID.getSchemeID", "");
$globalID = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getGlobalID.value", "");
$industryAssignedID = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getIndustryAssignedID.value", "");
$modelID = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getModelID.value", "");
$batchIDs = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getBatchID", "");
$batchID = isset($batchIDs[0]) ? $this->getObjectHelper()->tryCallAndReturn($batchIDs[0], "value") : "";
$brandName = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getBrandName.value", "");
$modelName = $this->getInvoiceValueByPathFrom($tradeLineItem, "getSpecifiedTradeProduct.getModelName.value", "");

return $this;
}

/**
* Get details of the related buyer order position
*
Expand Down
Loading

0 comments on commit d7fe3bd

Please sign in to comment.