update create order function
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Api::OrdersController < Api::ApiController
|
class Api::OrdersController < Api::ApiController
|
||||||
|
skip_before_action :authenticate
|
||||||
#Description
|
#Description
|
||||||
# This API show current order details
|
# This API show current order details
|
||||||
# Input Params - order_id
|
# Input Params - order_id
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
def show
|
def show
|
||||||
@menu = MenuCategory.all
|
@menu = MenuCategory.all
|
||||||
@table_id = params[:id]
|
@table_id = params[:id]
|
||||||
|
@table_type = DiningFacility.find(@table_id).type
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div>
|
<div>
|
||||||
<strong id="order-title">ORDER DETAILS </strong> | Table <%=@table_id%>
|
<strong id="order-title">ORDER DETAILS </strong> | Table <%=@table_id%>
|
||||||
|
<p class="hidden" id="table_id"><%=@table_id%></p>
|
||||||
|
<p class="hidden" id="table_type"><%=@table_type%></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-block">
|
<div class="card-block">
|
||||||
@@ -111,6 +113,11 @@
|
|||||||
<h4 class="col-md-6">Total</h4>
|
<h4 class="col-md-6">Total</h4>
|
||||||
<h4 class="col-md-6" id="total_price"></h4>
|
<h4 class="col-md-6" id="total_price"></h4>
|
||||||
<p class="hidden" id="unit_price"></p>
|
<p class="hidden" id="unit_price"></p>
|
||||||
|
<p class="hidden" id="instance_code"></p>
|
||||||
|
<p class="hidden" id="instance_name"></p>
|
||||||
|
<p class="hidden" id="promotion_price"></p>
|
||||||
|
<p class="hidden" id="item_instances"></p>
|
||||||
|
<p class="hidden" id="item_code"></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-7 item-detail">
|
<div class="col-md-7 item-detail">
|
||||||
@@ -134,309 +141,389 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|
||||||
//click menu sidebar menu category
|
|
||||||
$(".menu_category").on("click", function(){
|
|
||||||
var menu_id = $(this).find(".menu-id").text();
|
|
||||||
var url = $(this).attr('data-ref');
|
|
||||||
show_menu_item_list(url);
|
|
||||||
});
|
|
||||||
//End menu category Click
|
|
||||||
|
|
||||||
$(".change_qty").change(function(){
|
//click menu sidebar menu category
|
||||||
qty = $(this).val();
|
$(".menu_category").on("click", function(){
|
||||||
price = $("#unit_price").text();
|
var menu_id = $(this).find(".menu-id").text();
|
||||||
$("#total_price").text(qty*price);
|
var url = $(this).attr('data-ref');
|
||||||
|
show_menu_item_list(url);
|
||||||
});
|
});
|
||||||
|
//End menu category Click
|
||||||
//show menu item list when click menu category
|
|
||||||
function show_menu_item_list(url_item){
|
|
||||||
var menu_list = $('.menu_items_list');
|
|
||||||
menu_list.empty();
|
|
||||||
|
|
||||||
//Start Ajax
|
$(".change_qty").change(function(){
|
||||||
$.ajax({
|
qty = $(this).val();
|
||||||
type: "GET",
|
price = $("#unit_price").text();
|
||||||
url: url_item,
|
$("#total_price").text(qty*price);
|
||||||
data: {},
|
});
|
||||||
dataType: "json",
|
|
||||||
success: function(data) {
|
|
||||||
var menu_items_list = $('.menu_items_list');
|
|
||||||
menu_items_list.empty();
|
|
||||||
menu_items = data.menu_items;
|
|
||||||
|
|
||||||
for(var field in menu_items) {
|
|
||||||
instances = menu_items[field].instances ;
|
|
||||||
$(instances).each(function(i){
|
|
||||||
if (instances[i].is_default === true) {
|
|
||||||
code = instances[i].code;
|
|
||||||
name = instances[i].name;
|
|
||||||
price = parseFloat(instances[i].price).toFixed(2);
|
|
||||||
is_available = instances[i].is_available ;
|
|
||||||
is_on_promotion = instances[i].is_on_promotion;
|
|
||||||
item_attributes = instances[i].values;
|
|
||||||
promotion_price = instances[i].promotion_price;
|
|
||||||
code = instances[i].code;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
row = '<div class="card">'
|
//show menu item list when click menu category
|
||||||
+'<div class="card-head" style="line-height:14px;">'
|
function show_menu_item_list(url_item){
|
||||||
+'<small class="col-md-9">'+ menu_items[field].name +'</small>'
|
var menu_list = $('.menu_items_list');
|
||||||
+"<div class='col-md-3 add_icon' data-item-code='"+ menu_items[field].code +"' data-name='"+ menu_items[field].name +"' data-price = '"+ price +"' data-instance-code = '"+ code +"' data-instance = '"+ name +"' data-promotion-price = '"+ promotion_price +"' data-attributes = '"+ JSON.stringify(item_attributes) +"'>"
|
menu_list.empty();
|
||||||
+'<i class="fa fa-plus "'
|
//Start Ajax
|
||||||
+ 'style="margin-top:4px;">'
|
$.ajax({
|
||||||
+'</i></div>'
|
type: "GET",
|
||||||
+'</div>'
|
url: url_item,
|
||||||
|
data: {},
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data) {
|
||||||
|
var menu_items_list = $('.menu_items_list');
|
||||||
|
menu_items_list.empty();
|
||||||
|
menu_items = data.menu_items;
|
||||||
|
|
||||||
+"<div class='menu_item_box' data-instance = '"+JSON.stringify(menu_items[field].instances)+"' data-id = '"+JSON.stringify(menu_items[field].attributes)+"' data-item = '"+JSON.stringify(item_attributes)+"' data-toggle='modal' data-target='.sx_item_detailModal'>"
|
for(var field in menu_items) {
|
||||||
|
instances = menu_items[field].instances ;
|
||||||
|
$(instances).each(function(i){
|
||||||
|
if (instances[i].is_default === true) {
|
||||||
|
code = instances[i].code;
|
||||||
|
name = instances[i].name;
|
||||||
|
price = parseFloat(instances[i].price).toFixed(2);
|
||||||
|
is_available = instances[i].is_available ;
|
||||||
|
is_on_promotion = instances[i].is_on_promotion;
|
||||||
|
item_attributes = instances[i].values;
|
||||||
|
promotion_price = instances[i].promotion_price;
|
||||||
|
code = instances[i].code;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
+'<div class="card-block">'
|
qty = 1;
|
||||||
+'<%= image_tag "logo.png" ,width: '75', height: '75', :style => '' %>'
|
|
||||||
+'</div>'
|
|
||||||
|
|
||||||
+'<div class="card-footer">'
|
row = '<div class="card">'
|
||||||
+'<small>'+ price +'</small>'
|
+'<div class="card-head" style="line-height:14px;">'
|
||||||
+'</div>'
|
+'<small class="col-md-9">'+ menu_items[field].name +'</small>'
|
||||||
+'</div>';
|
+"<div class='col-md-3 add_icon' data-item-code='"+ menu_items[field].code +"' data-name='"+ menu_items[field].name +"' data-qty = '"+ qty +"' data-price = '"+ price +"' data-instance-code = '"+ code +"' data-instance = '"+ name +"' data-promotion-price = '"+ promotion_price +"' data-attributes = '"+ JSON.stringify(item_attributes) +"'>"
|
||||||
$('.menu_items_list').append(row);
|
+'<i class="fa fa-plus "'
|
||||||
}
|
+ 'style="margin-top:4px;">'
|
||||||
|
+'</i></div>'
|
||||||
}
|
+'</div>'
|
||||||
});
|
|
||||||
//end Ajax
|
|
||||||
}
|
|
||||||
//end show list function
|
|
||||||
|
|
||||||
//click item row for add order
|
+"<div class='menu_item_box' data-item-code='"+ menu_items[field].code +"' data-instance = '"+JSON.stringify(menu_items[field].instances)+"' data-id = '"+JSON.stringify(menu_items[field].attributes)+"' data-item = '"+JSON.stringify(item_attributes)+"' data-toggle='modal' data-target='.sx_item_detailModal'>"
|
||||||
$(document).on('click', '.menu_item_box', function(event){
|
|
||||||
$('.attributes-list').empty();
|
|
||||||
$('.attr-alert').addClass('hide');
|
|
||||||
|
|
||||||
data = $(this).parent().children().children('.add_icon');
|
+'<div class="card-block">'
|
||||||
attributes = $(this).data('id');
|
+'<%= image_tag "logo.png" ,width: '75', height: '75', :style => '' %>'
|
||||||
selected_item = $(this).data('item');
|
+'</div>'
|
||||||
instances = $(this).data('instance');
|
|
||||||
|
|
||||||
for(var field in attributes) {
|
+'<div class="card-footer">'
|
||||||
value = attributes[field]["values"];
|
+'<small>'+ price +'</small>'
|
||||||
type = attributes[field]["type"]
|
+'</div>'
|
||||||
row = "<h4>"+attributes[field]["type"]+"</h4>"
|
+'</div>';
|
||||||
|
$('.menu_items_list').append(row);
|
||||||
$(value).each(function(i){
|
|
||||||
status ="";
|
|
||||||
if(parseInt(jQuery.inArray(value[i], selected_item))!== -1){
|
|
||||||
status = "selected-option";
|
|
||||||
}
|
|
||||||
row +="<button id='selected-option' data-instances='"+JSON.stringify(instances)+"' data-type='"+type+"' data-value='"+value[i]+"' class='btn btn-default attribute_btn "+ status +" "+ type +" '>"+value[i]+"</button>";
|
|
||||||
});
|
|
||||||
$(".attributes-list").append(row);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//end Ajax
|
||||||
|
}
|
||||||
|
//end show list function
|
||||||
|
|
||||||
$('#change_qty').val(1);
|
//click item row for add order
|
||||||
$('#title_name').text(data.attr('data-name'));
|
$(document).on('click', '.menu_item_box', function(event){
|
||||||
$('#item_code').text(data.attr('data-item-code'));
|
$('.attributes-list').empty();
|
||||||
$('#total_price').text(data.attr('data-price'));
|
$('.attr-alert').addClass('hide');
|
||||||
$('#unit_price').text(data.attr('data-price'));
|
$('.add_to_order').removeAttr('data-instance-code');
|
||||||
|
$('.add_to_order').removeAttr('data-instance');
|
||||||
|
$('.add_to_order').removeAttr('data-price');
|
||||||
|
$('.add_to_order').removeAttr('data-promotion-price');
|
||||||
|
$('.add_to_order').removeAttr('data-item-code');
|
||||||
|
$('.add_to_order').removeAttr('data-qty');
|
||||||
|
$('.add_to_order').removeAttr('data-name');
|
||||||
|
$('.add_to_order').removeAttr('data-attributes');
|
||||||
|
|
||||||
|
data = $(this).parent().children().children('.add_icon');
|
||||||
|
attributes = $(this).data('id');
|
||||||
|
selected_item = $(this).data('item');
|
||||||
|
instances = $(this).data('instance');
|
||||||
|
|
||||||
|
for(var field in attributes) {
|
||||||
|
value = attributes[field]["values"];
|
||||||
|
type = attributes[field]["type"]
|
||||||
|
row = "<h4>"+attributes[field]["type"]+"</h4>"
|
||||||
|
|
||||||
|
$(value).each(function(i){
|
||||||
|
status ="";
|
||||||
|
if(parseInt(jQuery.inArray(value[i], selected_item))!== -1){
|
||||||
|
status = "selected-option";
|
||||||
|
}
|
||||||
|
row +="<button id='selected-option' data-instances='"+JSON.stringify(instances)+"' data-type='"+type+"' data-value='"+value[i]+"' class='btn btn-default attribute_btn "+ status +" "+ type +" '>"+value[i]+"</button>";
|
||||||
|
});
|
||||||
|
$(".attributes-list").append(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#change_qty').val(1);
|
||||||
|
$('#item_instances').text(instances);
|
||||||
|
$('#title_name').text(data.attr('data-name'));
|
||||||
|
$('#item_code').text(data.attr('data-item-code'));
|
||||||
|
$('#total_price').text(data.attr('data-price'));
|
||||||
|
$('#unit_price').text(data.attr('data-price'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// click select option icon for add
|
||||||
|
$(document).on('click', '.attribute_btn', function(event){
|
||||||
|
value = $(this).data('value');
|
||||||
|
type = $(this).data('type');
|
||||||
|
instances = $(this).data('instances');
|
||||||
|
if ($(".attribute_btn").attr("data-type")==type){
|
||||||
|
$('.'+type).removeClass("selected-option");
|
||||||
|
}
|
||||||
|
$(this).addClass('selected-option');
|
||||||
|
selected_item = $('.selected-option').text();
|
||||||
|
qty = $('#change_qty').val();
|
||||||
|
total_price = 0;
|
||||||
|
|
||||||
|
for(var field in instances) {
|
||||||
|
item_attr = instances[field].values;
|
||||||
|
if(parseInt(jQuery.inArray(selected_item, item_attr))!== -1){
|
||||||
|
unit_price = instances[field].price
|
||||||
|
total_price = qty * unit_price
|
||||||
|
$('#instance_name').text(instances[field].name);
|
||||||
|
$('#instance_code').text(instances[field].code);
|
||||||
|
$('#promotion_price').text(instances[field].promotion_price);
|
||||||
|
$('#total_price').text(total_price);
|
||||||
|
$('#unit_price').text(unit_price);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (total_price == 0) {
|
||||||
|
$('.attr-alert').removeClass('hide');
|
||||||
|
$('#total_price').text(total_price);
|
||||||
|
}else{
|
||||||
|
$('.attr-alert').addClass('hide');
|
||||||
|
$('#total_price').text(total_price);
|
||||||
|
}
|
||||||
|
}); //End selecct attribute buttom
|
||||||
|
|
||||||
|
// click add order
|
||||||
|
$(document).on('click', '.add_to_order', function(event){
|
||||||
|
total_price = $('#total_price').text();
|
||||||
|
qty = parseInt($('#change_qty').val());
|
||||||
|
var item_row = $('.selected-option');
|
||||||
|
var instances = jQuery.parseJSON(item_row.attr('data-instances'));
|
||||||
|
var attribute_arr = [];
|
||||||
|
$(item_row).each(function(i){
|
||||||
|
value = $(item_row[i]).attr('data-value');
|
||||||
|
str = value;
|
||||||
|
attribute_arr.push(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
// click select option icon for add
|
for(var field in instances) {
|
||||||
$(document).on('click', '.attribute_btn', function(event){
|
if (JSON.stringify(attribute_arr) === JSON.stringify(instances[field].values)) {
|
||||||
|
|
||||||
value = $(this).data('value');
|
$('.add_to_order').attr('data-instance-code',instances[field].code);
|
||||||
type = $(this).data('type');
|
$('.add_to_order').attr('data-instance',instances[field].name);
|
||||||
instances = $(this).data('instances');
|
$('.add_to_order').attr('data-price',instances[field].price);
|
||||||
console.log(instances);
|
$('.add_to_order').attr('data-promotion-price',instances[field].promotion_price);
|
||||||
if ($(".attribute_btn").attr("data-type")==type){
|
}
|
||||||
$('.'+type).removeClass("selected-option");
|
}
|
||||||
}
|
$('.add_to_order').attr('data-item-code',$('#item_code').text());
|
||||||
$(this).addClass('selected-option');
|
$('.add_to_order').attr('data-qty',qty);
|
||||||
selected_item = $('.selected-option').text();
|
$('.add_to_order').attr('data-name',$('#title_name').text());
|
||||||
qty = $('#change_qty').val();
|
$('.add_to_order').attr('data-attributes',JSON.stringify(attribute_arr));
|
||||||
total_price = 0;
|
var item_data = $(this);
|
||||||
|
show_item_detail(item_data);
|
||||||
|
calculate_sub_total();
|
||||||
|
|
||||||
for(var field in instances) {
|
// if(total_price > 0){
|
||||||
item_attr = instances[field].values;
|
// }else{
|
||||||
if(parseInt(jQuery.inArray(selected_item, item_attr))!== -1){
|
// $.alert({
|
||||||
unit_price = instances[field].price
|
// title: 'Alert!',
|
||||||
total_price = qty * unit_price
|
// content: 'Please select another item',
|
||||||
$('#instance_name').text(instances[field].name);
|
// type: 'red',
|
||||||
$('#instance_code').text(instances[field].code);
|
// typeAnimated: true,
|
||||||
$('#promotion_price').text(instances[field].promotion_price);
|
// btnClass: 'btn-danger',
|
||||||
$('#total_price').text(total_price);
|
// });
|
||||||
$('#unit_price').text(unit_price);
|
// }
|
||||||
}
|
|
||||||
}
|
}); //End Add Icon Click
|
||||||
if (total_price == 0) {
|
|
||||||
$('.attr-alert').removeClass('hide');
|
|
||||||
$('#total_price').text(total_price);
|
|
||||||
}else{
|
|
||||||
$('.attr-alert').addClass('hide');
|
|
||||||
$('#total_price').text(total_price);
|
|
||||||
}
|
|
||||||
}); //End selecct attribute buttom
|
|
||||||
|
|
||||||
// click add order
|
// click plus icon for add
|
||||||
$(document).on('click', '.add_to_order', function(event){
|
$(document).on('click', '.add_icon', function(event){
|
||||||
total_price = $('#total_price').text();
|
var item_data = $(this);
|
||||||
unit_price = $('#unit_price').text();
|
show_item_detail(item_data);
|
||||||
qty = $('#change_qty').val();
|
calculate_sub_total();
|
||||||
var item_row = $('.selected-option');
|
}); //End Add Icon Click
|
||||||
var arr = [];
|
|
||||||
|
|
||||||
var attribute_arr = [];
|
function show_item_detail(data){
|
||||||
$(item_row).each(function(i){
|
qty = parseInt(data.attr('data-qty'));
|
||||||
value = $(item_row[i]).attr('data-value');
|
append = 0;
|
||||||
arr = {value};
|
price = parseFloat(data.attr('data-price')).toFixed(2);
|
||||||
|
instance_name = data.attr('data-instance');
|
||||||
|
if (instance_name == "undefined"){
|
||||||
|
instance = '';
|
||||||
|
}else{
|
||||||
|
instance = "("+data.attr('data-instance')+")";
|
||||||
|
}
|
||||||
|
|
||||||
});
|
var rowCount = $('.summary-items tbody tr').length+1;
|
||||||
console.log(arr);
|
var item_row = $('.summary-items tbody tr');
|
||||||
if(total_price > 0){
|
|
||||||
|
$(item_row).each(function(i){
|
||||||
|
item_code = $(item_row[i]).attr('data-code');
|
||||||
|
instance_code = $(item_row[i]).attr('data-instance-code');
|
||||||
|
|
||||||
$('.add_to_order').attr('data-item-code',$('#item_code').text());
|
if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')) {
|
||||||
$('.add_to_order').attr('data-name',$('#title_name').text());
|
if (qty > 1) {
|
||||||
$('.add_to_order').attr('data-price',unit_price);
|
qty = parseInt($(item_row[i]).children('#item_qty').text()) + qty;
|
||||||
$('.add_to_order').attr('data-instance-code',$('#instance_code').text());
|
}else{
|
||||||
$('.add_to_order').attr('data-instance',$('#instance_name').text());
|
qty = parseInt($(item_row[i]).children('#item_qty').text()) + 1;
|
||||||
$('.add_to_order').attr('data-promotion-price',$('#promotion_price').text());
|
|
||||||
$('.add_to_order').attr('data-attributes',$('#instance_name').text());
|
|
||||||
|
|
||||||
var item_data = $(this);
|
|
||||||
show_item_detail(item_data);
|
|
||||||
calculate_sub_total();
|
|
||||||
}else{
|
|
||||||
$.alert({
|
|
||||||
title: 'Alert!',
|
|
||||||
content: 'Please select another item',
|
|
||||||
type: 'red',
|
|
||||||
typeAnimated: true,
|
|
||||||
btnClass: 'btn-danger',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}); //End Add Icon Click
|
$(item_row[i]).children('#item_qty').text(qty);
|
||||||
|
parseFloat($(item_row[i]).children('#item_price').text(price*qty)).toFixed(2);
|
||||||
// click plus icon for add
|
append =1;
|
||||||
$(document).on('click', '.add_icon', function(event){
|
|
||||||
var item_data = $(this);
|
|
||||||
show_item_detail(item_data);
|
|
||||||
calculate_sub_total();
|
|
||||||
}); //End Add Icon Click
|
|
||||||
|
|
||||||
function show_item_detail(data){
|
|
||||||
qty = 1;
|
|
||||||
append = 0;
|
|
||||||
price = parseFloat(data.attr('data-price')).toFixed(2);
|
|
||||||
instance_name = data.attr('data-instance');
|
|
||||||
|
|
||||||
if (instance_name == "undefined"){
|
|
||||||
instance = '';
|
|
||||||
}else{
|
}else{
|
||||||
instance = "("+data.attr('data-instance')+")";
|
if (qty > 1) {
|
||||||
}
|
qty = qty;
|
||||||
|
}else{
|
||||||
var rowCount = $('.summary-items tbody tr').length+1;
|
|
||||||
var item_row = $('.summary-items tbody tr');
|
|
||||||
|
|
||||||
$(item_row).each(function(i){
|
|
||||||
item_code = $(item_row[i]).attr('data-code');
|
|
||||||
instance_code = $(item_row[i]).attr('data-instance-code');
|
|
||||||
|
|
||||||
if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')) {
|
|
||||||
qty = parseInt($(item_row[i]).children('#item_qty').text()) +1;
|
|
||||||
$(item_row[i]).children('#item_qty').text(qty);
|
|
||||||
parseFloat($(item_row[i]).children('#item_price').text(price*qty)).toFixed(2);
|
|
||||||
append = 1;
|
|
||||||
}else{
|
|
||||||
qty = 1;
|
qty = 1;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
if (append===0) {
|
if (append===0) {
|
||||||
row ="<tr class='item_box' data-price ='"+price+ "'data-toggle='modal' data-target='#sx_itemModal' 'data-instance ='"+instance+ "' data-code='"+data.attr('data-item-code')+"' data-instance-code='"+data.attr('data-instance-code')+"' data-attributes='"+data.attr('data-attributes')+"'>"
|
row ="<tr class='item_box' data-price ='"+price+ "' data-toggle='modal' data-target='#sx_itemModal' 'data-instance ='"+instance+ "' data-code='"+data.attr('data-item-code')+"' data-instance-code='"+data.attr('data-instance-code')+"' data-attributes='"+data.attr('data-attributes')+"' data-row ='"+rowCount+ "'>"
|
||||||
+'<td class="item-cell-no">'+rowCount+'</td>'
|
+'<td class="item-cell-no">'+rowCount+'</td>'
|
||||||
+'<td class="item-cell-name" id="item_name" >' + data.attr('data-name')+ ' ' + instance +'</td>'
|
+'<td class="item-cell-name" id="item_name" >' + data.attr('data-name')+ ' ' + instance +'</td>'
|
||||||
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
|
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
|
||||||
+'<td class="item-cell-price" id="item_price">'
|
+'<td class="item-cell-price" id="item_price">'
|
||||||
+ parseFloat(price).toFixed(2)
|
+ parseFloat(price).toFixed(2)
|
||||||
+'</td>'
|
+'</td>'
|
||||||
+'</tr>';
|
+'</tr>';
|
||||||
$(".summary-items tbody").append(row);
|
$(".summary-items tbody").append(row);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//click item row for update qty
|
// Pay Discount for Payment
|
||||||
$('.summary-items').on('click', '.item_box', function(){
|
$("#create_order").on('click', function(e){
|
||||||
$(this).attr('data-active',true);
|
e.preventDefault();
|
||||||
name = $(this).children('#item_name').text();
|
$( "#loading_wrapper" ).show();
|
||||||
qty = $(this).children('#item_qty').text();
|
var table_id = $('#table_id').text();
|
||||||
$('#modal-item-name').text(name);
|
var table_type = $('#table_type').text();
|
||||||
$('#modal-qty').val(qty);
|
var order_items = get_order_item_rows();
|
||||||
});
|
|
||||||
|
|
||||||
//click remove buttom in modal box
|
console.log(order_items);
|
||||||
$('#sx_itemModal').on('click','#remove', function(){
|
var ajax_url = '<%= api_orders_path %>';
|
||||||
$('.summary-items tr').filter(function(){
|
|
||||||
if ($(this).attr('data-active') == 'true'){
|
var params = {'order_source': "cashier", 'order_type': "dine_in",
|
||||||
$(this).remove();
|
'customer_id': "", 'guest_info': "",
|
||||||
|
'table_id': table_id,
|
||||||
|
'order_items': order_items };
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: ajax_url,
|
||||||
|
data: params,
|
||||||
|
success:function(result){
|
||||||
|
$( "#loading_wrapper" ).show();
|
||||||
|
$.confirm({
|
||||||
|
title: 'Infomation!',
|
||||||
|
content: "result.status",
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Ok',
|
||||||
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
if(table_type == "Table"){
|
||||||
|
window.location.href = "/origami/table/" + result.table_id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location.href = "/origami/room/" + result.table_id
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
calculate_sub_total();
|
|
||||||
});
|
|
||||||
|
|
||||||
//click close
|
|
||||||
$('#sx_itemModal').on('click','#close', function(){
|
|
||||||
$(".item_box").removeAttr("data-active");
|
|
||||||
});
|
|
||||||
|
|
||||||
//click save buttom after change qty
|
|
||||||
$('#sx_itemModal').on('click','#save', function(){
|
|
||||||
summary_items_filter();
|
|
||||||
calculate_sub_total();
|
|
||||||
});
|
|
||||||
|
|
||||||
//calculate subtotal
|
|
||||||
function calculate_sub_total(){
|
|
||||||
var total_price = 0;
|
|
||||||
var taxable_amount = 0;
|
|
||||||
var item_row = $('.summary-items tbody tr');
|
|
||||||
|
|
||||||
$(item_row).each(function(i){
|
|
||||||
var unit_price = parseFloat($(item_row[i]).attr('data-price'));
|
|
||||||
var qty = parseFloat($(item_row[i]).children('#item_qty').text());
|
|
||||||
total_price += qty*unit_price;
|
|
||||||
});
|
|
||||||
var fixed_total_price = parseFloat(total_price).toFixed(2);
|
|
||||||
var fixed_taxable_amount = parseFloat(taxable_amount).toFixed(2);
|
|
||||||
|
|
||||||
$('#sub_total').empty();
|
|
||||||
$('#sub_total').append(fixed_total_price);
|
|
||||||
|
|
||||||
if (fixed_total_price > 0) {
|
|
||||||
$('.create').removeAttr("disabled", false);
|
|
||||||
}else{
|
|
||||||
$('.create').attr("disabled", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function summary_items_filter(){
|
|
||||||
$('.summary-items tr').filter(function(){
|
|
||||||
if ($(this).attr('data-active') == 'true'){
|
|
||||||
qty = $('#modal-qty').val();
|
|
||||||
price = parseFloat($(this).attr('data-price'));
|
|
||||||
total_price = parseFloat(price*qty).toFixed(2);
|
|
||||||
|
|
||||||
$(this).find('#item_qty').text(qty);
|
|
||||||
$(this).find('.item-cell-price').text(total_price);
|
|
||||||
|
|
||||||
$(this).removeAttr('data-active');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//click item row for update qty
|
||||||
|
$('.summary-items').on('click', '.item_box', function(){
|
||||||
|
$(this).attr('data-active',true);
|
||||||
|
name = $(this).children('#item_name').text();
|
||||||
|
qty = $(this).children('#item_qty').text();
|
||||||
|
$('#modal-item-name').text(name);
|
||||||
|
$('#modal-qty').val(qty);
|
||||||
|
});
|
||||||
|
|
||||||
|
//click remove buttom in modal box
|
||||||
|
$('#sx_itemModal').on('click','#remove', function(){
|
||||||
|
$('.summary-items tr').filter(function(){
|
||||||
|
if ($(this).attr('data-active') == 'true'){
|
||||||
|
$(this).remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
calculate_sub_total();
|
||||||
|
});
|
||||||
|
|
||||||
|
//click close
|
||||||
|
$('#sx_itemModal').on('click','#close', function(){
|
||||||
|
$(".item_box").removeAttr("data-active");
|
||||||
|
});
|
||||||
|
|
||||||
|
//click save buttom after change qty
|
||||||
|
$('#sx_itemModal').on('click','#save', function(){
|
||||||
|
summary_items_filter();
|
||||||
|
calculate_sub_total();
|
||||||
|
});
|
||||||
|
|
||||||
|
//calculate subtotal
|
||||||
|
function calculate_sub_total(){
|
||||||
|
var total_price = 0;
|
||||||
|
var taxable_amount = 0;
|
||||||
|
var item_row = $('.summary-items tbody tr');
|
||||||
|
|
||||||
|
$(item_row).each(function(i){
|
||||||
|
var unit_price = parseFloat($(item_row[i]).attr('data-price'));
|
||||||
|
var qty = parseFloat($(item_row[i]).children('#item_qty').text());
|
||||||
|
total_price += qty*unit_price;
|
||||||
|
});
|
||||||
|
var fixed_total_price = parseFloat(total_price).toFixed(2);
|
||||||
|
var fixed_taxable_amount = parseFloat(taxable_amount).toFixed(2);
|
||||||
|
|
||||||
|
$('#sub_total').empty();
|
||||||
|
$('#sub_total').append(fixed_total_price);
|
||||||
|
|
||||||
|
if (fixed_total_price > 0) {
|
||||||
|
$('.create').removeAttr("disabled", false);
|
||||||
|
}else{
|
||||||
|
$('.create').attr("disabled", true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function summary_items_filter(){
|
||||||
|
$('.summary-items tr').filter(function(){
|
||||||
|
if ($(this).attr('data-active') == 'true'){
|
||||||
|
qty = $('#modal-qty').val();
|
||||||
|
price = parseFloat($(this).attr('data-price'));
|
||||||
|
total_price = parseFloat(price*qty).toFixed(2);
|
||||||
|
|
||||||
|
$(this).find('#item_qty').text(qty);
|
||||||
|
$(this).find('.item-cell-price').text(total_price);
|
||||||
|
|
||||||
|
$(this).removeAttr('data-active');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get discount Item rows */
|
||||||
|
function get_order_item_rows(){
|
||||||
|
var order_items = [];
|
||||||
|
var item_row = $('.summary-items tbody tr');
|
||||||
|
$(item_row).each(function(i){
|
||||||
|
var order_item = {};
|
||||||
|
order_item.order_item_id = $(item_row[i]).attr('data-row');
|
||||||
|
order_item.item_instance_code = $(item_row[i]).attr('data-instance-code');
|
||||||
|
order_item.quantity = $(item_row[i]).children('#item_qty').text();
|
||||||
|
order_item.options = [];
|
||||||
|
order_items.push(order_item);
|
||||||
|
});
|
||||||
|
return order_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $(item_row).each(function(i){
|
||||||
|
// value = $(item_row[i]).attr('data-value');
|
||||||
|
// str = value;
|
||||||
|
// attribute_arr.push(str);
|
||||||
|
// });
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user