modify out of stock channel
This commit is contained in:
@@ -562,51 +562,9 @@ $(function() {
|
||||
// click plus icon for add
|
||||
$(document).on('click', '.add_icon', function(event){
|
||||
|
||||
if($(this).hasClass('product_item')) {
|
||||
$('.sx_item_detailModal').modal('hide');
|
||||
|
||||
var item_data = $(this);
|
||||
code = $(this).data('instance-code');
|
||||
|
||||
if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) {
|
||||
item = get_item(item_data,"add_icon");
|
||||
customer_display_view(item,"add");
|
||||
}
|
||||
show_item_detail(item_data,"add_icon");
|
||||
calculate_sub_total();
|
||||
autoScrollToItem(code)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if ($(this).data('instances').length == 1) {
|
||||
|
||||
$('.sx_item_detailModal').modal('hide');
|
||||
|
||||
if ($(this).data('instances')[0].out_of_stock == false ) {
|
||||
var item_data = $(this);
|
||||
code = $(this).data('instance-code');
|
||||
|
||||
if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) {
|
||||
item = get_item(item_data,"add_icon");
|
||||
customer_display_view(item,"add");
|
||||
}
|
||||
show_item_detail(item_data,"add_icon");
|
||||
calculate_sub_total();
|
||||
autoScrollToItem(code)
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
} else {
|
||||
count = 0
|
||||
for (var i in $(this).data('instances')) {
|
||||
if(!$(this).data('instances')[i].out_of_stock) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (count === 1) {
|
||||
if (window.location.pathname.includes('out_of_stock') == false) {
|
||||
|
||||
if($(this).hasClass('product_item')) {
|
||||
$('.sx_item_detailModal').modal('hide');
|
||||
|
||||
var item_data = $(this);
|
||||
@@ -619,16 +577,61 @@ $(function() {
|
||||
show_item_detail(item_data,"add_icon");
|
||||
calculate_sub_total();
|
||||
autoScrollToItem(code)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
attributes = $(this).data('id');
|
||||
selected_item = $(this).data('attributes');
|
||||
instances = $(this).data('instances');
|
||||
item_options = $(this).data('options');
|
||||
data = $(this)
|
||||
if ($(this).data('instances').length == 1) {
|
||||
|
||||
show_attribute_selection_modal(attributes, selected_item, instances, item_options, data)
|
||||
$('.sx_item_detailModal').modal('hide');
|
||||
|
||||
if ($(this).data('instances')[0].out_of_stock == false ) {
|
||||
var item_data = $(this);
|
||||
code = $(this).data('instance-code');
|
||||
|
||||
if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) {
|
||||
item = get_item(item_data,"add_icon");
|
||||
customer_display_view(item,"add");
|
||||
}
|
||||
show_item_detail(item_data,"add_icon");
|
||||
calculate_sub_total();
|
||||
autoScrollToItem(code)
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
} else {
|
||||
count = 0
|
||||
for (var i in $(this).data('instances')) {
|
||||
if(!$(this).data('instances')[i].out_of_stock) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (count === 1) {
|
||||
$('.sx_item_detailModal').modal('hide');
|
||||
|
||||
var item_data = $(this);
|
||||
code = $(this).data('instance-code');
|
||||
|
||||
if ($('#server_mode').val() != "cloud" && second_display_lookup == 2) {
|
||||
item = get_item(item_data,"add_icon");
|
||||
customer_display_view(item,"add");
|
||||
}
|
||||
show_item_detail(item_data,"add_icon");
|
||||
calculate_sub_total();
|
||||
autoScrollToItem(code)
|
||||
return
|
||||
}
|
||||
|
||||
attributes = $(this).data('id');
|
||||
selected_item = $(this).data('attributes');
|
||||
instances = $(this).data('instances');
|
||||
item_options = $(this).data('options');
|
||||
data = $(this)
|
||||
|
||||
show_attribute_selection_modal(attributes, selected_item, instances, item_options, data)
|
||||
}
|
||||
}
|
||||
}); //End Add Icon Click
|
||||
|
||||
@@ -1082,9 +1085,45 @@ $(function() {
|
||||
|
||||
// Create Order
|
||||
$("#create_order").on('click', function(e){
|
||||
|
||||
$(this).attr('disabled', 'disabled');
|
||||
e.preventDefault();
|
||||
name_list = ''
|
||||
count = 0;
|
||||
$('.summary-items').find(`tr[data-oos='true']`).each(function() {
|
||||
count += 1;
|
||||
name = $(this).data('name')
|
||||
name += $(this).data('instance').replace(/['"]+/g, '')
|
||||
if ((count + 1) == $('.summary-items').find(`tr[data-oos='true']`).length) {
|
||||
name += ' and '
|
||||
} else if(count != $('.summary-items').find(`tr[data-oos='true']`).length){
|
||||
name += ', '
|
||||
}
|
||||
name_list += name
|
||||
});
|
||||
wanring_text = name_list + 'are out of stock.'
|
||||
if (name_list) {
|
||||
|
||||
swal({
|
||||
title: "Out Of Stock Warning!",
|
||||
text: wanring_text,
|
||||
type: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: "Confrim",
|
||||
closeOnConfirm: false
|
||||
}, function (isConfirm) {
|
||||
if (isConfirm) {
|
||||
create_order($(this))
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
create_order($(this))
|
||||
}
|
||||
});
|
||||
|
||||
function create_order(data) {
|
||||
data.attr('disabled', 'disabled');
|
||||
$("#oqs_loading_wrapper").show();
|
||||
var cashier_type = $("#link_type").val();
|
||||
localStorage.setItem('cashier_type',cashier_type);
|
||||
@@ -1121,36 +1160,29 @@ $(function() {
|
||||
'order_items': order_items,'create_type' : "create_only" };
|
||||
}
|
||||
|
||||
// if (table_id.length>0 || role == 'waiter') {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
data: params,
|
||||
dataType: "json",
|
||||
success:function(result){
|
||||
if (type == "quick_service" || type=="food_court") {
|
||||
module_name = window.location.href.includes('foodcourt') ? 'foodcourt' : 'origami'
|
||||
window.location.href = "/"+module_name+"/"+type;
|
||||
}else{
|
||||
if(table_type == "Table"){
|
||||
window.location.href = "/origami/table/" + table_id;
|
||||
}
|
||||
else {
|
||||
window.location.href = "/origami/room/" + table_id;
|
||||
}
|
||||
}
|
||||
if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){
|
||||
customer_display_view(null,"reload");
|
||||
}
|
||||
}
|
||||
});
|
||||
// }else{
|
||||
// $(this).removeAttr('disabled', '');
|
||||
// $("#oqs_loading_wrapper").hide();
|
||||
|
||||
// swal("Opps","Please Select Table or Room","warning");
|
||||
// }
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
data: params,
|
||||
dataType: "json",
|
||||
success:function(result){
|
||||
if (type == "quick_service" || type=="food_court") {
|
||||
module_name = window.location.href.includes('foodcourt') ? 'foodcourt' : 'origami'
|
||||
window.location.href = "/"+module_name+"/"+type;
|
||||
}else{
|
||||
if(table_type == "Table"){
|
||||
window.location.href = "/origami/table/" + table_id;
|
||||
}
|
||||
else {
|
||||
window.location.href = "/origami/room/" + table_id;
|
||||
}
|
||||
}
|
||||
if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){
|
||||
customer_display_view(null,"reload");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Pay Discount for Payment
|
||||
@@ -1685,7 +1717,12 @@ $(function() {
|
||||
data_target = 'sx_item_set_detailModal';
|
||||
data_modal = 'modal'
|
||||
add_icon = "set_item_box"
|
||||
code = menu_items[field].code;
|
||||
code = ''
|
||||
menu_items[field].instances.forEach(ins => function (){
|
||||
if (ins.out_of_stock == false) {
|
||||
code = ins.code;
|
||||
}
|
||||
})
|
||||
name = menu_items[field].name;
|
||||
instances = menu_items[field].instances;
|
||||
$(instances).each(function(i){
|
||||
@@ -1709,8 +1746,18 @@ $(function() {
|
||||
add_icon = "add_icon"
|
||||
menu_instances = [];
|
||||
|
||||
code = '';
|
||||
name = '';
|
||||
price = '';
|
||||
is_available = '';
|
||||
is_on_promotion = '';
|
||||
item_attributes = '';
|
||||
promotion_price = '';
|
||||
out_of_stock = '';
|
||||
menu_insta = '';
|
||||
|
||||
$(instances).each(function(i){
|
||||
if (instances[i].is_default === true && !instances[i].out_of_stock) {
|
||||
if (!instances[i].out_of_stock) { //instances[i].is_default === true &&
|
||||
code = instances[i].code;
|
||||
name = instances[i].name;
|
||||
price = parseFloat(instances[i].price).toFixed(2);
|
||||
@@ -1718,13 +1765,10 @@ $(function() {
|
||||
is_on_promotion = instances[i].is_on_promotion;
|
||||
item_attributes = instances[i].values;
|
||||
promotion_price = instances[i].promotion_price;
|
||||
code = instances[i].code;
|
||||
out_of_stock = instances[i].out_of_stock;
|
||||
menu_insta = [code,name,item_attributes];
|
||||
}
|
||||
if(instances[i].out_of_stock === false){
|
||||
menu_instances.push(menu_insta);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1745,9 +1789,9 @@ $(function() {
|
||||
})
|
||||
|
||||
if (status) {
|
||||
price_tag = '<span class="text-danger" style="font-weight:900;flex-grow:1;">'+status+'</span>'
|
||||
price_tag = '<span class="text-danger price_tag" style="font-weight:900;flex-grow:1;">'+status+'</span>'
|
||||
} else {
|
||||
price_tag ='<span style="font-weight:900;flex-grow:1;">'+price+'</span>'
|
||||
price_tag ='<span class="price_tag" style="font-weight:900;flex-grow:1;">'+price+'</span>'
|
||||
}
|
||||
|
||||
image_path = '';
|
||||
|
||||
@@ -5,13 +5,10 @@ App.checkin = App.cable.subscriptions.create('OutOfStockChannel', {
|
||||
disconnected: function() {},
|
||||
|
||||
received: function(data) {
|
||||
if (data && data.item_instance_code) {
|
||||
console.log("out of stock channel!!!!");
|
||||
item_code = data.item_instance_code;
|
||||
item_code_id = '#' + data.item_instance_code;
|
||||
oos_id = '#oos' + data.item_instance_code;
|
||||
head_oos = 'head' + data.item_instance_code;
|
||||
rm_oos = '.' + head_oos;
|
||||
if (data && data.item_code) {
|
||||
item_code = data.item_code
|
||||
item_instance_code = data.item_instance_code;
|
||||
item_instance_code_id = '#' + item_instance_code;
|
||||
menus = localStorage.getItem('menus');
|
||||
|
||||
if (menus) {
|
||||
@@ -20,23 +17,119 @@ App.checkin = App.cable.subscriptions.create('OutOfStockChannel', {
|
||||
m.categories.forEach(c => {
|
||||
c.items.forEach(i => {
|
||||
i.instances.forEach(instance => {
|
||||
if (instance.code == item_code) {
|
||||
if (data.status == true) {
|
||||
instance.out_of_stock = true;
|
||||
oos_header = '<div class="'+head_oos+'" style="position: absolute;z-index: 5;top: 0;left: 0;right: 0;text-align: center;background: #fb483a;margin: auto;color: #fff;padding: 8px;font-weight: bolder;">OUT OF STOCK</div>';
|
||||
$(item_code_id).css({"height": "100%", "pointer-events": "none", "opacity": "0.4"});
|
||||
$(oos_header).insertBefore($(oos_id));
|
||||
|
||||
if (instance.code == item_instance_code) {
|
||||
|
||||
card_header = $('.menu_items_list').find(`[data-item-code='${item_code}']`).first();
|
||||
card_footer = $(card_header).parent('.card').find('.card-footer');
|
||||
price_tag = $(card_footer).find('.price_tag')
|
||||
item_box = $(card_footer).find('.menu_item_box')
|
||||
|
||||
instance_list = $('.menu_items_list').find(`[data-item-code='${item_code}']`).data('instances')
|
||||
|
||||
if (instance_list.length == 1) {
|
||||
|
||||
if (data.status == true) {
|
||||
instance.out_of_stock = true;
|
||||
|
||||
$(card_header).css({"pointer-events": "none", "opacity": "0.4"});
|
||||
$(item_box).css({"pointer-events": "none", "opacity": "0.4"});
|
||||
|
||||
$(price_tag).empty().addClass('text-danger').text('out of stock')
|
||||
|
||||
} else {
|
||||
instance.out_of_stock = false;
|
||||
|
||||
$(card_header).css({"pointer-events": "auto", "opacity": ""});
|
||||
$(item_box).css({"pointer-events": "auto", "opacity": ""});
|
||||
|
||||
price = $(card_header).data('price')
|
||||
$(price_tag).removeClass('text-danger').empty().text(price)
|
||||
|
||||
}
|
||||
} else {
|
||||
instance.out_of_stock = false;
|
||||
$(item_code_id).css({"height": "", "pointer-events": "", "opacity": ""});
|
||||
$(rm_oos).remove();
|
||||
if (data.status == true) {
|
||||
instance.out_of_stock = true;
|
||||
|
||||
oos_count = 0
|
||||
data_instance_code = $(card_header).data('instance-code')
|
||||
instance_list.forEach(i => {
|
||||
if (i.code == item_instance_code) {
|
||||
i.out_of_stock = true
|
||||
name = $('.menu_items_list').find(`[data-item-code='${item_code}']`).data('name')
|
||||
$('.summary-items').find(`tr[data-instance-code='${item_instance_code}']`).attr({'data-oos': true, 'data-name': name});
|
||||
}
|
||||
if (i.out_of_stock == true) {
|
||||
oos_count += 1
|
||||
}
|
||||
if (data_instance_code == item_instance_code) {
|
||||
console.log('Equal');
|
||||
if (i.out_of_stock == false) {
|
||||
code = i.code
|
||||
price = parseFloat(i.price).toFixed(2);
|
||||
name = i.name
|
||||
item_attributes = i.values
|
||||
promotion_price = i.promotion_price
|
||||
$(card_header).removeAttr('data-price', 'data-instance-code', 'data-promotion-price', 'data-attributes', 'data-instance')
|
||||
$(card_header).attr({'data-price': price,
|
||||
'data-instance-code': code,
|
||||
'data-promotion-price': promotion_price,
|
||||
'data-attributes': JSON.stringify(item_attributes),
|
||||
'data-instance': name
|
||||
})
|
||||
|
||||
$(card_footer).find('.menu_item_box').removeAttr('data-item').attr('data-item', JSON.stringify(item_attributes))
|
||||
$(price_tag).removeClass('text-danger').empty().text(price)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (oos_count == instance_list.length) {
|
||||
$(card_header).css({"pointer-events": "none", "opacity": "0.4"});
|
||||
$(item_box).css({"pointer-events": "none", "opacity": "0.4"});
|
||||
$(price_tag).empty().addClass('text-danger').text('out of stock')
|
||||
}
|
||||
|
||||
} else { // status == false
|
||||
instance.out_of_stock = false;
|
||||
|
||||
instance_list.forEach(i => {
|
||||
if (i.code == item_instance_code) {
|
||||
i.out_of_stock = false
|
||||
code = i.code
|
||||
price = parseFloat(i.price).toFixed(2);
|
||||
name = i.name
|
||||
item_attributes = i.values
|
||||
promotion_price = i.promotion_price
|
||||
}
|
||||
})
|
||||
|
||||
$(card_header).removeAttr('data-price', 'data-instance-code', 'data-promotion-price', 'data-attributes', 'data-instance')
|
||||
$(card_header).attr({'data-price': price,
|
||||
'data-instance-code': code,
|
||||
'data-promotion-price': promotion_price,
|
||||
'data-attributes': JSON.stringify(item_attributes),
|
||||
'data-instance': name
|
||||
})
|
||||
|
||||
$(card_footer).find('.menu_item_box').removeAttr('data-item').attr('data-item', JSON.stringify(item_attributes))
|
||||
|
||||
$(card_header).css({"pointer-events": "auto", "opacity": ""});
|
||||
$(item_box).css({"pointer-events": "auto", "opacity": ""});
|
||||
|
||||
$(price_tag).removeClass('text-danger').empty().text(price)
|
||||
|
||||
}
|
||||
|
||||
// update data-attribute
|
||||
$(card_header).removeData('instances').attr('data-instances', JSON.stringify(instance_list));
|
||||
$(card_footer).find('.menu_item_box').removeData('instance').attr('data-instance', JSON.stringify(instance_list));
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
localStorage.setItem('menus', JSON.stringify(menus));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user