466 lines
11 KiB
JavaScript
Executable File
466 lines
11 KiB
JavaScript
Executable File
$(function(){
|
|
|
|
var that = this;
|
|
that.currentSale = null;
|
|
that.salesType = ['product', 'order', 'summary'];
|
|
|
|
that.property = {
|
|
'ajax': 1,
|
|
'token': token_private_sale
|
|
};
|
|
|
|
that.displayError = function(error){
|
|
// $("#content").prepend('<div class="error privatesale_error">'+error+'</div>');
|
|
// setTimeout(function(){
|
|
// $('.privatesale_error').remove();
|
|
// }, 3000);
|
|
showErrorMessage(error);
|
|
}
|
|
|
|
that.filtreListe = function(ChampFiltre,FiltreContent) {
|
|
var FiltreAppareil = $("#"+ChampFiltre).val(); var arrayShow = []; var arrayHide = []; if (FiltreAppareil != "") {$(FiltreContent).each(function(){var Trouve = $(this).text().toUpperCase().indexOf(FiltreAppareil.toUpperCase(),0); var TrouveBis = $(this).text().toLowerCase().indexOf(FiltreAppareil.toLowerCase(),0); if(Trouve == -1 && TrouveBis == -1) {$(this).hide(); } else {$(this).show(); } }); } else {$(FiltreContent).each(function(){$(this).show(); }); }
|
|
}
|
|
|
|
that.sale = function(id_sale){
|
|
|
|
var thatSale = this;
|
|
thatSale.id_sale = id_sale;
|
|
that.currentSale = id_sale;
|
|
|
|
thatSale.property = {
|
|
'ajax': 1,
|
|
'sale': thatSale.id_sale,
|
|
'token': token_private_sale
|
|
};
|
|
|
|
thatSale.initFilter = function(){
|
|
$('#filter_sale').keyup(function(){
|
|
that.filtreListe('filter_sale', '#sale option');
|
|
});
|
|
}
|
|
|
|
that.initSale();
|
|
if($('body').hasClass('adminprivatesalesstats')) {
|
|
that.initSaleHistory();
|
|
}
|
|
}
|
|
|
|
that.initSale = function(){
|
|
if(that.init_type == 'stats') {
|
|
for(var j = 0; j < that.salesType.length; j++) {
|
|
that.loadStats(that.salesType[j]);
|
|
}
|
|
}
|
|
else {
|
|
that.loadOrderForm();
|
|
}
|
|
}
|
|
|
|
that.initSaleHistory = function(){
|
|
$('#sale_history').die('change').html('');
|
|
|
|
var property = {
|
|
'ajax': 1,
|
|
'token': token_private_sale,
|
|
'action': 'getSalesHistory',
|
|
'sale' : that.currentSale
|
|
};
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: currentIndex,
|
|
dataType : "json",
|
|
data : property,
|
|
success: function(data) {
|
|
if(data.hasError) {
|
|
that.displayError(data.error);
|
|
}
|
|
else {
|
|
var content = '<option>Sélectionnez une date...</option>';
|
|
for(var h = 0; h < data['data'].length; h++) {
|
|
content += '<option data-date-start="'+data['data'][h]['date_start']+'" data-date-end="'+data['data'][h]['date_end']+'">'+data['data'][h]['date_start_lang']+' - '+data['data'][h]['date_end_lang']+'</option>';
|
|
}
|
|
$('#sale_history').html(content);
|
|
|
|
$('#sale_history').on('change', function(){
|
|
|
|
$('#date_by_sale_from').val( $(this).find('option:selected').attr('data-date-start') );
|
|
$('#date_by_sale_to').val( $(this).find('option:selected').attr('data-date-end') );
|
|
$('#refresh_by_sales').trigger('click');
|
|
|
|
});
|
|
}
|
|
|
|
},
|
|
error: function() {
|
|
that.displayError('An error occured in PHP');
|
|
}
|
|
});
|
|
}
|
|
|
|
that.loadOrderForm = function() {
|
|
if(that.currentSale === null)
|
|
return;
|
|
|
|
var property = {
|
|
'ajax': 1,
|
|
'token': token_private_sale,
|
|
'action': 'exportForm',
|
|
'sale' : that.currentSale
|
|
};
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: currentIndex,
|
|
dataType : "json",
|
|
data : property,
|
|
success: function(data) {
|
|
if(data.hasError) {
|
|
that.displayError(data.error);
|
|
}
|
|
else {
|
|
$('#content_order_form').html(data.content);
|
|
that.showSale();
|
|
}
|
|
|
|
},
|
|
error: function() {
|
|
that.displayError('An error occured in PHP');
|
|
}
|
|
});
|
|
}
|
|
|
|
that.loadStats = function(type) {
|
|
|
|
if(that.currentSale === null)
|
|
return;
|
|
|
|
var property = {
|
|
'ajax': 1,
|
|
'token': token_private_sale,
|
|
'action': 'stats',
|
|
'type' : type,
|
|
'sale' : that.currentSale,
|
|
'date_by_sale_from' : $('#date_by_sale_from').val(),
|
|
'date_by_sale_to' : $('#date_by_sale_to').val(),
|
|
'check_by_date' : $('#check_refresh_by_sales').is(':checked') ? 1 : 0
|
|
};
|
|
|
|
var ordered = $('.ordered[data-ordered-identifier='+type+'][data-direction]');
|
|
|
|
if(ordered.size() > 0) {
|
|
property.orderby = ordered.data('direction');
|
|
property.order = ordered.data('ordered');
|
|
}
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: currentIndex,
|
|
dataType : "json",
|
|
data : property,
|
|
success: function(data) {
|
|
if(data.hasError) {
|
|
that.displayError(data.error);
|
|
}
|
|
else {
|
|
$('#stats_content_'+type).html(data.content);
|
|
that.showSale();
|
|
}
|
|
|
|
},
|
|
error: function() {
|
|
that.displayError('An error occured in PHP');
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
that.showList = function(){
|
|
$('.content_sale').removeClass('hidden_list col-md-3');
|
|
$('#content_right').hide();
|
|
$('#stats_divers_list').show();
|
|
}
|
|
that.showSale = function(){
|
|
if(that.init_type == 'stats') {
|
|
$('.content_sale').addClass('hidden_list col-md-3');
|
|
}
|
|
$('#content_right').show('slow');
|
|
$('#stats_divers_list').hide();
|
|
}
|
|
|
|
that.loadStatsGlobal = function() {
|
|
|
|
var property = {
|
|
'ajax': 1,
|
|
'token': token_private_sale,
|
|
'action': 'statsGlobal',
|
|
'date_sale_from' : $('#date_sale_from').val(),
|
|
'date_sale_to' : $('#date_sale_to').val(),
|
|
'date_order_from' : $('#date_order_from').val(),
|
|
'date_order_to' : $('#date_order_to').val(),
|
|
'check_by_date' : $('#check_by_date').is(':checked') ? 1 : 0
|
|
};
|
|
|
|
var ordered = $('.ordered[data-ordered-identifier=global][data-direction]');
|
|
|
|
if(ordered.size() > 0) {
|
|
property.orderby = ordered.data('direction');
|
|
property.order = ordered.data('ordered');
|
|
}
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: currentIndex,
|
|
dataType : "json",
|
|
data : property,
|
|
success: function(data) {
|
|
|
|
if(data.hasError) {
|
|
that.displayError(data.error);
|
|
}
|
|
else {
|
|
$('#content_sale_global').html(data.content);
|
|
that.showList();
|
|
}
|
|
|
|
},
|
|
error: function() {
|
|
that.displayError('An error occured in PHP');
|
|
}
|
|
});
|
|
}
|
|
|
|
that.loadSaleList = function() {
|
|
var property = {
|
|
'date_sale_from' : $('#date_sale_from').val(),
|
|
'date_sale_to' : $('#date_sale_to').val(),
|
|
'ajax': 1,
|
|
'token': token_private_sale,
|
|
'action': 'sales',
|
|
'check_by_date' : $('#check_by_date').is(':checked') ? 1 : 0
|
|
};
|
|
|
|
var ordered = $('.ordered[data-ordered-identifier=global][data-direction]');
|
|
|
|
if(ordered.size() > 0) {
|
|
property.orderby = ordered.data('direction');
|
|
property.order = ordered.data('ordered');
|
|
}
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: currentIndex,
|
|
dataType : "json",
|
|
data : property,
|
|
success: function(data) {
|
|
|
|
if(data.hasError) {
|
|
that.displayError(data.error);
|
|
}
|
|
else {
|
|
$('#content_sale_global').html(data.content);
|
|
that.showList();
|
|
}
|
|
|
|
},
|
|
error: function() {
|
|
that.displayError('An error occured in PHP');
|
|
}
|
|
});
|
|
}
|
|
|
|
that.launchFilter = function(type) {
|
|
|
|
if(that.init_type == 'stats') {
|
|
switch(type) {
|
|
case 'global':
|
|
that.loadStatsGlobal();
|
|
break;
|
|
case 'product':
|
|
case 'order':
|
|
that.loadStats(type);
|
|
break;
|
|
}
|
|
}
|
|
else {
|
|
that.loadSaleList();
|
|
}
|
|
|
|
}
|
|
|
|
that.initSaleOrdered = function() {
|
|
var types = that.salesType;
|
|
types.push('global');
|
|
|
|
$('body').on('click', '.ordered', function(){
|
|
|
|
var filter = $(this).attr('data-ordered');
|
|
var identifier = $(this).attr('data-ordered-identifier');
|
|
|
|
if(filter != '') {
|
|
var filter_direction = $(this).attr('data-direction');
|
|
$('.ordered[data-ordered-identifier='+identifier+']').removeAttr('data-direction');
|
|
|
|
switch(filter_direction){
|
|
case undefined:
|
|
$(this).attr('data-direction', 'ASC');
|
|
break;
|
|
case 'DESC':
|
|
$(this).removeAttr('data-direction');
|
|
break;
|
|
case 'ASC':
|
|
$(this).attr('data-direction', 'DESC');
|
|
break;
|
|
}
|
|
|
|
that.launchFilter(identifier);
|
|
}
|
|
});
|
|
}
|
|
|
|
that.initStatsGlobal = function() {
|
|
|
|
$('#refresh_sales').on('click', function(){
|
|
that.loadStatsGlobal();
|
|
|
|
if($('#check_by_date').attr('checked') == 'checked') {
|
|
$('#date_by_sale_from').val( $('#date_order_from').val() );
|
|
$('#date_by_sale_to').val( $('#date_order_to').val() );
|
|
if(!$('#check_refresh_by_sales').attr('checked')) {
|
|
$('#check_refresh_by_sales').trigger('click');
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
$('#refresh_by_sales').on('click', function(){
|
|
that.initSale();
|
|
});
|
|
|
|
that.loadStatsGlobal();
|
|
}
|
|
|
|
that.initSaleList = function() {
|
|
$('#refresh_sales').on('click', function(){
|
|
that.loadSaleList();
|
|
});
|
|
|
|
that.loadSaleList();
|
|
}
|
|
|
|
that.initBDCUpdate = function() {
|
|
|
|
$('#opt_formulary').on('submit', function(){
|
|
var property = {
|
|
'ajax': 1,
|
|
'token': token_private_sale,
|
|
'action': 'BDCUpdate'
|
|
};
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: currentIndex+"&"+$(this).serialize(),
|
|
dataType : "json",
|
|
data : property,
|
|
success: function(data) {
|
|
if(data.hasError) {
|
|
that.displayError(data.error);
|
|
}
|
|
else {
|
|
showSuccessMessage(update_success_msg);
|
|
}
|
|
|
|
},
|
|
error: function() {
|
|
that.displayError('An error occured in PHP');
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
}
|
|
|
|
that.init = function(init_type){
|
|
that.init_type = init_type;
|
|
$('#content_sale_global').on('click', '.sale_detail', function(){
|
|
|
|
$('.selected_sale').removeClass('selected_sale');
|
|
$(this).addClass('selected_sale');
|
|
that.sale( $(this).data('idSale') );
|
|
|
|
});
|
|
|
|
if(that.init_type == 'stats') {
|
|
that.initStatsGlobal();
|
|
}
|
|
else {
|
|
that.initSaleList();
|
|
that.initBDCUpdate();
|
|
}
|
|
|
|
that.initSaleOrdered();
|
|
that.initOrderState();
|
|
}
|
|
|
|
that.initOrderState = function(){
|
|
$('#content_order_form').on('click', '#order_state_all', function(){
|
|
var elem = $('#content_order_form').find('input[type=checkbox][name="order_states[]"]');
|
|
if($(this).attr('checked') == 'checked')
|
|
elem.attr('checked', 'checked');
|
|
else elem.removeAttr('checked');
|
|
});
|
|
}
|
|
|
|
that.runCheckbox = function(elem){
|
|
var class_fields = $(elem).attr('id');
|
|
if($(elem).is(':checked')) {
|
|
$('.'+class_fields).show();
|
|
}
|
|
else {
|
|
$('.'+class_fields).hide();
|
|
}
|
|
}
|
|
|
|
$('.set-list-date').on('click', function(){
|
|
var set_date = $(this).data('orderByDate');
|
|
var date_from = $(this).data('dateFrom');
|
|
var date_to = $(this).data('dateTo');
|
|
|
|
if(set_date == 0) {
|
|
if($('#check_by_date').attr('checked') == 'checked') {
|
|
$('#check_by_date').trigger('click');
|
|
}
|
|
}
|
|
else {
|
|
$('#date_order_from').val(date_from);
|
|
$('#date_order_to').val(date_to);
|
|
|
|
if($('#check_by_date').attr('checked') != 'checked') {
|
|
$('#check_by_date').trigger('click');
|
|
}
|
|
}
|
|
|
|
$('#refresh_sales').trigger('click');
|
|
});
|
|
|
|
$(document).ready(function(){
|
|
|
|
that.init(init_type);
|
|
$('.datepicker').datepicker();
|
|
|
|
$('#check_by_date, #check_refresh_by_sales').on('click', function(){
|
|
that.runCheckbox($(this));
|
|
});
|
|
|
|
$('#check_by_date, #check_refresh_by_sales').each(function(){
|
|
that.runCheckbox($(this));
|
|
});
|
|
|
|
$('.go_to_list').on('click', function(){
|
|
that.showList();
|
|
});
|
|
|
|
});
|
|
|
|
|
|
}); |