bebeboutik/modules/eanmanager/AdminEANManager.php
Srv Bebeboutik 6c0978166c add modules
2016-01-04 12:49:26 +01:00

312 lines
11 KiB
PHP
Executable File

<?php
if(!defined('_PS_VERSION_')) {
exit;
}
require_once dirname(__FILE__).'/../privatesales/Sale.php';
class AdminEANManager extends AdminTab {
public $_html = '';
public function display() {
global $cookie;
$current_sale = Tools::getValue('id_sale');
$current_category = Tools::getValue('id_category');
$this->_html .= '
<style type="text/css">
#barcodeinput::-webkit-input-placeholder {
color: #bcbcbc;
}
#barcodeinput:-moz-placeholder {
color: #bcbcbc;
}
#barcodeinput:focus {
border-color: #66dd66;
}
table.table.std th.width1 {
width: 48px;
}
table.table.std th.width2 {
width: 70px;
}
table.table.std td {
font-size: 12px;
}
table.table.std tr.selected td {
background: #bfe3ed;
}
table.table.std td.center {
text-align: center;
}
table.table.std td.right {
text-align: right;
}
table.table.std {
width: 100%;
}
#ean_notification {
position: absolute;
background: #fff3b4;
font-weight: bold;
padding: 5px 10px;
display: none;
}
tr.noexist {
display: table-row;
}
tr.exist {
display: none;
}
</style>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/eanmanager/jquery.hotkeys.js"></script>
<script type="text/javascript">
<!--
var timeout = null;
function highlightProduct(value) {
if(value != "") {
$("table.std.table .selected").removeClass("selected");
var el = $("table.std.table td.ean").filter(function() { return $(this).text() === value; });
if(el.length > 0) {
el.parent().addClass("selected");
$("html, body").animate({
scrollTop: el.offset().top
});
el.parent().find("input").focus();
}
}
}
function searchProduct(value) {
if(value != "") {
$.post("'.__PS_BASE_URI__.'modules/eanmanager/ajax_find.php?id_employee='.(int) $cookie->id_employee.'&token='.Tools::getValue('token').'", {ean: value}, function(loaded) {
if(loaded) {
$("#content table.std").remove();
$("#content").append(loaded);
}
});
}
}
function saveEAN(event, id_product, id_product_attribute, value) {
if(event.keyCode == 13 && (value != "" || value2 != "")) {
$.post("'.__PS_BASE_URI__.'modules/eanmanager/ajax.php?id_employee='.(int) $cookie->id_employee.'&token='.Tools::getValue('token').'", {id_product: id_product, id_product_attribute: id_product_attribute, value: value}, function(loaded) {
if(loaded) {
var loaded = $.parseJSON(loaded);
if(loaded.result == "OK") {
$("#ean_notification").text("'.$this->l('Product updated').'").css({
top: $("#ean_" + id_product + "_" + id_product_attribute).offset().top + 20,
left: $("#ean_" + id_product + "_" + id_product_attribute).offset().left
}).fadeIn().delay(3000).fadeOut();
if(value != "") {
$("#ean_" + id_product + "_" + id_product_attribute).parent().parent().find(".ean").text(value == "0"? "": value);
}
} else if(loaded.result == "DUPLICATE") {
$("#ean_notification").text("'.$this->l('The EAN already exists').'").css({
top: $("#ean_" + id_product + "_" + id_product_attribute).offset().top + 20,
left: $("#ean_" + id_product + "_" + id_product_attribute).offset().left
}).fadeIn().delay(3000).fadeOut();
} else if(loaded.result == "EMPTY") {
$("#ean_notification").text("'.$this->l('The EAN value is empty').'").css({
top: $("#ean_" + id_product + "_" + id_product_attribute).offset().top + 20,
left: $("#ean_" + id_product + "_" + id_product_attribute).offset().left
}).fadeIn().delay(3000).fadeOut();
} else if(loaded.result == "PRODUCT") {
$("#ean_notification").text("'.$this->l('Product ID missing').'").css({
top: $("#ean_" + id_product + "_" + id_product_attribute).offset().top + 20,
left: $("#ean_" + id_product + "_" + id_product_attribute).offset().left
}).fadeIn().delay(3000).fadeOut();
} else if(loaded.result == "FORMAT") {
$("#ean_notification").text("'.$this->l('Invalid format, EAN13 can only contain numbers').'").css({
top: $("#ean_" + id_product + "_" + id_product_attribute).offset().top + 20,
left: $("#ean_" + id_product + "_" + id_product_attribute).offset().left
}).fadeIn().delay(3000).fadeOut();
}
}
});
}
}
$(document).ready(function() {
$("#barcodeinput").focus(function() {
$(this).attr("placeholder", "'.$this->l('Waiting for a barcode scan').'");
});
$("#barcodeinput").blur(function() {
$(this).attr("placeholder", "'.$this->l('Click here and scan a barcode').'");
});
$("#barcodeinput").trigger("focus");
$("#barcodeinput").keyup(function(event) {
clearTimeout(timeout);
if($("#id_sale").val() != "") {
timeout = setTimeout(highlightProduct, 500, $(this).val());
} else {
timeout = setTimeout(searchProduct, 500, $(this).val());
}
});
$(document).bind("keydown", "f1", function (evt) {
$("html, body").animate({
scrollTop: $("#barcodeinput").offset().top - 100
});
$("#barcodeinput").focus();
return false;
});
$("#all_products").live("click" , function(event) {
$(".noexist").css("display", "table-row");
$(".exist").css("display", "table-row");
});
$("#without_ean").live("click" , function(event) {
$(".noexist").css("display", "table-row");
$(".exist").css("display", "none");
});
});
-->
</script>
<fieldset>
<legend>'.$this->l('Products selection').'</legend>
<div class="margin-form">
<label for="id_sale" style="display: inline; float: none; width: auto;">'.$this->l('Select a sale:').'</label>
<select class="chosen-select" id="id_sale" name="id_sale">
<option value=""></option>
';
foreach(Sale::getSales(NULL, NULL, NULL, NULL, FALSE, FALSE, '`date_start` DESC', NULL) as $sale) {
$this->_html .= '<option value="'.(int) $sale->id.'"'.($sale->id == $current_sale? ' selected="selected"': '').'>'.$sale->id.' - '.$sale->title[(int) $cookie->id_lang].'</option>';
}
$this->_html .= '
</select>
</div>
<div class="margin-form">
<label for="barcodeinput" style="display: inline; float: none; width: auto;">'.$this->l('Barcode input:').'</label>
<input type="text" id="barcodeinput" value="" autocomplete="off" placeholder="'.$this->l('Click here and scan a barcode').'" style="width: 250px;" />
</div>
</fieldset>
<br /><br />';
if($current_sale) {
if($current_sale == 999999 || $sale = new Sale($current_sale)) {
$link = new Link();
$this->_html .= '
<button class="button" id="all_products">Voir tous les produits</button>
<button class="button" id="without_ean">Voir les produits sans EAN</button>
<table class="std table">
<thead>
<tr>
<th style="width: 100px;"></th>
<th>'.$this->l('ID').'</th>
<th>'.$this->l('EAN').'</th>
<th>'.$this->l('Reference').'</th>
<th>'.$this->l('Name').'</th>
<th>'.$this->l('New EAN').'</th>
</tr>
</thead>
<tbody>';
$sale_products = array();
$sale_products = $sale->getProducts(TRUE);
foreach($sale_products as $id_product) {
$product = new Product($id_product, FALSE, (int) $cookie->id_lang);
$attributes = array();
foreach(Db::getInstance()->ExecuteS('
SELECT pa.`id_product_attribute`, pa.`id_product`, pa.`quantity`, ag.`public_name` as `group`, al.`name`, pa.`ean13`, pa.`location`, pa.`reference`
FROM `'._DB_PREFIX_.'product_attribute` pa, `'._DB_PREFIX_.'product_attribute_combination` ac, `'._DB_PREFIX_.'attribute` a, `'._DB_PREFIX_.'attribute_lang` al, `'._DB_PREFIX_.'attribute_group_lang` ag
WHERE pa.`id_product` = '.(int) $product->id.'
AND ac.`id_product_attribute` = pa.`id_product_attribute`
AND al.`id_attribute` = ac.`id_attribute`
AND al.`id_lang` = '.(int) $cookie->id_lang.'
AND a.`id_attribute` = al.`id_attribute`
AND ag.`id_attribute_group` = a.`id_attribute_group`
AND ag.`id_lang` = '.(int) $cookie->id_lang.'
ORDER BY pa.`id_product` ASC, ag.`public_name` ASC, al.`name` ASC
') as $attr) {
if(!isset($attributes[$attr['id_product_attribute']])) {
$attributes[$attr['id_product_attribute']] = array();
}
$attributes[$attr['id_product_attribute']]['name'] .= '<br />'.$attr['group'].' : '.$attr['name'];
$attributes[$attr['id_product_attribute']]['id_product_attribute'] = $attr['id_product_attribute'];
$attributes[$attr['id_product_attribute']]['ean13'] = $attr['ean13'];
$attributes[$attr['id_product_attribute']]['reference'] = $attr['reference'];
}
$cover = Product::getCover($product->id);
if(count($attributes) > 0) {
foreach($attributes as $attr) {
$this->_html .= '<tr '.(!empty($attr['ean13']) ? 'class="exist" ': 'class="noexist" ').'>
<td><img src="'.$link->getImageLink($product->link_rewrite, $product->id.'-'.$cover['id_image'], 'small').'" alt="" style="width: 80px; height: 80px;" /></td>
<td>'.$product->id.'<br />'.$attr['id_product_attribute'].'</td>
<td class="ean">'.(!empty($attr['ean13'])? $attr['ean13']: '<span style="opacity: .4">'.$product->ean13).'</span>'.'</td>
<td>'.((string) $attr['reference'] == ''? $product->reference: $attr['reference']).'</td>
<td>'.$product->name.$attr['name'].'</td>
<td><input id="ean_'.(int) $product->id.'_'.$attr['id_product_attribute'].'" type="text" value="" autocomplete="off" onkeyup="saveEAN(event, '.(int) $product->id.', '.(int) $attr['id_product_attribute'].', $(this).val());" /></td>
</tr>';
}
} else {
$this->_html .= '<tr '.(!empty($product->ean13) ? 'class="exist" ': 'class="noexist" ').'>
<td><img src="'.$link->getImageLink($product->link_rewrite, $product->id.'-'.$cover['id_image'], 'small').'" alt="" style="width: 100px; height: 100px;" /></td>
<td>'.$product->id.'</td>
<td class="ean">'.$product->ean13.'</td>
<td>'.$product->reference.'</td>
<td>'.$product->name.'</td>
<td><input id="ean_'.(int) $product->id.'_0" type="text" value="" autocomplete="off" onkeyup="saveEAN(event, '.(int) $product->id.', 0, $(this).val());" /></td>
</tr>';
}
}
$this->_html .= '</tbody></table>
<div id="ean_notification"></div>
';
}
}
$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>';
$this->_html.= '<script type="text/javascript">
$(function() {
$(".chosen-select").chosen(
{
allow_single_deselect:true,
placeholder_text_single : "Choisir une vente",
no_results_text : "Aucun résultat",
enable_split_word_search : true,
search_contains : true,
}
);
$(".chosen-select").chosen().change( function() {
if($(this).val() != 999999) {
$(\'#category_selector\').hide();
document.location.href=\'index.php?tab=AdminEANManager&token='.Tools::getAdminTokenLite('AdminEANManager').'&id_sale=\' + $(this).val();
}
});
});
</script>';
echo $this->_html;
}
}