Merge branch 'rack-labelgenerate'

This commit is contained in:
Marion Muszynski 2016-04-08 10:36:20 +02:00
commit 49e9ffa2fd
2 changed files with 86 additions and 1 deletions

View File

@ -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 .= '<p class="conf">Rack générés : <a target="_blank" href="/modules/labelgenerate/img/rack/rack.pdf">Télécharger le PDF rack</a></p>';
}
} elseif ($current_sale && Tools::getValue('deleteEAN')) {
$sale = new Sale((int)$current_sale);
if(!Validate::isLoadedObject($sale)) {
@ -181,6 +199,14 @@ class AdminLabelGenerate extends AdminTab {
</fieldset>
<br /><br />';
/*$this->_html .='<fieldset>
<legend>'.$this->l('Rack barcode').'</legend>
<div class="margin-form">
<button class="button" id="generateRack">'.$this->l('Generate rack').'</button>
</div>
</fieldset>
<br /><br />';*/
$this->_html.= '<link type="text/css" rel="stylesheet" href="'._MODULE_DIR_.'bulkupdate/chosen.min.css" />';
$this->_html.= '<script type="text/javascript" src="'._MODULE_DIR_.'bulkupdate/chosen.jquery.min.js"></script>';
@ -214,6 +240,10 @@ class AdminLabelGenerate extends AdminTab {
}
});
$("#generateRack").click(function(){
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&rack=1\';
});
});
</script>';

View File

@ -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);