update add order and calculate subtotal

This commit is contained in:
Aung Myo
2017-08-17 13:51:01 +06:30
parent d4d8961b87
commit 7f2bfa2348
4 changed files with 64 additions and 36 deletions

View File

@@ -13,9 +13,7 @@ class Api::Restaurant::MenuCategoriesController < Api::ApiController
# This API show current order details
# Input Params - menu_id
def show
puts "SSSSSSSSSSSSS"
@menu = menu_detail(params[:id])
puts @menu.to_json
end

View File

@@ -32,8 +32,8 @@ elsif item.menu_item_instances.count > 1 then
end
#Child Menu items
if (item.children) then
json.set_items item.children.each do |item|
if (item.menu_item_sets) then
json.set_items item.menu_item_sets.each do |item|
json.partial! 'api/restaurant/menu/menu_item', item: item
end

View File

@@ -6,8 +6,8 @@ if @menu.menu_items
json.alt_name item.alt_name
json.type item.type
json.min_qty item.min_qty
json.min_selectable_item item.min_selectable_item
json.max_selectable_item item.max_selectable_item
# json.min_selectable_item item.min_selectable_item
# json.max_selectable_item item.max_selectable_item
#Item instance
if item.menu_item_instances.count == 1 then
@@ -33,11 +33,11 @@ if @menu.menu_items
end
#Child Menu items
if (item.children) then
json.set_items item.children.each do |item|
if (item.menu_item_sets) then
json.set_items item.menu_item_sets.each do |item|
json.partial! 'api/restaurant/menu/menu_item', item: item
end
end
end
end
end

View File

@@ -23,7 +23,7 @@
</div>
</div>
<div class="card-block">
<div class="card-text" style="min-height:500px; max-height:500px; overflow:auto">
<div class="card-text" style="max-height:500px; overflow:auto"">
<table class="table table-striped summary-items">
<thead>
<tr>
@@ -42,7 +42,7 @@
<table class="table" id="order-charges-table" border="0">
<tr>
<td class="charges-name"><strong>Sub Total:</strong></td>
<td class="item-attr"><strong id="order-sub-total">22222</strong></td>
<td class="item-attr"><strong id="sub_total">0.00</strong></td>
</tr>
</table>
</div>
@@ -53,14 +53,16 @@
$(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
});
//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();
@@ -74,7 +76,7 @@ $(function(){
var menu_items_list = $('.menu_items_list');
menu_items_list.empty();
menu_items = data.menu_items;
console.log(data);
for(var field in menu_items) {
if (menu_items[field].item_instances){
var price = parseFloat(menu_items[field].item_instances[1].price).toFixed(2);
@@ -130,47 +132,75 @@ $(function(){
}
//end show detail function
// click plus icon for add
$(document).on('click', '.add_icon', function(event){
var item_data = $(this);
show_item_detail(item_data);
show_item_detail(item_data);
calculate_sub_total();
}); //End Add Icon Click
function show_item_detail(data){
qty = 1;
append = 0;
price = data.attr('data-price');
instance_code = data.attr('data-instance');
price = data.attr('data-price');
if (data.attr('data-qty') === undefined){
qty = 1;
}else{
qty = data.attr('data-qty');
}
if (data.attr('data-instance') == "undefined"){
if (instance_code == "undefined"){
instance = '';
}else{
instance = data.attr('data-instance');
instance = "("+data.attr('data-instance')+")";
}
var rowCount = $('.summary-items tbody tr').length+1;
var item_row = $('.summary-items tbody tr');
$(item_row).each(function(i){
if ($(item_row[i]).attr('data-code') == data.attr('data-item-code')) {
qty = parseInt($(item_row[i]).children('#item_qty').text()) +1;
$(item_row[i]).children('#item_qty').text(qty);
$(item_row[i]).children('#item_price').text(price*qty);
append = 1;
}else{
qty = 1;
}
});
var rowCount = $('.summary-items tbody');
console.log(rowCount);
for(var field in rowCount) {
// console.log(rowCount[field].attr('data-code'));
}
row ='<tr>'
if (append===0) {
row ="<tr data-price ='"+price+ "'data-instance ='"+instance+ "'data-code='"+data.attr('data-item-code')+"'>"
+'<td class="item-cell-no">'+rowCount+'</td>'
+'<td class="item-cell-name" data-code='+data.attr('data-item-code')+'>' + data.attr('data-name')+ ' ' + instance + '</td>'
+'<td class="item-cell-name" >' + data.attr('data-name')+ ' ' + instance + '</td>'
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
+'<td class="item-cell-price" id="item_price">'
+ parseFloat(price).toFixed(2)
+'</td>'
+'</tr>';
$(".summary-items tbody").append(row);
$(".summary-items tbody").append(row);
}
}
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 taxable = $(item_row[i]).attr('data-taxable');
var unit_price = parseFloat($(item_row[i]).attr('data-price'));
var qty = parseFloat($(item_row[i]).children('#item_qty').text());
// if(taxable == 'true'){
// taxable_amount += qty*unit_price;
// }
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);
// $('#sub_total').attr('taxable_amount',fixed_taxable_amount);
// $('#show_sub').text(fixed_total_price);
}
});
</script>