diff --git a/src/FacturX.php b/src/FacturX.php index e73a245..9a1036b 100644 --- a/src/FacturX.php +++ b/src/FacturX.php @@ -5,6 +5,7 @@ // Factur-X Xml Stuff use Easybill\ZUGFeRD211\Builder; use Easybill\ZUGFeRD211\Model\Amount; +use Easybill\ZUGFeRD211\Model\BinaryObject; use Easybill\ZUGFeRD211\Model\CreditorFinancialAccount; use Easybill\ZUGFeRD211\Model\CreditorFinancialInstitution; use Easybill\ZUGFeRD211\Model\CrossIndustryInvoice; @@ -25,6 +26,7 @@ use Easybill\ZUGFeRD211\Model\Note; use Easybill\ZUGFeRD211\Model\Quantity; +use Easybill\ZUGFeRD211\Model\ReferencedDocument; use Easybill\ZUGFeRD211\Model\SupplyChainEvent; use Easybill\ZUGFeRD211\Model\SupplyChainTradeLineItem; use Easybill\ZUGFeRD211\Model\SupplyChainTradeTransaction; @@ -366,4 +368,20 @@ public function addNote(string $content, ?string $subjectCode = null, ?string $c { $this->invoice->exchangedDocument->notes[] = Note::create($content, $subjectCode, $contentCode); } + + public function addEmbeddedAttachment( ?string $id, ?string $scheme, ?string $filename, ?string $contents, ?string $mimeCode, ?string $description ){ + // The attachement is correctly added but schematron fails, need to + // $attachment = ReferencedDocument::create($id); + // $attachment->name = $description; + // $binary = new BinaryObject(); + // $binary->filename=$filename; + // $binary->mimeCode=$mimeCode; + // $binary->value=base64_encode($contents); + // $attachment->attachmentBinaryObject = $binary; + + // switch($scheme) { + // // TODO, depending on the type of documents it could be attached + // default : $this->invoice->supplyChainTradeTransaction->applicableHeaderTradeSettlement->invoiceReferencedDocument = $attachment; + // } + } } \ No newline at end of file diff --git a/src/Invoice.php b/src/Invoice.php index 3227f4f..baa86f4 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -215,4 +215,8 @@ public function getPdf($pdf , $addFacturxLogo = false ) $addFacturxLogo ); } + public function addEmbeddedAttachment( ?string $id, ?string $scheme, ?string $filename, ?string $contents, ?string $mimeCode, ?string $description ){ + $this->xmlGenerator->addEmbeddedAttachment( $id,$scheme, $filename, $contents, $mimeCode, $description ); + } + } diff --git a/src/Ubl.php b/src/Ubl.php index c23a122..31d7df8 100644 --- a/src/Ubl.php +++ b/src/Ubl.php @@ -3,6 +3,7 @@ namespace DigitalInvoice; use DateTime; +use Einvoicing\Attachment; use Einvoicing\Delivery; use Einvoicing\Exceptions\ValidationException; use Einvoicing\Identifier; @@ -51,7 +52,7 @@ public function validate(string $xml, $schematron) * @return boolean */ protected function euValidation(string $contents, string $type) { - + $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => 'https://www.itb.ec.europa.eu/vitb/rest/invoice/api/validate', @@ -189,4 +190,25 @@ public function addPaymentMean(PaymentMeansCode $typeCode, ?string $ibanId = nul $payment->addTransfer($transfer); } + + public function addEmbeddedAttachment( ?string $id, ?string $scheme, ?string $filename, ?string $contents, ?string $mimeCode, ?string $description ){ + // not implemented + $embeddedAttachment = new Attachment(); + if($id){ + $embeddedAttachment->setId( new Identifier($id, $scheme) ); + } + if($filename){ + $embeddedAttachment->setFilename($filename ); + } + if($contents){ + $embeddedAttachment->setContents($contents ); + } + if($mimeCode){ + $embeddedAttachment->setMimeCode($mimeCode ); + } + if($description){ + $embeddedAttachment->setDescription($description ); + } + $this->invoice->addAttachment($embeddedAttachment); + } } \ No newline at end of file diff --git a/src/XmlGenerator.php b/src/XmlGenerator.php index 1dd4767..f4f41d7 100644 --- a/src/XmlGenerator.php +++ b/src/XmlGenerator.php @@ -19,6 +19,7 @@ public function setBuyerAddress(string $lineOne, string $postCode, string $city, public function addItem(string $name, float $price, float $taxRatePercent, float $quantity, UnitOfMeasurement $unit, ?string $globalID = null, ?string $globalIDCode =null ): float; public function addNote(string $content, ?string $subjectCode = null, ?string $contentCode = null); public function addPaymentMean(PaymentMeansCode $typeCode , ?string $ibanId = null,?string $accountName = null, ?string $bicId = null); + public function addEmbeddedAttachment( ?string $id, ?string $scheme, ?string $filename, ?string $contents, ?string $mimeCode, ?string $description ); } @@ -76,6 +77,12 @@ public function addTaxLine($rate , $totalLineBasis ){ } + public function addEmbeddedAttachment( ?string $id, ?string $scheme, ?string $filename, ?string $contents, ?string $mimeCode, ?string $description ){ + // not implemented + } + + + diff --git a/test/InvoiceTest.php b/test/InvoiceTest.php index e458d47..83eff6a 100644 --- a/test/InvoiceTest.php +++ b/test/InvoiceTest.php @@ -24,21 +24,21 @@ public function profilesProvider() [Zugferd::ZUGFERD_BASIC, true], [Zugferd::ZUGFERD_CONFORT, true], [Zugferd::ZUGFERD_EXTENDED, true], - [FacturX::XRECHNUNG, false], - [Ubl::PEPPOL, false], - [Ubl::NLCIUS, false], - [Ubl::CIUS_RO, false], - [Ubl::CIUS_IT, false], - [Ubl::CIUS_ES_FACE, false], - [Ubl::CIUS_AT_GOV, false], - [Ubl::CIUS_AT_NAT, false] + [FacturX::XRECHNUNG, false, false], + [Ubl::PEPPOL, false , true], + [Ubl::NLCIUS, false, true], + [Ubl::CIUS_RO, false, true], + [Ubl::CIUS_IT, false, true], + [Ubl::CIUS_ES_FACE, false, true], + [Ubl::CIUS_AT_GOV, false, true], + [Ubl::CIUS_AT_NAT, false, true] ]; } /** * @dataProvider profilesProvider */ - public function testInvoiceXml($profile, $isPdf): void + public function testInvoiceXml($profile, $isPdf, $embedPdf = false ): void { $invoice = new Invoice('123', new \Datetime('2023-11-07'), null , CurrencyCode::EURO , $profile); @@ -81,6 +81,12 @@ public function testInvoiceXml($profile, $isPdf): void // add payment $invoice->addPaymentMean('58','MA2120300000000202051' , 'Youniwemi'); + + // Embedding pdf + if ($embedPdf){ + $pdfFile = file_get_contents(__DIR__.'/examples/basic.pdf'); + $invoice->addEmbeddedAttachment('123', null, 'basic', $pdfFile, 'application/pdf', 'The pdf invoice'); + } $xml = $invoice->getXml(); self::assertNotEmpty($xml); @@ -103,7 +109,6 @@ public function testInvoiceXml($profile, $isPdf): void } catch (\Exception $e) { $this->fail('Error extractiong xml '. $e->getMessage()); } - } // A complete validation using schematron