A free open source IT asset/license management system
fixes label rotation, swaps logo and 2d code in config and gui
Godfrey Ma6956bc095e1
diff --git a/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.php b/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.phpindex 16991c618f..e3fe42ce50 100644--- a/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.php+++ b/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.php@@ -175,7 +175,12 @@ trait RenderCustomLabelContent$y = $layout['fields']['start_y'];foreach ($layout['fields']['fields'] as $field) {- if ($y + $layout['fields']['row_advance'] > $layout['fields']['bottom_limit']) {+ $rowHeight = max(+ $layout['fields']['label_size'],+ $layout['fields']['field_size']+ );++ if ($y + $rowHeight > $layout['fields']['bottom_limit']) {break;}@@ -394,4 +399,25 @@ trait RenderCustomLabelContentreturn min($body['w'] * 0.35, $body['w']);}++ protected function oppositeHAlign(string $align): string+ {+ return strtoupper($align) === 'L' ? 'R' : 'L';+ }++ protected function syncLogoAnd2DBarcodeHAlign(?string $changedKey = null): void+ {+ if (!$this->getSupportLogo() || !$this->getSupport2DBarcode()) {+ return;+ }++ if ($changedKey === 'barcode2D_h_align') {+ $this->logoHAlign = $this->oppositeHAlign($this->barcode2DHAlign);+ return;+ }++ if ($changedKey === 'logo_h_align') {+ $this->barcode2DHAlign = $this->oppositeHAlign($this->logoHAlign);+ }+ }}\ No newline at end of filediff --git a/app/Models/Labels/CustomLabels/CustomSheetLabel.php b/app/Models/Labels/CustomLabels/CustomSheetLabel.phpindex c8b7e485da..be743a5d93 100644--- a/app/Models/Labels/CustomLabels/CustomSheetLabel.php+++ b/app/Models/Labels/CustomLabels/CustomSheetLabel.php@@ -662,6 +662,13 @@ abstract class CustomSheetLabel extends RectangleSheet$this->titleOffsetX = isset($content['title_offset_x']) ? (float) $content['title_offset_x'] : $this->titleOffsetX;$this->labelMargin = isset($content['field_label_margin']) ? (float) $content['field_label_margin'] : $this->labelMargin;$this->fieldMargin = isset($content['field_value_margin']) ? (float) $content['field_value_margin'] : $this->fieldMargin;++ //If the logo and 2D barcode are both present, and one is moved to the other side, they will flip positions.+ if (array_key_exists('barcode2D_h_align', $content)) {+ $this->syncLogoAnd2DBarcodeHAlign('barcode2D_h_align');+ } elseif (array_key_exists('logo_h_align', $content)) {+ $this->syncLogoAnd2DBarcodeHAlign('logo_h_align');+ }}public function write($pdf, $record)diff --git a/app/Models/Labels/CustomLabels/CustomTapeLabel.php b/app/Models/Labels/CustomLabels/CustomTapeLabel.phpindex b2e85b95ef..b065ad7ed4 100644--- a/app/Models/Labels/CustomLabels/CustomTapeLabel.php+++ b/app/Models/Labels/CustomLabels/CustomTapeLabel.php@@ -288,6 +288,12 @@ abstract class CustomTapeLabel extends Labelreturn $this->textAreaOffsetY;}+ public function getRotation()+ {+ return $this->rotation;+ }++public function preparePDF($pdf){$pdf->SetMargins(0, 0, 0);@@ -312,7 +318,7 @@ abstract class CustomTapeLabel extends Label'barcode_size' => $this->getBarcodeSize(),'barcode_margin' => $this->getBarcodeMargin(),'barcode1D_v_align' => $this->getBarcode1DVAlign(),- 'barcode1d_placement' => $this->getBarcode1DPlacement(),+ 'barcode1D_placement' => $this->getBarcode1DPlacement(),'barcode_2d_size' => $this->get2DBarcodeSize(),'barcode2D_h_align' => $this->getBarcode2DHAlign(),'barcode2D_v_align' => $this->getBarcode2DVAlign(),@@ -321,7 +327,7 @@ abstract class CustomTapeLabel extends Label'tag_font_size' => $this->getTagSize(),'tag_offset_x' => $this->getTagOffsetX(),'tag_offset_y' => $this->getTagOffsetY(),- 'field_label_font_size' => $this->getFieldSize(),+ 'field_label_font_size' => $this->getLabelSize(),'field_value_font_size' => $this->getFieldSize(),'field_value_margin' => $this->getFieldMargin(),'tag_alignment' => $this->getTagAlignment(),@@ -459,10 +465,6 @@ abstract class CustomTapeLabel extends Label? (int)$template->getRotation(): $this->rotation;- $this->rotation = method_exists($template, 'getOrientation')- ? (int)$template->getOrientation()- : $this->rotation;-return $this;}@@ -526,7 +528,14 @@ abstract class CustomTapeLabel extends Label$this->logoHAlign = isset($content['logo_h_align']) ? (string)$content['logo_h_align'] : $this->logoHAlign;$this->logoVAlign = isset($content['logo_v_align']) ? (string)$content['logo_v_align'] : $this->logoVAlign;- $this->orientation = isset($meta['rotation']) ? (string)$meta['rotation'] : $this->orientation;+ //If the logo and 2D barcode are both present, and one is moved to the other side, they will flip positions.+ if (array_key_exists('barcode2D_h_align', $content)) {+ $this->syncLogoAnd2DBarcodeHAlign('barcode2D_h_align');+ } elseif (array_key_exists('logo_h_align', $content)) {+ $this->syncLogoAnd2DBarcodeHAlign('logo_h_align');+ }++ $this->rotation = isset($meta['rotation']) ? (int)$meta['rotation'] : $this->rotation;}public function write($pdf, $record)@@ -534,11 +543,11 @@ abstract class CustomTapeLabel extends Label$pa = $this->getPrintableArea();$layout = $this->buildLayout($pdf, $record, $pa);-$this->render1DBarcode($pdf, $record, $layout);$this->renderLogo($pdf, $record, $layout);$this->render2DBarcode($pdf, $record, $layout);$this->renderTag($pdf, $record, $layout);+$this->renderTextBlock($pdf, $record, $layout);}diff --git a/resources/views/settings/label-edit.blade.php b/resources/views/settings/label-edit.blade.phpindex a66023276d..9a04d0c8d8 100644--- a/resources/views/settings/label-edit.blade.php+++ b/resources/views/settings/label-edit.blade.php@@ -269,7 +269,8 @@<label class="col-md-5 control-label">{{ $key }}</label><div class="col-md-7">@if($key === 'tag_alignment' || $key === 'logo_h_align' || $key === 'barcode2D_h_align')- <select name="content[{{ $key }}]" class="form-control">+ <select name="content[{{ $key }}]" class="form-control align-sync"+ data-key="{{ $key }}"><option value="L" {{ $value === 'L' ? 'selected' : '' }}>Left</option>@@ -357,5 +358,21 @@</div>@stop@push('js')+ <script>+ $(document).on('change', '.align-sync', function () {+ const key = $(this).data('key');+ const value = $(this).val();++ if (key === 'logo_h_align') {+ $('select[name="content[barcode2D_h_align]"]')+ .val(value === 'L' ? 'R' : 'L');+ }++ if (key === 'barcode2D_h_align') {+ $('select[name="content[logo_h_align]"]')+ .val(value === 'L' ? 'R' : 'L');+ }+ });+ </script>@livewireScripts@endpush\ No newline at end of file