diff --git a/modules/labelgenerate/AdminLabelGenerate.php b/modules/labelgenerate/AdminLabelGenerate.php
index a5672463..39f86a78 100644
--- a/modules/labelgenerate/AdminLabelGenerate.php
+++ b/modules/labelgenerate/AdminLabelGenerate.php
@@ -12,8 +12,26 @@ class AdminLabelGenerate extends AdminTab {
public function display() {
global $cookie;
+ $rack = Tools::getValue('rack');
$current_sale = Tools::getValue('id_sale');
- if ($current_sale && Tools::getValue('deleteEAN')) {
+ if ($rack) {
+ // button commenté en fin de page
+ $barcode = new GenerateBarcode();
+ $barcode->createRackFolder();
+ $rackCodes = array();
+ for ($i=1;$i<21;$i++) {
+ for ($j=1;$j<6;$j++) {
+ $name = $i.$j;
+ $barcode->generateRack($name);
+ $rackCodes[] = $name;
+ }
+ }
+ $barcode->printRackPDF($rackCodes);
+
+ if (glob(_PS_MODULE_DIR_.'labelgenerate/img/rack/rack.pdf')) {
+ $this->_html .= '
Rack générés : Télécharger le PDF rack
';
+ }
+ } elseif ($current_sale && Tools::getValue('deleteEAN')) {
$sale = new Sale((int)$current_sale);
if(!Validate::isLoadedObject($sale)) {
@@ -181,6 +199,14 @@ class AdminLabelGenerate extends AdminTab {
';
+ /*$this->_html .='
+
';*/
+
$this->_html.= '';
$this->_html.= '';
@@ -214,6 +240,10 @@ class AdminLabelGenerate extends AdminTab {
}
});
+ $("#generateRack").click(function(){
+ document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&rack=1\';
+ });
+
});
';
diff --git a/modules/labelgenerate/models/generatebarcode.php b/modules/labelgenerate/models/generatebarcode.php
index fc5e20c4..649c69a8 100644
--- a/modules/labelgenerate/models/generatebarcode.php
+++ b/modules/labelgenerate/models/generatebarcode.php
@@ -18,6 +18,61 @@ class GenerateBarcode {
}
}
+ public function createRackFolder() {
+ if (!(is_dir(self::$barcode_directory.'rack'))) {
+ mkdir(self::$barcode_directory.'rack', 0775);
+ }
+ }
+
+ public function generateRack($name) {
+ $width = 320;
+ $height = 80;
+ $im = imagecreatetruecolor($width, $height);
+ $black = ImageColorAllocate($im, 0x00, 0x00, 0x00);
+ $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
+ imagefilledrectangle($im, 0, 0, $width, $height, $white);
+ Barcode::gd($im, $black, $width / 2, $height / 2 - 10 , 0, "code128", $name, 3, 50);
+ imagettftext($im, 11, 0, $width / 2 - (strlen('*'.$name.'*')* 4), $height - 10 , $black, dirname(__FILE__).'/arial.ttf', '*'.$name.'*' );
+
+ imagegif($im, self::$barcode_directory.'rack/img-'.$name.'.gif');
+ }
+
+ public function printRackPDF($codes) {
+ ob_start();
+ $pdf = new FPDF('P', 'mm', 'A4');
+ $nb_per_page = 0;
+ $pdf->SetMargins(9,12,9);
+ $pdf->SetAutoPageBreak(FALSE);
+ $pdf->AddPage();
+ $pdf->SetFont('Arial','',14);
+
+ $nb_line = ceil((count($codes)/4));
+ for ($i=1; $i <= $nb_line; $i++) {
+ $img_per_line = array_slice($codes, 0, 4);
+ $codes = array_splice($codes, 4);
+
+ if($nb_per_page == self::_TOTAL_PER_PAGE_) {
+ $pdf->addPage();
+ $nb_per_page = 0;
+ }
+ foreach ($img_per_line as $key => $value) {
+ $this->_printLabel($pdf, $value, 1);
+ }
+ $pdf->Ln(4);
+
+ foreach ($img_per_line as $key => $value) {
+ $image = self::$barcode_directory.'rack/img-'.$value.'.gif';
+ $this->_printEAN($pdf, $image, 1);
+ }
+ $pdf->Ln(13);
+
+ $nb_per_page += 1;
+ }
+ $pdf->Output(self::$barcode_directory.'rack/rack.pdf', 'F');
+ ob_clean();
+ return TRUE;
+ }
+
public function createFolder($name) {
if (!(is_dir(self::$barcode_directory.$name))) {
mkdir(self::$barcode_directory.$name, 0775);