New button
This commit is contained in:
parent
c658d0ec75
commit
0b835a3af5
@ -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 :<br><a class="btn btn-primary btn-xs" target="_blank" href="/modules/labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf?v='.time().'">Télécharger le PDF</a>');
|
||||
} 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 .= '<br>Dernières étiquettes générées : <a class="btn btn-primary btn-xs" target="_blank" href="/modules/labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf?v='.time().'">Télécharger le PDF</a>';
|
||||
}
|
||||
$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
|
||||
<p><button class="btn btn-primary" id="generateALLEAN_initial" data-toggle="tooltip" data-placement="left" title="Tous les EAN et génère les manquants des quantités initiales">Générer EANs (qté initiales)</button></p>
|
||||
<p><button class="btn btn-default" id="deleteEAN" data-toggle="tooltip" data-placement="left" title="Supprimer tous les EAN de la vente">Supprimer les EANs</button></p>
|
||||
<p class="hidden"><button class="hidden btn btn-default" id="generateRack">Générer Rack</button></p>
|
||||
<p> </p>
|
||||
<p><button class="btn btn-primary" id="generateIdentification" data-toggle="tooltip" data-placement="left" title="Générer Etiquette Référence Bebeboutik">Générer Référence</button></p>
|
||||
</div>
|
||||
|
||||
<div class="clear"></div>
|
||||
@ -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
|
||||
|
||||
});
|
||||
</script>';
|
||||
|
||||
|
||||
$this->_html .= $helperForm->renderScript();
|
||||
echo $this->_html;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user