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,7 +141,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|
||||||
//click menu sidebar menu category
|
//click menu sidebar menu category
|
||||||
@@ -149,14 +155,12 @@ $(function(){
|
|||||||
qty = $(this).val();
|
qty = $(this).val();
|
||||||
price = $("#unit_price").text();
|
price = $("#unit_price").text();
|
||||||
$("#total_price").text(qty*price);
|
$("#total_price").text(qty*price);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//show menu item list when click menu category
|
//show menu item list when click menu category
|
||||||
function show_menu_item_list(url_item){
|
function show_menu_item_list(url_item){
|
||||||
var menu_list = $('.menu_items_list');
|
var menu_list = $('.menu_items_list');
|
||||||
menu_list.empty();
|
menu_list.empty();
|
||||||
|
|
||||||
//Start Ajax
|
//Start Ajax
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@@ -183,16 +187,18 @@ $(function(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
qty = 1;
|
||||||
|
|
||||||
row = '<div class="card">'
|
row = '<div class="card">'
|
||||||
+'<div class="card-head" style="line-height:14px;">'
|
+'<div class="card-head" style="line-height:14px;">'
|
||||||
+'<small class="col-md-9">'+ menu_items[field].name +'</small>'
|
+'<small class="col-md-9">'+ menu_items[field].name +'</small>'
|
||||||
+"<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) +"'>"
|
+"<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) +"'>"
|
||||||
+'<i class="fa fa-plus "'
|
+'<i class="fa fa-plus "'
|
||||||
+ 'style="margin-top:4px;">'
|
+ 'style="margin-top:4px;">'
|
||||||
+'</i></div>'
|
+'</i></div>'
|
||||||
+'</div>'
|
+'</div>'
|
||||||
|
|
||||||
+"<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'>"
|
+"<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'>"
|
||||||
|
|
||||||
+'<div class="card-block">'
|
+'<div class="card-block">'
|
||||||
+'<%= image_tag "logo.png" ,width: '75', height: '75', :style => '' %>'
|
+'<%= image_tag "logo.png" ,width: '75', height: '75', :style => '' %>'
|
||||||
@@ -204,7 +210,6 @@ $(function(){
|
|||||||
+'</div>';
|
+'</div>';
|
||||||
$('.menu_items_list').append(row);
|
$('.menu_items_list').append(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//end Ajax
|
//end Ajax
|
||||||
@@ -215,6 +220,14 @@ $(function(){
|
|||||||
$(document).on('click', '.menu_item_box', function(event){
|
$(document).on('click', '.menu_item_box', function(event){
|
||||||
$('.attributes-list').empty();
|
$('.attributes-list').empty();
|
||||||
$('.attr-alert').addClass('hide');
|
$('.attr-alert').addClass('hide');
|
||||||
|
$('.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');
|
data = $(this).parent().children().children('.add_icon');
|
||||||
attributes = $(this).data('id');
|
attributes = $(this).data('id');
|
||||||
@@ -237,6 +250,7 @@ $(function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('#change_qty').val(1);
|
$('#change_qty').val(1);
|
||||||
|
$('#item_instances').text(instances);
|
||||||
$('#title_name').text(data.attr('data-name'));
|
$('#title_name').text(data.attr('data-name'));
|
||||||
$('#item_code').text(data.attr('data-item-code'));
|
$('#item_code').text(data.attr('data-item-code'));
|
||||||
$('#total_price').text(data.attr('data-price'));
|
$('#total_price').text(data.attr('data-price'));
|
||||||
@@ -245,11 +259,9 @@ $(function(){
|
|||||||
|
|
||||||
// click select option icon for add
|
// click select option icon for add
|
||||||
$(document).on('click', '.attribute_btn', function(event){
|
$(document).on('click', '.attribute_btn', function(event){
|
||||||
|
|
||||||
value = $(this).data('value');
|
value = $(this).data('value');
|
||||||
type = $(this).data('type');
|
type = $(this).data('type');
|
||||||
instances = $(this).data('instances');
|
instances = $(this).data('instances');
|
||||||
console.log(instances);
|
|
||||||
if ($(".attribute_btn").attr("data-type")==type){
|
if ($(".attribute_btn").attr("data-type")==type){
|
||||||
$('.'+type).removeClass("selected-option");
|
$('.'+type).removeClass("selected-option");
|
||||||
}
|
}
|
||||||
@@ -282,40 +294,43 @@ $(function(){
|
|||||||
// click add order
|
// click add order
|
||||||
$(document).on('click', '.add_to_order', function(event){
|
$(document).on('click', '.add_to_order', function(event){
|
||||||
total_price = $('#total_price').text();
|
total_price = $('#total_price').text();
|
||||||
unit_price = $('#unit_price').text();
|
qty = parseInt($('#change_qty').val());
|
||||||
qty = $('#change_qty').val();
|
|
||||||
var item_row = $('.selected-option');
|
var item_row = $('.selected-option');
|
||||||
var arr = [];
|
var instances = jQuery.parseJSON(item_row.attr('data-instances'));
|
||||||
|
|
||||||
var attribute_arr = [];
|
var attribute_arr = [];
|
||||||
$(item_row).each(function(i){
|
$(item_row).each(function(i){
|
||||||
value = $(item_row[i]).attr('data-value');
|
value = $(item_row[i]).attr('data-value');
|
||||||
arr = {value};
|
str = value;
|
||||||
|
attribute_arr.push(str);
|
||||||
});
|
});
|
||||||
console.log(arr);
|
|
||||||
if(total_price > 0){
|
|
||||||
|
|
||||||
|
for(var field in instances) {
|
||||||
|
if (JSON.stringify(attribute_arr) === JSON.stringify(instances[field].values)) {
|
||||||
|
|
||||||
|
$('.add_to_order').attr('data-instance-code',instances[field].code);
|
||||||
|
$('.add_to_order').attr('data-instance',instances[field].name);
|
||||||
|
$('.add_to_order').attr('data-price',instances[field].price);
|
||||||
|
$('.add_to_order').attr('data-promotion-price',instances[field].promotion_price);
|
||||||
|
}
|
||||||
|
}
|
||||||
$('.add_to_order').attr('data-item-code',$('#item_code').text());
|
$('.add_to_order').attr('data-item-code',$('#item_code').text());
|
||||||
|
$('.add_to_order').attr('data-qty',qty);
|
||||||
$('.add_to_order').attr('data-name',$('#title_name').text());
|
$('.add_to_order').attr('data-name',$('#title_name').text());
|
||||||
$('.add_to_order').attr('data-price',unit_price);
|
$('.add_to_order').attr('data-attributes',JSON.stringify(attribute_arr));
|
||||||
$('.add_to_order').attr('data-instance-code',$('#instance_code').text());
|
|
||||||
$('.add_to_order').attr('data-instance',$('#instance_name').text());
|
|
||||||
$('.add_to_order').attr('data-promotion-price',$('#promotion_price').text());
|
|
||||||
$('.add_to_order').attr('data-attributes',$('#instance_name').text());
|
|
||||||
|
|
||||||
var item_data = $(this);
|
var item_data = $(this);
|
||||||
show_item_detail(item_data);
|
show_item_detail(item_data);
|
||||||
calculate_sub_total();
|
calculate_sub_total();
|
||||||
}else{
|
|
||||||
$.alert({
|
// if(total_price > 0){
|
||||||
title: 'Alert!',
|
// }else{
|
||||||
content: 'Please select another item',
|
// $.alert({
|
||||||
type: 'red',
|
// title: 'Alert!',
|
||||||
typeAnimated: true,
|
// content: 'Please select another item',
|
||||||
btnClass: 'btn-danger',
|
// type: 'red',
|
||||||
});
|
// typeAnimated: true,
|
||||||
}
|
// btnClass: 'btn-danger',
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
}); //End Add Icon Click
|
}); //End Add Icon Click
|
||||||
|
|
||||||
@@ -327,11 +342,10 @@ $(function(){
|
|||||||
}); //End Add Icon Click
|
}); //End Add Icon Click
|
||||||
|
|
||||||
function show_item_detail(data){
|
function show_item_detail(data){
|
||||||
qty = 1;
|
qty = parseInt(data.attr('data-qty'));
|
||||||
append = 0;
|
append = 0;
|
||||||
price = parseFloat(data.attr('data-price')).toFixed(2);
|
price = parseFloat(data.attr('data-price')).toFixed(2);
|
||||||
instance_name = data.attr('data-instance');
|
instance_name = data.attr('data-instance');
|
||||||
|
|
||||||
if (instance_name == "undefined"){
|
if (instance_name == "undefined"){
|
||||||
instance = '';
|
instance = '';
|
||||||
}else{
|
}else{
|
||||||
@@ -346,17 +360,25 @@ $(function(){
|
|||||||
instance_code = $(item_row[i]).attr('data-instance-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')) {
|
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;
|
if (qty > 1) {
|
||||||
|
qty = parseInt($(item_row[i]).children('#item_qty').text()) + qty;
|
||||||
|
}else{
|
||||||
|
qty = parseInt($(item_row[i]).children('#item_qty').text()) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
$(item_row[i]).children('#item_qty').text(qty);
|
$(item_row[i]).children('#item_qty').text(qty);
|
||||||
parseFloat($(item_row[i]).children('#item_price').text(price*qty)).toFixed(2);
|
parseFloat($(item_row[i]).children('#item_price').text(price*qty)).toFixed(2);
|
||||||
append = 1;
|
append =1;
|
||||||
|
}else{
|
||||||
|
if (qty > 1) {
|
||||||
|
qty = qty;
|
||||||
}else{
|
}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>'
|
||||||
@@ -368,6 +390,50 @@ $(function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pay Discount for Payment
|
||||||
|
$("#create_order").on('click', function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
$( "#loading_wrapper" ).show();
|
||||||
|
var table_id = $('#table_id').text();
|
||||||
|
var table_type = $('#table_type').text();
|
||||||
|
var order_items = get_order_item_rows();
|
||||||
|
|
||||||
|
console.log(order_items);
|
||||||
|
var ajax_url = '<%= api_orders_path %>';
|
||||||
|
|
||||||
|
var params = {'order_source': "cashier", 'order_type': "dine_in",
|
||||||
|
'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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//click item row for update qty
|
//click item row for update qty
|
||||||
$('.summary-items').on('click', '.item_box', function(){
|
$('.summary-items').on('click', '.item_box', function(){
|
||||||
$(this).attr('data-active',true);
|
$(this).attr('data-active',true);
|
||||||
@@ -420,7 +486,6 @@ $(function(){
|
|||||||
}else{
|
}else{
|
||||||
$('.create').attr("disabled", true);
|
$('.create').attr("disabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function summary_items_filter(){
|
function summary_items_filter(){
|
||||||
@@ -437,6 +502,28 @@ $(function(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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