From bf20d2be173ce37ed304982fcee58577e57d4760 Mon Sep 17 00:00:00 2001 From: Srv Bebeboutik Date: Tue, 22 Mar 2016 17:23:04 +0100 Subject: [PATCH 1/2] fix labelgenerate --- modules/labelgenerate/models/generatebarcode.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/labelgenerate/models/generatebarcode.php b/modules/labelgenerate/models/generatebarcode.php index 954fb299..316e4f5e 100644 --- a/modules/labelgenerate/models/generatebarcode.php +++ b/modules/labelgenerate/models/generatebarcode.php @@ -30,7 +30,7 @@ class GenerateBarcode { $str = $ean; $width = 320; - $height = 100; + $height = 80; $im = imagecreatetruecolor($width, $height); $black = ImageColorAllocate($im, 0x00, 0x00, 0x00); $white = ImageColorAllocate($im, 0xff, 0xff, 0xff); @@ -109,9 +109,9 @@ class GenerateBarcode { } ob_start(); - $pdf = new FPDF(); + $pdf = new FPDF('P', 'mm', 'A4'); $nb_per_page = 0; - $pdf->SetMargins(8,15,8); + $pdf->SetMargins(9,12,9); $pdf->SetAutoPageBreak(FALSE); $pdf->AddPage(); $pdf->SetFont('Arial','',14); @@ -129,6 +129,7 @@ class GenerateBarcode { $pdf->addPage(); $nb_per_page = 0; } + foreach ($product_per_line as $key => $product) { if (empty($product)) { $pdf->Cell(48, 4, '', 0,0, 'C'); From 0974e32f3c75eeca3edb1e8f28e3a641ef6e8bae Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Tue, 22 Mar 2016 17:31:19 +0100 Subject: [PATCH 2/2] fix labelgenerate --- modules/labelgenerate/AdminLabelGenerate.php | 4 +- .../labelgenerate/models/generatebarcode.php | 66 ++++++++++++++++--- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php index a4acde27..500be3ad 100644 --- a/modules/labelgenerate/AdminLabelGenerate.php +++ b/modules/labelgenerate/AdminLabelGenerate.php @@ -47,7 +47,7 @@ class AdminLabelGenerate extends AdminTab { } 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); + $barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product_attribute` @@ -78,7 +78,7 @@ class AdminLabelGenerate extends AdminTab { } if ($quantity>0) { $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference); - $barcode->assocProduct($product->id, NULL, $quantity); + $barcode->assocProduct($product->id, NULL, $quantity, $product->reference); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product` diff --git a/modules/labelgenerate/models/generatebarcode.php b/modules/labelgenerate/models/generatebarcode.php index 316e4f5e..698f8445 100644 --- a/modules/labelgenerate/models/generatebarcode.php +++ b/modules/labelgenerate/models/generatebarcode.php @@ -54,7 +54,7 @@ class GenerateBarcode { return $number; } - public function assocProduct($id_product, $id_product_attribute = NULL, $quantity) { + public function assocProduct($id_product, $id_product_attribute = NULL, $quantity, $ref) { global $cookie; $p = Db::getInstance()->getRow(' SELECT pl.name @@ -71,18 +71,20 @@ class GenerateBarcode { for ($i=1; $i <= $quantity; $i++) { $this->products[] = array( 'key' => ($id_product.'-'.$id_product_attribute), - 'label' => ($name_combination . ' ' . $p['name']) + 'label' => ($name_combination . ' ' . $p['name']), + 'ref' => $ref ); } } else { for ($i=1; $i <= $quantity; $i++) { $this->products[] = array( 'key' => $id_product.'-0', - 'label' => $p['name'] + 'label' => $p['name'], + 'ref' => $ref ); } } - $this->products[] = array(); + //$this->products[] = array(); } public function printPDF() { @@ -92,21 +94,22 @@ class GenerateBarcode { /*for ($i=0; $i < 30; $i++) { $this->products[$i] = array( 'key' => "125415-322", - 'label' => "03 mois (62 cm)- Lot de 2 bodies Ri" + 'label' => "03 mois (62 cm)- Lot de 2 bodies Ri", + "ref" => "FIX-06-86763" ); } - $this->products[count($this->products)] = array(); for ($i=31; $i < 80; $i++) { $this->products[$i] = array( 'key' => "125416-332", - 'label' => "03 mois (62 cm)- Ensemble grenouill" + 'label' => "03 mois (62 cm)- Ensemble grenouill", + "ref" => "FIX-04-86763" ); - } - $this->products[count($this->products)] = array();*/ + }*/ if (empty($this->products)) { die('Tous les produits ont déjà un EAN'); } + $this->products = $this->_sortProducts($this->products, 'ref'); ob_start(); $pdf = new FPDF('P', 'mm', 'A4'); @@ -170,4 +173,49 @@ class GenerateBarcode { } } + private function _sortProducts($array = array(), $field, $order=SORT_ASC) { + $new_array = array(); + $sortable_array = array(); + + if (!empty($array)) { + foreach ($array as $k => $v) { + if (is_array($v)) { + foreach ($v as $k2 => $v2) { + if ($k2 == $field) { + $sortable_array[$k] = $v2; + } + } + } elseif (!empty($v)) { + $sortable_array[$k] = $v; + } + } + switch ($order) { + case SORT_ASC: + asort($sortable_array); + break; + case SORT_DESC: + arsort($sortable_array); + break; + } + + foreach ($sortable_array as $k => $v) { + $new_array[] = $array[$k]; + } + + $ref = ''; + $products = array(); + foreach ($new_array as $k => $v) { + if ($ref !== $v['ref'] && !empty($ref)) { + $products[] = array(); + $products[] = $v; + $ref = $v['ref']; + continue; + } + $products[] = $v; + $ref = $v['ref']; + } + } + return $products; + } + }