diff --git a/composer.json b/composer.json index 8792e11c..7225ddbd 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,7 @@ "symfony/web-link": "4.4.*", "symfony/webpack-encore-bundle": "^1.1", "symfony/yaml": "4.4.*", + "tecnickcom/tc-lib-barcode": "^1.15", "twig/cssinliner-extra": "^3.0", "twig/extra-bundle": "^3.0", "twig/inky-extra": "^3.0", diff --git a/composer.lock b/composer.lock index 4fe3da4f..249dab94 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2f3beef4790ec9595fcb7f0a03abbaec", + "content-hash": "c0b791f7fcf138f1677c99085ca3488d", "packages": [ { "name": "beberlei/assert", @@ -8378,6 +8378,159 @@ "homepage": "https://symfony.com", "time": "2020-03-30T11:41:10+00:00" }, + { + "name": "tecnickcom/tc-lib-barcode", + "version": "1.15.20", + "source": { + "type": "git", + "url": "https://github.com/tecnickcom/tc-lib-barcode.git", + "reference": "dd8de5620ec436d61cc8535e11f2879146ebc16b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tecnickcom/tc-lib-barcode/zipball/dd8de5620ec436d61cc8535e11f2879146ebc16b", + "reference": "dd8de5620ec436d61cc8535e11f2879146ebc16b", + "shasum": "" + }, + "require": { + "ext-bcmath": "*", + "ext-date": "*", + "ext-gd": "*", + "ext-pcre": "*", + "php": ">=5.3", + "tecnickcom/tc-lib-color": "^1.12.15" + }, + "require-dev": { + "apigen/apigen": "^2.8.1 || ^4.1.2", + "bartlett/php-compatinfo": "^4.5.2 || ^5.0.10 || ^5.0.12", + "pdepend/pdepend": "^2.5.2", + "phploc/phploc": "^2.1 || ^3.0 || ^4.0", + "phpmd/phpmd": "^2.6.0", + "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.1", + "sebastian/phpcpd": "^2.0 || ^3.0 || ^4.0", + "squizlabs/php_codesniffer": "^2.8.0 || ^3.2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Com\\Tecnick\\Barcode\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Nicola Asuni", + "email": "info@tecnick.com", + "role": "lead" + } + ], + "description": "PHP library to generate linear and bidimensional barcodes", + "homepage": "http://www.tecnick.com", + "keywords": [ + "3 of 9", + "ANSI MH10.8M-1983", + "CBC", + "CODABAR", + "CODE 11", + "CODE 128 A B C", + "CODE 39", + "CODE 93", + "EAN 13", + "EAN 8", + "ECC200", + "Intelligent Mail Barcode", + "Interleaved 2 of 5", + "KIX", + "Klant", + "MSI", + "Onecode", + "PHARMACODE", + "PHARMACODE TWO-TRACKS", + "POSTNET", + "RMS4CC", + "Standard 2 of 5", + "UPC-A", + "UPC-E", + "USD-3", + "USPS-B-3200", + "USS-93", + "barcode", + "datamatrix", + "pdf417", + "planet", + "qr-code", + "royal mail", + "tc-lib-barcode", + "upc" + ], + "time": "2020-01-02T16:01:18+00:00" + }, + { + "name": "tecnickcom/tc-lib-color", + "version": "1.12.15", + "source": { + "type": "git", + "url": "https://github.com/tecnickcom/tc-lib-color.git", + "reference": "2f4860cbac4d58c210b6bec4c5806906278962c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tecnickcom/tc-lib-color/zipball/2f4860cbac4d58c210b6bec4c5806906278962c1", + "reference": "2f4860cbac4d58c210b6bec4c5806906278962c1", + "shasum": "" + }, + "require": { + "ext-pcre": "*", + "php": ">=5.3" + }, + "require-dev": { + "apigen/apigen": "^2.8.1 || ^4.1.2", + "bartlett/php-compatinfo": "^4.5.2 || ^5.0.10 || ^5.0.12", + "pdepend/pdepend": "^2.5.2", + "phploc/phploc": "^2.1 || ^3.0 || ^4.0", + "phpmd/phpmd": "^2.6.0", + "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.1", + "sebastian/phpcpd": "^2.0 || ^3.0 || ^4.0", + "squizlabs/php_codesniffer": "^2.8.0 || ^3.2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Com\\Tecnick\\Color\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Nicola Asuni", + "email": "info@tecnick.com", + "role": "lead" + } + ], + "description": "PHP library to manipulate various color representations", + "homepage": "http://www.tecnick.com", + "keywords": [ + "cmyk", + "color", + "colors", + "colour", + "colours", + "hsl", + "hsla", + "javascript", + "rgb", + "rgba", + "tc-lib-color", + "web" + ], + "time": "2020-01-02T16:01:17+00:00" + }, { "name": "thecodingmachine/safe", "version": "v1.1", @@ -9863,9 +10016,9 @@ "authors": [ { "name": "Christian Weiske", - "role": "Developer", "email": "cweiske@cweiske.de", - "homepage": "http://github.com/cweiske/jsonmapper/" + "homepage": "http://github.com/cweiske/jsonmapper/", + "role": "Developer" } ], "description": "Map nested JSON structures onto PHP classes", @@ -11661,12 +11814,12 @@ "source": { "type": "git", "url": "https://github.com/symplify/auto-bind-parameter.git", - "reference": "e07e2d6228b8211321098647166c6c48fcd58498" + "reference": "43ab403cb0b5e9e7e0d45268635fb43d9723a50b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/auto-bind-parameter/zipball/e07e2d6228b8211321098647166c6c48fcd58498", - "reference": "e07e2d6228b8211321098647166c6c48fcd58498", + "url": "https://api.github.com/repos/symplify/auto-bind-parameter/zipball/43ab403cb0b5e9e7e0d45268635fb43d9723a50b", + "reference": "43ab403cb0b5e9e7e0d45268635fb43d9723a50b", "shasum": "" }, "require": { @@ -11703,12 +11856,12 @@ "source": { "type": "git", "url": "https://github.com/symplify/autowire-array-parameter.git", - "reference": "8a0b518432dfa8d9d5a6b3848683609683f0696b" + "reference": "ba054f1d47e4544ac91aebbf91a291290a4b04b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/autowire-array-parameter/zipball/8a0b518432dfa8d9d5a6b3848683609683f0696b", - "reference": "8a0b518432dfa8d9d5a6b3848683609683f0696b", + "url": "https://api.github.com/repos/symplify/autowire-array-parameter/zipball/ba054f1d47e4544ac91aebbf91a291290a4b04b0", + "reference": "ba054f1d47e4544ac91aebbf91a291290a4b04b0", "shasum": "" }, "require": { @@ -11745,12 +11898,12 @@ "source": { "type": "git", "url": "https://github.com/symplify/coding-standard.git", - "reference": "900e96cf4dc7315c038f6f8d565c9bc83d9fd649" + "reference": "0c766cf020b27e2d5dc8efb1bbfcafb4da7c97a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/coding-standard/zipball/900e96cf4dc7315c038f6f8d565c9bc83d9fd649", - "reference": "900e96cf4dc7315c038f6f8d565c9bc83d9fd649", + "url": "https://api.github.com/repos/symplify/coding-standard/zipball/0c766cf020b27e2d5dc8efb1bbfcafb4da7c97a1", + "reference": "0c766cf020b27e2d5dc8efb1bbfcafb4da7c97a1", "shasum": "" }, "require": { @@ -11795,12 +11948,12 @@ "source": { "type": "git", "url": "https://github.com/symplify/easy-coding-standard.git", - "reference": "8b62588f3f7c6c2605d3d7693297ebed9b4956e5" + "reference": "3e5ad25d1d1172a76f533ac469a76cc2ac44cae8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/easy-coding-standard/zipball/8b62588f3f7c6c2605d3d7693297ebed9b4956e5", - "reference": "8b62588f3f7c6c2605d3d7693297ebed9b4956e5", + "url": "https://api.github.com/repos/symplify/easy-coding-standard/zipball/3e5ad25d1d1172a76f533ac469a76cc2ac44cae8", + "reference": "3e5ad25d1d1172a76f533ac469a76cc2ac44cae8", "shasum": "" }, "require": { @@ -11866,12 +12019,12 @@ "source": { "type": "git", "url": "https://github.com/symplify/package-builder.git", - "reference": "95f3ac3cccc6e247d71c5830879c25c8207b0297" + "reference": "576a99d2973a700c7f60d3c55bbb558b406e9537" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/package-builder/zipball/95f3ac3cccc6e247d71c5830879c25c8207b0297", - "reference": "95f3ac3cccc6e247d71c5830879c25c8207b0297", + "url": "https://api.github.com/repos/symplify/package-builder/zipball/576a99d2973a700c7f60d3c55bbb558b406e9537", + "reference": "576a99d2973a700c7f60d3c55bbb558b406e9537", "shasum": "" }, "require": { @@ -11912,12 +12065,12 @@ "source": { "type": "git", "url": "https://github.com/symplify/set-config-resolver.git", - "reference": "275e882c5cb175bbb9520c652b9d25a23a678d30" + "reference": "dc622c2601ba3b019586c8eb7712357bd5a1155a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/set-config-resolver/zipball/275e882c5cb175bbb9520c652b9d25a23a678d30", - "reference": "275e882c5cb175bbb9520c652b9d25a23a678d30", + "url": "https://api.github.com/repos/symplify/set-config-resolver/zipball/dc622c2601ba3b019586c8eb7712357bd5a1155a", + "reference": "dc622c2601ba3b019586c8eb7712357bd5a1155a", "shasum": "" }, "require": { @@ -11955,12 +12108,12 @@ "source": { "type": "git", "url": "https://github.com/symplify/smart-file-system.git", - "reference": "c7496682de3aeb006ef360431ba5d04ed262f802" + "reference": "bfea2807b8f68ae483bbd71903ac7311f2983855" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/smart-file-system/zipball/c7496682de3aeb006ef360431ba5d04ed262f802", - "reference": "c7496682de3aeb006ef360431ba5d04ed262f802", + "url": "https://api.github.com/repos/symplify/smart-file-system/zipball/bfea2807b8f68ae483bbd71903ac7311f2983855", + "reference": "bfea2807b8f68ae483bbd71903ac7311f2983855", "shasum": "" }, "require": { diff --git a/src/Controller/ScanController.php b/src/Controller/ScanController.php new file mode 100644 index 00000000..5c1a8b35 --- /dev/null +++ b/src/Controller/ScanController.php @@ -0,0 +1,43 @@ +. + */ + +namespace App\Controller; + + +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Routing\Annotation\Route; + +/** + * @Route("/scan") + * @package App\Controller + */ +class ScanController extends AbstractController +{ + /** + * @Route("/{type}/{id}", name="scan_qr") + * @param string $type + * @param int $id + */ + public function scanQRCode(string $type, int $id) + { + $this->addFlash('success', 'QR Code scanned!'); + return $this->redirectToRoute('homepage'); + } +} \ No newline at end of file diff --git a/src/Services/LabelSystem/BarcodeGenerator.php b/src/Services/LabelSystem/BarcodeGenerator.php new file mode 100644 index 00000000..47c1f949 --- /dev/null +++ b/src/Services/LabelSystem/BarcodeGenerator.php @@ -0,0 +1,74 @@ +. + */ + +namespace App\Services\LabelSystem; + +use App\Entity\LabelSystem\LabelOptions; +use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator; +use Com\Tecnick\Barcode\Barcode; + +class BarcodeGenerator +{ + protected $barcodeContentGenerator; + + public function __construct(BarcodeContentGenerator $barcodeContentGenerator) + { + $this->barcodeContentGenerator = $barcodeContentGenerator; + } + + public function generateSVG(LabelOptions $options, object $target): ?string + { + $barcode = new Barcode(); + + switch ($options->getBarcodeType()) { + case 'qr': + $type = 'QRCODE'; + break; + case 'code39': + $type = 'C93'; + break; + case 'none': + return null; + default: + throw new \InvalidArgumentException('Unknown label type!'); + } + + + + $bobj = $barcode->getBarcodeObj($type, $this->getContent($options, $target)); + + return $bobj->getSvgCode(); + } + + public function getContent(LabelOptions $options, object $target): ?string + { + switch ($options->getBarcodeType()) { + case 'qr': + return $this->barcodeContentGenerator->getURLContent($target); + case 'code39': + return $this->barcodeContentGenerator->get1DBarcodeContent($target); + case 'none': + return null; + default: + throw new \InvalidArgumentException('Unknown label type!'); + } + } + +} \ No newline at end of file diff --git a/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php new file mode 100644 index 00000000..54d3f79f --- /dev/null +++ b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php @@ -0,0 +1,101 @@ +. + */ + +namespace App\Services\LabelSystem\Barcodes; + + +use App\Entity\Base\AbstractDBElement; +use App\Entity\Parts\Manufacturer; +use App\Entity\Parts\Part; +use App\Entity\Parts\PartLot; +use App\Entity\Parts\Storelocation; +use App\Entity\Parts\Supplier; +use App\Exceptions\EntityNotSupportedException; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; + +class BarcodeContentGenerator +{ + protected $urlGenerator; + + public const PREFIX_MAP = [ + Part::class => 'P', + PartLot::class => 'L', + Storelocation::class => 'S' + ]; + + protected const URL_MAP = [ + Part::class => 'part', + PartLot::class => 'lot', + Storelocation::class => 'location', + ]; + + public function __construct(UrlGeneratorInterface $urlGenerator) + { + $this->urlGenerator = $urlGenerator; + } + + /** + * Generates a fixed URL to the given Element that can be embedded in a 2D code (e.g. QR code). + * @param AbstractDBElement $target + * @return string + */ + public function getURLContent(AbstractDBElement $target): string + { + if ($target instanceof Part) { + $type = 'part'; + } else { + throw new EntityNotSupportedException(); + } + + return $this->urlGenerator->generate('scan_qr', [ + 'type' => $type, + 'id' => $target->getID(), + ], UrlGeneratorInterface::ABSOLUTE_URL); + } + + /** + * Returns a Code that can be used in a 1D barcode. + * The return value has a format of "L-000123" + * @param AbstractDBElement $target + * @return string + */ + public function get1DBarcodeContent(AbstractDBElement $target): string + { + $prefix = $this->classToString(self::PREFIX_MAP, $target); + $id = sprintf('%06d', $target->getID()); + return $prefix . '-' . $id; + } + + protected function classToString(array $map, object $target): string + { + $class = get_class($target); + if (isset($map[$class])) { + return $map[$class]; + } + + foreach($map as $class => $string) { + if (is_a($target, $class)) { + return $string; + } + } + + throw new \InvalidArgumentException('Unknown object class ' . get_class($target)); + } +} \ No newline at end of file diff --git a/src/Services/LabelSystem/LabelHTMLGenerator.php b/src/Services/LabelSystem/LabelHTMLGenerator.php index 4b8bcf2f..ed9aef94 100644 --- a/src/Services/LabelSystem/LabelHTMLGenerator.php +++ b/src/Services/LabelSystem/LabelHTMLGenerator.php @@ -23,6 +23,7 @@ namespace App\Services\LabelSystem; use App\Entity\Contracts\NamedElementInterface; use App\Entity\LabelSystem\LabelOptions; use App\Services\ElementTypeNameGenerator; +use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator; use Twig\Environment; class LabelHTMLGenerator @@ -30,12 +31,15 @@ class LabelHTMLGenerator protected $twig; protected $elementTypeNameGenerator; protected $replacer; + protected $barcodeGenerator; - public function __construct(ElementTypeNameGenerator $elementTypeNameGenerator, LabelTextReplacer $replacer, Environment $twig) + public function __construct(ElementTypeNameGenerator $elementTypeNameGenerator, LabelTextReplacer $replacer, Environment $twig, + BarcodeGenerator $barcodeGenerator) { $this->twig = $twig; $this->elementTypeNameGenerator = $elementTypeNameGenerator; $this->replacer = $replacer; + $this->barcodeGenerator = $barcodeGenerator; } public function getLabelHTML(LabelOptions $options, array $elements): string @@ -48,13 +52,16 @@ class LabelHTMLGenerator foreach ($elements as $element) { $twig_elements[] = [ 'element' => $element, - 'lines' => $this->replacer->replace($options->getLines(), $element) + 'lines' => $this->replacer->replace($options->getLines(), $element), + 'barcode' => $this->barcodeGenerator->generateSVG($options, $element), + 'barcode_content' => $this->barcodeGenerator->getContent($options, $element), ]; } return $this->twig->render('LabelSystem/labels/base_label.html.twig', [ 'meta_title' => $this->getPDFTitle($options, $elements[0]), 'elements' => $twig_elements, + 'options' => $options, ]); } diff --git a/symfony.lock b/symfony.lock index 93d0255d..b0ec1c31 100644 --- a/symfony.lock +++ b/symfony.lock @@ -857,6 +857,12 @@ "symplify/smart-file-system": { "version": "v7.1.3" }, + "tecnickcom/tc-lib-barcode": { + "version": "1.15.20" + }, + "tecnickcom/tc-lib-color": { + "version": "1.12.15" + }, "thecodingmachine/safe": { "version": "v0.1.16" }, diff --git a/templates/LabelSystem/labels/base_label.html.twig b/templates/LabelSystem/labels/base_label.html.twig index 138e5ab0..5e086d75 100644 --- a/templates/LabelSystem/labels/base_label.html.twig +++ b/templates/LabelSystem/labels/base_label.html.twig @@ -1,21 +1,26 @@ - - - {{ meta_title }} - - - - - - - {% for element in elements %} - {% include "LabelSystem/labels/label_page.html.twig" %} - {% if not loop.last %} -
- {% endif %} - {% endfor %} - + + + {{ meta_title }} + + + + + + +{% for element in elements %} +
+ {% if options.barcodeType == 'none' %} + {% include "LabelSystem/labels/label_page_none.html.twig" %} + {% elseif options.barcodeType == 'qr' %} + {% include "LabelSystem/labels/label_page_qr.html.twig" %} + {% elseif options.barcodeType == 'code39' %} + {% include "LabelSystem/labels/label_page_1d.html.twig" %} + {% endif %} +
+{% endfor %} + \ No newline at end of file diff --git a/templates/LabelSystem/labels/label_page_1d.html.twig b/templates/LabelSystem/labels/label_page_1d.html.twig new file mode 100644 index 00000000..f8c856c1 --- /dev/null +++ b/templates/LabelSystem/labels/label_page_1d.html.twig @@ -0,0 +1,27 @@ +
+
+ {{ element.lines | raw }} +
+
+ + {{ element.barcode_content }} +
+
+ +{# +
+
+
+
+ +
+ +
+
+
+ {{ element.lines | raw }} +
+
+
+
+#} \ No newline at end of file diff --git a/templates/LabelSystem/labels/label_page.html.twig b/templates/LabelSystem/labels/label_page_none.html.twig similarity index 100% rename from templates/LabelSystem/labels/label_page.html.twig rename to templates/LabelSystem/labels/label_page_none.html.twig diff --git a/templates/LabelSystem/labels/label_page_qr.html.twig b/templates/LabelSystem/labels/label_page_qr.html.twig new file mode 100644 index 00000000..a46a97e3 --- /dev/null +++ b/templates/LabelSystem/labels/label_page_qr.html.twig @@ -0,0 +1,17 @@ +
+
+
+
+ + + +
+ {#{{ element.barcode | raw }} #} +
+
+
+ {{ element.lines | raw }} +
+
+
+
\ No newline at end of file diff --git a/templates/LabelSystem/labels/label_style.css.twig b/templates/LabelSystem/labels/label_style.css.twig index 22c61c0a..0c3199f9 100644 --- a/templates/LabelSystem/labels/label_style.css.twig +++ b/templates/LabelSystem/labels/label_style.css.twig @@ -1,5 +1,5 @@ @page { - margin: 5px 5px; + margin: 12px 6px; } body { @@ -14,4 +14,144 @@ p { hr { margin: 2px; -} \ No newline at end of file +} + +.qr { + max-width: 80%; +} + +.qr-container a { + display: block; +} + +.C39 { + max-width: 150px; +} + +.C39-container { + display: inline-block; + align-content: center; + text-align: left; + position: fixed; + bottom: 32px; +} + +.C39-text { + display: block; + margin-top: -6px; + font-size: 6pt; +} + +/************************************** + Grid system token from simplegrid.io + + SIMPLE GRID + (C) ZACH COLE 2016 + ************************************/ +.font-light { + font-weight: 300; +} + +.font-regular { + font-weight: 400; +} + +.font-heavy { + font-weight: 700; +} + +/* POSITIONING */ + +.left { + text-align: left; +} + +.right { + text-align: right; +} + +.center { + text-align: center; + margin-left: auto; + margin-right: auto; +} + +.justify { + text-align: justify; +} + +/* ==== GRID SYSTEM ==== */ + +.container { + width: 90%; + margin-left: auto; + margin-right: auto; +} + +.row { + position: relative; + width: 100%; + page-break-after: avoid; + page-break-before: avoid; + page-break-inside: avoid; +} + +.row [class^="col"] { + float: left; + margin: 0 1%; + min-height: 0.125rem ; +} + +.row::after { + content: ""; + display: table; + clear: both; +} + +.col-1 { + width: 4.33%; +} + +.col-2 { + width: 12.66%; +} + +.col-3 { + width: 21%; +} + +.col-4 { + width: 29.33%; +} + +.col-5 { + width: 37.66%; +} + +.col-6 { + width: 46%; +} + +.col-7 { + width: 54.33%; +} + +.col-8 { + width: 62.66%; +} + +.col-9 { + width: 71%; +} + +.col-10 { + width: 79.33%; +} + +.col-11 { + width: 87.66%; +} + +.col-12 { + width: 96%; +}