2016-03-16 11:49:15 +01:00
|
|
|
<?php
|
|
|
|
if(!defined('_PS_VERSION_')) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
class AdminBraderie extends AdminTab
|
|
|
|
{
|
|
|
|
private $_html = '';
|
|
|
|
private $error = '';
|
|
|
|
|
|
|
|
public function display()
|
|
|
|
{
|
|
|
|
global $cookie;
|
|
|
|
|
|
|
|
$id_category = Tools::getValue('id_category', 1);
|
|
|
|
$id_product = Tools::getValue('id_product', false);
|
|
|
|
|
|
|
|
$db = Db::getInstance();
|
|
|
|
$sql_category = '
|
|
|
|
SELECT * FROM `'._DB_PREFIX_.'privatesale` ps
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ps.`id_category` = cl.`id_category`
|
|
|
|
WHERE ps.`braderie` = 1
|
|
|
|
AND cl.`id_lang` = '.(int) $cookie->id_lang;
|
|
|
|
$categories = $db->ExecuteS($sql_category);
|
|
|
|
|
|
|
|
$this->_html .= $this->_buildHtmlCategoryBlock($categories);
|
|
|
|
|
|
|
|
$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,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
var $token = "'.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'";
|
2016-03-21 10:07:35 +01:00
|
|
|
var $product_id = 0;
|
2016-03-16 11:49:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
$(\'#sale\').change(function() {
|
|
|
|
$.ajax({
|
|
|
|
type: \'POST\',
|
|
|
|
url: \''._MODULE_DIR_.'braderie/ajax.php?action=getCategories'.'\',
|
|
|
|
dataType: \'json\',
|
|
|
|
data: { sale: $(this).val() },
|
|
|
|
success: function(response) {
|
|
|
|
$(\'#category\').empty();
|
|
|
|
for (var i in response) {
|
|
|
|
var html = \'<option value="\'+ response[i].id_category +\'">\'+ response[i].id_category +\' - \'+ response[i].name +\'</option>\';
|
|
|
|
$(\'#category\').append(html);
|
|
|
|
}
|
|
|
|
$(".chosen-select").trigger("chosen:updated");
|
2016-03-16 18:05:41 +01:00
|
|
|
$("#divider, #category_input_group, #ean_input_group, #storage_input_group, #button_input_group, #show_current_category_button, #quantity_input_group").show();
|
2016-03-16 11:49:15 +01:00
|
|
|
$("#error").empty();
|
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
$("#ean_from_product").empty();
|
|
|
|
$("#error").empty().append(JSON.parse(xhr.responseText));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-03-22 16:55:07 +01:00
|
|
|
$("#category").change(function(event) {
|
2016-03-16 11:49:15 +01:00
|
|
|
$("#show_current_category_button").show();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-03-22 16:55:07 +01:00
|
|
|
$("#input_ean").change(function(event) {
|
2016-03-16 11:49:15 +01:00
|
|
|
$.ajax({
|
|
|
|
type: \'POST\',
|
|
|
|
url: \''._MODULE_DIR_.'braderie/ajax.php?action=getProductId'.'\',
|
|
|
|
dataType: \'json\',
|
|
|
|
data: { ean: $(this).val() },
|
|
|
|
success: function(response) {
|
2016-03-22 16:32:33 +01:00
|
|
|
if (response.name == null) {
|
|
|
|
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
|
|
|
|
$("#ean_from_product").empty();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-16 11:49:15 +01:00
|
|
|
$product_id = response.id_product;
|
2016-03-21 10:07:35 +01:00
|
|
|
$attibute_id = response.id_product_attribute;
|
2016-03-16 11:49:15 +01:00
|
|
|
$("#ean_from_product").empty().append(response.name);
|
2016-03-21 10:07:35 +01:00
|
|
|
if ($attibute_id) {
|
|
|
|
$("#hidden_attribute_id").val($attibute_id);
|
|
|
|
} else {
|
|
|
|
$("#hidden_attribute_id").val(0);
|
|
|
|
}
|
2016-03-16 11:49:15 +01:00
|
|
|
$("#error").empty()
|
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
$("#ean_from_product").empty();
|
|
|
|
$("#error").empty().append(JSON.parse(xhr.responseText));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-22 16:55:07 +01:00
|
|
|
$("#check_button").click(function(event) {
|
2016-03-21 10:07:35 +01:00
|
|
|
if ($product_id == 0) {
|
2016-03-16 11:49:15 +01:00
|
|
|
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($token.length == 0) {
|
|
|
|
$("#error").empty().append("'.$this->l('Un problème de sécurité est survenu. Merci de réinitialisé la page').'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location.href = "?tab=AdminCatalog&updateproduct&id_product=" + $product_id + "&token=" + $token;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-22 16:55:07 +01:00
|
|
|
$("#add_button").click(function(event) {
|
2016-03-21 10:07:35 +01:00
|
|
|
event.preventDefault();
|
2016-03-22 16:32:33 +01:00
|
|
|
if ($product_id == undefined || $product_id == 0) {
|
2016-03-16 11:49:15 +01:00
|
|
|
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var emplacement = $("#input_storage").val();
|
|
|
|
|
|
|
|
if (emplacement.length == 0) {
|
|
|
|
$("#error").empty().append("'.$this->l('L\'emplacement n\'est pas renseigné').'");
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-22 16:32:33 +01:00
|
|
|
|
|
|
|
if ($("#input_quantity").val().length == 0) {
|
|
|
|
$("#error").empty().append("'.$this->l('La quantité n\'est pas renseignée').'");
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-16 11:49:15 +01:00
|
|
|
|
|
|
|
$("#hidden_product_id").val($product_id);
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: \'POST\',
|
|
|
|
url: \''._MODULE_DIR_.'braderie/ajax.php?action=addToSellout'.'\',
|
|
|
|
dataType: \'json\',
|
|
|
|
data: {
|
|
|
|
category: $("#category").val(),
|
|
|
|
storage: $("#input_storage").val(),
|
2016-03-16 18:05:41 +01:00
|
|
|
product: $("#hidden_product_id").val(),
|
2016-03-21 10:07:35 +01:00
|
|
|
quantity: $("#input_quantity").val(),
|
|
|
|
attribute: $("#hidden_attribute_id").val()
|
2016-03-16 11:49:15 +01:00
|
|
|
},
|
|
|
|
success: function(response) {
|
|
|
|
$("#error").empty().append(response);
|
2016-03-17 11:57:24 +01:00
|
|
|
$("#input_ean, #input_storage, #input_quantity").val("");
|
2016-03-16 11:49:15 +01:00
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
$("#error").empty().append(JSON.parse(xhr.responseText));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#show_current_category_button").click(function() {
|
|
|
|
$category = $("#category").val();
|
|
|
|
if ($category.length == 0) {
|
|
|
|
$("#error").empty().append("'.$this->l('Catégorie invalide').'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
window.open("?tab=AdminCatalog&viewcategory&id_category=" + $category + "&token=" + $token, "_blank");
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
</script>';
|
|
|
|
echo $this->_html;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _buildHtmlCategoryBlock($categories)
|
|
|
|
{
|
|
|
|
global $cookie;
|
|
|
|
|
|
|
|
$token = Tools::getAdminToken('AdminBraderie'.(int)(Tab::getIdFromClassName('AdminBraderie')).(int)($cookie->id_employee));
|
|
|
|
|
|
|
|
$html = '
|
|
|
|
<style>
|
|
|
|
.chosen-container { width: 315px !important; }
|
|
|
|
.button-container input { margin: 10px 25px; }
|
|
|
|
#error, #ean_from_product { margin-left: 210px; }
|
|
|
|
#error { font-weight: bold; margin-bottom: 20px; color: #CC0000; }
|
|
|
|
</style>
|
|
|
|
<fieldset>
|
|
|
|
<legend>'.$this->l('Braderie').'</legend>';
|
|
|
|
if ($this->error) {
|
|
|
|
$html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
|
|
|
|
} else {
|
|
|
|
$html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
|
|
|
|
}
|
|
|
|
$html .= '<form action="?tab=AdminBraderie&token='.$token.'" method="POST">
|
|
|
|
<div class="margin-form">
|
|
|
|
<label>'.$this->l('Ventes').' : </label>
|
|
|
|
<select class="chosen-select" id="sale" name="sale">
|
|
|
|
<option value=""></option>';
|
|
|
|
|
|
|
|
foreach ($categories as $key => $value) {
|
|
|
|
$html .= '<option value="'.$value['id_sale'].'">'.$value['id_sale'].' - '.$value['name'].'</option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= ' </select>
|
|
|
|
</div>
|
|
|
|
<hr id="divider" style="display: none;">
|
|
|
|
<div class="margin-form" id="category_input_group" style="display: none;">
|
|
|
|
<label>'.$this->l('Catégories').' : </label>
|
|
|
|
<select class="chosen-select" id="category" name="category">
|
|
|
|
<option value=""></option>
|
|
|
|
</select>
|
|
|
|
<input type="submit" class="button" id="show_current_category_button" value="'.$this->l('Voir cette catégorie').'" style="margin-left: 20px; display: none">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="margin-form" id="ean_input_group" style="display: none;">
|
|
|
|
<label>'.$this->l('Code EAN').' : </label>
|
|
|
|
<input type="text" name="ean" id="input_ean">
|
|
|
|
<p id="ean_from_product"></p>
|
|
|
|
</div>
|
|
|
|
<div class="margin-form" id="storage_input_group" style="display: none;">
|
|
|
|
<label>'.$this->l('Emplacement').' : </label>
|
|
|
|
<input type="text" name="storage" id="input_storage">
|
|
|
|
</div>
|
2016-03-16 18:05:41 +01:00
|
|
|
<div class="margin-form" id="quantity_input_group" style="display: none;">
|
|
|
|
<label>'.$this->l('Quantité').' : </label>
|
|
|
|
<input type="number" name="quantity" id="input_quantity">
|
|
|
|
</div>
|
2016-03-16 11:49:15 +01:00
|
|
|
<div class="margin-form button-container" id="button_input_group" style="display: none;">
|
|
|
|
<input type="submit" class="button" name="adminbraderie" value="'.$this->l('Ajouter').'" style="margin-left: 200px;" id="add_button">
|
|
|
|
<input type="submit" class="button" value="'.$this->l('Vérifier').'" id="check_button">
|
|
|
|
</div>
|
|
|
|
<input type="hidden" name="product" id="hidden_product_id">
|
2016-03-21 10:07:35 +01:00
|
|
|
<input type="hidden" name="attribute" id="hidden_attribute_id">
|
2016-03-16 11:49:15 +01:00
|
|
|
</form>
|
|
|
|
</fieldset>';
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|