ok
This commit is contained in:
186
Production/SNIPE-IT/app/Models/Labels/DefaultLabel.php
Normal file
186
Production/SNIPE-IT/app/Models/Labels/DefaultLabel.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Setting;
|
||||
|
||||
class DefaultLabel extends RectangleSheet
|
||||
{
|
||||
private const BARCODE1D_SIZE = 0.15;
|
||||
|
||||
private const BARCODE2D_SIZE = 0.76;
|
||||
private const BARCODE2D_MARGIN = 0.075;
|
||||
|
||||
private const LOGO_SIZE = [0.75, 0.50];
|
||||
private const LOGO_MARGIN = 0.05;
|
||||
|
||||
private const TEXT_MARGIN = 0.04;
|
||||
|
||||
|
||||
private float $textSize;
|
||||
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
private float $labelSpacingH;
|
||||
private float $labelSpacingV;
|
||||
|
||||
private float $pageMarginTop;
|
||||
private float $pageMarginBottom;
|
||||
private float $pageMarginLeft;
|
||||
private float $pageMarginRight;
|
||||
|
||||
private float $pageWidth;
|
||||
private float $pageHeight;
|
||||
|
||||
private int $columns;
|
||||
private int $rows;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$settings = Setting::getSettings();
|
||||
|
||||
$this->textSize = Helper::convertUnit($settings->labels_fontsize, 'pt', 'in');
|
||||
|
||||
$this->labelWidth = $settings->labels_width;
|
||||
$this->labelHeight = $settings->labels_height;
|
||||
|
||||
$this->labelSpacingH = $settings->labels_display_sgutter;
|
||||
$this->labelSpacingV = $settings->labels_display_bgutter;
|
||||
|
||||
$this->pageMarginTop = $settings->labels_pmargin_top;
|
||||
$this->pageMarginBottom = $settings->labels_pmargin_bottom;
|
||||
$this->pageMarginLeft = $settings->labels_pmargin_left;
|
||||
$this->pageMarginRight = $settings->labels_pmargin_right;
|
||||
|
||||
$this->pageWidth = $settings->labels_pagewidth;
|
||||
$this->pageHeight = $settings->labels_pageheight;
|
||||
|
||||
$usableWidth = $this->pageWidth - $this->pageMarginLeft - $this->pageMarginRight;
|
||||
$usableHeight = $this->pageHeight - $this->pageMarginTop - $this->pageMarginBottom;
|
||||
|
||||
$this->columns = ($usableWidth + $this->labelSpacingH) / ($this->labelWidth + $this->labelSpacingH);
|
||||
$this->rows = ($usableHeight + $this->labelSpacingV) / ($this->labelHeight + $this->labelSpacingV);
|
||||
|
||||
// Make sure the columns and rows are never zero, since that scenario should never happen
|
||||
if ($this->columns == 0) {
|
||||
$this->columns = 1;
|
||||
}
|
||||
|
||||
if ($this->rows == 0) {
|
||||
$this->rows = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginBottom; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginRight; }
|
||||
|
||||
public function getColumns() { return $this->columns; }
|
||||
public function getRows() { return $this->rows; }
|
||||
public function getLabelBorder() { return 0; }
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
|
||||
public function getLabelMarginTop() { return 0; }
|
||||
public function getLabelMarginBottom() { return 0; }
|
||||
public function getLabelMarginLeft() { return 0; }
|
||||
public function getLabelMarginRight() { return 0; }
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->labelSpacingH; }
|
||||
public function getLabelRowSpacing() { return $this->labelSpacingV; }
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 4; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportLogo() { return true; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
|
||||
$asset = $record->get('asset');
|
||||
$settings = Setting::getSettings();
|
||||
|
||||
$textY = 0;
|
||||
$textX1 = 0;
|
||||
$textX2 = $this->getLabelWidth();
|
||||
|
||||
// 1D Barcode
|
||||
if ($record->get('barcode1d')) {
|
||||
static::write1DBarcode(
|
||||
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
|
||||
0.05, $this->getLabelHeight() - self::BARCODE1D_SIZE,
|
||||
$this->getLabelWidth() - 0.1, self::BARCODE1D_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
// 2D Barcode
|
||||
if ($record->get('barcode2d')) {
|
||||
static::write2DBarcode(
|
||||
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
|
||||
0, 0, self::BARCODE2D_SIZE, self::BARCODE2D_SIZE
|
||||
);
|
||||
$textX1 += self::BARCODE2D_SIZE + self::BARCODE2D_MARGIN;
|
||||
}
|
||||
|
||||
// Logo
|
||||
if ($record->get('logo')) {
|
||||
$logoSize = static::writeImage(
|
||||
$pdf, $record->get('logo'),
|
||||
$this->labelWidth - self::LOGO_SIZE[0], 0,
|
||||
self::LOGO_SIZE[0], self::LOGO_SIZE[1],
|
||||
'R', 'T', 300, true, false, 0
|
||||
);
|
||||
$textX2 -= ($logoSize[0] + self::LOGO_MARGIN);
|
||||
}
|
||||
|
||||
$textW = $textX2 - $textX1;
|
||||
|
||||
// Title
|
||||
if ($record->get('title')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('title'),
|
||||
$textX1, 0,
|
||||
'freesans', 'b', $this->textSize, 'L',
|
||||
$textW, $this->textSize,
|
||||
true, 0
|
||||
);
|
||||
$textY += $this->textSize + self::TEXT_MARGIN;
|
||||
}
|
||||
|
||||
// Render the selected fields with their labels
|
||||
$fieldsDone = 0;
|
||||
if ($fieldsDone < $this->getSupportFields()) {
|
||||
|
||||
foreach ($record->get('fields') as $field) {
|
||||
|
||||
// Actually write the selected fields and their matching values
|
||||
static::writeText(
|
||||
$pdf, (($field['label']) ? $field['label'].' ' : '') . $field['value'],
|
||||
$textX1, $textY,
|
||||
'freesans', '', $this->textSize, 'L',
|
||||
$textW, $this->textSize,
|
||||
true, 0
|
||||
);
|
||||
|
||||
$textY += $this->textSize + self::TEXT_MARGIN;
|
||||
$fieldsDone++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
41
Production/SNIPE-IT/app/Models/Labels/Field.php
Normal file
41
Production/SNIPE-IT/app/Models/Labels/Field.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels;
|
||||
|
||||
use App\Models\Asset;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Field {
|
||||
protected Collection $options;
|
||||
public function getOptions() { return $this->options; }
|
||||
public function setOptions($options) {
|
||||
$tempCollect = collect($options);
|
||||
if (!$tempCollect->contains(fn($o) => !is_subclass_of($o, FieldOption::class))) {
|
||||
$this->options = $options;
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray(Asset $asset) { return Field::makeArray($this, $asset); }
|
||||
|
||||
/* Statics */
|
||||
|
||||
public static function makeArray(Field $field, Asset $asset) {
|
||||
return $field->getOptions()
|
||||
// filter out any FieldOptions that are accidentally null
|
||||
->filter()
|
||||
->map(fn($option) => $option->toArray($asset))
|
||||
->filter(fn($result) => $result['value'] != null);
|
||||
}
|
||||
|
||||
public static function makeString(Field $option) {
|
||||
return implode('|', $option->getOptions());
|
||||
}
|
||||
|
||||
public static function fromString(string $theString) {
|
||||
$field = new Field();
|
||||
$field->options = collect(explode('|', $theString))
|
||||
->filter(fn($optionString) => !empty($optionString))
|
||||
->map(fn($optionString) => FieldOption::fromString($optionString));
|
||||
return $field;
|
||||
}
|
||||
}
|
63
Production/SNIPE-IT/app/Models/Labels/FieldOption.php
Normal file
63
Production/SNIPE-IT/app/Models/Labels/FieldOption.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels;
|
||||
|
||||
use App\Models\Asset;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class FieldOption {
|
||||
protected string $label;
|
||||
public function getLabel() { return $this->label; }
|
||||
|
||||
protected string $dataSource;
|
||||
public function getDataSource() { return $this->dataSource; }
|
||||
|
||||
public function getValue(Asset $asset) {
|
||||
$dataPath = collect(explode('.', $this->dataSource));
|
||||
|
||||
// assignedTo directly on the asset is a special case where
|
||||
// we want to avoid returning the property directly
|
||||
// and instead return the entity's presented name.
|
||||
if ($dataPath[0] === 'assignedTo') {
|
||||
if ($asset->relationLoaded('assignedTo')) {
|
||||
// If the "assignedTo" relationship was eager loaded then the way to get the
|
||||
// relationship changes from $asset->assignedTo to $asset->assigned.
|
||||
return $asset->assigned ? $asset->assigned->present()->fullName() : null;
|
||||
}
|
||||
|
||||
return $asset->assignedTo ? $asset->assignedTo->present()->fullName() : null;
|
||||
}
|
||||
|
||||
return $dataPath->reduce(function ($myValue, $path) {
|
||||
try { return $myValue ? $myValue->{$path} : ${$myValue}; }
|
||||
catch (\Exception $e) { return $myValue; }
|
||||
}, $asset);
|
||||
}
|
||||
|
||||
public function toArray(Asset $asset=null) { return FieldOption::makeArray($this, $asset); }
|
||||
public function toString() { return FieldOption::makeString($this); }
|
||||
|
||||
/* Statics */
|
||||
|
||||
public static function makeArray(FieldOption $option, Asset $asset=null) {
|
||||
return [
|
||||
'label' => $option->getLabel(),
|
||||
'dataSource' => $option->getDataSource(),
|
||||
'value' => $asset ? $option->getValue($asset) : null
|
||||
];
|
||||
}
|
||||
|
||||
public static function makeString(FieldOption $option) {
|
||||
return $option->getLabel() . '=' . $option->getDataSource();
|
||||
}
|
||||
|
||||
public static function fromString(string $theString) {
|
||||
$parts = explode('=', $theString);
|
||||
if (count($parts) == 2) {
|
||||
$option = new FieldOption();
|
||||
$option->label = $parts[0];
|
||||
$option->dataSource = $parts[1];
|
||||
return $option;
|
||||
}
|
||||
}
|
||||
}
|
603
Production/SNIPE-IT/app/Models/Labels/Label.php
Normal file
603
Production/SNIPE-IT/app/Models/Labels/Label.php
Normal file
@ -0,0 +1,603 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use TCPDF;
|
||||
use TCPDF_STATIC;
|
||||
use TypeError;
|
||||
|
||||
/**
|
||||
* Model for Labels.
|
||||
*
|
||||
* @version v1.0
|
||||
*/
|
||||
abstract class Label
|
||||
{
|
||||
/**
|
||||
* Returns the unit of measure used
|
||||
* 'pt', 'mm', 'cm', 'in'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public abstract function getUnit();
|
||||
|
||||
/**
|
||||
* Returns the label's width in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getWidth();
|
||||
|
||||
/**
|
||||
* Returns the label's height in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getHeight();
|
||||
|
||||
/**
|
||||
* Returns the label's top margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getMarginTop();
|
||||
|
||||
/**
|
||||
* Returns the label's bottom margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getMarginBottom();
|
||||
|
||||
/**
|
||||
* Returns the label's left margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getMarginLeft();
|
||||
|
||||
/**
|
||||
* Returns the label's right margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public abstract function getSupport1DBarcode();
|
||||
|
||||
/**
|
||||
* Returns whether the template supports a 2D barcode.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public abstract function getSupport2DBarcode();
|
||||
|
||||
/**
|
||||
* Returns the number of fields the template supports.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function getSupportFields();
|
||||
|
||||
/**
|
||||
* Returns whether the template supports a logo.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public abstract function getSupportLogo();
|
||||
|
||||
/**
|
||||
* Returns whether the template supports a title.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public abstract function getSupportTitle();
|
||||
|
||||
/**
|
||||
* Make changes to the PDF properties here. OPTIONAL.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
*/
|
||||
public abstract function preparePDF(TCPDF $pdf);
|
||||
|
||||
/**
|
||||
* Write single data record as content here.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $record A data record
|
||||
*/
|
||||
public abstract function write(TCPDF $pdf, Collection $record);
|
||||
|
||||
/**
|
||||
* Handle the data here. Override for multiple-per-page handling
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $data The data
|
||||
*/
|
||||
public function writeAll(TCPDF $pdf, Collection $data) {
|
||||
$data->each(function ($record, $index) use ($pdf) {
|
||||
$pdf->AddPage();
|
||||
$this->write($pdf, $record);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the qualified class name relative to the Label class's namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getName() {
|
||||
$refClass = new \ReflectionClass(Label::class);
|
||||
return str_replace($refClass->getNamespaceName() . '\\', '', get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label's orientation as a string.
|
||||
* 'L' = Landscape
|
||||
* 'P' = Portrait
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getOrientation() {
|
||||
return ($this->getWidth() >= $this->getHeight()) ? 'L' : 'P';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label's printable area as an object.
|
||||
*
|
||||
* @return object [ 'x1'=>0.00, 'y1'=>0.00, 'x2'=>0.00, 'y2'=>0.00, 'w'=>0.00, 'h'=>0.00 ]
|
||||
*/
|
||||
public final function getPrintableArea() {
|
||||
return (object)[
|
||||
'x1' => $this->getMarginLeft(),
|
||||
'y1' => $this->getMarginTop(),
|
||||
'x2' => $this->getWidth() - $this->getMarginRight(),
|
||||
'y2' => $this->getHeight() - $this->getMarginBottom(),
|
||||
'w' => $this->getWidth() - $this->getMarginLeft() - $this->getMarginRight(),
|
||||
'h' => $this->getHeight() - $this->getMarginTop() - $this->getMarginBottom(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a text cell.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $text The text to write. Supports 'some **bold** text'.
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param string $font The font family
|
||||
* @param string $style The font style
|
||||
* @param int $size The font size in getUnit() units
|
||||
* @param string $align Align text in the box. 'L' left, 'R' right, 'C' center.
|
||||
* @param float $width Force text box width. NULL to auto-fit.
|
||||
* @param float $height Force text box height. NULL to auto-fit.
|
||||
* @param bool $squash Squash text if it's too big
|
||||
* @param int $border Thickness of border. Default = 0.
|
||||
* @param int $spacing Letter spacing. Default = 0.
|
||||
*/
|
||||
public final function writeText(TCPDF $pdf, $text, $x, $y, $font=null, $style=null, $size=null, $align='L', $width=null, $height=null, $squash=false, $border=0, $spacing=0) {
|
||||
$prevFamily = $pdf->getFontFamily();
|
||||
$prevStyle = $pdf->getFontStyle();
|
||||
$prevSizePt = $pdf->getFontSizePt();
|
||||
|
||||
$text = !empty($text) ? $text : '';
|
||||
|
||||
$fontFamily = !empty($font) ? $font : $prevFamily;
|
||||
$fontStyle = !empty($style) ? $style : $prevStyle;
|
||||
if ($size) $fontSizePt = Helper::convertUnit($size, $this->getUnit(), 'pt', true);
|
||||
else $fontSizePt = $prevSizePt;
|
||||
|
||||
$pdf->SetFontSpacing($spacing);
|
||||
|
||||
$parts = collect(explode('**', $text))
|
||||
->map(function ($part, $index) use ($pdf, $fontFamily, $fontStyle, $fontSizePt) {
|
||||
$modStyle = ($index % 2 == 1) ? 'B' : $fontStyle;
|
||||
$pdf->setFont($fontFamily, $modStyle, $fontSizePt);
|
||||
return [
|
||||
'text' => $part,
|
||||
'text_width' => $pdf->GetStringWidth($part),
|
||||
'font_family' => $fontFamily,
|
||||
'font_style' => $modStyle,
|
||||
'font_size' => $fontSizePt,
|
||||
];
|
||||
});
|
||||
|
||||
$textWidth = $parts->reduce(function ($carry, $part) { return $carry += $part['text_width']; });
|
||||
$cellWidth = !empty($width) ? $width : $textWidth;
|
||||
|
||||
if ($squash && ($textWidth > 0)) {
|
||||
$scaleFactor = min(1.0, $cellWidth / $textWidth);
|
||||
$parts = $parts->map(function ($part, $index) use ($scaleFactor) {
|
||||
$part['text_width'] = $part['text_width'] * $scaleFactor;
|
||||
return $part;
|
||||
});
|
||||
}
|
||||
$cellHeight = !empty($height) ? $height : Helper::convertUnit($fontSizePt, 'pt', $this->getUnit());
|
||||
|
||||
if ($border) {
|
||||
$prevLineWidth = $pdf->getLineWidth();
|
||||
$pdf->setLineWidth($border);
|
||||
$pdf->Rect($x, $y, $cellWidth, $cellHeight);
|
||||
$pdf->setLineWidth($prevLineWidth);
|
||||
}
|
||||
|
||||
switch($align) {
|
||||
case 'R': $startX = ($x + $cellWidth) - min($cellWidth, $textWidth); break;
|
||||
case 'C': $startX = ($x + ($cellWidth / 2)) - (min($cellWidth, $textWidth) / 2); break;
|
||||
case 'L':
|
||||
default: $startX = $x; break;
|
||||
}
|
||||
|
||||
$parts->reduce(function ($currentX, $part) use ($pdf, $y, $cellHeight) {
|
||||
$pdf->SetXY($currentX, $y);
|
||||
$pdf->setFont($part['font_family'], $part['font_style'], $part['font_size']);
|
||||
$pdf->Cell($part['text_width'], $cellHeight, $part['text'], 0, 0, '', false, '', 1, true);
|
||||
return $currentX += $part['text_width'];
|
||||
}, $startX);
|
||||
|
||||
$pdf->SetFont($prevFamily, $prevStyle, $prevSizePt);
|
||||
$pdf->SetFontSpacing(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an image.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $image The image to write
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
* @param string $halign Align text in the box. 'L' left, 'R' right, 'C' center. Default 'L'.
|
||||
* @param string $valign Align text in the box. 'T' top, 'B' bottom, 'C' center. Default 'T'.
|
||||
* @param int $dpi Pixels per inch
|
||||
* @param bool $resize Resize to fit container
|
||||
* @param bool $stretch Stretch (vs Scale) to fit container
|
||||
* @param int $border Thickness of border. Default = 0.
|
||||
*
|
||||
* @return array Returns the final calculated size [w,h]
|
||||
*/
|
||||
public final function writeImage(TCPDF $pdf, $image, $x, $y, $width=null, $height=null, $halign='L', $valign='L', $dpi=300, $resize=false, $stretch=false, $border=0) {
|
||||
|
||||
if (empty($image)) return [0,0];
|
||||
|
||||
$imageInfo = getimagesize($image);
|
||||
if (!$imageInfo) return [0,0]; // TODO: SVG or other
|
||||
|
||||
$imageWidthPx = $imageInfo[0];
|
||||
$imageHeightPx = $imageInfo[1];
|
||||
$imageType = image_type_to_extension($imageInfo[2], false);
|
||||
|
||||
$imageRatio = $imageWidthPx / $imageHeightPx;
|
||||
$dpu = Helper::convertUnit($dpi, $this->getUnit(), 'in');
|
||||
$imageWidth = $imageWidthPx / $dpu;
|
||||
$imageHeight = $imageHeightPx / $dpu;
|
||||
|
||||
$outputWidth = $imageWidth;
|
||||
$outputHeight = $imageHeight;
|
||||
|
||||
if ($resize) {
|
||||
// Assign specified parameters
|
||||
$limitWidth = $width;
|
||||
$limitHeight = $height;
|
||||
|
||||
// If not, try calculating from the other dimension
|
||||
$limitWidth = ($limitWidth > 0) ? $limitWidth : ($limitHeight / $imageRatio);
|
||||
$limitHeight = ($limitHeight > 0) ? $limitHeight : ($limitWidth * $imageRatio);
|
||||
|
||||
// If not, just use the image size
|
||||
$limitWidth = ($limitWidth > 0) ? $limitWidth : $imageWidth;
|
||||
$limitHeight = ($limitHeight > 0) ? $limitHeight : $imageHeight;
|
||||
|
||||
$scaleWidth = $limitWidth / $imageWidth;
|
||||
$scaleHeight = $limitHeight / $imageHeight;
|
||||
|
||||
// If non-stretch, make both scales factors equal
|
||||
if (!$stretch) {
|
||||
// Do we need to scale down at all? That's most important.
|
||||
if (($scaleWidth < 1.0) || ($scaleHeight < 1.0)) {
|
||||
// Choose largest scale-down
|
||||
$scaleWidth = min($scaleWidth, $scaleHeight);
|
||||
} else {
|
||||
// Choose smallest scale-up
|
||||
$scaleWidth = min(max($scaleWidth, 1.0), max($scaleHeight, 1.0));
|
||||
}
|
||||
$scaleHeight = $scaleWidth;
|
||||
}
|
||||
|
||||
$outputWidth = $imageWidth * $scaleWidth;
|
||||
$outputHeight = $imageHeight * $scaleHeight;
|
||||
}
|
||||
|
||||
// Container
|
||||
$containerWidth = !empty($width) ? $width : $outputWidth;
|
||||
$containerHeight = !empty($height) ? $height : $outputHeight;
|
||||
|
||||
// Horizontal Position
|
||||
switch ($halign) {
|
||||
case 'R': $originX = ($x + $containerWidth) - $outputWidth; break;
|
||||
case 'C': $originX = ($x + ($containerWidth / 2)) - ($outputWidth / 2); break;
|
||||
case 'L':
|
||||
default: $originX = $x; break;
|
||||
}
|
||||
|
||||
// Vertical Position
|
||||
switch ($valign) {
|
||||
case 'B': $originY = ($y + $containerHeight) - $outputHeight; break;
|
||||
case 'C': $originY = ($y + ($containerHeight / 2)) - ($outputHeight / 2); break;
|
||||
case 'T':
|
||||
default: $originY = $y; break;
|
||||
}
|
||||
|
||||
// Actual Image
|
||||
$pdf->Image($image, $originX, $originY, $outputWidth, $outputHeight, $imageType, '', '', true);
|
||||
|
||||
// Border
|
||||
if ($border) {
|
||||
$prevLineWidth = $pdf->getLineWidth();
|
||||
$pdf->setLineWidth($border);
|
||||
$pdf->Rect($x, $y, $containerWidth, $containerHeight);
|
||||
$pdf->setLineWidth($prevLineWidth);
|
||||
}
|
||||
|
||||
return [ $outputWidth, $outputHeight ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a 1D barcode.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $value The barcode content
|
||||
* @param string $type The barcode type
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
*/
|
||||
public final function write1DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height) {
|
||||
if (empty($value)) return;
|
||||
try {
|
||||
$pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
|
||||
} catch (\Exception|TypeError $e) {
|
||||
\Log::debug('The 1D barcode ' . $value . ' is not compliant with the barcode type '. $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a 2D barcode.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $value The barcode content
|
||||
* @param string $type The barcode type
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
*/
|
||||
public final function write2DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height) {
|
||||
if (empty($value)) return;
|
||||
$pdf->write2DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks the template is internally valid
|
||||
*/
|
||||
public final function validate() {
|
||||
$this->validateUnits();
|
||||
$this->validateSize();
|
||||
$this->validateMargins();
|
||||
$this->validateSupport();
|
||||
}
|
||||
|
||||
private function validateUnits() {
|
||||
$validUnits = [ 'pt', 'mm', 'cm', 'in' ];
|
||||
$unit = $this->getUnit();
|
||||
if (!in_array(strtolower($unit), $validUnits)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_value', [
|
||||
'name' => 'getUnit()',
|
||||
'expected' => '[ \''.implode('\', \'', $validUnits).'\' ]',
|
||||
'actual' => '\''.$unit.'\''
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
private function validateSize() {
|
||||
$width = $this->getWidth();
|
||||
if (!is_numeric($width) || is_string($width)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getWidth()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($width)
|
||||
]));
|
||||
}
|
||||
|
||||
$height = $this->getHeight();
|
||||
if (!is_numeric($height) || is_string($height)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getHeight()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($height)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
private function validateMargins() {
|
||||
$marginTop = $this->getMarginTop();
|
||||
if (!is_numeric($marginTop) || is_string($marginTop)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginTop()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginTop)
|
||||
]));
|
||||
}
|
||||
|
||||
$marginBottom = $this->getMarginBottom();
|
||||
if (!is_numeric($marginBottom) || is_string($marginBottom)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginBottom()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginBottom)
|
||||
]));
|
||||
}
|
||||
|
||||
$marginLeft = $this->getMarginLeft();
|
||||
if (!is_numeric($marginLeft) || is_string($marginLeft)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginLeft()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginLeft)
|
||||
]));
|
||||
}
|
||||
|
||||
$marginRight = $this->getMarginRight();
|
||||
if (!is_numeric($marginRight) || is_string($marginRight)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginRight()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginRight)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
private function validateSupport() {
|
||||
$support1D = $this->getSupport1DBarcode();
|
||||
if (!is_bool($support1D)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupport1DBarcode()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($support1D)
|
||||
]));
|
||||
}
|
||||
|
||||
$support2D = $this->getSupport2DBarcode();
|
||||
if (!is_bool($support2D)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupport2DBarcode()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($support2D)
|
||||
]));
|
||||
}
|
||||
|
||||
$supportFields = $this->getSupportFields();
|
||||
if (!is_int($supportFields)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportFields()',
|
||||
'expected' => 'integer',
|
||||
'actual' => gettype($supportFields)
|
||||
]));
|
||||
}
|
||||
|
||||
$supportLogo = $this->getSupportLogo();
|
||||
if (!is_bool($supportLogo)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportLogo()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($supportLogo)
|
||||
]));
|
||||
}
|
||||
|
||||
$supportTitle = $this->getSupportTitle();
|
||||
if (!is_bool($supportTitle)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportTitle()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($supportTitle)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Public Static Functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find size of a page by its format.
|
||||
*
|
||||
* @param string $format Format name (eg: 'A4', 'LETTER', etc.)
|
||||
* @param string $orientation 'L' for Landscape, 'P' for Portrait ('L' default)
|
||||
* @param string $unit Unit of measure to return in ('mm' default)
|
||||
*
|
||||
* @return object (object)[ 'width' => (float)123.4, 'height' => (float)123.4 ]
|
||||
*/
|
||||
public static function fromFormat($format, $orientation='L', $unit='mm', $round=false) {
|
||||
$size = collect(TCPDF_STATIC::getPageSizeFromFormat(strtoupper($format)))
|
||||
->sort()
|
||||
->map(function ($value) use ($unit) {
|
||||
return Helper::convertUnit($value, 'pt', $unit);
|
||||
})
|
||||
->toArray();
|
||||
$width = ($orientation == 'L') ? $size[1] : $size[0];
|
||||
$height = ($orientation == 'L') ? $size[0] : $size[1];
|
||||
return (object)[
|
||||
'width' => ($round !== false) ? round($width, $round) : $width,
|
||||
'height' => ($round !== false) ? round($height, $round) : $height,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a Label by its path (or just return them all).
|
||||
*
|
||||
* Unlike most Models, these are defined by their existence as non-
|
||||
* abstract classes stored in Models\Labels.
|
||||
*
|
||||
* @param string|Arrayable|array|null $path Label path[s]
|
||||
* @return Collection|Label|null
|
||||
*/
|
||||
public static function find($name=null) {
|
||||
// Find many
|
||||
if (is_array($name) || $name instanceof Arrayable) {
|
||||
$labels = collect($name)
|
||||
->map(function ($thisname) {
|
||||
return static::find($thisname);
|
||||
})
|
||||
->whereNotNull();
|
||||
return ($labels->count() > 0) ? $labels : null;
|
||||
}
|
||||
|
||||
// Find one
|
||||
if ($name !== null) {
|
||||
return static::find()
|
||||
->sole(function ($label) use ($name) {
|
||||
return $label->getName() == $name;
|
||||
});
|
||||
}
|
||||
|
||||
// Find all
|
||||
return collect(File::allFiles(__DIR__))
|
||||
->map(function ($file) {
|
||||
preg_match_all('/\/*(.+?)(?:\/|\.)/', $file->getRelativePathName(), $matches);
|
||||
return __NAMESPACE__ . '\\' . implode('\\', $matches[1]);
|
||||
})
|
||||
->filter(function ($name) {
|
||||
if (!class_exists($name)) return false;
|
||||
$refClass = new \ReflectionClass($name);
|
||||
if ($refClass->isAbstract()) return false;
|
||||
return $refClass->isSubclassOf(Label::class);
|
||||
})
|
||||
->map(function ($name) {
|
||||
return new $name();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
48
Production/SNIPE-IT/app/Models/Labels/RectangleSheet.php
Normal file
48
Production/SNIPE-IT/app/Models/Labels/RectangleSheet.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels;
|
||||
|
||||
abstract class RectangleSheet extends Sheet
|
||||
{
|
||||
/**
|
||||
* Returns the number of columns per sheet
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function getColumns();
|
||||
|
||||
/**
|
||||
* Returns the number of rows per sheet
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function getRows();
|
||||
|
||||
/**
|
||||
* Returns the spacing between columns
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function getLabelColumnSpacing();
|
||||
|
||||
/**
|
||||
* Returns the spacing between rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function getLabelRowSpacing();
|
||||
|
||||
|
||||
public function getLabelsPerPage() { return $this->getColumns() * $this->getRows(); }
|
||||
|
||||
public function getLabelPosition($index) {
|
||||
$printIndex = $index + $this->getLabelIndexOffset();
|
||||
$row = (int)($printIndex / $this->getColumns());
|
||||
$col = $printIndex - ($row * $this->getColumns());
|
||||
$x = $this->getPageMarginLeft() + (($this->getLabelWidth() + $this->getLabelColumnSpacing()) * $col);
|
||||
$y = $this->getPageMarginTop() + (($this->getLabelHeight() + $this->getLabelRowSpacing()) * $row);
|
||||
return [ $x, $y ];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
209
Production/SNIPE-IT/app/Models/Labels/Sheet.php
Normal file
209
Production/SNIPE-IT/app/Models/Labels/Sheet.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels;
|
||||
|
||||
abstract class Sheet extends Label
|
||||
{
|
||||
protected int $indexOffset = 0;
|
||||
|
||||
public function getWidth() { return $this->getPageWidth(); }
|
||||
public function getHeight() { return $this->getPageHeight(); }
|
||||
public function getMarginTop() { return $this->getPageMarginTop(); }
|
||||
public function getMarginBottom() { return $this->getPageMarginBottom(); }
|
||||
public function getMarginLeft() { return $this->getPageMarginLeft(); }
|
||||
public function getMarginRight() { return $this->getPageMarginRight(); }
|
||||
|
||||
/**
|
||||
* Returns the page width in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getPageWidth();
|
||||
|
||||
/**
|
||||
* Returns the page height in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getPageHeight();
|
||||
|
||||
/**
|
||||
* Returns the page top margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getPageMarginTop();
|
||||
|
||||
/**
|
||||
* Returns the page bottom margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getPageMarginBottom();
|
||||
|
||||
/**
|
||||
* Returns the page left margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getPageMarginLeft();
|
||||
|
||||
/**
|
||||
* Returns the page right margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getPageMarginRight();
|
||||
|
||||
/**
|
||||
* Returns the page width in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getLabelWidth();
|
||||
|
||||
/**
|
||||
* Returns each label's height in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getLabelHeight();
|
||||
|
||||
/**
|
||||
* Returns each label's top margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getLabelMarginTop();
|
||||
|
||||
/**
|
||||
* Returns each label's bottom margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getLabelMarginBottom();
|
||||
|
||||
/**
|
||||
* Returns each label's left margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getLabelMarginLeft();
|
||||
|
||||
/**
|
||||
* Returns each label's right margin in getUnit() units
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getLabelMarginRight();
|
||||
|
||||
/**
|
||||
* Returns the number of labels each page supports
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function getLabelsPerPage();
|
||||
|
||||
/**
|
||||
* Returns label position based on its index
|
||||
*
|
||||
* @param int $index
|
||||
*
|
||||
* @return array [x,y]
|
||||
*/
|
||||
public abstract function getLabelPosition(int $index);
|
||||
|
||||
/**
|
||||
* Returns the border to draw around labels
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function getLabelBorder();
|
||||
|
||||
/**
|
||||
* Handle the data here. Override for multiple-per-page handling
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $data The data
|
||||
*/
|
||||
public function writeAll($pdf, $data) {
|
||||
$prevPageNumber = -1;
|
||||
|
||||
foreach ($data->toArray() as $recordIndex => $record) {
|
||||
|
||||
$pageNumber = (int)($recordIndex / $this->getLabelsPerPage());
|
||||
if ($pageNumber != $prevPageNumber) {
|
||||
$pdf->AddPage();
|
||||
$prevPageNumber = $pageNumber;
|
||||
}
|
||||
|
||||
$pageIndex = $recordIndex - ($this->getLabelsPerPage() * $pageNumber);
|
||||
$position = $this->getLabelPosition($pageIndex);
|
||||
|
||||
$pdf->StartTemplate();
|
||||
$this->write($pdf, $data->get($recordIndex));
|
||||
$template = $pdf->EndTemplate();
|
||||
|
||||
$pdf->printTemplate($template, $position[0], $position[1]);
|
||||
|
||||
if ($this->getLabelBorder()) {
|
||||
$prevLineWidth = $pdf->GetLineWidth();
|
||||
|
||||
$borderThickness = $this->getLabelBorder();
|
||||
$borderOffset = $borderThickness / 2;
|
||||
$borderX = $position[0]- $borderOffset;
|
||||
$borderY = $position[1] - $borderOffset;
|
||||
$borderW = $this->getLabelWidth() + $borderThickness;
|
||||
$borderH = $this->getLabelHeight() + $borderThickness;
|
||||
|
||||
$pdf->setLineWidth($borderThickness);
|
||||
$pdf->Rect($borderX, $borderY, $borderW, $borderH);
|
||||
$pdf->setLineWidth($prevLineWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns each label's orientation as a string.
|
||||
* 'L' = Landscape
|
||||
* 'P' = Portrait
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getLabelOrientation() {
|
||||
return ($this->getLabelWidth() >= $this->getLabelHeight()) ? 'L' : 'P';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns each label's printable area as an object.
|
||||
*
|
||||
* @return object [ 'x1'=>0.00, 'y1'=>0.00, 'x2'=>0.00, 'y2'=>0.00, 'w'=>0.00, 'h'=>0.00 ]
|
||||
*/
|
||||
public final function getLabelPrintableArea() {
|
||||
return (object)[
|
||||
'x1' => $this->getLabelMarginLeft(),
|
||||
'y1' => $this->getLabelMarginTop(),
|
||||
'x2' => $this->getLabelWidth() - $this->getLabelMarginRight(),
|
||||
'y2' => $this->getLabelHeight() - $this->getLabelMarginBottom(),
|
||||
'w' => $this->getLabelWidth() - $this->getLabelMarginLeft() - $this->getLabelMarginRight(),
|
||||
'h' => $this->getLabelHeight() - $this->getLabelMarginTop() - $this->getLabelMarginBottom(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns label index offset (skip positions)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLabelIndexOffset() { return $this->indexOffset; }
|
||||
|
||||
/**
|
||||
* Sets label index offset (skip positions)
|
||||
*
|
||||
* @param int $offset
|
||||
*
|
||||
*/
|
||||
public function setLabelIndexOffset(int $offset) { $this->indexOffset = $offset; }
|
||||
}
|
||||
|
||||
?>
|
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7162.php
Normal file
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7162.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Sheets\Avery;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Labels\RectangleSheet;
|
||||
|
||||
abstract class L7162 extends RectangleSheet
|
||||
{
|
||||
|
||||
private const PAPER_FORMAT = 'A4';
|
||||
private const PAPER_ORIENTATION = 'P';
|
||||
|
||||
/* Data in pt from Word Template */
|
||||
private const COLUMN1_X = 13.25;
|
||||
private const COLUMN2_X = 301.25;
|
||||
private const ROW1_Y = 37.00;
|
||||
private const ROW2_Y = 133.00;
|
||||
private const LABEL_W = 280.80;
|
||||
private const LABEL_H = 96.00;
|
||||
|
||||
|
||||
private float $pageWidth;
|
||||
private float $pageHeight;
|
||||
private float $pageMarginLeft;
|
||||
private float $pageMarginTop;
|
||||
|
||||
private float $columnSpacing;
|
||||
private float $rowSpacing;
|
||||
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 0);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
|
||||
$this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
|
||||
$this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
|
||||
|
||||
$columnSpacingPt = self::COLUMN2_X - self::COLUMN1_X - self::LABEL_W;
|
||||
$this->columnSpacing = Helper::convertUnit($columnSpacingPt, 'pt', $this->getUnit());
|
||||
$rowSpacingPt = self::ROW2_Y - self::ROW1_Y - self::LABEL_H;
|
||||
$this->rowSpacing = Helper::convertUnit($rowSpacingPt, 'pt', $this->getUnit());
|
||||
|
||||
$this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
|
||||
public function getColumns() { return 2; }
|
||||
public function getRows() { return 8; }
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
}
|
||||
|
||||
?>
|
100
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7162_A.php
Normal file
100
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7162_A.php
Normal 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 $field) {
|
||||
static::writeText(
|
||||
$pdf, $field['label'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::LABEL_SIZE, 'L',
|
||||
$usableWidth, self::LABEL_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
|
||||
|
||||
static::writeText(
|
||||
$pdf, $field['value'],
|
||||
$currentX, $currentY,
|
||||
'freemono', 'B', self::FIELD_SIZE, 'L',
|
||||
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
|
||||
);
|
||||
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
103
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7162_B.php
Normal file
103
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7162_B.php
Normal 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 $field) {
|
||||
static::writeText(
|
||||
$pdf, $field['label'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::LABEL_SIZE, 'L',
|
||||
$usableWidth, self::LABEL_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
|
||||
|
||||
static::writeText(
|
||||
$pdf, $field['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
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7163.php
Normal file
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/L7163.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Sheets\Avery;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Labels\RectangleSheet;
|
||||
|
||||
abstract class L7163 extends RectangleSheet
|
||||
{
|
||||
|
||||
private const PAPER_FORMAT = 'A4';
|
||||
private const PAPER_ORIENTATION = 'P';
|
||||
|
||||
/* Data in pt from Word Template */
|
||||
private const COLUMN1_X = 13.25;
|
||||
private const COLUMN2_X = 301.25;
|
||||
private const ROW1_Y = 43.05;
|
||||
private const ROW2_Y = 151.05;
|
||||
private const LABEL_W = 280.80;
|
||||
private const LABEL_H = 108.00;
|
||||
|
||||
|
||||
private float $pageWidth;
|
||||
private float $pageHeight;
|
||||
private float $pageMarginLeft;
|
||||
private float $pageMarginTop;
|
||||
|
||||
private float $columnSpacing;
|
||||
private float $rowSpacing;
|
||||
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 0);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
|
||||
$this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
|
||||
$this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
|
||||
|
||||
$columnSpacingPt = self::COLUMN2_X - self::COLUMN1_X - self::LABEL_W;
|
||||
$this->columnSpacing = Helper::convertUnit($columnSpacingPt, 'pt', $this->getUnit());
|
||||
$rowSpacingPt = self::ROW2_Y - self::ROW1_Y - self::LABEL_H;
|
||||
$this->rowSpacing = Helper::convertUnit($rowSpacingPt, 'pt', $this->getUnit());
|
||||
|
||||
$this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
|
||||
public function getColumns() { return 2; }
|
||||
public function getRows() { return 7; }
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Sheets\Avery;
|
||||
|
||||
|
||||
class L7163_A extends L7163
|
||||
{
|
||||
private const BARCODE_MARGIN = 1.80;
|
||||
private const TAG_SIZE = 4.80;
|
||||
private const TITLE_SIZE = 5.00;
|
||||
private const TITLE_MARGIN = 1.80;
|
||||
private const LABEL_SIZE = 2.35;
|
||||
private const LABEL_MARGIN = - 0.30;
|
||||
private const FIELD_SIZE = 4.80;
|
||||
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;
|
||||
|
||||
if ($record->has('title')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('title'),
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::TITLE_SIZE, 'C',
|
||||
$usableWidth, self::TITLE_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
|
||||
}
|
||||
|
||||
$barcodeSize = $pa->h - self::TITLE_SIZE - self::TITLE_MARGIN - 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, $currentY,
|
||||
$barcodeSize, $barcodeSize
|
||||
);
|
||||
$currentX += $barcodeSize + self::BARCODE_MARGIN;
|
||||
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
|
||||
} else {
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $pa->y2 - self::TAG_SIZE,
|
||||
'freemono', 'b', self::TAG_SIZE, 'R',
|
||||
$usableWidth, self::TAG_SIZE, true, 0
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($record->get('fields') as $field) {
|
||||
static::writeText(
|
||||
$pdf, $field['label'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::LABEL_SIZE, 'L',
|
||||
$usableWidth, self::LABEL_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
|
||||
|
||||
static::writeText(
|
||||
$pdf, $field['value'],
|
||||
$currentX, $currentY,
|
||||
'freemono', 'B', self::FIELD_SIZE, 'L',
|
||||
$usableWidth, self::FIELD_SIZE, true, 0, 0.5
|
||||
);
|
||||
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/_5267.php
Normal file
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/_5267.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Sheets\Avery;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Labels\RectangleSheet;
|
||||
|
||||
abstract class _5267 extends RectangleSheet
|
||||
{
|
||||
|
||||
private const PAPER_FORMAT = 'LETTER';
|
||||
private const PAPER_ORIENTATION = 'P';
|
||||
|
||||
/* Data in pt from Word Template */
|
||||
private const COLUMN1_X = 21.60;
|
||||
private const COLUMN2_X = 169.20;
|
||||
private const ROW1_Y = 36.10;
|
||||
private const ROW2_Y = 72.10;
|
||||
private const LABEL_W = 126.00;
|
||||
private const LABEL_H = 36.00;
|
||||
|
||||
|
||||
private float $pageWidth;
|
||||
private float $pageHeight;
|
||||
private float $pageMarginLeft;
|
||||
private float $pageMarginTop;
|
||||
|
||||
private float $columnSpacing;
|
||||
private float $rowSpacing;
|
||||
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 2);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
|
||||
$this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
|
||||
$this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
|
||||
|
||||
$columnSpacingPt = self::COLUMN2_X - self::COLUMN1_X - self::LABEL_W;
|
||||
$this->columnSpacing = Helper::convertUnit($columnSpacingPt, 'pt', $this->getUnit());
|
||||
$rowSpacingPt = self::ROW2_Y - self::ROW1_Y - self::LABEL_H;
|
||||
$this->rowSpacing = Helper::convertUnit($rowSpacingPt, 'pt', $this->getUnit());
|
||||
|
||||
$this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
|
||||
public function getColumns() { return 4; }
|
||||
public function getRows() { return 20; }
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Sheets\Avery;
|
||||
|
||||
|
||||
class _5267_A extends _5267
|
||||
{
|
||||
private const BARCODE_SIZE = 0.175;
|
||||
private const BARCODE_MARGIN = 0.000;
|
||||
private const TAG_SIZE = 0.125;
|
||||
private const TITLE_SIZE = 0.140;
|
||||
private const FIELD_SIZE = 0.150;
|
||||
private const FIELD_MARGIN = 0.012;
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
|
||||
public function getLabelMarginTop() { return 0.02; }
|
||||
public function getLabelMarginBottom() { return 0.00; }
|
||||
public function getLabelMarginLeft() { return 0.04; }
|
||||
public function getLabelMarginRight() { return 0.04; }
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return false; }
|
||||
public function getSupportFields() { return 1; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
static::write1DBarcode(
|
||||
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
|
||||
$pa->x1, $pa->y2 - self::BARCODE_SIZE,
|
||||
$pa->w, self::BARCODE_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
if ($record->has('title')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('title'),
|
||||
$pa->x1, $pa->y1,
|
||||
'freesans', '', self::TITLE_SIZE, 'L',
|
||||
$pa->w, self::TITLE_SIZE, true, 0
|
||||
);
|
||||
}
|
||||
|
||||
$fieldY = $pa->y2 - self::BARCODE_SIZE - self::BARCODE_MARGIN - self::FIELD_SIZE;
|
||||
if ($record->has('fields')) {
|
||||
if ($record->get('fields')->count() >= 1) {
|
||||
$field = $record->get('fields')->first();
|
||||
static::writeText(
|
||||
$pdf, $field['value'],
|
||||
$pa->x1, $fieldY,
|
||||
'freemono', 'B', self::FIELD_SIZE, 'C',
|
||||
$pa->w, self::FIELD_SIZE, true, 0, 0.01
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/_5520.php
Normal file
71
Production/SNIPE-IT/app/Models/Labels/Sheets/Avery/_5520.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Sheets\Avery;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Labels\RectangleSheet;
|
||||
|
||||
abstract class _5520 extends RectangleSheet
|
||||
{
|
||||
|
||||
private const PAPER_FORMAT = 'LETTER';
|
||||
private const PAPER_ORIENTATION = 'P';
|
||||
|
||||
/* Data in pt from Word Template */
|
||||
private const COLUMN1_X = 13.55;
|
||||
private const COLUMN2_X = 211.55;
|
||||
private const ROW1_Y = 36.10;
|
||||
private const ROW2_Y = 108.10;
|
||||
private const LABEL_W = 189.35;
|
||||
private const LABEL_H = 72.00;
|
||||
|
||||
|
||||
private float $pageWidth;
|
||||
private float $pageHeight;
|
||||
private float $pageMarginLeft;
|
||||
private float $pageMarginTop;
|
||||
|
||||
private float $columnSpacing;
|
||||
private float $rowSpacing;
|
||||
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 2);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
|
||||
$this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
|
||||
$this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
|
||||
|
||||
$columnSpacingPt = self::COLUMN2_X - self::COLUMN1_X - self::LABEL_W;
|
||||
$this->columnSpacing = Helper::convertUnit($columnSpacingPt, 'pt', $this->getUnit());
|
||||
$rowSpacingPt = self::ROW2_Y - self::ROW1_Y - self::LABEL_H;
|
||||
$this->rowSpacing = Helper::convertUnit($rowSpacingPt, 'pt', $this->getUnit());
|
||||
|
||||
$this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
|
||||
public function getColumns() { return 3; }
|
||||
public function getRows() { return 10; }
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Sheets\Avery;
|
||||
|
||||
|
||||
class _5520_A extends _5520
|
||||
{
|
||||
private const BARCODE_MARGIN = 0.075;
|
||||
private const TAG_SIZE = 0.125;
|
||||
private const TITLE_SIZE = 0.140;
|
||||
private const TITLE_MARGIN = 0.040;
|
||||
private const LABEL_SIZE = 0.090;
|
||||
private const LABEL_MARGIN = -0.015;
|
||||
private const FIELD_SIZE = 0.150;
|
||||
private const FIELD_MARGIN = 0.012;
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
|
||||
public function getLabelMarginTop() { return 0.06; }
|
||||
public function getLabelMarginBottom() { return 0.06; }
|
||||
public function getLabelMarginLeft() { return 0.06; }
|
||||
public function getLabelMarginRight() { return 0.06; }
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
$currentY = $pa->y1;
|
||||
$usableWidth = $pa->w;
|
||||
$usableHeight = $pa->h;
|
||||
|
||||
if ($record->has('title')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('title'),
|
||||
$pa->x1, $pa->y1,
|
||||
'freesans', '', self::TITLE_SIZE, 'C',
|
||||
$pa->w, self::TITLE_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
|
||||
$usableHeight -= self::TITLE_SIZE + self::TITLE_MARGIN;
|
||||
}
|
||||
|
||||
$barcodeSize = $usableHeight;
|
||||
if ($record->has('barcode2d')) {
|
||||
static::write2DBarcode(
|
||||
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
|
||||
$currentX, $currentY,
|
||||
$barcodeSize, $barcodeSize
|
||||
);
|
||||
$currentX += $barcodeSize + self::BARCODE_MARGIN;
|
||||
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
|
||||
}
|
||||
|
||||
foreach ($record->get('fields') as $field) {
|
||||
static::writeText(
|
||||
$pdf, $field['label'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::LABEL_SIZE, 'L',
|
||||
$usableWidth, self::LABEL_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
|
||||
|
||||
static::writeText(
|
||||
$pdf, $field['value'],
|
||||
$currentX, $currentY,
|
||||
'freemono', 'B', self::FIELD_SIZE, 'L',
|
||||
$usableWidth, self::FIELD_SIZE, true, 0, 0.01
|
||||
);
|
||||
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Brother;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Labels\Label;
|
||||
|
||||
abstract class TZe_12mm extends Label
|
||||
{
|
||||
private const HEIGHT = 12.00;
|
||||
private const MARGIN_SIDES = 3.20;
|
||||
private const MARGIN_ENDS = 3.20;
|
||||
|
||||
public function getHeight() { return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Brother;
|
||||
|
||||
class TZe_12mm_A extends TZe_12mm
|
||||
{
|
||||
private const BARCODE_SIZE = 3.20;
|
||||
private const BARCODE_MARGIN = 0.30;
|
||||
private const TEXT_SIZE_MOD = 1.00;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 50.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return false; }
|
||||
public function getSupportFields() { return 1; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return false; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
static::write1DBarcode(
|
||||
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
|
||||
$pa->x1, $pa->y1, $pa->w, self::BARCODE_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
$currentY = $pa->y1 + self::BARCODE_SIZE + self::BARCODE_MARGIN;
|
||||
$usableHeight = $pa->h - self::BARCODE_SIZE - self::BARCODE_MARGIN;
|
||||
$fontSize = $usableHeight + self::TEXT_SIZE_MOD;
|
||||
|
||||
$tagWidth = $pa->w / 3;
|
||||
$fieldWidth = $pa->w / 3 * 2;
|
||||
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $currentY,
|
||||
'freemono', 'b', $fontSize, 'L',
|
||||
$tagWidth, $usableHeight, true, 0, 0
|
||||
);
|
||||
|
||||
if ($record->get('fields')->count() >= 1) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('fields')->values()->get(0)['value'],
|
||||
$pa->x1 + ($tagWidth), $currentY,
|
||||
'freemono', 'b', $fontSize, 'R',
|
||||
$fieldWidth, $usableHeight, true, 0, 0
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Brother;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Labels\Label;
|
||||
|
||||
abstract class TZe_24mm extends Label
|
||||
{
|
||||
private const HEIGHT = 24.00;
|
||||
private const MARGIN_SIDES = 3.20;
|
||||
private const MARGIN_ENDS = 3.20;
|
||||
|
||||
public function getHeight() { return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Brother;
|
||||
|
||||
class TZe_24mm_A extends TZe_24mm
|
||||
{
|
||||
private const BARCODE_MARGIN = 1.40;
|
||||
private const TAG_SIZE = 2.80;
|
||||
private const TITLE_SIZE = 2.80;
|
||||
private const TITLE_MARGIN = 0.50;
|
||||
private const LABEL_SIZE = 2.00;
|
||||
private const LABEL_MARGIN = - 0.35;
|
||||
private const FIELD_SIZE = 3.20;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 65.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
$currentY = $pa->y1;
|
||||
$usableWidth = $pa->w;
|
||||
|
||||
$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,
|
||||
$currentX, $currentY,
|
||||
$barcodeSize, $barcodeSize
|
||||
);
|
||||
$currentX += $barcodeSize + self::BARCODE_MARGIN;
|
||||
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
|
||||
} else {
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $pa->y2 - self::TAG_SIZE,
|
||||
'freemono', 'b', self::TAG_SIZE, 'R',
|
||||
$usableWidth, self::TAG_SIZE, true, 0
|
||||
);
|
||||
}
|
||||
|
||||
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 $field) {
|
||||
static::writeText(
|
||||
$pdf, $field['label'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::LABEL_SIZE, 'L',
|
||||
$usableWidth, self::LABEL_SIZE, true, 0, 0
|
||||
);
|
||||
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
|
||||
|
||||
static::writeText(
|
||||
$pdf, $field['value'],
|
||||
$currentX, $currentY,
|
||||
'freemono', 'B', self::FIELD_SIZE, 'L',
|
||||
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
|
||||
);
|
||||
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Dymo;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Labels\Label;
|
||||
|
||||
abstract class LabelWriter extends Label
|
||||
{
|
||||
private const HEIGHT = 1.15;
|
||||
private const MARGIN_SIDES = 0.1;
|
||||
private const MARGIN_ENDS = 0.1;
|
||||
|
||||
public function getHeight() { return Helper::convertUnit(self::HEIGHT, 'in', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit()); }
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Dymo;
|
||||
|
||||
|
||||
class LabelWriter_1933081 extends LabelWriter
|
||||
{
|
||||
private const BARCODE_MARGIN = 1.80;
|
||||
private const TAG_SIZE = 2.80;
|
||||
private const TITLE_SIZE = 2.80;
|
||||
private const TITLE_MARGIN = 0.50;
|
||||
private const LABEL_SIZE = 2.80;
|
||||
private const LABEL_MARGIN = - 0.35;
|
||||
private const FIELD_SIZE = 2.80;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 89; }
|
||||
public function getHeight() { return 25; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 5; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
$currentY = $pa->y1;
|
||||
$usableWidth = $pa->w;
|
||||
|
||||
$barcodeSize = $pa->h - self::TAG_SIZE;
|
||||
|
||||
if ($record->has('barcode2d')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $pa->y2 - self::TAG_SIZE,
|
||||
'freesans', 'b', self::TAG_SIZE, 'C',
|
||||
$barcodeSize, self::TAG_SIZE, true, 0
|
||||
);
|
||||
static::write2DBarcode(
|
||||
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
|
||||
$currentX, $currentY,
|
||||
$barcodeSize, $barcodeSize
|
||||
);
|
||||
$currentX += $barcodeSize + self::BARCODE_MARGIN;
|
||||
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
|
||||
} else {
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $pa->y2 - self::TAG_SIZE,
|
||||
'freesans', 'b', self::TAG_SIZE, 'R',
|
||||
$usableWidth, self::TAG_SIZE, true, 0
|
||||
);
|
||||
}
|
||||
|
||||
if ($record->has('title')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('title'),
|
||||
$currentX, $currentY,
|
||||
'freesans', 'b', self::TITLE_SIZE, 'L',
|
||||
$usableWidth, self::TITLE_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
|
||||
}
|
||||
|
||||
foreach ($record->get('fields') as $field) {
|
||||
static::writeText(
|
||||
$pdf, (($field['label']) ? $field['label'].' ' : '') . $field['value'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::FIELD_SIZE, 'L',
|
||||
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
|
||||
);
|
||||
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
|
||||
}
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
static::write1DBarcode(
|
||||
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
|
||||
$currentX, $barcodeSize + self::BARCODE_MARGIN, $usableWidth - self::TAG_SIZE, self::TAG_SIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Dymo;
|
||||
|
||||
|
||||
class LabelWriter_2112283 extends LabelWriter
|
||||
{
|
||||
private const BARCODE_MARGIN = 1.80;
|
||||
private const TAG_SIZE = 2.80;
|
||||
private const TITLE_SIZE = 2.80;
|
||||
private const TITLE_MARGIN = 0.50;
|
||||
private const LABEL_SIZE = 2.80;
|
||||
private const LABEL_MARGIN = - 0.35;
|
||||
private const FIELD_SIZE = 2.80;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 54; }
|
||||
public function getHeight() { return 25; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 5; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
$currentY = $pa->y1;
|
||||
$usableWidth = $pa->w;
|
||||
|
||||
$barcodeSize = $pa->h - self::TAG_SIZE;
|
||||
|
||||
if ($record->has('barcode2d')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $pa->y2 - self::TAG_SIZE,
|
||||
'freesans', 'b', self::TAG_SIZE, 'C',
|
||||
$barcodeSize, self::TAG_SIZE, true, 0
|
||||
);
|
||||
static::write2DBarcode(
|
||||
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
|
||||
$currentX, $currentY,
|
||||
$barcodeSize, $barcodeSize
|
||||
);
|
||||
$currentX += $barcodeSize + self::BARCODE_MARGIN;
|
||||
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
|
||||
} else {
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $pa->y2 - self::TAG_SIZE,
|
||||
'freesans', 'b', self::TAG_SIZE, 'R',
|
||||
$usableWidth, self::TAG_SIZE, true, 0
|
||||
);
|
||||
}
|
||||
|
||||
if ($record->has('title')) {
|
||||
static::writeText(
|
||||
$pdf, $record->get('title'),
|
||||
$currentX, $currentY,
|
||||
'freesans', 'b', self::TITLE_SIZE, 'L',
|
||||
$usableWidth, self::TITLE_SIZE, true, 0
|
||||
);
|
||||
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
|
||||
}
|
||||
|
||||
foreach ($record->get('fields') as $field) {
|
||||
static::writeText(
|
||||
$pdf, (($field['label']) ? $field['label'].' ' : '') . $field['value'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::FIELD_SIZE, 'L',
|
||||
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
|
||||
);
|
||||
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
|
||||
}
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
static::write1DBarcode(
|
||||
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
|
||||
$currentX, $barcodeSize + self::BARCODE_MARGIN, $usableWidth - self::TAG_SIZE, self::TAG_SIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Labels\Tapes\Dymo;
|
||||
|
||||
|
||||
class LabelWriter_30252 extends LabelWriter
|
||||
{
|
||||
private const BARCODE_MARGIN = 1.80;
|
||||
private const TAG_SIZE = 2.80;
|
||||
private const TITLE_SIZE = 2.80;
|
||||
private const TITLE_MARGIN = 0.50;
|
||||
private const LABEL_SIZE = 2.00;
|
||||
private const LABEL_MARGIN = - 0.35;
|
||||
private const FIELD_SIZE = 3.20;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 96.52; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
$currentY = $pa->y1;
|
||||
$usableWidth = $pa->w;
|
||||
|
||||
$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,
|
||||
$currentX, $currentY,
|
||||
$barcodeSize, $barcodeSize
|
||||
);
|
||||
$currentX += $barcodeSize + self::BARCODE_MARGIN;
|
||||
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
|
||||
} else {
|
||||
static::writeText(
|
||||
$pdf, $record->get('tag'),
|
||||
$pa->x1, $pa->y2 - self::TAG_SIZE,
|
||||
'freemono', 'b', self::TAG_SIZE, 'R',
|
||||
$usableWidth, self::TAG_SIZE, true, 0
|
||||
);
|
||||
}
|
||||
|
||||
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 $field) {
|
||||
static::writeText(
|
||||
$pdf, $field['label'],
|
||||
$currentX, $currentY,
|
||||
'freesans', '', self::LABEL_SIZE, 'L',
|
||||
$usableWidth, self::LABEL_SIZE, true, 0, 0
|
||||
);
|
||||
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
|
||||
|
||||
static::writeText(
|
||||
$pdf, $field['value'],
|
||||
$currentX, $currentY,
|
||||
'freemono', 'B', self::FIELD_SIZE, 'L',
|
||||
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
|
||||
);
|
||||
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
|
||||
}
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
static::write1DBarcode(
|
||||
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
|
||||
$currentX, $barcodeSize + self::BARCODE_MARGIN, $usableWidth - self::TAG_SIZE, self::TAG_SIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user