From 0b835a3af5c759c1410e832afbdcde6bd53d1981 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 6 Mar 2018 14:34:46 +0100 Subject: [PATCH 1/4] New button --- modules/labelgenerate/AdminLabelGenerate.php | 112 ++++++++++++++++-- .../labelgenerate/models/generatebarcode.php | 51 +++++--- 2 files changed, 140 insertions(+), 23 deletions(-) diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php index de7ee436..b51a3be1 100644 --- a/modules/labelgenerate/AdminLabelGenerate.php +++ b/modules/labelgenerate/AdminLabelGenerate.php @@ -466,6 +466,102 @@ class AdminLabelGenerate extends AdminTab } } } + + // Generate label with ref and attribute name + elseif ($current_sale && Tools::getValue('generateIdentification')) { + $sale = new Sale((int)$current_sale); + $big_label = Tools::getValue('big_label'); + + if(!Validate::isLoadedObject($sale)) { + throw new Exception('This sale doesnt exist'); + } + else { + $products = $sale->getProducts(); + $ean_generate = ''; + $products_generate = array(); + + $barcode = new GenerateBarcode(); + $barcode->id_sale = $sale->id; + $barcode->createFolder($barcode->id_sale); + + foreach ($products as $key => $id_product) { + $product = new Product($id_product, FALSE, (int) $cookie->id_lang); + $attributes = array(); + + $combinations = $product->getAttributeCombinaisons($cookie->id_lang); + // Product with attributes + if ($combinations) { + foreach ($combinations as $key => $combination) { + if (empty($combination['ean13'])) { + $result_quantities = Db::getInstance()->executeS(' + SELECT od.`product_quantity`,od.`product_quantity_reinjected` + FROM '._DB_PREFIX_.'order_detail od + LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`) + WHERE od.`product_id` = ' . (int)$combination['id_product'] .' + AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute'].' + AND o.`valid` != 0' + ); + $quantity = 0; + foreach ($result_quantities as $od) { + $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); + } + if ($quantity > 0) { + + + $ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference); + $barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference); + + + } + } + } + } + // Product without attributes + else { + if (empty($product->ean13)) { + $result_quantities = Db::getInstance()->executeS(' + SELECT od.`product_quantity`,od.`product_quantity_reinjected` + FROM '._DB_PREFIX_.'order_detail od + LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`) + WHERE od.`product_id` = ' . (int)$product->id . ' AND `product_attribute_id` = 0 AND o.`valid` != 0' + ); + + $quantity = 0; + foreach ($result_quantities as $od) { + $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); + } + + if ($quantity > 0) { + + + $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference); + $barcode->assocProduct($product->id, NULL, $quantity, $product->reference); + + + } + } + } + } + + if (!empty($ean_generate)) { + if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf')) { + unlink(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf'); + } + if ($barcode->printPDF($big_label)) { + $this->_html .= $this->displaySuccess('Génération terminée :
Télécharger le PDF'); + } else { + $this->_html .= $this->displayError('Pas de produit à générer !'); + } + } else { + $message = 'Tous les produits de la vente ont déjà des EANS'; + if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf')) { + $message .= '
Dernières étiquettes générées : Télécharger le PDF'; + } + $this->_html .= $this->displayWarning($message); + } + } + + } $helperForm = new HelperFormBootstrap(); $helperForm->_select2 = true; @@ -497,8 +593,8 @@ class AdminLabelGenerate extends AdminTab 'label' => $this->l('Select a sale:'), 'label-class' => 'text-left', 'select-class' => 'text-left', - 'name' => 'id_sale', - 'id' => 'id_sale', + 'name' => 'id_sale2', + 'id' => 'id_sale2', 'options' => $id_sale_options, ); $this->_html .= $helperForm->generateInput($input); @@ -508,7 +604,7 @@ class AdminLabelGenerate extends AdminTab 'label-class' => 'col-md-4', 'input-class' => 'col-md-6', 'class-group' => 'switch', - 'name' => 'big_label', + 'name' => 'big_label2', 'title' => $this->l('Big labels ?'), ); $this->_html .= $helperForm->generateInput($input).' @@ -521,6 +617,8 @@ class AdminLabelGenerate extends AdminTab

+

 

+

@@ -569,9 +667,9 @@ class AdminLabelGenerate extends AdminTab $("#deleteEAN").click(function(){ ok = confirm("Êtes vous sur de vouloir supprimer les eans de cette vente ?") if (ok == true){ - if ($("#id_sale").val() != 999999) { - document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&deleteEAN=1&id_sale=\' + $("#id_sale").val(); - } + if ($("#id_sale").val() != 999999) { + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&deleteEAN=1&id_sale=\' + $("#id_sale").val(); + } } }); @@ -581,7 +679,7 @@ class AdminLabelGenerate extends AdminTab }); '; - + $this->_html .= $helperForm->renderScript(); echo $this->_html; } diff --git a/modules/labelgenerate/models/generatebarcode.php b/modules/labelgenerate/models/generatebarcode.php index 3e983200..ea188f16 100644 --- a/modules/labelgenerate/models/generatebarcode.php +++ b/modules/labelgenerate/models/generatebarcode.php @@ -2,8 +2,8 @@ require_once dirname(__FILE__).'/php-barcode.php'; include_once(_PS_FPDF_PATH_.'fpdf.php'); -class GenerateBarcode { - +class GenerateBarcode +{ static private $barcode_directory = NULL; private $directory; public $id_sale; @@ -14,19 +14,23 @@ class GenerateBarcode { const _NB_PER_LINE_BIG_ = 4; const _TOTAL_PER_PAGE_BIG_ = 10; - public function __construct() { - if (is_null(self::$barcode_directory)) { + public function __construct() + { + if (is_null(self::$barcode_directory)) + { self::$barcode_directory = dirname(__FILE__).'/../img/'; } } - public function createRackFolder() { + public function createRackFolder() + { if (!(is_dir(self::$barcode_directory.'rack'))) { mkdir(self::$barcode_directory.'rack', 0775); } } - public function generateRack($name) { + public function generateRack($name) + { $width = 320; $height = 80; $im = imagecreatetruecolor($width, $height); @@ -39,7 +43,8 @@ class GenerateBarcode { imagegif($im, self::$barcode_directory.'rack/img-'.$name.'.gif'); } - public function printRackPDF($codes) { + public function printRackPDF($codes) + { ob_start(); $pdf = new FPDF('P', 'mm', 'A4'); $nb_per_page = 0; @@ -75,14 +80,16 @@ class GenerateBarcode { return TRUE; } - public function createFolder($name) { + public function createFolder($name) + { if (!(is_dir(self::$barcode_directory.$name))) { mkdir(self::$barcode_directory.$name, 0775); } $this->directory = self::$barcode_directory.$name; } - public function generateBarcode($id_product, $id_product_attribute = NULL, $reference = NULL, $ean = NULL, $big_label = false) { + public function generateBarcode($id_product, $id_product_attribute = NULL, $reference = NULL, $ean = NULL, $big_label = false) + { if($ean == null) { $ean = $this->_getEanNumber(); } @@ -110,14 +117,21 @@ class GenerateBarcode { return $ean; } - private function _getEanNumber() { + public function generateIdentification() + { + + } + + private function _getEanNumber() + { // min 1111111111 $number = Configuration::get('BARCODE_NUMBER') + 1; Configuration::updateValue('BARCODE_NUMBER', $number); return $number; } - public function assocProduct($id_product, $id_product_attribute = NULL, $quantity, $ref) { + public function assocProduct($id_product, $id_product_attribute = NULL, $quantity, $ref) + { global $cookie; $p = Db::getInstance()->getRow(' SELECT pl.name @@ -152,7 +166,8 @@ class GenerateBarcode { //$this->products[] = array(); } - public function printPDF($big_label = false, $file = 'barcode') { + public function printPDF($big_label = false, $file = 'barcode') + { global $cookie; if($big_label){ @@ -295,20 +310,23 @@ class GenerateBarcode { return TRUE; } - private function _printLabel($pdf, $label, $limit = 1, $width = 48, $height = 4, $font_size = 5) { + private function _printLabel($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 _printEAN($pdf, $ean_image, $limit = 1, $width = 48, $height = 10) { + private function _printEAN($pdf, $ean_image, $limit = 1, $width = 48, $height = 10) + { for ($i=0; $i < $limit; $i++) { $pdf->Cell($width, $height, $pdf->Image($ean_image, $pdf->GetX(), $pdf->GetY(),($width-2), $height), 0,0, 'C'); } } - private function _multiSortProduct($products = array()){ + private function _multiSortProduct($products = array()) + { if (!empty($products)) { $ref = array(); $decli = array(); @@ -334,7 +352,8 @@ class GenerateBarcode { return $result; } - private function _sortProducts($array = array(), $field, $order=SORT_ASC) { + private function _sortProducts($array = array(), $field, $order=SORT_ASC) + { $new_array = array(); $sortable_array = array(); $products = array(); From 1d5eb5ec9771ea2e6f6e607ee87b14287b26312b Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 8 Mar 2018 14:54:52 +0100 Subject: [PATCH 2/4] New label --- modules/labelgenerate/AdminLabelGenerate.php | 118 ++++++++---------- .../labelgenerate/models/generatebarcode.php | 106 +++++++++++++++- 2 files changed, 155 insertions(+), 69 deletions(-) diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php index b51a3be1..671cae14 100644 --- a/modules/labelgenerate/AdminLabelGenerate.php +++ b/modules/labelgenerate/AdminLabelGenerate.php @@ -492,73 +492,54 @@ class AdminLabelGenerate extends AdminTab // Product with attributes if ($combinations) { foreach ($combinations as $key => $combination) { - if (empty($combination['ean13'])) { - $result_quantities = Db::getInstance()->executeS(' - SELECT od.`product_quantity`,od.`product_quantity_reinjected` - FROM '._DB_PREFIX_.'order_detail od - LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`) - WHERE od.`product_id` = ' . (int)$combination['id_product'] .' - AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute'].' - AND o.`valid` != 0' - ); - $quantity = 0; - foreach ($result_quantities as $od) { - $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); - } - if ($quantity > 0) { - - - $ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference); - $barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference); - - - } - } + $result_quantities = Db::getInstance()->executeS(' + SELECT od.`product_quantity`,od.`product_quantity_reinjected` + FROM '._DB_PREFIX_.'order_detail od + LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`) + WHERE od.`product_id` = ' . (int)$combination['id_product'] .' + AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute'].' + AND o.`valid` != 0' + ); + $quantity = 0; + foreach ($result_quantities as $od) { + $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); + } } } // Product without attributes else { - if (empty($product->ean13)) { - $result_quantities = Db::getInstance()->executeS(' - SELECT od.`product_quantity`,od.`product_quantity_reinjected` - FROM '._DB_PREFIX_.'order_detail od - LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`) - WHERE od.`product_id` = ' . (int)$product->id . ' AND `product_attribute_id` = 0 AND o.`valid` != 0' - ); + $result_quantities = Db::getInstance()->executeS(' + SELECT od.`product_quantity`,od.`product_quantity_reinjected` + FROM '._DB_PREFIX_.'order_detail od + LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`) + WHERE od.`product_id` = ' . (int)$product->id . ' AND `product_attribute_id` = 0 AND o.`valid` != 0' + ); - $quantity = 0; - foreach ($result_quantities as $od) { - $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); - } + $quantity = 0; + foreach ($result_quantities as $od) { + $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); + } - if ($quantity > 0) { - - - $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference); - $barcode->assocProduct($product->id, NULL, $quantity, $product->reference); - - - } - } + if ($quantity > 0) { + $barcode->generateIdentification($combination['id_product'], null, $product->reference); + $barcode->assocProduct($product->id, null, $quantity, $product->reference); + } } } - - if (!empty($ean_generate)) { - if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf')) { - unlink(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf'); - } - if ($barcode->printPDF($big_label)) { - $this->_html .= $this->displaySuccess('Génération terminée :
Télécharger le PDF'); - } else { - $this->_html .= $this->displayError('Pas de produit à générer !'); - } - } else { - $message = 'Tous les produits de la vente ont déjà des EANS'; - if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf')) { - $message .= '
Dernières étiquettes générées : Télécharger le PDF'; - } - $this->_html .= $this->displayWarning($message); - } + exit; + if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/identification.pdf')) { + unlink(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/identification.pdf'); + } + + if ($barcode->printIdentification($big_label)) { + $this->_html .= $this->displaySuccess('Génération terminée :
Télécharger le PDF'); + } else { + $this->_html .= $this->displayError('Pas de produit à générer !'); + } } } @@ -593,8 +574,8 @@ class AdminLabelGenerate extends AdminTab 'label' => $this->l('Select a sale:'), 'label-class' => 'text-left', 'select-class' => 'text-left', - 'name' => 'id_sale2', - 'id' => 'id_sale2', + 'name' => 'id_sale', + 'id' => 'id_sale', 'options' => $id_sale_options, ); $this->_html .= $helperForm->generateInput($input); @@ -604,7 +585,7 @@ class AdminLabelGenerate extends AdminTab 'label-class' => 'col-md-4', 'input-class' => 'col-md-6', 'class-group' => 'switch', - 'name' => 'big_label2', + 'name' => 'big_label', 'title' => $this->l('Big labels ?'), ); $this->_html .= $helperForm->generateInput($input).' @@ -639,28 +620,28 @@ class AdminLabelGenerate extends AdminTab $("#generateEAN").click(function(){ if ($("#id_sale").val() != 999999) { $(\'#category_selector\').hide(); - document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateEAN=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val(); + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateEAN=1&big_label=\'+ big_label +\'&id_sale=\'+$("#id_sale").val(); } }); $("#generateRef").click(function(){ if ($("#id_sale").val() != 999999) { $(\'#category_selector\').hide(); - document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateRef=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val(); + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateRef=1&big_label=\'+ big_label +\'&id_sale=\'+$("#id_sale").val(); } }); $("#generateALLEAN").click(function(){ if ($("#id_sale").val() != 999999) { $(\'#category_selector\').hide(); - document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val(); + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN=1&big_label=\'+ big_label +\'&id_sale=\'+$("#id_sale").val(); } }); $("#generateALLEAN_initial").click(function(){ if ($("#id_sale").val() != 999999) { $(\'#category_selector\').hide(); - document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN_initial=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val(); + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN_initial=1&big_label=\'+ big_label +\'&id_sale=\'+$("#id_sale").val(); } }); @@ -668,7 +649,7 @@ class AdminLabelGenerate extends AdminTab ok = confirm("Êtes vous sur de vouloir supprimer les eans de cette vente ?") if (ok == true){ if ($("#id_sale").val() != 999999) { - document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&deleteEAN=1&id_sale=\' + $("#id_sale").val(); + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&deleteEAN=1&id_sale=\'+$("#id_sale").val(); } } }); @@ -677,6 +658,9 @@ class AdminLabelGenerate extends AdminTab document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&rack=1\'; }); + $("#generateIdentification").click(function(){ + document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateIdentification=1&id_sale=\'+$("#id_sale").val(); + }); }); '; diff --git a/modules/labelgenerate/models/generatebarcode.php b/modules/labelgenerate/models/generatebarcode.php index ea188f16..e90a523a 100644 --- a/modules/labelgenerate/models/generatebarcode.php +++ b/modules/labelgenerate/models/generatebarcode.php @@ -117,9 +117,32 @@ class GenerateBarcode return $ean; } - public function generateIdentification() + public function generateIdentification($id_product, $id_product_attribute = null, $reference = null, $attribute_ref = null, $big_label = false) { - + $width = 320; + $height = 80; + + 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, 11, 0, $width / 2, $height / 2 - 10, $black, dirname(__FILE__).'/arial.ttf', $ref); + + if ($id_product_attribute !== null) { + imagettftext($im, 11, 0, $width / 2 - (strlen($attribute_ref)* 4), $height - 10 , $black, dirname(__FILE__).'/arial.ttf', $attribute_ref); + } + + if ($id_product_attribute) { + $result = imagegif($im, $this->directory.'/id-'.$id_product.'-'.$id_product_attribute.'.gif'); + } else { + $result = imagegif($im, $this->directory.'/id-'.$id_product.'-0.gif'); + } + + return $result; } private function _getEanNumber() @@ -310,6 +333,85 @@ class GenerateBarcode return TRUE; } + public function printIdentification($big_label = false, $file = 'identification') + { + global $cookie; + + if ($big_label) { + // 52*30 + $width = 51.5; + $height_label = 14; + $height_text = 7; + $ln_label = 15; + $ln_text = 7.1; + $nb_per_line = self::_NB_PER_LINE_BIG_; + $total_per_page = self::_TOTAL_PER_PAGE_BIG_; + $font_size = 9; + $font_size_ref = 10; + $margin = 3; + $margin_top = 3; + } else { + // 48*17 + $width = 48; + $height_label = 10; + $height_text = 4; + $ln_label = 13; + $ln_text = 4; + $nb_per_line = self::_NB_PER_LINE_; + $total_per_page = self::_TOTAL_PER_PAGE_; + $font_size = 5; + $margin = 9; + $margin_top = 12; + } + + if (empty($this->products)) { + return false; + } + + $this->products = $this->_multiSortProduct($this->products); + ob_start(); + $pdf = new FPDF('P', 'mm', 'A4'); + $nb_per_page = 0; + $pdf->SetMargins($margin,$margin_top,$margin); + $pdf->SetAutoPageBreak(FALSE); + $pdf->AddPage(); + $pdf->SetFont('Arial','',14); + + $nb_line = ceil((count($this->products)/$nb_per_line)); + for ($i=1; $i <= $nb_line; $i++) { + if (empty($this->products[0])) { + unset($this->products[0]); + } + if (!empty($this->products)) { + $product_per_line = array_slice($this->products, 0, $nb_per_line); + $this->products = array_splice($this->products, $nb_per_line); + + if($nb_per_page == $total_per_page) { + $pdf->addPage(); + $nb_per_page = 0; + } + + 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); + } + } + $pdf->Ln($ln_label); + + $nb_per_page += 1; + } + } + + $pdf->Output($this->directory.'/'.$file.'.pdf', 'F'); + + ob_clean(); + + return true; + } + private function _printLabel($pdf, $label, $limit = 1, $width = 48, $height = 4, $font_size = 5) { $pdf->SetFont('Arial', '', $font_size); From 490baf50f4f1567f076501d4364c539c091ed708 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 8 Mar 2018 14:57:54 +0100 Subject: [PATCH 3/4] Clean --- modules/labelgenerate/AdminLabelGenerate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php index 671cae14..78c95c8d 100644 --- a/modules/labelgenerate/AdminLabelGenerate.php +++ b/modules/labelgenerate/AdminLabelGenerate.php @@ -530,7 +530,7 @@ class AdminLabelGenerate extends AdminTab } } } - exit; + if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/identification.pdf')) { unlink(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/identification.pdf'); } From cab5635c8ff9aac04a88b0ecdf94c1a860a31ce6 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 8 Mar 2018 16:29:11 +0100 Subject: [PATCH 4/4] Test format image --- modules/labelgenerate/AdminLabelGenerate.php | 3 ++- modules/labelgenerate/models/generatebarcode.php | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php index 78c95c8d..3f89c998 100644 --- a/modules/labelgenerate/AdminLabelGenerate.php +++ b/modules/labelgenerate/AdminLabelGenerate.php @@ -505,6 +505,7 @@ class AdminLabelGenerate extends AdminTab $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); } if ($quantity > 0) { + print_r($combination); $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); } @@ -525,7 +526,7 @@ class AdminLabelGenerate extends AdminTab } if ($quantity > 0) { - $barcode->generateIdentification($combination['id_product'], null, $product->reference); + $barcode->generateIdentification($product->id, null, $product->reference); $barcode->assocProduct($product->id, null, $quantity, $product->reference); } } diff --git a/modules/labelgenerate/models/generatebarcode.php b/modules/labelgenerate/models/generatebarcode.php index e90a523a..b225afb8 100644 --- a/modules/labelgenerate/models/generatebarcode.php +++ b/modules/labelgenerate/models/generatebarcode.php @@ -121,6 +121,7 @@ class GenerateBarcode { $width = 320; $height = 80; + $font = dirname(__FILE__).'/arial.ttf'; preg_match('/.*-(.*)-.*/', $reference, $matches); $ref = $matches[1]; @@ -130,16 +131,13 @@ class GenerateBarcode $white = ImageColorAllocate($im, 0xff, 0xff, 0xff); imagefilledrectangle($im, 0, 0, $width, $height, $white); - imagettftext($im, 11, 0, $width / 2, $height / 2 - 10, $black, dirname(__FILE__).'/arial.ttf', $ref); + imagettftext($im, 30, 0, 10, 50, $black, $font, $ref); - if ($id_product_attribute !== null) { - imagettftext($im, 11, 0, $width / 2 - (strlen($attribute_ref)* 4), $height - 10 , $black, dirname(__FILE__).'/arial.ttf', $attribute_ref); - } - - if ($id_product_attribute) { - $result = imagegif($im, $this->directory.'/id-'.$id_product.'-'.$id_product_attribute.'.gif'); - } else { + if ($id_product_attribute === null) { $result = imagegif($im, $this->directory.'/id-'.$id_product.'-0.gif'); + } else { + imagettftext($im, 12, 0, 65, 50 , $black, $font, $attribute_ref); + $result = imagegif($im, $this->directory.'/id-'.$id_product.'-'.$id_product_attribute.'.gif'); } return $result;