mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-20 02:11:31 +00:00
Added label placeholders to add a barcode version of the IPN to a label
This fixes issue #373
This commit is contained in:
parent
3c52e57a44
commit
5e326bca12
9 changed files with 243 additions and 60 deletions
|
|
@ -24,12 +24,18 @@ namespace App\Services\LabelSystem\PlaceholderProviders;
|
|||
|
||||
use App\Entity\LabelSystem\BarcodeType;
|
||||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Services\LabelSystem\BarcodeGenerator;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Services\LabelSystem\Barcodes\BarcodeHelper;
|
||||
use App\Services\LabelSystem\LabelBarcodeGenerator;
|
||||
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
|
||||
use Com\Tecnick\Barcode\Exception;
|
||||
|
||||
final class BarcodeProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
public function __construct(private readonly BarcodeGenerator $barcodeGenerator, private readonly BarcodeContentGenerator $barcodeContentGenerator)
|
||||
public function __construct(private readonly LabelBarcodeGenerator $barcodeGenerator,
|
||||
private readonly BarcodeContentGenerator $barcodeContentGenerator,
|
||||
private readonly BarcodeHelper $barcodeHelper)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -69,6 +75,36 @@ final class BarcodeProvider implements PlaceholderProviderInterface
|
|||
return $this->barcodeGenerator->generateHTMLBarcode($label_options, $label_target);
|
||||
}
|
||||
|
||||
if ($label_target instanceof Part || $label_target instanceof PartLot) {
|
||||
if ($label_target instanceof PartLot) {
|
||||
$label_target = $label_target->getPart();
|
||||
}
|
||||
|
||||
if ($label_target === null || $label_target->getIPN() === null || $label_target->getIPN() === '') {
|
||||
//Replace with empty result, if no IPN is set
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
//Add placeholders for the IPN barcode
|
||||
if ('[[IPN_BARCODE_C39]]' === $placeholder) {
|
||||
return $this->barcodeHelper->barcodeAsHTML($label_target->getIPN(), BarcodeType::CODE39);
|
||||
}
|
||||
if ('[[IPN_BARCODE_C128]]' === $placeholder) {
|
||||
return $this->barcodeHelper->barcodeAsHTML($label_target->getIPN(), BarcodeType::CODE128);
|
||||
}
|
||||
if ('[[IPN_BARCODE_QR]]' === $placeholder) {
|
||||
return $this->barcodeHelper->barcodeAsHTML($label_target->getIPN(), BarcodeType::QR);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//If an error occurs, output it
|
||||
return '<b>IPN Barcode ERROR!</b>: '.$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue