Compare commits
2 Commits
master
...
module-lab
Author | SHA1 | Date | |
---|---|---|---|
|
5229f2c42f | ||
|
76ee0c4c15 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -110,4 +110,5 @@ modules/privatesales_logistique/files/*
|
||||
modules/emarsys_rss/flux.xml
|
||||
modules/emarsys_rss/*.xml
|
||||
modules/bulkupdate/*.csv
|
||||
modules/logistics/carriers/laposte/summaries/*.pdf
|
||||
modules/logistics/carriers/laposte/summaries/*.pdf
|
||||
modules/labelgenerate/img/*
|
@ -30,13 +30,13 @@ class AdminLabelGenerate extends AdminTab {
|
||||
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`
|
||||
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
|
||||
FROM '._DB_PREFIX_.'order_detail od
|
||||
WHERE od.`product_id` = ' . (int)$combination['id_product'] .'
|
||||
AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute']
|
||||
@ -47,9 +47,9 @@ 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->_assocProductTest($combination['id_product'], $combination['id_product_attribute'], $quantity);
|
||||
Db::getInstance()->execute('
|
||||
UPDATE
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'product_attribute`
|
||||
SET `ean13` = '. $ean_generate . '
|
||||
WHERE `id_product` = ' . (int)$product->id .'
|
||||
@ -61,7 +61,7 @@ class AdminLabelGenerate extends AdminTab {
|
||||
} else {
|
||||
if (empty($product->ean13)) {
|
||||
$result_quantities = Db::getInstance()->executeS('
|
||||
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
|
||||
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
|
||||
FROM '._DB_PREFIX_.'order_detail od
|
||||
WHERE od.`product_id` = ' . (int)$product->id
|
||||
);
|
||||
@ -71,9 +71,9 @@ class AdminLabelGenerate extends AdminTab {
|
||||
}
|
||||
if ($quantity>0) {
|
||||
$ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference);
|
||||
$barcode->_assocProduct($product->id, NULL, $quantity);
|
||||
$barcode->_assocProductTest($product->id, NULL, $quantity);
|
||||
Db::getInstance()->execute('
|
||||
UPDATE
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'product`
|
||||
SET `ean13` = '. $ean_generate . '
|
||||
WHERE `id_product` = ' . (int)$product->id
|
||||
@ -82,21 +82,19 @@ class AdminLabelGenerate extends AdminTab {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($ean_generate)) {
|
||||
$barcode->_printPDF();
|
||||
$barcode->_printPDFTest();
|
||||
$this->_html .= '<p class="conf">Génération terminée : <a target="_blank" href="/modules/labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf">Télécharger le PDF</a></p>';
|
||||
} else {
|
||||
$barcode->_printPDF();
|
||||
$this->_html .= '<p class="conf">Génération terminée : <a target="_blank" href="/modules/labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf">Télécharger le PDF</a></p>';
|
||||
/*$this->_html .= '<p class="conf">Tous les produits de la vente ont déjà des EANS</p>';
|
||||
$this->_html .= '<p class="conf">Tous les produits de la vente ont déjà des EANS</p>';
|
||||
if (glob(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf')) {
|
||||
$this->_html .= '<p class="conf">Dernières étiquettes générées : <a target="_blank" href="/modules/labelgenerate/img/'.$barcode->id_sale.'/barcode.pdf">Télécharger le PDF</a></p>';
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->_html .= '<fieldset>
|
||||
<legend>'.$this->l('Sale selection').'</legend>
|
||||
<div class="margin-form">
|
||||
@ -118,7 +116,7 @@ class AdminLabelGenerate extends AdminTab {
|
||||
$this->_html.= '<script type="text/javascript" src="'._MODULE_DIR_.'bulkupdate/chosen.jquery.min.js"></script>';
|
||||
$this->_html.= '<script type="text/javascript">
|
||||
$(function() {
|
||||
$(".chosen-select").chosen(
|
||||
$(".chosen-select").chosen(
|
||||
{
|
||||
allow_single_deselect:true,
|
||||
placeholder_text_single : "Choisir une vente",
|
||||
@ -127,11 +125,11 @@ class AdminLabelGenerate extends AdminTab {
|
||||
search_contains : true,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$(".chosen-select").chosen().change( function() {
|
||||
if($(this).val() != 999999) {
|
||||
$(\'#category_selector\').hide();
|
||||
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&id_sale=\' + $(this).val();
|
||||
if($(this).val() != 999999) {
|
||||
$(\'#category_selector\').hide();
|
||||
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&id_sale=\' + $(this).val();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -38,7 +38,7 @@ class GenerateBarcode {
|
||||
Barcode::gd($im, $black, $width / 2, $height / 2 - 10 , 0, "code128", $str, 3, 50);
|
||||
/* imagettftext($im, 11, 0, $width / 2 - (strlen('*'.$ean.'*')* 4), $height - 10 , $black, dirname(__FILE__).'/arial.ttf', substr(str_replace(' ', '_', '*'.$ean.'*'),0, 35) );*/
|
||||
imagettftext($im, 11, 0, $width / 2 - (strlen('*'.$reference.'*')* 4), $height - 10 , $black, dirname(__FILE__).'/arial.ttf', '*'.$reference.'*' );
|
||||
|
||||
|
||||
if ($id_product_attribute) {
|
||||
imagegif($im, $this->directory.'/ean-'.$id_product.'-'.$id_product_attribute.'.gif');
|
||||
} else {
|
||||
@ -92,6 +92,37 @@ class GenerateBarcode {
|
||||
}
|
||||
}
|
||||
|
||||
public function _assocProductTest($id_product, $id_product_attribute = NULL, $quantity) {
|
||||
global $cookie;
|
||||
$p = Db::getInstance()->getRow('
|
||||
SELECT pl.name
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = p.`id_product`
|
||||
WHERE p.`id_product` = '.(int)$id_product.'
|
||||
AND pl.`id_lang`='.(int)$cookie->id_lang);
|
||||
if ($id_product_attribute) {
|
||||
$details = Product::getDetailsCombination($id_product_attribute, $cookie->id_lang);
|
||||
$name_combination = '';
|
||||
foreach ($details as $key_attr => $detail) {
|
||||
$name_combination .= $detail['attribute_name'].'-';
|
||||
}
|
||||
for ($i=1; $i <= $quantity; $i++) {
|
||||
$this->products[] = array(
|
||||
'key' => ($id_product.'-'.$id_product_attribute),
|
||||
'label' => ($name_combination . ' ' . $p['name'])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for ($i=1; $i <= $quantity; $i++) {
|
||||
$this->products[] = array(
|
||||
'key' => $id_product.'-0',
|
||||
'label' => $p['name']
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->products[] = array();
|
||||
}
|
||||
|
||||
public function printPDF() {
|
||||
global $cookie;
|
||||
|
||||
@ -112,7 +143,7 @@ class GenerateBarcode {
|
||||
$pdf->SetAutoPageBreak(FALSE);
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('Arial','',14);
|
||||
|
||||
|
||||
foreach ($this->products as $key => $quantity) {
|
||||
$quantity_already_print = 0;
|
||||
$explode = explode('-', $key);
|
||||
@ -131,10 +162,10 @@ class GenerateBarcode {
|
||||
$label = $product->name;
|
||||
}
|
||||
|
||||
// printed line
|
||||
// printed line
|
||||
$nb_line = ceil(($quantity/self::_NB_PER_LINE_));
|
||||
for ($i=1; $i <= $nb_line; $i++) {
|
||||
|
||||
|
||||
if($nb_per_page == self::_TOTAL_PER_PAGE_) {
|
||||
$pdf->addPage();
|
||||
$nb_per_page = 0;
|
||||
@ -200,10 +231,10 @@ class GenerateBarcode {
|
||||
foreach ($this->products as $k => $p) {
|
||||
$quantity_already_print = 0;
|
||||
if ($this->products[$k]['quantity']>0){
|
||||
// printed line
|
||||
// printed line
|
||||
$nb_line = ceil(($this->products[$k]['quantity']/self::_NB_PER_LINE_));
|
||||
for ($i=1; $i <= $nb_line; $i++) {
|
||||
|
||||
|
||||
if($nb_per_page == self::_TOTAL_PER_PAGE_) {
|
||||
$pdf->addPage();
|
||||
$nb_per_page = 0;
|
||||
@ -255,15 +286,86 @@ class GenerateBarcode {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function _printPDFTest() {
|
||||
global $cookie;
|
||||
|
||||
// données test
|
||||
/*for ($i=0; $i < 30; $i++) {
|
||||
$this->products[$i] = array(
|
||||
'key' => "125415-322",
|
||||
'label' => "03 mois (62 cm)- Lot de 2 bodies Ri"
|
||||
);
|
||||
}
|
||||
$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"
|
||||
);
|
||||
}
|
||||
$this->products[count($this->products)] = array();*/
|
||||
|
||||
if (empty($this->products)) {
|
||||
die('Tous les produits ont déjà un EAN');
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$pdf = new FPDF();
|
||||
$nb_per_page = 0;
|
||||
$pdf->SetMargins(8,15,8);
|
||||
$pdf->SetAutoPageBreak(FALSE);
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('Arial','',14);
|
||||
|
||||
$nb_line = ceil((count($this->products)/self::_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, self::_NB_PER_LINE_);
|
||||
$this->products = array_splice($this->products, self::_NB_PER_LINE_);
|
||||
|
||||
if($nb_per_page == self::_TOTAL_PER_PAGE_) {
|
||||
$pdf->addPage();
|
||||
$nb_per_page = 0;
|
||||
}
|
||||
foreach ($product_per_line as $key => $product) {
|
||||
if (empty($product)) {
|
||||
$pdf->Cell(48, 4, '', 0,0, 'C');
|
||||
} else {
|
||||
$this->_printLabel($pdf, $product['label'], 1);
|
||||
}
|
||||
}
|
||||
$pdf->Ln(4);
|
||||
|
||||
foreach ($product_per_line as $key => $product) {
|
||||
if (empty($product)) {
|
||||
$pdf->Cell(48, 10, '', 0,0, 'C');
|
||||
} else {
|
||||
$ean_image = $this->directory.'/ean-'.$product['key'].'.gif';
|
||||
$this->_printEAN($pdf, $ean_image, 1);
|
||||
}
|
||||
}
|
||||
$pdf->Ln(13);
|
||||
|
||||
$nb_per_page += 1;
|
||||
}
|
||||
}
|
||||
$pdf->Output($this->directory.'/barcode.pdf', 'F');
|
||||
ob_clean();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
private function _printLabel($pdf, $label, $limit = 1) {
|
||||
$pdf->SetFont('Arial', '', 5);
|
||||
for ($i=0; $i < $limit; $i++) {
|
||||
$pdf->Cell(48, 4, substr(utf8_decode($label), 0, 35), 0,0, 'C');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _printEAN($pdf, $ean_image, $limit = 1) {
|
||||
for ($i=0; $i < $limit; $i++) {
|
||||
for ($i=0; $i < $limit; $i++) {
|
||||
$pdf->Cell(48, 10, $pdf->Image($ean_image, $pdf->GetX(), $pdf->GetY(),48, 10), 0,0, 'C');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user