update addorder
This commit is contained in:
@@ -12,6 +12,12 @@ $(function(){
|
||||
qty = $(this).val();
|
||||
price = $("#unit_price").text();
|
||||
$("#total_price").text(qty*price);
|
||||
});
|
||||
|
||||
$("#set_change_qty").change(function(){
|
||||
qty = $(this).val();
|
||||
price = $("#set_total_price").text();
|
||||
$("#set_total_price").text(qty*price);
|
||||
});
|
||||
|
||||
//show menu item list when click menu category
|
||||
@@ -98,23 +104,13 @@ $(function(){
|
||||
//end Ajax
|
||||
}
|
||||
//end show list function
|
||||
//click item row for add order
|
||||
//click item row for item set
|
||||
$(document).on('click', '.set_item_box', function(event){
|
||||
$(".instance-list").empty();
|
||||
$(".options-list").empty();
|
||||
|
||||
data = $(this).parent().children().children('.add_icon');
|
||||
|
||||
item_options = $(this).data('option');
|
||||
for(var field in item_options) {
|
||||
value = item_options[field]["values"];
|
||||
type = item_options[field]["type"];
|
||||
row = "<p style='font-size:15px'>"+type+"</p>"
|
||||
$(value).each(function(i){
|
||||
row +="<button class='btn btn-default option_btn "+ type +"' data-type='"+type+"' data-value='"
|
||||
+value[i]+"'>"+value[i]+"</button>";
|
||||
});
|
||||
$(".opt-list").append(row);
|
||||
}
|
||||
|
||||
instances = $(this).data('instance');
|
||||
item_sets = $(this).data('item-sets');
|
||||
|
||||
@@ -123,21 +119,25 @@ $(function(){
|
||||
$(value).each(function(i){
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: '../../settings/menu_item_instances/get_instance/'+value[i]["id"],
|
||||
url: '../../api/restaurant/menu_item_instances/'+value[i]["id"],
|
||||
data: {id:value[i]},
|
||||
success:function(result){
|
||||
// var image_path = ""
|
||||
console.log(result)
|
||||
row = '<div class="col-md-4 instance_box" >'
|
||||
+'<div class="card">'
|
||||
success:function(result){
|
||||
|
||||
row = '<div class="col-md-4 " >'
|
||||
+"<div class='card instance_box' data-name='"+result["name"]
|
||||
+"' data-code='"+result["code"]
|
||||
+"' data-price='"+result["price"]
|
||||
+"' data-option='"+JSON.stringify(result["options"])
|
||||
+"'>"
|
||||
+'<div class="card-head" style="line-height:14px;">'
|
||||
+'<small class="">'+result["name"]+'</small>'
|
||||
+'</div>'
|
||||
+'<div class="card-block">'
|
||||
+'<img id="" src="/image/logo.png">'
|
||||
+'<img id="" src="/image/logo.png" height="40px">'
|
||||
+'</div>'
|
||||
+'<div class="card-footer">'
|
||||
+' <small>'+result["price"]+'</small>'
|
||||
+' <small style="float:right" id="instance_option"></small>'
|
||||
+'</div>'
|
||||
+'</div>'
|
||||
+' </div>'
|
||||
@@ -146,16 +146,97 @@ $(function(){
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$('#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'));
|
||||
$('#set_change_qty').val(1);
|
||||
$('#set_item_instances').text(instances);
|
||||
$('#set_name').text(data.attr('data-name'));
|
||||
$('#set_item_code').text(data.attr('data-item-code'));
|
||||
$('#set_total_price').text(data.attr('data-price'));
|
||||
$('#set_unit_price').text(data.attr('data-price'));
|
||||
});
|
||||
// click instance for add item set
|
||||
$(document).on('click', '.instance_box', function(event){
|
||||
|
||||
$(".options-list").empty();
|
||||
|
||||
item_options = $(this).data('option');
|
||||
code = $(this).data('code');
|
||||
|
||||
for(var field in item_options) {
|
||||
value = item_options[field]["values"];
|
||||
type = item_options[field]["type"];
|
||||
row = "<p style='font-size:16px;margin-bottom:3px'>"+type+"</p>"
|
||||
$(value).each(function(i){
|
||||
row +="<button class='btn btn-default btn-sm option_btn "+ type +"' data-type='"
|
||||
+type+"' data-value='"+value[i]+"' data-code='"+code+"' data-group='set_menu'>"
|
||||
+value[i]+"</button>";
|
||||
});
|
||||
$(".options-list").append(row);
|
||||
}
|
||||
|
||||
if($(this).hasClass('selected-instance') == true){
|
||||
sub_total = $('#set_total_price').text();
|
||||
name = $(this).data('name');
|
||||
price = $(this).data('price');
|
||||
qty = $('#set_change_qty').val();
|
||||
total = qty*price;
|
||||
var total_price = +sub_total - +total;
|
||||
$(this).removeClass('selected-instance');
|
||||
$(".options-list").empty();
|
||||
$(this).removeAttr('data-options');
|
||||
$('#instance_option').text('')
|
||||
}else {
|
||||
sub_total = $('#set_total_price').text();
|
||||
name = $(this).data('name');
|
||||
price = $(this).data('price');
|
||||
qty = $('#set_change_qty').val();
|
||||
total = qty*price;
|
||||
var total_price = +sub_total + +total;
|
||||
$(this).addClass('selected-instance');
|
||||
}
|
||||
$('#set_total_price').text(total_price);
|
||||
}); //End selecct attribute buttom
|
||||
|
||||
// click add order
|
||||
$(document).on('click', '.set_order', function(event){
|
||||
total_price = $('#set_total_price').text();
|
||||
qty = parseInt($('#set_change_qty').val());
|
||||
item_code = $('#set_item_code').text();
|
||||
item_name = $('#set_name').text();
|
||||
|
||||
var items = $('.selected-instance');
|
||||
|
||||
attribute_arr = []
|
||||
option_arr = []
|
||||
var rowCount = $('.summary-items tbody tr').length+1;
|
||||
$(items).each(function(i){
|
||||
code = $(items[i]).attr('data-code');
|
||||
name = $(items[i]).attr('data-name');
|
||||
price = $(items[i]).attr('data-price');
|
||||
option = $(items[i]).attr('data-options');
|
||||
total = qty * price ;
|
||||
option_arr.push(option);
|
||||
row ="<tr class='item_box' data-price ='"
|
||||
+price+ "' data-toggle='modal' data-target='#sx_itemModal' 'data-instance ='"
|
||||
+name+ "' data-code='"+item_code+"' data-instance-code='"
|
||||
+code+"' data-attributes='"
|
||||
+attribute_arr+"' data-options ='"
|
||||
+option_arr+"' data-row ='"+rowCount+ "'>"
|
||||
+'<td class="item-cell-no">'+rowCount+'</td>'
|
||||
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'</td>'
|
||||
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
|
||||
+'<td class="item-cell-price" id="item_price">'
|
||||
+ parseFloat(total).toFixed(2)
|
||||
+'</td>'
|
||||
+'</tr>';
|
||||
$(".summary-items tbody").append(row);
|
||||
rowCount = rowCount + 1;
|
||||
});
|
||||
calculate_sub_total();
|
||||
|
||||
}); //End add order Click
|
||||
|
||||
//click item row for add order
|
||||
$(document).on('click', '.menu_item_box', function(event){
|
||||
$('.attributes-list').empty();
|
||||
@@ -214,8 +295,8 @@ $(function(){
|
||||
type = item_options[field]["type"];
|
||||
row = "<h4>"+type+"</h4>"
|
||||
$(value).each(function(i){
|
||||
row +="<button class='btn btn-default option_btn "+ type +"' data-type='"+type+"' data-value='"
|
||||
+value[i]+"'>"+value[i]+"</button>";
|
||||
row +="<button class='btn btn-default option_btn "+ type +"' data-type='"
|
||||
+type+"' data-value='"+value[i]+"' data-group='simple_menu'>"+value[i]+"</button>";
|
||||
});
|
||||
$(".options-list").append(row);
|
||||
}
|
||||
@@ -271,13 +352,27 @@ $(function(){
|
||||
$(document).on('click', '.option_btn', function(event){
|
||||
value = $(this).data('value');
|
||||
type = $(this).data('type');
|
||||
options = $(".option_btn");
|
||||
group = $(this).data('group');
|
||||
options = $(".option_btn");
|
||||
$(options).each(function(i){
|
||||
if ($(options[i]).attr('data-type')==type){
|
||||
$('.'+type).removeClass("selected-option");
|
||||
}
|
||||
});
|
||||
$(this).addClass('selected-option');
|
||||
|
||||
if(group == "set_menu"){
|
||||
code = $(this).data('code');
|
||||
value = $(this).data('value');
|
||||
|
||||
instance = $(".selected-instance");
|
||||
$(instance).each(function(i){
|
||||
if ($(instance[i]).attr('data-code')==code){
|
||||
$(instance[i]).attr('data-options',value);
|
||||
$(instance[i]).children().children('#instance_option').text(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}); //End selecct attribute buttom
|
||||
|
||||
@@ -310,7 +405,7 @@ $(function(){
|
||||
show_item_detail(item_data);
|
||||
calculate_sub_total();
|
||||
|
||||
}); //End Add Icon Click
|
||||
}); //End add order Click
|
||||
|
||||
// click plus icon for add
|
||||
$(document).on('click', '.add_icon', function(event){
|
||||
@@ -320,6 +415,7 @@ $(function(){
|
||||
}); //End Add Icon Click
|
||||
|
||||
function show_item_detail(data){
|
||||
console.log(data)
|
||||
qty = parseInt(data.attr('data-qty'));
|
||||
append = 0;
|
||||
price = parseFloat(data.attr('data-price')).toFixed(2);
|
||||
@@ -376,11 +472,11 @@ $(function(){
|
||||
// Pay Discount for Payment
|
||||
$("#create_order").on('click', function(e){
|
||||
e.preventDefault();
|
||||
$( "#loading_wrapper" ).show();
|
||||
$("#loading_wrapper").show();
|
||||
var table_id = $('#table_id').text();
|
||||
var booking_id = $('#booking_id').text();
|
||||
if (!booking_id.length > 0) {
|
||||
console.log("hi")
|
||||
|
||||
var params = {'order_source': "cashier", 'order_type': "dine_in",
|
||||
'customer_id': "", 'guest_info': "",'booking_id':booking_id,
|
||||
'table_id': table_id,
|
||||
@@ -390,7 +486,7 @@ $(function(){
|
||||
var order_items = JSON.stringify(get_order_item_rows());
|
||||
|
||||
var ajax_url = '../addorders/create';
|
||||
console.log(ajax_url)
|
||||
|
||||
|
||||
var params = {'order_source': "cashier", 'order_type': "dine_in",
|
||||
'customer_id': "", 'guest_info': "",
|
||||
@@ -403,10 +499,10 @@ $(function(){
|
||||
data: params,
|
||||
dataType: "json",
|
||||
success:function(result){
|
||||
$( "#loading_wrapper" ).show();
|
||||
$("#loading_wrapper").hide();
|
||||
$.confirm({
|
||||
title: 'Infomation!',
|
||||
content: "result.status",
|
||||
content: "Order has been successfully created",
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: 'Ok',
|
||||
@@ -501,6 +597,7 @@ $(function(){
|
||||
var item_row = $('.summary-items tbody tr');
|
||||
$(item_row).each(function(i){
|
||||
var order_item = {};
|
||||
console.log($(item_row[i]).attr('data-options'));
|
||||
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();
|
||||
|
||||
@@ -87,9 +87,16 @@ element.style {
|
||||
color: #fff !important;
|
||||
background-color: green !important;
|
||||
}
|
||||
.card {
|
||||
border: 2px solid rgba(0, 0, 0, 0.125) !important;
|
||||
}
|
||||
.selected-instance {
|
||||
border: 2px solid #7a62d3 !important;
|
||||
}
|
||||
|
||||
.attribute_btn {
|
||||
white-space: normal !important;
|
||||
height: 40px;
|
||||
|
||||
/*width: 80px;*/
|
||||
margin-bottom: 5px;
|
||||
margin-right: 5px;
|
||||
@@ -97,7 +104,7 @@ element.style {
|
||||
|
||||
.option_btn {
|
||||
white-space: normal !important;
|
||||
height: 40px;
|
||||
|
||||
/*width: 80px;*/
|
||||
margin-bottom: 5px;
|
||||
margin-right: 5px;
|
||||
@@ -115,4 +122,34 @@ element.style {
|
||||
height: 80px;
|
||||
border: 1px solid #54A5AF;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.card-footer{
|
||||
padding:0.35rem 1.25rem !important;
|
||||
}
|
||||
|
||||
/*Loading gif for payment*/
|
||||
|
||||
#loading_wrapper{
|
||||
|
||||
position: fixed;
|
||||
background-color: #C8C8C8 ;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
left: 0;
|
||||
opacity: 0.6;
|
||||
top: 0;
|
||||
z-index: 9999999;
|
||||
}
|
||||
#loading{
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-image: url('../../../image/loading-ajax.gif');
|
||||
background-position: center center;
|
||||
background-repeat: no-repeat;
|
||||
opacity: 1;
|
||||
filter: alpha(opacity=100); /* ie */
|
||||
-moz-opacity: 1; /* mozilla */
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class Api::Restaurant::MenuItemInstancesController < Api::ApiController
|
||||
skip_before_action :authenticate
|
||||
#Description
|
||||
# Pull the default menu details and also other available (active) menus
|
||||
# Input Params - order_id
|
||||
def show
|
||||
@id = MenuItemInstance.find(params[:id])
|
||||
end
|
||||
end
|
||||
@@ -37,6 +37,7 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
def create
|
||||
Rails.logger.debug "Order Source - " + params[:order_source].to_s
|
||||
Rails.logger.debug "Table ID - " + params[:table_id].to_s
|
||||
puts params[:order_items]
|
||||
items_arr = []
|
||||
JSON.parse(params[:order_items]).each { |i|
|
||||
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
if(@id)
|
||||
menu_item = MenuItem.find(@id.menu_item_id)
|
||||
# Format for option json
|
||||
opt_format = []
|
||||
# Format for attributes json
|
||||
menu_item.item_options.each do|opt|
|
||||
menu_opt = MenuItemOption.find(opt)
|
||||
if opt_format.count == 0
|
||||
opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] })
|
||||
next
|
||||
end
|
||||
|
||||
opt_format.each do |of|
|
||||
if menu_opt.option_type.in? opt_format.map {|k| k[:type]}
|
||||
if menu_opt.option_type == of[:type]
|
||||
of[:values].push(menu_opt.name)
|
||||
end
|
||||
else
|
||||
new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
|
||||
opt_format.push(new_opt)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
json.success true
|
||||
json.id @id.id
|
||||
json.name @id.item_instance_name
|
||||
json.code @id.item_instance_code
|
||||
|
||||
json.item_id @id.menu_item_id
|
||||
json.attributes @id.item_attributes
|
||||
json.price @id.price
|
||||
json.is_default @id.is_default
|
||||
|
||||
json.options opt_format
|
||||
else
|
||||
json.success false
|
||||
end
|
||||
@@ -147,39 +147,41 @@
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="background-color: #54A5AF;">
|
||||
<h4 class="modal-title" style="color:#fff;" id="title_name"></h4>
|
||||
<h4 class="modal-title" style="color:#fff;" id="set_name"></h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="font-size: 20px;color:#fff;">×</button>
|
||||
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row set-item">
|
||||
<div class="col-md-5">
|
||||
<div class="col-md-4">
|
||||
<p style="text-align: center;"> <%= image_tag "logo.png" ,width: '', height: '', :id => 'logo' %></p>
|
||||
<div class="form-group">
|
||||
<label class="col-md-6" style="margin-top:5px">Quantity</label>
|
||||
<input type="number" name="qty" class="form-control col-md-5 input-number change_qty" id="change_qty" value="" min="1" max="100">
|
||||
<input type="number" name="qty" class="form-control col-md-5 input-number change_qty" id="set_change_qty" value="" min="1" max="100">
|
||||
</div>
|
||||
<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>
|
||||
<p class="hidden" id="set_unit_price"></p>
|
||||
<p class="hidden" id="set_instance_code"></p>
|
||||
<p class="hidden" id="set_instance_name"></p>
|
||||
<p class="hidden" id="set_promotion_price"></p>
|
||||
<p class="hidden" id="set_item_instances"></p>
|
||||
<p class="hidden" id="set_item_code"></p>
|
||||
<p></p>
|
||||
<div class="opt-list">
|
||||
<h4>Options</h4>
|
||||
<br><br><br><br>
|
||||
<div class="options-list">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<div class="col-md-8">
|
||||
<div class="instance-list"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="mr-auto">
|
||||
<h4 class=" pull-left">Total : <span id="total_price"></span></h4>
|
||||
<h4 class=" pull-left">Total : <span id="set_total_price"></span></h4>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal" id="close">Close</button>
|
||||
<button type="button" class="btn btn-success add_to_order" data-dismiss="modal" id="add_to_order">Add to Order</button>
|
||||
<button type="button" class="btn btn-success set_order" data-dismiss="modal" id="set_order">Add to Order</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,28 @@
|
||||
if(@id)
|
||||
menu_item = MenuItem.find(@id.menu_item_id)
|
||||
# Format for option json
|
||||
opt_format = []
|
||||
# Format for attributes json
|
||||
menu_item.item_options.each do|opt|
|
||||
menu_opt = MenuItemOption.find(opt)
|
||||
if opt_format.count == 0
|
||||
opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] })
|
||||
next
|
||||
end
|
||||
|
||||
opt_format.each do |of|
|
||||
if menu_opt.option_type.in? opt_format.map {|k| k[:type]}
|
||||
if menu_opt.option_type == of[:type]
|
||||
of[:values].push(menu_opt.name)
|
||||
end
|
||||
else
|
||||
new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
|
||||
opt_format.push(new_opt)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
json.success true
|
||||
json.id @id.id
|
||||
json.name @id.item_instance_name
|
||||
@@ -8,6 +32,8 @@ if(@id)
|
||||
json.attributes @id.item_attributes
|
||||
json.price @id.price
|
||||
json.is_default @id.is_default
|
||||
|
||||
json.options opt_format
|
||||
else
|
||||
json.success false
|
||||
end
|
||||
|
||||
@@ -35,6 +35,7 @@ Rails.application.routes.draw do
|
||||
resources :menu_item_attributes, only: [:index]
|
||||
resources :menu_item_options, only: [:index]
|
||||
resources :menu_sold_out, only: [:index]
|
||||
resources :menu_item_instances, only: [:show]
|
||||
get "item_sets" => "item_sets#index"
|
||||
end
|
||||
|
||||
@@ -291,7 +292,7 @@ Rails.application.routes.draw do
|
||||
resources :promotion_products
|
||||
end
|
||||
|
||||
get 'menu_item_instances/get_instance/:id' => 'menu_item_instances#get_instance',:as => "show_instance"
|
||||
# get 'menu_item_instances/get_instance/:id' => 'menu_item_instances#get_instance',:as => "show_instance"
|
||||
end
|
||||
|
||||
#--------- Transactions Sections ------------#
|
||||
|
||||
Reference in New Issue
Block a user