From d6dbc5f479aef3c122090639a7f9b8a464ec3d6b Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 13 Mar 2018 15:18:14 +0100 Subject: [PATCH] New label format --- modules/labelgenerate/AdminLabelGenerate.php | 5 +- .../labelgenerate/models/generatebarcode.php | 60 +++++++++---------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php index 69dc9074..7b8b00d2 100644 --- a/modules/labelgenerate/AdminLabelGenerate.php +++ b/modules/labelgenerate/AdminLabelGenerate.php @@ -505,7 +505,6 @@ class AdminLabelGenerate extends AdminTab $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); } if ($quantity > 0) { - $barcode->generateIdentification($combination['id_product'], $combination['id_product_attribute'], $product->reference, $combination['attribute_name']); $barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference); } } @@ -523,9 +522,7 @@ class AdminLabelGenerate extends AdminTab foreach ($result_quantities as $od) { $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); } - if ($quantity > 0) { - $barcode->generateIdentification($product->id, null, $product->reference); $barcode->assocProduct($product->id, null, $quantity, $product->reference); } } @@ -659,7 +656,7 @@ class AdminLabelGenerate extends AdminTab }); $("#generateIdentification").click(function(){ - document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateIdentification=1&id_sale=\'+$("#id_sale").val(); + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateIdentification=1&big_label=\'+ big_label +\'&id_sale=\'+$("#id_sale").val(); }); }); '; diff --git a/modules/labelgenerate/models/generatebarcode.php b/modules/labelgenerate/models/generatebarcode.php index b3a8cabe..39c66116 100644 --- a/modules/labelgenerate/models/generatebarcode.php +++ b/modules/labelgenerate/models/generatebarcode.php @@ -116,32 +116,6 @@ class GenerateBarcode return $ean; } - - public function generateIdentification($id_product, $id_product_attribute = null, $reference = null, $attribute_ref = null, $big_label = false) - { - $width = 320; - $height = 80; - $font = dirname(__FILE__).'/arial.ttf'; - - preg_match('/.*-(.*)-.*/', $reference, $matches); - $ref = $matches[1]; - - $im = imagecreatetruecolor($width, $height); - $black = ImageColorAllocate($im, 0x00, 0x00, 0x00); - $white = ImageColorAllocate($im, 0xff, 0xff, 0xff); - imagefilledrectangle($im, 0, 0, $width, $height, $white); - - imagettftext($im, 40, 0, 10, 40, $black, $font, $ref); - - if ($id_product_attribute === null) { - $result = imagegif($im, $this->directory.'/id-'.$id_product.'-0.gif'); - } else { - imagettftext($im, 12, 0, 110, 40 , $black, $font, $attribute_ref); - $result = imagegif($im, $this->directory.'/id-'.$id_product.'-'.$id_product_attribute.'.gif'); - } - - return $result; - } private function _getEanNumber() { @@ -296,7 +270,7 @@ class GenerateBarcode if (empty($product)) { $pdf->Cell($width, $height_text, '', 0,0, 'C'); } else { - $this->_printLabel($pdf, $product['ref'], 1,$width,$height_text, $font_size_ref); + $this->_printLabel($pdf, $product['ref'], 1, $width, $height_text, $font_size_ref); } } $pdf->Ln(($ln_text)); @@ -306,7 +280,7 @@ class GenerateBarcode if (empty($product)) { $pdf->Cell($width, $height_text, '', 0,0, 'C'); } else { - $this->_printLabel($pdf, $product['label'], 1,$width,$height_text, $font_size); + $this->_printLabel($pdf, $product['label'], 1, $width, $height_text, $font_size); } } $pdf->Ln(($ln_text)); @@ -335,6 +309,8 @@ class GenerateBarcode { global $cookie; + $big_label = true; + if ($big_label) { // 52*30 $width = 51.5; @@ -389,12 +365,26 @@ class GenerateBarcode $nb_per_page = 0; } + foreach ($product_per_line as $key => $product) { + if (empty($product)) { + $pdf->Cell($width, $height_label, '', 0, 0, 'C'); + } + // Mark in ref + else { + preg_match('/.*-(.*)-.*/', $product['ref'], $matches); + $ref = $matches[1]; + $this->_printIdMark($pdf, $ref, 1, $width, $height_label, 30); + } + } + $pdf->Ln($ln_text+$ln_text); + foreach ($product_per_line as $key => $product) { if (empty($product)) { $pdf->Cell($width, $height_label, '', 0, 0, 'C'); - } else { - $image = $this->directory.'/id-'.$product['key'].'.gif'; - $this->_printEAN($pdf, $image, 1, $width, $height_label); + } + // Attribute name + else { + $this->_printIdMark($pdf, $product['label'], 1, $width, $height_label, 9); } } $pdf->Ln($ln_label); @@ -424,6 +414,14 @@ class GenerateBarcode $pdf->Cell($width, $height, $pdf->Image($ean_image, $pdf->GetX(), $pdf->GetY(),($width-2), $height), 0,0, 'C'); } } + + private function _printIdMark($pdf, $label, $limit = 1, $width = 48, $height = 4, $font_size = 5) + { + $pdf->SetFont('Arial', '', $font_size); + for ($i=0; $i < $limit; $i++) { + $pdf->Cell($width, $height, substr(utf8_decode($label), 0, 30), 0, 0, 'C'); + } + } private function _multiSortProduct($products = array()) {