Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Added translations #8

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
688 changes: 392 additions & 296 deletions README.md

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
parameters:
paths:
- ../src
- ../tests
level: 5
treatPhpDocTypesAsCertain: false
excludePaths:
- ../src/entities/*
parameters:
paths:
- ../src
- ../tests
level: 5
treatPhpDocTypesAsCertain: false
excludePaths:
- ../src/renderer/ZugferdVisualizerLaravelRenderer.php
- ../src/translators/ZugferdVisualizerLaravelTranslator.php
58 changes: 30 additions & 28 deletions build/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="../vendor/autoload.php">
<testsuites>
<testsuite name="Basic">
<file>../tests/testcases/BasicTest.php</file>
<file>../tests/testcases/VisualizerText.php</file>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src</directory>
</include>
<exclude>
<directory suffix=".php">../src/contracts</directory>
<directory suffix=".php">../src/exception</directory>
<file>../src/renderer/ZugferdVisualizerLaravelRenderer.php</file>
</exclude>
<report>
<xml outputDirectory="coverage"/>
<html outputDirectory="coverage-html"/>
<clover outputFile="logs/clover.xml"/>
<crap4j outputFile="logs/crap4j.xml" threshold="50"/>
</report>
</coverage>
<logging>
<junit outputFile="logs/junit.xml"/>
<testdoxHtml outputFile="logs/testdox.html"/>
</logging>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="../vendor/autoload.php">
<testsuites>
<testsuite name="Basic">
<file>../tests/testcases/BasicTest.php</file>
<file>../tests/testcases/DefaultTranslatorTest.php</file>
<file>../tests/testcases/VisualizerText.php</file>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src</directory>
</include>
<exclude>
<directory suffix=".php">../src/contracts</directory>
<directory suffix=".php">../src/exception</directory>
<file>../src/renderer/ZugferdVisualizerLaravelRenderer.php</file>
<file>../src/translators/ZugferdVisualizerLaravelTranslator.php</file>
</exclude>
<report>
<xml outputDirectory="coverage"/>
<html outputDirectory="coverage-html"/>
<clover outputFile="logs/clover.xml"/>
<crap4j outputFile="logs/crap4j.xml" threshold="50"/>
</report>
</coverage>
<logging>
<junit outputFile="logs/junit.xml"/>
<testdoxHtml outputFile="logs/testdox.html"/>
</logging>
</phpunit>
140 changes: 75 additions & 65 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,75 @@
{
"name": "horstoeko/zugferdvisualizer",
"keywords": [],
"description": "A library",
"homepage": "https://github.com/horstoeko/zugferdvisualizer",
"type": "package",
"license": "MIT",
"prefer-stable": true,
"authors": [
{
"name": "Daniel Erling",
"email": "daniel@erling.com.de",
"role": "lead"
}
],
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"autoload": {
"psr-4": {
"horstoeko\\zugferdvisualizer\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"horstoeko\\zugferdvisualizer\\tests\\": "tests"
}
},
"require": {
"php": "^7.3|^7.4|^8",
"ext-dom": "*",
"ext-mbstring": "*",
"dompdf/dompdf": "^2.0",
"horstoeko/zugferd": "^1",
"league/commonmark": "^1|^2",
"mpdf/mpdf": "^8"
},
"require-dev": {
"ext-gd": "*",
"ext-json": "*",
"ext-zip": "*",
"pdepend/pdepend": "^2",
"phploc/phploc": "^7",
"phpmd/phpmd": "^2",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9",
"sebastian/phpcpd": "^6",
"squizlabs/php_codesniffer": "^3"
},
"scripts": {
"tests": "./vendor/bin/phpunit ./tests/",
"testsreal": "./vendor/bin/phpunit --configuration ./build/phpunit.xml",
"phpcs": "./vendor/bin/phpcs --standard=./build/phpcsrules.xml --extensions=php --ignore=autoload.php ./src ./tests",
"phpcs12": "./vendor/bin/phpcs --standard=./build/phpcsrules_psr12.xml --extensions=php --ignore=autoload.php ./src ./tests",
"phpcbf": "./vendor/bin/phpcbf -q ./src ./tests",
"phpcbf1": "./vendor/bin/phpcbf --standard=./build/phpcsrules_psr1.xml -q ./src ./tests",
"phpcbf2": "./vendor/bin/phpcbf --standard=./build/phpcsrules_psr2.xml -q ./src ./tests",
"phpcbf12": "./vendor/bin/phpcbf --standard=./build/phpcsrules_psr12.xml -q ./src ./tests",
"phpcbfsq": "./vendor/bin/phpcbf --standard=./build/phpcsrules_squiz.xml -q ./src ./tests",
"phpstan": "./vendor/bin/phpstan analyze -c ./build/phpstan.neon --autoload-file=vendor/autoload.php --no-interaction --no-progress --xdebug",
"phpstan_cs": "./vendor/bin/phpstan analyze -c ./build/phpstan.neon --autoload-file=vendor/autoload.php --no-interaction --no-progress --error-format=checkstyle --xdebug",
"makedoc": "phing -f ./build.xml projectdoc"
}
}
{
"name": "horstoeko/zugferdvisualizer",
"keywords": [],
"description": "A library",
"homepage": "https://github.com/horstoeko/zugferdvisualizer",
"type": "package",
"license": "MIT",
"prefer-stable": true,
"authors": [
{
"name": "Daniel Erling",
"email": "daniel@erling.com.de",
"role": "lead"
}
],
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"autoload": {
"psr-4": {
"horstoeko\\zugferdvisualizer\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"horstoeko\\zugferdvisualizer\\tests\\": "tests"
}
},
"require": {
"php": "^7.3|^7.4|^8",
"ext-dom": "*",
"ext-mbstring": "*",
"dompdf/dompdf": "^2.0",
"horstoeko/zugferd": "^1",
"league/commonmark": "^1|^2",
"mpdf/mpdf": "^8"
},
"require-dev": {
"ext-gd": "*",
"ext-json": "*",
"ext-zip": "*",
"illuminate/contracts": "*",
"pdepend/pdepend": "^2",
"phploc/phploc": "^7",
"phpmd/phpmd": "^2",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9",
"sebastian/phpcpd": "^6",
"squizlabs/php_codesniffer": "^3"
},
"scripts": {
"tests": "./vendor/bin/phpunit ./tests/",
"testsreal": "./vendor/bin/phpunit --configuration ./build/phpunit.xml",
"phpcs": "./vendor/bin/phpcs --standard=./build/phpcsrules.xml --extensions=php --ignore=autoload.php ./src ./tests",
"phpcs12": "./vendor/bin/phpcs --standard=./build/phpcsrules_psr12.xml --extensions=php --ignore=autoload.php ./src ./tests",
"phpcbf": "./vendor/bin/phpcbf -q ./src ./tests",
"phpcbf1": "./vendor/bin/phpcbf --standard=./build/phpcsrules_psr1.xml -q ./src ./tests",
"phpcbf2": "./vendor/bin/phpcbf --standard=./build/phpcsrules_psr2.xml -q ./src ./tests",
"phpcbf12": "./vendor/bin/phpcbf --standard=./build/phpcsrules_psr12.xml -q ./src ./tests",
"phpcbfsq": "./vendor/bin/phpcbf --standard=./build/phpcsrules_squiz.xml -q ./src ./tests",
"phpstan": "./vendor/bin/phpstan analyze -c ./build/phpstan.neon --autoload-file=vendor/autoload.php --no-interaction --no-progress --xdebug",
"phpstan_cs": "./vendor/bin/phpstan analyze -c ./build/phpstan.neon --autoload-file=vendor/autoload.php --no-interaction --no-progress --error-format=checkstyle --xdebug",
"makedoc": "phing -f ./build.xml projectdoc",
"checkstyle": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phploc --count-tests --log-csv build/logs/phploc.csv --log-xml build/logs/phploc.xml src tests",
"vendor/bin/pdepend --jdepend-xml=build/logs/jdepend.xml --jdepend-chart=build/pdepend/dependencies.svg --overview-pyramid=build/pdepend/overview-pyramid.svg src",
"vendor/bin/phpmd src xml build/phpmd.xml --reportfile build/logs/pmd.xml --exclude src/entities/",
"vendor/bin/phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/phpcsrules.xml --extensions=php --ignore=autoload.php src tests",
"vendor/bin/phpstan analyze -c build/phpstan.neon --autoload-file=vendor/autoload.php --no-interaction --no-progress --error-format=checkstyle > build/logs/checkstyle_phpstan.xml",
"vendor/bin/phpcpd --log-pmd build/logs/pmd-cpd.xml --exclude src/entities/ src"
]
}
}
142 changes: 72 additions & 70 deletions examples/BuildFromDocumentBuilder.php
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
<?php

use horstoeko\zugferd\ZugferdProfiles;
use horstoeko\zugferd\ZugferdDocumentBuilder;
use horstoeko\zugferdvisualizer\ZugferdVisualizer;
use horstoeko\zugferd\codelists\ZugferdPaymentMeans;
use horstoeko\zugferd\ZugferdDocumentPdfMerger;
use horstoeko\zugferd\ZugferdDocumentReader;

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

// Create an invoice document

$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", "info@lieferant.de")
->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% Skonto innerhalb 10 Tagen bis 15.03.2018")
->addNewPosition("1")
->setDocumentPositionNote("Bemerkung zu Zeile 1")
->setDocumentPositionProductDetails("Trennblätter A4", "", "TB100A4", null, "0160", "4012345001235")
->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")
->SetDocumentPositionGrossPrice(5.5000)
->SetDocumentPositionNetPrice(5.5000)
->SetDocumentPositionQuantity(50, "H87")
->AddDocumentPositionTax('S', 'VAT', 7)
->SetDocumentPositionLineSummation(275.0);

// Read content

$reader = ZugferdDocumentReader::readAndGuessFromContent($document->getContent());

// Run the visualizer using the default renderer

$visualizer = new ZugferdVisualizer($reader);
$visualizer->setDefaultTemplate();
$visualizer->addPdfFontDirectory(dirname(__FILE__) . '/fonts/');
$visualizer->addPdfFontData('comicsans', 'R', 'comic.ttf');
$visualizer->addPdfFontData('comicsans', 'I', 'comici.ttf');
$visualizer->setPdfFontDefault("courier");
$visualizer->setPdfPaperSize('A4-P');

// Merge XML and PDF

$merger = new ZugferdDocumentPdfMerger($document->getContent(), $visualizer->renderPdf());
$merger->generateDocument();
$merger->saveDocument(dirname(__FILE__) . "/invoice_2.pdf");
<?php

use horstoeko\zugferd\ZugferdProfiles;
use horstoeko\zugferd\ZugferdDocumentBuilder;
use horstoeko\zugferdvisualizer\ZugferdVisualizer;
use horstoeko\zugferd\codelists\ZugferdPaymentMeans;
use horstoeko\zugferd\ZugferdDocumentPdfMerger;
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferdvisualizer\translators\ZugferdVisualizerDefaultTranslator;

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

// Create an invoice document

$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", "info@lieferant.de")
->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% Skonto innerhalb 10 Tagen bis 15.03.2018")
->addNewPosition("1")
->setDocumentPositionNote("Bemerkung zu Zeile 1")
->setDocumentPositionProductDetails("Trennblätter A4", "", "TB100A4", null, "0160", "4012345001235")
->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")
->SetDocumentPositionGrossPrice(5.5000)
->SetDocumentPositionNetPrice(5.5000)
->SetDocumentPositionQuantity(50, "H87")
->AddDocumentPositionTax('S', 'VAT', 7)
->SetDocumentPositionLineSummation(275.0);

// Read content

$reader = ZugferdDocumentReader::readAndGuessFromContent($document->getContent());

// Run the visualizer using the default renderer

$visualizer = new ZugferdVisualizer($reader);
$visualizer->setDefaultTemplate();
$visualizer->setTranslator((new ZugferdVisualizerDefaultTranslator())->addLanguageDirectory(__DIR__)->setCurrentLanguage('de-DE')->setFallbackLanguage('en-US'));
$visualizer->addPdfFontDirectory(dirname(__FILE__) . '/fonts/');
$visualizer->addPdfFontData('comicsans', 'R', 'comic.ttf');
$visualizer->addPdfFontData('comicsans', 'I', 'comici.ttf');
$visualizer->setPdfFontDefault("courier");
$visualizer->setPdfPaperSize('A4-P');

// Merge XML and PDF

$merger = new ZugferdDocumentPdfMerger($document->getContent(), $visualizer->renderPdf());
$merger->generateDocument();
$merger->saveDocument(dirname(__FILE__) . "/invoice_2.pdf");
Loading