Merge remote-tracking branch 'origin/ticket/r15862-label_refbbb'
This commit is contained in:
commit
eed8873dc5
@ -466,6 +466,84 @@ 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) {
|
||||
$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) {
|
||||
print_r($combination);
|
||||
$barcode->generateIdentification($combination['id_product'], $combination['id_product_attribute'], $product->reference, $combination['attribute_name']);
|
||||
$barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Product without attributes
|
||||
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->generateIdentification($product->id, null, $product->reference);
|
||||
$barcode->assocProduct($product->id, null, $quantity, $product->reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/identification.pdf')) {
|
||||
unlink(_PS_MODULE_DIR_.'labelgenerate/img/'.$barcode->id_sale.'/identification.pdf');
|
||||
}
|
||||
|
||||
if ($barcode->printIdentification($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.'/identification.pdf?v='.time().'">Télécharger le PDF</a>');
|
||||
} else {
|
||||
$this->_html .= $this->displayError('Pas de produit à générer !');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$helperForm = new HelperFormBootstrap();
|
||||
$helperForm->_select2 = true;
|
||||
@ -521,6 +599,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>
|
||||
@ -541,37 +621,37 @@ class AdminLabelGenerate extends AdminTab
|
||||
$("#generateEAN").click(function(){
|
||||
if ($("#id_sale").val() != 999999) {
|
||||
$(\'#category_selector\').hide();
|
||||
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateEAN=1&big_label=\'+ big_label +\'&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&big_label=\'+ big_label +\'&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&big_label=\'+ big_label +\'&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&big_label=\'+ big_label +\'&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();
|
||||
}
|
||||
});
|
||||
|
||||
$("#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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -579,9 +659,12 @@ class AdminLabelGenerate extends AdminTab
|
||||
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&rack=1\';
|
||||
});
|
||||
|
||||
$("#generateIdentification").click(function(){
|
||||
document.location.href=\'index.php?tab=AdminLabelGenerate&token='.Tools::getAdminTokenLite('AdminLabelGenerate').'&generateIdentification=1&id_sale=\'+$("#id_sale").val();
|
||||
});
|
||||
});
|
||||
</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,42 @@ class GenerateBarcode {
|
||||
return $ean;
|
||||
}
|
||||
|
||||
private function _getEanNumber() {
|
||||
public function generateIdentification($id_product, $id_product_attribute = null, $reference = null, $attribute_ref = null, $big_label = false)
|
||||
{
|
||||
$width = 320;
|
||||
$height = 80;
|
||||
$font = dirname(__FILE__).'/arial.ttf';
|
||||
|
||||
preg_match('/.*-(.*)-.*/', $reference, $matches);
|
||||
$ref = $matches[1];
|
||||
|
||||
$im = imagecreatetruecolor($width, $height);
|
||||
$black = ImageColorAllocate($im, 0x00, 0x00, 0x00);
|
||||
$white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
|
||||
imagefilledrectangle($im, 0, 0, $width, $height, $white);
|
||||
|
||||
imagettftext($im, 30, 0, 10, 50, $black, $font, $ref);
|
||||
|
||||
if ($id_product_attribute === null) {
|
||||
$result = imagegif($im, $this->directory.'/id-'.$id_product.'-0.gif');
|
||||
} else {
|
||||
imagettftext($im, 12, 0, 65, 50 , $black, $font, $attribute_ref);
|
||||
$result = imagegif($im, $this->directory.'/id-'.$id_product.'-'.$id_product_attribute.'.gif');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
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 +187,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 +331,102 @@ class GenerateBarcode {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
private function _printLabel($pdf, $label, $limit = 1, $width = 48, $height = 4, $font_size = 5) {
|
||||
public function printIdentification($big_label = false, $file = 'identification')
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if ($big_label) {
|
||||
// 52*30
|
||||
$width = 51.5;
|
||||
$height_label = 14;
|
||||
$height_text = 7;
|
||||
$ln_label = 15;
|
||||
$ln_text = 7.1;
|
||||
$nb_per_line = self::_NB_PER_LINE_BIG_;
|
||||
$total_per_page = self::_TOTAL_PER_PAGE_BIG_;
|
||||
$font_size = 9;
|
||||
$font_size_ref = 10;
|
||||
$margin = 3;
|
||||
$margin_top = 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;
|
||||
$margin_top = 12;
|
||||
}
|
||||
|
||||
if (empty($this->products)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->products = $this->_multiSortProduct($this->products);
|
||||
ob_start();
|
||||
$pdf = new FPDF('P', 'mm', 'A4');
|
||||
$nb_per_page = 0;
|
||||
$pdf->SetMargins($margin,$margin_top,$margin);
|
||||
$pdf->SetAutoPageBreak(FALSE);
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('Arial','',14);
|
||||
|
||||
$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, $nb_per_line);
|
||||
$this->products = array_splice($this->products, $nb_per_line);
|
||||
|
||||
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($width, $height_label, '', 0, 0, 'C');
|
||||
} else {
|
||||
$image = $this->directory.'/id-'.$product['key'].'.gif';
|
||||
$this->_printEAN($pdf, $image, 1, $width, $height_label);
|
||||
}
|
||||
}
|
||||
$pdf->Ln($ln_label);
|
||||
|
||||
$nb_per_page += 1;
|
||||
}
|
||||
}
|
||||
|
||||
$pdf->Output($this->directory.'/'.$file.'.pdf', 'F');
|
||||
|
||||
ob_clean();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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 +452,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