Skip to content

Commit

Permalink
Merge pull request #148 from horstoeko/Issue_147
Browse files Browse the repository at this point in the history
#147 Added "setAttachmentRelationshipType" to ZugferdDocumentPdfBuild…
  • Loading branch information
horstoeko authored Oct 24, 2024
2 parents 78a896e + 0da33d0 commit 8180c5a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
6 changes: 1 addition & 5 deletions examples/En16931PdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
->addNewPosition("1")
->setDocumentPositionNote("Bemerkung zu Zeile 1")
->setDocumentPositionProductDetails("Trennblätter A4", "", "TB100A4", null, "0160", "4012345001235")
->addDocumentPositionProductCharacteristic("Farbe", "Gelb")
->addDocumentPositionProductClassification("ClassCode", "ClassName", "ListId", "ListVersionId")
->setDocumentPositionProductOriginTradeCountry("CN")
->setDocumentPositionGrossPrice(9.9000)
->setDocumentPositionNetPrice(9.9000)
Expand All @@ -42,8 +40,6 @@
->addNewPosition("2")
->setDocumentPositionNote("Bemerkung zu Zeile 2")
->setDocumentPositionProductDetails("Joghurt Banane", "", "ARNR2", null, "0160", "4000050986428")
->addDocumentPositionProductCharacteristic("Suesstoff", "Nein")
->addDocumentPositionProductClassification("ClassCode", "ClassName", "ListId", "ListVersionId")
->SetDocumentPositionGrossPrice(5.5000)
->SetDocumentPositionNetPrice(5.5000)
->SetDocumentPositionQuantity(50, "H87")
Expand All @@ -59,4 +55,4 @@
}

$documentPdfBuilder = new ZugferdDocumentPdfBuilder($document, $existingPdf);
$documentPdfBuilder->generateDocument()->saveDocument($mergeToPdf);
$documentPdfBuilder->setAttachmentRelationshipType('Alternative')->generateDocument()->saveDocument($mergeToPdf);
46 changes: 42 additions & 4 deletions src/ZugferdDocumentPdfBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ abstract class ZugferdDocumentPdfBuilderAbstract
*/
private $additionalCreatorTool = "";

/**
* The relationship type to use for the XML attachment. Detault is Data
*
* @var string
*/
private $attachmentRelationshipType = 'Data';

/**
* Instance of the pdfwriter
*
Expand Down Expand Up @@ -68,7 +75,7 @@ public function __construct(string $pdfData)
/**
* Generates the final document
*
* @return self
* @return static
*/
public function generateDocument()
{
Expand All @@ -83,7 +90,7 @@ public function generateDocument()
* @param string $toFilename
* The full qualified filename to which the generated PDF (with attachment)
* is stored
* @return self
* @return static
*/
public function saveDocument(string $toFilename)
{
Expand Down Expand Up @@ -119,7 +126,7 @@ public function downloadString(string $toFilename): string
*
* @param string $additionalCreatorTool
* The name of the creator
* @return self
* @return static
*/
public function setAdditionalCreatorTool(string $additionalCreatorTool)
{
Expand All @@ -136,12 +143,43 @@ public function setAdditionalCreatorTool(string $additionalCreatorTool)
public function getCreatorToolName(): string
{
$toolName = sprintf('Factur-X PHP library v%s by HorstOeko', ZugferdPackageVersion::getInstalledVersion());

if ($this->additionalCreatorTool) {
return $this->additionalCreatorTool . ' / ' . $toolName;
}

return $toolName;
}

/**
* Set the type of relationship for the XML attachment. Allowed
* types are 'Data', 'Alternative'
*
* @param string $relationshipType
* @return static
*/
public function setAttachmentRelationshipType(string $relationshipType)
{
if (!in_array($relationshipType, ['Data', 'Alternative'])) {
$relationshipType = 'Data';
}

$this->attachmentRelationshipType = $relationshipType;

return $this;
}

/**
* Returns the relationship type for the XML attachment. This
* can return 'Data', 'Alternative'
*
* @return string
*/
public function getAttachmentRelationshipType(): string
{
return $this->attachmentRelationshipType;
}

/**
* Get the content of XML to attach
*
Expand Down Expand Up @@ -190,7 +228,7 @@ private function startCreatePdf(): void
$documentBuilderXmlDataRef,
$this->getXmlAttachmentFilename(),
'Factur-X Invoice',
'Data',
$this->getAttachmentRelationshipType(),
'text#2Fxml'
);

Expand Down

0 comments on commit 8180c5a

Please sign in to comment.