createRackFolder(); $rackCodes = array(); for ($i=0;$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->displaySucess('Rack générés : Télécharger le PDF rack'); } } elseif ($current_sale && Tools::getValue('generateRef')) { $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(); $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); if ($combinations) { foreach ($combinations as $key => $combination) { $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->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference); } } } else { $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) { $barcode->assocProduct($product->id, NULL, $quantity, $product->reference); } } } if (glob(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/reference.pdf')) { $this->displayWarning('Les références ont déjà été générées
Dernières ref générées : Télécharger le PDF'); } else { if($barcode->printPDF($big_label, 'reference')) { $this->displaySucess('Génération terminée : Télécharger le PDF'); } else { $this->_html .= $this->displayError('Pas de produit à générer !'); } } } } elseif ($current_sale && Tools::getValue('deleteEAN')) { $sale = new Sale((int)$current_sale); if(!Validate::isLoadedObject($sale)) { throw new Exception('This sale doesnt exist'); } else { $products = $sale->getProducts(); foreach ($products as $key => $id_product) { $product = new Product($id_product, FALSE, (int) $cookie->id_lang); $attributes = array(); $combinations = $product->getAttributeCombinaisons($cookie->id_lang); if ($combinations) { foreach ($combinations as $key => $combination) { if (!empty($combination['ean13'])) { Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product_attribute` SET `ean13` = "" WHERE `id_product` = ' . (int)$product->id .' AND `id_product_attribute` = ' . (int)$combination['id_product_attribute'] ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = '. (int)$combination['id_product_attribute'] ); } } } else { if (!empty($product->ean13)) { Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product` SET `ean13` = "" WHERE `id_product` = ' . (int)$product->id ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = 0 '); } } } $this->_html .= $this->displaySuccess('Suppression terminée'); } } elseif ($current_sale && Tools::getValue('generateALLEAN')) { $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); $count = 0; foreach ($products as $key => $id_product) { $product = new Product($id_product, FALSE, (int) $cookie->id_lang); $attributes = array(); $combinations = $product->getAttributeCombinaisons($cookie->id_lang); if ($combinations) { foreach ($combinations as $key => $combination) { $quantity = 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)$combination['id_product'] .' AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute'].' AND o.`valid` != 0' ); foreach ($result_quantities as $od) { $quantity += ((int)$od['product_quantity'] - (int)$od['product_quantity_reinjected']); } if($quantity>0){ $count++; if (empty($combination['ean13'])) { $ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product_attribute` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id .' AND `id_product_attribute` = ' . (int)$combination['id_product_attribute'] ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "'. pSQL($ean_generate) .'" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = '. (int)$combination['id_product_attribute'] ); } else { $ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference, $combination['ean13']); } $barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference); } } } else { $quantity = 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' ); foreach ($result_quantities as $od) { $quantity += ((int)$od['product_quantity'] - (int)$od['product_quantity_reinjected']); } if($quantity>0){ $count++; if (empty($product->ean13)) { $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "'. pSQL($ean_generate) .'" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = 0 '); } else { $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference, $product->ean13); } $barcode->assocProduct($product->id, NULL, $quantity, $product->reference); } } } if (!empty($ean_generate)) { if (glob(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode_all.pdf')) { unlink(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode_all.pdf'); } if($barcode->printPDF($big_label,'barcode_all')) { $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 = 'Aucun ean trouvé ou généré !'; if (glob(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode_all.pdf')) { $message .= '
Dernières étiquettes générées : Télécharger le PDF'; } $this->_html .= $this->displayWarning($message); } } } elseif ($current_sale && Tools::getValue('generateALLEAN_initial')) { $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); if ($combinations) { foreach ($combinations as $key => $combination) { $quantity = (int)$combination['quantity']; $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' ); foreach ($result_quantities as $od) { $quantity += ((int)$od['product_quantity'] - (int)$od['product_quantity_reinjected']); } if (empty($combination['ean13'])) { $ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product_attribute` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id .' AND `id_product_attribute` = ' . (int)$combination['id_product_attribute'] ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "'. pSQL($ean_generate) .'" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = '. (int)$combination['id_product_attribute'] ); } else { $ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference, $combination['ean13']); } $barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference); } } else { $quantity = $product->quantity; $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' ); foreach ($result_quantities as $od) { $quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']); } if (empty($product->ean13)) { $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "'. pSQL($ean_generate) .'" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = 0 '); } else { $ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference, $product->ean13); } $barcode->assocProduct($product->id, NULL, $quantity, $product->reference); } } if (!empty($ean_generate)) { if (glob(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode_all_initial.pdf')) { unlink(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode_all_initial.pdf'); } if($barcode->printPDF($big_label,'barcode_all_initial')) { $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 = 'Aucun ean trouvé ou généré !'; if (glob(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode_all_initial.pdf')) { $message .= '
Dernières étiquettes générées : Télécharger le PDF'; } $this->_html .= $this->displayWarning($message); } } } elseif ($current_sale && Tools::getValue('generateEAN')) { $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); 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); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product_attribute` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id .' AND `id_product_attribute` = ' . (int)$combination['id_product_attribute'] ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "'. pSQL($ean_generate) .'" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = '. (int)$combination['id_product_attribute'] ); } } } } 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); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'product` SET `ean13` = '. $ean_generate . ' WHERE `id_product` = ' . (int)$product->id ); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_ean13` = "'. pSQL($ean_generate) .'" WHERE `product_id` = '. (int)$product->id .' AND `product_attribute_id` = 0 '); } } } } if (!empty($ean_generate)) { if (glob(_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 (glob(_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; $helperForm->_inputSwitch = true; $id_sale_options = array(); foreach(Sale::getSales(NULL, NULL, NULL, NULL, FALSE, FALSE, '`date_start` DESC', 500) as $sale) { $id_sale_options[(int)$sale->id] = array( 'label' => $sale->id.' - '.$sale->title[(int) $cookie->id_lang], 'value' => (int) $sale->id ); if($sale->id == $current_sale) { $id_sale_options[(int)$sale->id]['selected'] = true; } } $this->_html .= $helperForm->renderStyle(); $this->_html .= '

'.$this->l('Génération EAN').'

'; $input = array( 'type' => 'select2', 'label' => $this->l('Select a sale:'), 'label-class' => 'text-left', 'select-class' => 'text-left', 'name' => 'id_sale', 'id' => 'id_sale', 'options' => $id_sale_options, ); $this->_html .= $helperForm->generateInput($input); $input = array( 'type' => 'switch', 'label' => '', 'label-class' => 'col-md-4', 'input-class' => 'col-md-6', 'class-group' => 'switch', 'name' => 'big_label', 'title' => $this->l('Big labels ?'), ); $this->_html .= $helperForm->generateInput($input).'

'; $helperForm->_js .=''; $this->_html .= $helperForm->renderScript(); echo $this->_html; } public function displaySuccess($message){ return '
'.$message.'
'; } public function displayWarning($message){ return '
'.$message.'
'; } public function displayError($message){ return '
'.$message.'
'; } }