Merge branch 'ticket-12379-updateLabelgenerateEan' into develop

This commit is contained in:
Marion Muszynski 2017-02-08 12:04:23 +01:00
commit 8203ea5774
2 changed files with 93 additions and 54 deletions

View File

@ -35,6 +35,7 @@ class AdminLabelGenerate extends AdminTab {
}
} 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');
@ -85,7 +86,7 @@ class AdminLabelGenerate extends AdminTab {
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<br>Dernières ref générées : <a class="btn btn-primary btn-xs" target="_blank" href="/modules/labelgenerate/img/'.$barcode->id_sale.'/reference.pdf">Télécharger le PDF</a>');
} else {
if($barcode->printPDF(true)) {
if($barcode->printPDF($big_label, 'reference')) {
$this->displaySucess('Génération terminée : <a class="btn btn-primary btn-xs" target="_blank" href="/modules/labelgenerate/img/'.$barcode->id_sale.'/reference.pdf">Télécharger le PDF</a>');
} else {
$this->_html .= $this->displayError('Pas de produit à générer !');
@ -146,6 +147,7 @@ class AdminLabelGenerate extends AdminTab {
}
} 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');
@ -238,7 +240,7 @@ class AdminLabelGenerate extends AdminTab {
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(false,'barcode_all')) {
if($barcode->printPDF($big_label,'barcode_all')) {
$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_all.pdf">Télécharger le PDF</a>');
} else {
$this->_html .= $this->displayError('Pas de produit à générer !');
@ -252,7 +254,8 @@ class AdminLabelGenerate extends AdminTab {
}
}
} elseif ($current_sale && Tools::getValue('generateALLEAN_initial')) {
$sale = new Sale((int)$current_sale);
$sale = new Sale((int)$current_sale);
$big_label = Tools::getValue('big_label');
if(!Validate::isLoadedObject($sale)) {
throw new Exception('This sale doesnt exist');
@ -339,7 +342,7 @@ class AdminLabelGenerate extends AdminTab {
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(false,'barcode_all_initial')) {
if($barcode->printPDF($big_label,'barcode_all_initial')) {
$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_all_initial.pdf">Télécharger le PDF</a>');
} else {
$this->_html .= $this->displayError('Pas de produit à générer !');
@ -354,6 +357,7 @@ class AdminLabelGenerate extends AdminTab {
}
} 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');
@ -440,7 +444,7 @@ class AdminLabelGenerate extends AdminTab {
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()) {
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">Télécharger le PDF</a>');
} else {
$this->_html .= $this->displayError('Pas de produit à générer !');
@ -457,6 +461,7 @@ class AdminLabelGenerate extends AdminTab {
$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) {
@ -490,7 +495,18 @@ class AdminLabelGenerate extends AdminTab {
'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).'
<div class="clearfix"></div>
</div>
<div class="col-md-3 col-md-offset-1 lateral-solid-l">
<p class="hidden"><button class="btn btn-primary" id="generateRef" data-toggle="tooltip" data-placement="left" title="Produits vendus">Générer Refs</button></p>
@ -507,33 +523,40 @@ class AdminLabelGenerate extends AdminTab {
$helperForm->_js .='<script type="text/javascript">
$(function() {
var big_label = 0;
$(\'[data-toggle="tooltip"]\').tooltip();
$(\'.js-switch\').change(function(){
if($(this).is(\':checked\')) {
big_label = 1;
}
});
$("#generateEAN").click(function(){
if ($("#id_sale").val() != 999999) {
$(\'#category_selector\').hide();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateEAN=1&id_sale=\' + $("#id_sale").val();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateEAN=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val();
}
});
$("#generateRef").click(function(){
if ($("#id_sale").val() != 999999) {
$(\'#category_selector\').hide();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateRef=1&id_sale=\' + $("#id_sale").val();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateRef=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val();
}
});
$("#generateALLEAN").click(function(){
if ($("#id_sale").val() != 999999) {
$(\'#category_selector\').hide();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN=1&id_sale=\' + $("#id_sale").val();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val();
}
});
$("#generateALLEAN_initial").click(function(){
if ($("#id_sale").val() != 999999) {
$(\'#category_selector\').hide();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN_initial=1&id_sale=\' + $("#id_sale").val();
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateALLEAN_initial=1&big_label=\'+ big_label +\'&id_sale=\' + $("#id_sale").val();
}
});

View File

@ -11,6 +11,8 @@ class GenerateBarcode {
const _NB_PER_LINE_ = 4;
const _TOTAL_PER_PAGE_ = 16;
const _NB_PER_LINE_BIG_ = 4;
const _TOTAL_PER_PAGE_BIG_ = 9;
public function __construct() {
if (is_null(self::$barcode_directory)) {
@ -146,9 +148,34 @@ class GenerateBarcode {
//$this->products[] = array();
}
public function printPDF($generate_ref = false,$file='') {
public function printPDF($big_label = false, $file = 'barcode') {
global $cookie;
if($big_label){
// 52*30
$width = 52;
$height_label = 13;
$height_text = 7;
$ln_label = 16;
$ln_text = 7;
$nb_per_line = self::_NB_PER_LINE_BIG_;
$total_per_page = self::_TOTAL_PER_PAGE_BIG_;
$font_size = 6;
$font_size_ref = 10;
$margin = 3;
} else {
// 48*17
$width = 48;
$height_label = 10;
$height_text = 4;
$ln_label = 13;
$ln_text = 4;
$nb_per_line = self::_NB_PER_LINE_;
$total_per_page = self::_TOTAL_PER_PAGE_;
$font_size = 5;
$margin = 9;
}
// données test
// for ($i=0; $i < 60; $i++) {
// $this->products[$i] = array(
@ -200,89 +227,78 @@ class GenerateBarcode {
// $this->products = $this->_sortProducts($this->products, 'ref');
// }
$this->products = $this->_multiSortProduct($this->products);
ob_start();
$pdf = new FPDF('P', 'mm', 'A4');
$nb_per_page = 0;
if($generate_ref) {
$pdf->SetMargins(9,13,9);
} else {
$pdf->SetMargins(9,12,9);
}
$pdf->SetMargins($margin,12,$margin);
$pdf->SetAutoPageBreak(FALSE);
$pdf->AddPage();
$pdf->SetFont('Arial','',14);
$nb_line = ceil((count($this->products)/self::_NB_PER_LINE_));
$nb_line = ceil((count($this->products)/$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_);
$product_per_line = array_slice($this->products, 0, $nb_per_line);
$this->products = array_splice($this->products, $nb_per_line);
if($nb_per_page == self::_TOTAL_PER_PAGE_) {
if($nb_per_page == $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');
} elseif($generate_ref) {
$pdf->SetFont('Arial', '', 7);
$pdf->Cell(48, 8, substr(utf8_decode($product['decli']), 0, 35), 0,0, 'C');
} else {
$this->_printLabel($pdf, $product['label'], 1);
if($big_label){
foreach ($product_per_line as $key => $product) {
if (empty($product)) {
$pdf->Cell($width, $height_text, '', 0,0, 'C');
} else {
$this->_printLabel($pdf, $product['ref'], 1,$width,$height_text, $font_size_ref);
}
}
}
if($generate_ref) {
$pdf->Ln(8);
} else {
$pdf->Ln(4);
$pdf->Ln(($ln_text));
}
foreach ($product_per_line as $key => $product) {
if (empty($product)) {
$pdf->Cell(48, 10, '', 0,0, 'C');
} elseif($generate_ref) {
$pdf->SetFont('Arial', '', 7);
$pdf->Cell(48, 8, $product['ref'], 0,0, 'C');
$pdf->Cell($width, $height_text, '', 0,0, 'C');
} else {
$ean_image = $this->directory.'/ean-'.$product['key'].'.gif';
$this->_printEAN($pdf, $ean_image, 1);
$this->_printLabel($pdf, $product['label'], 1,$width,$height_text, $font_size);
}
}
if($generate_ref) {
$pdf->Ln(9);
} else {
$pdf->Ln(13);
$pdf->Ln(($ln_text));
foreach ($product_per_line as $key => $product) {
if (empty($product)) {
$pdf->Cell($width, $height_label, '', 0,0, 'C');
} else {
$ean_image = $this->directory.'/ean-'.$product['key'].'.gif';
$this->_printEAN($pdf, $ean_image, 1,$width,$height_label);
}
}
$pdf->Ln($ln_label);
$nb_per_page += 1;
}
}
if($generate_ref){
$pdf->Output($this->directory.'/reference.pdf', 'F');
} else {
$file = $file!=''?$file:'barcode';
$pdf->Output($this->directory.'/'.$file.'.pdf', 'F');
}
$pdf->Output($this->directory.'/'.$file.'.pdf', 'F');
ob_clean();
return TRUE;
}
private function _printLabel($pdf, $label, $limit = 1) {
$pdf->SetFont('Arial', '', 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(48, 4, substr(utf8_decode($label), 0, 35), 0,0, 'C');
$pdf->Cell($width, $height, substr(utf8_decode($label), 0, 35), 0,0, 'C');
}
}
private function _printEAN($pdf, $ean_image, $limit = 1) {
private function _printEAN($pdf, $ean_image, $limit = 1, $width = 48, $height = 10) {
for ($i=0; $i < $limit; $i++) {
$pdf->Cell(48, 10, $pdf->Image($ean_image, $pdf->GetX(), $pdf->GetY(),48, 10), 0,0, 'C');
$pdf->Cell($width, $height, $pdf->Image($ean_image, $pdf->GetX(), $pdf->GetY(),($width-2), $height), 0,0, 'C');
}
}