Add Asset Tag as separate supported feature

This commit is contained in:
Cram42 2022-11-02 16:07:50 +08:00
parent 06ce40ac08
commit 4bb40adfce
11 changed files with 223 additions and 168 deletions

View file

@ -34,6 +34,7 @@ class LabelsTransformer
'margin_left' => $label->getMarginLeft(), 'margin_left' => $label->getMarginLeft(),
'margin_right' => $label->getMarginRight(), 'margin_right' => $label->getMarginRight(),
'support_asset_tag' => $label->getSupportAssetTag(),
'support_1d_barcode' => $label->getSupport1DBarcode(), 'support_1d_barcode' => $label->getSupport1DBarcode(),
'support_2d_barcode' => $label->getSupport2DBarcode(), 'support_2d_barcode' => $label->getSupport2DBarcode(),
'support_fields' => $label->getSupportFields(), 'support_fields' => $label->getSupportFields(),

View file

@ -90,6 +90,7 @@ class DefaultLabel extends RectangleSheet
public function getLabelColumnSpacing() { return $this->labelSpacingH; } public function getLabelColumnSpacing() { return $this->labelSpacingH; }
public function getLabelRowSpacing() { return $this->labelSpacingV; } public function getLabelRowSpacing() { return $this->labelSpacingV; }
public function getSupportAssetTag() { return false; }
public function getSupport1DBarcode() { return true; } public function getSupport1DBarcode() { return true; }
public function getSupport2DBarcode() { return true; } public function getSupport2DBarcode() { return true; }
public function getSupportFields() { return 4; } public function getSupportFields() { return 4; }

View file

@ -65,6 +65,13 @@ abstract class Label
*/ */
public abstract function getMarginRight(); public abstract function getMarginRight();
/**
* Returns whether the template supports an asset tag.
*
* @return bool
*/
public abstract function getSupportAssetTag();
/** /**
* Returns whether the template supports a 1D barcode. * Returns whether the template supports a 1D barcode.
* *

View file

@ -0,0 +1,100 @@
<?php
namespace App\Models\Labels\Sheets\Avery;
class L7162_A extends L7162
{
private const BARCODE_MARGIN = 1.60;
private const TAG_SIZE = 4.60;
private const TITLE_SIZE = 4.20;
private const TITLE_MARGIN = 1.40;
private const LABEL_SIZE = 2.20;
private const LABEL_MARGIN = - 0.50;
private const FIELD_SIZE = 4.60;
private const FIELD_MARGIN = 0.30;
public function getUnit() { return 'mm'; }
public function getLabelMarginTop() { return 1.0; }
public function getLabelMarginBottom() { return 1.0; }
public function getLabelMarginLeft() { return 1.0; }
public function getLabelMarginRight() { return 1.0; }
public function getSupportAssetTag() { return true; }
public function getSupport1DBarcode() { return false; }
public function getSupport2DBarcode() { return true; }
public function getSupportFields() { return 4; }
public function getSupportLogo() { return false; }
public function getSupportTitle() { return true; }
public function preparePDF($pdf) {}
public function write($pdf, $record) {
$pa = $this->getLabelPrintableArea();
$usableWidth = $pa->w;
$usableHeight = $pa->h;
$currentX = $pa->x1;
$currentY = $pa->y1;
$titleShiftX = 0;
$barcodeSize = $pa->h - self::TAG_SIZE;
if ($record->has('barcode2d')) {
static::writeText(
$pdf, $record->get('tag'),
$pa->x1, $pa->y2 - self::TAG_SIZE,
'freemono', 'b', self::TAG_SIZE, 'C',
$barcodeSize, self::TAG_SIZE, true, 0
);
static::write2DBarcode(
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
$pa->x1, $pa->y1,
$barcodeSize, $barcodeSize
);
$currentX += $barcodeSize + self::BARCODE_MARGIN;
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
} else {
static::writeText(
$pdf, $record->get('tag'),
$pa->x1, $pa->y1,
'freemono', 'b', self::TITLE_SIZE, 'L',
$barcodeSize, self::TITLE_SIZE, true, 0
);
$titleShiftX = $barcodeSize;
}
if ($record->has('title')) {
static::writeText(
$pdf, $record->get('title'),
$currentX + $titleShiftX, $currentY,
'freesans', '', self::TITLE_SIZE, 'L',
$usableWidth, self::TITLE_SIZE, true, 0
);
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
}
foreach ($record->get('fields') as $label => $value) {
static::writeText(
$pdf, $label,
$currentX, $currentY,
'freesans', '', self::LABEL_SIZE, 'L',
$usableWidth, self::LABEL_SIZE, true, 0
);
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
static::writeText(
$pdf, $value,
$currentX, $currentY,
'freemono', 'B', self::FIELD_SIZE, 'L',
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
);
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
}
}
}
?>

View file

@ -0,0 +1,103 @@
<?php
namespace App\Models\Labels\Sheets\Avery;
class L7162_B extends L7162
{
private const BARCODE_SIZE = 6.00;
private const BARCODE_MARGIN = 1.40;
private const TAG_SIZE = 3.20;
private const LOGO_MAX_WIDTH = 25.00;
private const LOGO_MARGIN = 2.20;
private const TITLE_SIZE = 4.20;
private const TITLE_MARGIN = 1.20;
private const LABEL_SIZE = 2.20;
private const LABEL_MARGIN = - 0.50;
private const FIELD_SIZE = 4.20;
private const FIELD_MARGIN = 0.30;
public function getUnit() { return 'mm'; }
public function getLabelMarginTop() { return 1.0; }
public function getLabelMarginBottom() { return 0; }
public function getLabelMarginLeft() { return 1.0; }
public function getLabelMarginRight() { return 1.0; }
public function getSupportAssetTag() { return true; }
public function getSupport1DBarcode() { return true; }
public function getSupport2DBarcode() { return false; }
public function getSupportFields() { return 3; }
public function getSupportLogo() { return true; }
public function getSupportTitle() { return true; }
public function preparePDF($pdf) {}
public function write($pdf, $record) {
$pa = $this->getLabelPrintableArea();
$usableWidth = $pa->w;
$usableHeight = $pa->h;
$currentX = $pa->x1;
$currentY = $pa->y1;
if ($record->has('barcode1d')) {
static::write1DBarcode(
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
$pa->x1, $pa->y2 - self::BARCODE_SIZE,
$usableWidth, self::BARCODE_SIZE
);
$usableHeight -= self::BARCODE_SIZE + self::BARCODE_MARGIN;
}
if ($record->has('logo')) {
$logoSize = static::writeImage(
$pdf, $record->get('logo'),
$pa->x1, $pa->y1,
self::LOGO_MAX_WIDTH, $usableHeight,
'L', 'T', 300, true, false, 0.1
);
$currentX += $logoSize[0] + self::LOGO_MARGIN;
$usableWidth -= $logoSize[0] + self::LOGO_MARGIN;
}
if ($record->has('title')) {
static::writeText(
$pdf, $record->get('title'),
$currentX, $currentY,
'freesans', '', self::TITLE_SIZE, 'L',
$usableWidth, self::TITLE_SIZE, true, 0
);
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
}
foreach ($record->get('fields') as $label => $value) {
static::writeText(
$pdf, $label,
$currentX, $currentY,
'freesans', '', self::LABEL_SIZE, 'L',
$usableWidth, self::LABEL_SIZE, true, 0
);
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
static::writeText(
$pdf, $value,
$currentX, $currentY,
'freemono', 'B', self::FIELD_SIZE, 'L',
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
);
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
}
static::writeText(
$pdf, $record->get('tag'),
$currentX, $pa->y2 - self::BARCODE_SIZE - self::BARCODE_MARGIN - self::TAG_SIZE,
'freemono', 'b', self::TAG_SIZE, 'R',
$usableWidth, self::TAG_SIZE, true, 0, 0.3
);
}
}
?>

View file

@ -1,91 +0,0 @@
<?php
namespace App\Models\Labels\Sheets\Avery;
class L7162_Example extends L7162
{
private const BARCODE1D_SIZE = 6.0;
private const LOGO_MAX_WIDTH = 25.0;
private const LOGO_MARGIN = 1.4;
private const TITLE_SIZE = 4.0;
private const TITLE_MARGIN = 1.6;
private const LABEL_SIZE = 2.2;
private const LABEL_MARGIN = -0.5;
private const FIELD_SIZE = 4.8;
private const FIELD_MARGIN = 0.3;
public function getUnit() { return 'mm'; }
public function getLabelMarginTop() { return 1.0; }
public function getLabelMarginBottom() { return 0; }
public function getLabelMarginLeft() { return 1.0; }
public function getLabelMarginRight() { return 1.0; }
public function getSupport1DBarcode() { return true; }
public function getSupport2DBarcode() { return false; }
public function getSupportFields() { return 3; }
public function getSupportLogo() { return true; }
public function getSupportTitle() { return true; }
public function preparePDF($pdf) {}
public function write($pdf, $record) {
$pa = $this->getLabelPrintableArea();
$x = $pa->x1;
$y = $pa->y1;
$w = $pa->w;
static::write1DBarcode(
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
$pa->x1, $pa->y2 - self::BARCODE1D_SIZE,
$pa->w, self::BARCODE1D_SIZE
);
if ($record->get('logo')) {
$logoMaxHeight = $pa->h - self::BARCODE1D_SIZE - self::LOGO_MARGIN;
$logoSize = static::writeImage(
$pdf, $record->get('logo'),
$x, $y,
self::LOGO_MAX_WIDTH, $logoMaxHeight,
'L', 'T', 300,
true, false, 0
);
$x += $logoSize[0] + self::LOGO_MARGIN;
$w -= ($logoSize[0] + self::LOGO_MARGIN);
}
if ($record->get('title')) {
static::writeText(
$pdf, $record->get('title'),
$x, $y,
'freesans', '', self::TITLE_SIZE, 'L',
$w, self::TITLE_SIZE, true, 0
);
$y += self::TITLE_SIZE + self::TITLE_MARGIN;
}
foreach ($record->get('fields') as $label => $value) {
static::writeText(
$pdf, $label,
$x, $y,
'freesans', '', self::LABEL_SIZE, 'L',
$w, self::LABEL_SIZE, true, 0
);
$y += self::LABEL_SIZE + self::LABEL_MARGIN;
static::writeText(
$pdf, $value,
$x, $y,
'freemono', 'B', self::FIELD_SIZE, 'L',
$w, self::FIELD_SIZE, true, 0, 0.3
);
$y += self::FIELD_SIZE + self::FIELD_MARGIN;
}
}
}
?>

View file

@ -1,77 +0,0 @@
<?php
namespace App\Models\Labels\Sheets\Avery;
class L7162_Example_QR extends L7162
{
private const BARCODE1D_SIZE = 6.0;
private const BARCODE2D_MARGIN = 1.4;
private const TITLE_SIZE = 4.0;
private const TITLE_MARGIN = 1.6;
private const LABEL_SIZE = 2.2;
private const LABEL_MARGIN = - 0.5;
private const FIELD_SIZE = 4.8;
private const FIELD_MARGIN = 0.3;
public function getUnit() { return 'mm'; }
public function getLabelMarginTop() { return 1.0; }
public function getLabelMarginBottom() { return 1.0; }
public function getLabelMarginLeft() { return 1.0; }
public function getLabelMarginRight() { return 1.0; }
public function getSupport1DBarcode() { return false; }
public function getSupport2DBarcode() { return true; }
public function getSupportFields() { return 4; }
public function getSupportLogo() { return false; }
public function getSupportTitle() { return true; }
public function preparePDF($pdf) {}
public function write($pdf, $record) {
$pa = $this->getLabelPrintableArea();
static::write2DBarcode(
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
$pa->x1, $pa->y1,
$pa->h, $pa->h
);
$x = $pa->x1 + $pa->h + self::BARCODE2D_MARGIN;
$y = $pa->y1;
$w = $pa->w - $pa->h - self::BARCODE2D_MARGIN;
if ($record->get('title')) {
static::writeText(
$pdf, $record->get('title'),
$x, $y,
'freesans', '', self::TITLE_SIZE, 'L',
$w, self::TITLE_SIZE, true, 0
);
$y += self::TITLE_SIZE + self::TITLE_MARGIN;
}
foreach ($record->get('fields') as $label => $value) {
static::writeText(
$pdf, $label,
$x, $y,
'freesans', '', self::LABEL_SIZE, 'L',
$w, self::LABEL_SIZE, true, 0
);
$y += self::LABEL_SIZE + self::LABEL_MARGIN;
static::writeText(
$pdf, $value,
$x, $y,
'freemono', 'B', self::FIELD_SIZE, 'L',
$w, self::FIELD_SIZE, true, 0, 0.3
);
$y += self::FIELD_SIZE + self::FIELD_MARGIN;
}
}
}
?>

View file

@ -10,6 +10,7 @@ class TZe_12mm_A extends TZe_12mm
public function getUnit() { return 'mm'; } public function getUnit() { return 'mm'; }
public function getWidth() { return 50.0; } public function getWidth() { return 50.0; }
public function getSupportAssetTag() { return false; }
public function getSupport1DBarcode() { return true; } public function getSupport1DBarcode() { return true; }
public function getSupport2DBarcode() { return false; } public function getSupport2DBarcode() { return false; }
public function getSupportFields() { return 2; } public function getSupportFields() { return 2; }

View file

@ -14,6 +14,7 @@ class TZe_24mm_A extends TZe_24mm
public function getUnit() { return 'mm'; } public function getUnit() { return 'mm'; }
public function getWidth() { return 65.0; } public function getWidth() { return 65.0; }
public function getSupportAssetTag() { return false; }
public function getSupport1DBarcode() { return false; } public function getSupport1DBarcode() { return false; }
public function getSupport2DBarcode() { return true; } public function getSupport2DBarcode() { return true; }
public function getSupportFields() { return 3; } public function getSupportFields() { return 3; }

View file

@ -48,6 +48,14 @@ class LabelPresenter extends Presenter
'switchable' => true, 'switchable' => true,
'title' => trans('admin/labels/table.support_fields'), 'title' => trans('admin/labels/table.support_fields'),
'visible' => true 'visible' => true
], [
'field' => 'support_asset_tag',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/labels/table.support_asset_tag'),
'visible' => true,
'formatter' => 'trueFalseFormatter'
], [ ], [
'field' => 'support_1d_barcode', 'field' => 'support_1d_barcode',
'searchable' => false, 'searchable' => false,

View file

@ -4,6 +4,7 @@ return [
'labels_per_page' => 'Labels', 'labels_per_page' => 'Labels',
'support_fields' => 'Fields', 'support_fields' => 'Fields',
'support_asset_tag' => 'Tag',
'support_1d_barcode' => '1D', 'support_1d_barcode' => '1D',
'support_2d_barcode' => '2D', 'support_2d_barcode' => '2D',
'support_logo' => 'Logo', 'support_logo' => 'Logo',