Skip to content

Commit

Permalink
[DOC] Added samples for the Wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Dec 27, 2024
1 parent 410fc9d commit 86b819b
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 1 deletion.
1 change: 0 additions & 1 deletion make/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
classes/
download/
md/
50 changes: 50 additions & 0 deletions make/md/ZugferdDocumentBuilder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
```php
use horstoeko\zugferd\ZugferdDocumentBuilder;
use horstoeko\zugferd\ZugferdProfiles;
use horstoeko\zugferd\codelists\ZugferdPaymentMeans;

require dirname(__FILE__) . "/../vendor/autoload.php";

$document = ZugferdDocumentBuilder::createNew(ZugferdProfiles::PROFILE_EN16931);
$document
->setDocumentInformation("471102", "380", \DateTime::createFromFormat("Ymd", "20180305"), "EUR")
->addDocumentNote('Rechnung gemäß Bestellung vom 01.03.2018.')
->addDocumentNote('Lieferant GmbH' . PHP_EOL . 'Lieferantenstraße 20' . PHP_EOL . '80333 München' . PHP_EOL . 'Deutschland' . PHP_EOL . 'Geschäftsführer: Hans Muster' . PHP_EOL . 'Handelsregisternummer: H A 123' . PHP_EOL . PHP_EOL, null, 'REG')
->setDocumentSupplyChainEvent(\DateTime::createFromFormat('Ymd', '20180305'))
->addDocumentPaymentMean(ZugferdPaymentMeans::UNTDID_4461_58, null, null, null, null, null, "DE12500105170648489890", null, null, null)
->setDocumentSeller("Lieferant GmbH", "549910")
->addDocumentSellerGlobalId("4000001123452", "0088")
->addDocumentSellerTaxRegistration("FC", "201/113/40209")
->addDocumentSellerTaxRegistration("VA", "DE123456789")
->setDocumentSellerAddress("Lieferantenstraße 20", "", "", "80333", "München", "DE")
->setDocumentSellerContact("Heinz Mükker", "Buchhaltung", "+49-111-2222222", "+49-111-3333333","[email protected]")
->setDocumentBuyer("Kunden AG Mitte", "GE2020211")
->setDocumentBuyerReference("34676-342323")
->setDocumentBuyerAddress("Kundenstraße 15", "", "", "69876", "Frankfurt", "DE")
->addDocumentTax("S", "VAT", 275.0, 19.25, 7.0)
->addDocumentTax("S", "VAT", 198.0, 37.62, 19.0)
->setDocumentSummation(529.87, 529.87, 473.00, 0.0, 0.0, 473.00, 56.87, null, 0.0)
->addDocumentPaymentTerm("Zahlbar innerhalb 30 Tagen netto bis 04.04.2018, 3 Prozent Skonto innerhalb 10 Tagen bis 15.03.2018")
->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)
->setDocumentPositionQuantity(20, "H87")
->addDocumentPositionTax('S', 'VAT', 19)
->setDocumentPositionLineSummation(198.0)
->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")
->AddDocumentPositionTax('S', 'VAT', 7)
->SetDocumentPositionLineSummation(275.0)
->writeFile(dirname(__FILE__) . "/factur-x.xml");
```
4 changes: 4 additions & 0 deletions make/md/ZugferdDocumentBuilder_setDocumentInformation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```php
$document = ZugferdDocumentBuilder::CreateNew(ZugferdProfiles::PROFILE_EN16931);
$document->setDocumentInformation("471102", "380", \DateTime::createFromFormat("Ymd", "20180305"), "EUR");
```
67 changes: 67 additions & 0 deletions make/md/ZugferdDocumentPdfMerger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
### Example for merging an existing PDF file with an existing XML file

```php
use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$existingXmlFile = "/tmp/invoice_1.xml";
$existingPdfFile = "/tmp/emptypdf.pdf";
$mergeToPdf = "/tmp/fullpdf.pdf";

if (!file_exists($existingXmlFile) || !file_exists($existingPdfFile)) {
throw new \Exception("XML and/or PDF does not exist");
}

(new ZugferdDocumentPdfMerger($existingXmlFile, $existingPdfFile))
->generateDocument()
->saveDocument($mergeToPdf);
```

### Example for merging an existing PDF file with a string which contains the XML

```php
use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$xmlString= "<xml>...</xml>";
$existingPdfFile = "/tmp/emptypdf.pdf";
$mergeToPdf = "/tmp/fullpdf.pdf";

if (!file_exists($existingPdfFile)) {
throw new \Exception("XML and/or PDF does not exist");
}

(new ZugferdDocumentPdfMerger($xmlString, $existingPdfFile))
->generateDocument()
->saveDocument($mergeToPdf);
```

### Example for merging a string which contains a PDF with an existing XML file

```php
use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$existingXmlFile = "/tmp/invoice_1.xml";
$pdfString = "%PDF-1.4.....";
$mergeToPdf = "/tmp/fullpdf.pdf";

if (!file_exists($existingXmlFile)) {
throw new \Exception("XML and/or PDF does not exist");
}

(new ZugferdDocumentPdfMerger($existingXmlFile, $pdfString))
->generateDocument()
->saveDocument($mergeToPdf);
```

### Example for merging a string which contains a PDF with a string which contains the XML

```php
use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$xmlString= "<xml>...</xml>";
$pdfString = "%PDF-1.4.....";
$mergeToPdf = "/tmp/fullpdf.pdf";

(new ZugferdDocumentPdfMerger($xmlString, $pdfString))
->generateDocument()
->saveDocument($mergeToPdf);
```
35 changes: 35 additions & 0 deletions make/md/ZugferdKositValidator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Validation of a document read by ZugferdDocumentPdfReader

```php
$kositValidator = new ZugferdKositValidator();

$document = ZugferdDocumentPdfReader::readAndGuessFromFile("/tmp/invoice.pdf");
$kositValidator->setDocument($document)->disableCleanup()->validate();

if ($kositValidator->hasValidationErrors()) {
echo "Validation failed";
foreach ($kositValidator->getValidationErrors() as $validationError) {
echo " - " . $validationError . PHP_EOL;
}
} else {
echo "mValidation passed";
}
```

### Validation of a document read by ZugferdDocumentReader

```php
$kositValidator = new ZugferdKositValidator();

$document = ZugferdDocumentReader::readAndGuessFromFile("/tmp/factur-x.xml");
$kositValidator->setDocument($document)->disableCleanup()->validate();

if ($kositValidator->hasValidationErrors()) {
echo "Validation failed";
foreach ($kositValidator->getValidationErrors() as $validationError) {
echo " - " . $validationError . PHP_EOL;
}
} else {
echo "mValidation passed";
}
```

0 comments on commit 86b819b

Please sign in to comment.