From f4f591553276678bbd2caa931f642fe314342865 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 26 Feb 2018 09:19:14 +0630 Subject: [PATCH] update waiter view add order --- app/assets/javascripts/addorder.js | 84 +++++---- .../origami/addorders_controller.rb | 13 +- .../origami/payments_controller.rb | 2 +- .../origami/pending_order_controller.rb | 39 +++- .../origami/quick_service_controller.rb | 33 ++-- .../origami/request_bills_controller.rb | 3 + app/models/sale.rb | 9 +- app/views/origami/addorders/detail.html.erb | 17 +- app/views/origami/home/show.html.erb | 2 +- app/views/origami/payments/show.html.erb | 30 +-- .../origami/pending_order/index.html.erb | 9 +- app/views/origami/pending_order/show.html.erb | 178 ++++++++++++------ 12 files changed, 259 insertions(+), 160 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 25b9aa9b..c55525bc 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1,5 +1,5 @@ $(function() { - + var role = $('#role').val(); type = $('#type').val(); modify_order = $('#modify_order').val(); //click menu sidebar menu category @@ -758,7 +758,11 @@ $(function() { type = $('#type').val(); if (type == 'true') { - type = 'cashier' + // if (role == 'waiter') { + type = 'quick_service' + // }else{ + // type = 'cashier' + // } var table_type = $('#table_type').text(); var table_id = $('#table_id').val(); @@ -773,42 +777,45 @@ $(function() { var booking_id = $('#booking_id').text(); var ajax_url = '../addorders/create'; } - if (!booking_id.length > 0) { + var order_items = JSON.stringify(get_order_item_rows()); + if (booking_id.length > 0) { var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, 'order_items': order_items }; - } - - var order_items = JSON.stringify(get_order_item_rows()); - - var params = {'order_source': type, 'order_type': "dine_in", + }else{ + var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, 'order_items': order_items }; - if (table_id.length>0) { - $.ajax({ - type: "POST", - url: ajax_url, - data: params, - dataType: "json", - success:function(result){ - - if(table_type == "Table"){ - window.location.href = "/origami/table/" + table_id - } - else { - window.location.href = "/origami/room/" + table_id - } - } - }); - }else{ - $(this).removeAttr('disabled', ''); - $("#oqs_loading_wrapper").hide(); - - swal("Opps","Please Select Table or Room","warning"); } + + if (table_id.length>0 || role == 'waiter') { + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + dataType: "json", + success:function(result){ + if (type == "quick_service") { + window.location.href = "/origami/quick_service" + }else{ + if(table_type == "Table"){ + window.location.href = "/origami/table/" + table_id + } + else { + window.location.href = "/origami/room/" + table_id + } + } + } + }); + }else{ + $(this).removeAttr('disabled', ''); + $("#oqs_loading_wrapper").hide(); + + swal("Opps","Please Select Table or Room","warning"); + } }); @@ -835,21 +842,20 @@ $(function() { var booking_id = $('#booking_id').text(); var sale_id = "" } - - if (!booking_id.length > 0) { + var order_items = JSON.stringify(get_order_item_rows()); + if (booking_id.length > 0) { var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, - 'order_items': order_items }; - } - var order_items = JSON.stringify(get_order_item_rows()); - - var params = {'order_source': type, 'order_type': "dine_in", + 'order_items': order_items,'sale_id': sale_id }; + }else{ + var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, 'order_items': order_items,'sale_id': sale_id }; - console.log(params) + } + $.ajax({ type: "POST", url: ajax_url, @@ -858,7 +864,11 @@ $(function() { success:function(result){ console.log(result) if (result.status) { + if (result.data == null){ + window.location.href = '/origami/quick_service/pending_order/' + $('#sale_id').text(); + }else{ window.location.href = "/origami/sale/"+result.data["sale_id"]+"/"+type+"/payment" + } } } }); diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index add3065b..42412c51 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -153,13 +153,18 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController end @status, @booking = @order.generate - - if @status && @booking && @order.source == 'quick_service' + if current_user.role != "waiter" + if @status && @booking && @order.source == 'quick_service' - @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) - result = {:status=> @status, :data => @sale } + @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) + result = {:status=> @status, :data => @sale } + render :json => result.to_json + end + else + result = {:status=> @status, :data => 0 } render :json => result.to_json end + end # render json for http status code diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index e79e92f6..404f8c6b 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -93,7 +93,7 @@ class Origami::PaymentsController < BaseOrigamiController #end rounding adjustment sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, @usercurrent_user.name, cash, "cash") + sale_payment.process_payment(saleObj, current_user.name, cash, "cash") render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error "}) rebate_amount = nil diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index a1942a27..4ed81121 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -2,21 +2,46 @@ class Origami::PendingOrderController < BaseOrigamiController def index # @dining= DiningFacility.where("status = 'occupied'") # @order = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status = 'billed' and source = 'quick_service'",DateTime.now.strftime('%Y-%m-%d')) - @sale = Sale.pending_order + @sale = Sale.pending_sale + @order = Sale.pending_order + end def show - @sales = Sale.pending_order - @sale = Sale.find(params[:sale_id]) - @order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id - @booking = BookingOrder.find_by_order_id(@order).booking_id - if Booking.find(@booking).dining_facility_id.to_i > 0 - @table_id = Booking.find(@booking).dining_facility_id + @sales = Sale.pending_sale + @orders = Sale.pending_order + @id = params[:sale_id] + if(@id[0,3] == "SAL") + @sale = Sale.find(@id) + @order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id + @booking = BookingOrder.find_by_order_id(@order).booking_id + @bookings = Booking.find(@booking) + @status = "sale" + else + # @booking = BookingOrder.find_by_order_id(@order).booking_id + @bookings = Booking.find(@id) + @status = "order" + + @order_items = Array.new + @bookings.booking_orders.each do |booking_order| + order = Order.find(booking_order.order_id) + if (order.status == "new") + order.order_items.each do |item| + @order_items.push(item) + end + end + end + end + + if @bookings.dining_facility_id.to_i > 0 + @table_id = Booking.find(@bookings.booking_id).dining_facility_id @dining = DiningFacility.find(@table_id) else @table_id = nil @dining = nil end + end + helper_method :shop_detail def shop_detail @shop = Shop.first diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index ef170480..2b943e7e 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -134,21 +134,26 @@ class Origami::QuickServiceController < ApplicationController end @status, @booking = @order.generate - - if @status && @booking && @order.source == 'quick_service' - if params[:sale_id] - @sale = Sale.find(params[:sale_id]) - if @order.table_id.to_i > 0 - @table_id = @order.table_id - else - @table_id = nil + if(params[:sale_id][0,3] == "SAL") + if @status && @booking && @order.source == 'quick_service' + if params[:sale_id] + @sale = Sale.find(params[:sale_id]) + if @order.table_id.to_i > 0 + @table_id = @order.table_id + else + @table_id = nil + end + update = Sale.add_to_existing_pending_invoice(@table_id,params[:sale_id],@booking) end - update = Sale.add_to_existing_pending_invoice(@table_id,params[:sale_id],@booking) - end - - result = {:status=> true, :data => @sale } - render :json => result.to_json - end + + result = {:status=> true, :data => @sale } + render :json => result.to_json + end + else + result = {:status=> true, :data => nil } + render :json => result.to_json + end + end def get_menu_category () diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index ad46ede6..409177fe 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -8,6 +8,9 @@ class Origami::RequestBillsController < ApplicationController if !ShiftSale.current_shift.nil? order_id = params[:id] # order_id bk_order = BookingOrder.find_by_order_id(order_id) + puts params[:id] + puts bk_order + puts bk_order.booking_id check_booking = Booking.find_by_booking_id(bk_order.booking_id) if check_booking.sale_id.nil? diff --git a/app/models/sale.rb b/app/models/sale.rb index cf45f3a6..8ae6656d 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1315,12 +1315,19 @@ end end end - def self.pending_order + def self.pending_sale query = Sale.all query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id") .joins("join orders as orders on orders.order_id = sale_orders.order_id") query = query.where("sales.sale_status = 'new' AND orders.status = 'billed' AND orders.source =? ","quick_service") end + def self.pending_order + query = Booking.all + query = query.joins("join booking_orders as booking_orders on booking_orders.booking_id = bookings.booking_id") + .joins("join orders as orders on orders.order_id = booking_orders.order_id") + query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","quick_service") + .group("bookings.booking_id") + end private diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 58011788..c2bd6deb 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -9,6 +9,8 @@ <% modify_order = request.path_info.include?('modify_order')%> + +
Back - <% if current_user.role != "waiter"%> + - <%end%> + <%elsif !modify_order && type%> - <% if current_user.role != "waiter"%> + - <%end%> + Select @@ -225,10 +227,13 @@ <% if current_user.role != "waiter"%> + + <%end%> + <% if current_user.role == "waiter"%> + <%end%> - <%else%> - + <%end%> diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 6e70730a..ceaca628 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -276,11 +276,11 @@ <% - # end end end if @status_order == 'order' && @status_sale != 'sale' + puts unless @order_items.nil? || @order_items.empty? count = 0 @order_items.each do |order_item| diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index ade7b51c..60ea300a 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -734,15 +734,11 @@ console.log("fffffffffffff") url: ajax_url, data: "remark="+ remark + "&sale_id=" + sale_id, success: function () { -<<<<<<< HEAD if (cashier_type=="cashier") { window.location.href = '/origami'; }else{ window.location.href = '/origami/quick_service'; - } -======= - window.location.href = '/origami/'; ->>>>>>> 77a66d726bc48a7c5d8be7c12728c1d0a9a5621e + } } }) } @@ -782,29 +778,6 @@ console.log("fffffffffffff") var params = { 'cash':cash,'sale_id':sale_id,'sub_total':sub_total,'remark':remark }; if ($(this).attr('active')=== "true") { -<<<<<<< HEAD - $.ajax({ - type: "POST", - url: "<%= origami_payment_foc_path %>", - data: params, - success:function(result){ - - //$( "#loading_wrapper" ).hide(); - - if (cash >= 0) { - swal({ - title: "Information!", - text: 'Thank You !', - }, function () { - if (cashier_type=="cashier") { - window.location.href = '/origami'; - }else{ - window.location.href = '/origami/quick_service'; - } - }); - } - -======= swal({ title: "Alert", text: "Are you sure want to FOC This Receipt?", @@ -830,7 +803,6 @@ console.log("fffffffffffff") } } }); ->>>>>>> 77a66d726bc48a7c5d8be7c12728c1d0a9a5621e } }); diff --git a/app/views/origami/pending_order/index.html.erb b/app/views/origami/pending_order/index.html.erb index a3df293c..8fa9a7af 100644 --- a/app/views/origami/pending_order/index.html.erb +++ b/app/views/origami/pending_order/index.html.erb @@ -12,10 +12,17 @@ <% @sale.each do |sale| %>
- <%= sale.receipt_no %><%= sale.sale_status %> + <%= sale.receipt_no %>Billed
<% end %> + <% @order.each do |order| %> +
+
+ <%= order.booking_id %>new +
+
+ <% end %>
diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index c7233400..c400071e 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -10,12 +10,19 @@
<% @sales.each do |sale| %> -
-
- <%= sale.receipt_no %><%= sale.sale_status %> -
-
- <% end %> +
+
+ <%= sale.receipt_no %>Billed +
+
+ <% end %> + <% @orders.each do |order| %> +
+
+ <%= order.booking_id %>new +
+
+ <% end %>
@@ -31,19 +38,38 @@
-
-   Receipt No: - <%= @sale.receipt_no rescue '' %> - -
-
- Date: <%= @sale.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>   -
+ + <% if @status == 'sale' %> +
+   Receipt No: + <%= @sale.receipt_no rescue '' %> +
+ <% else%> + +
+   Order No: + <%= @bookings.booking_orders[0].order_id rescue '' %> +
+ <% end%> + + + <% if @status == 'sale' %> +
+ Date: <%= @sale.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>   +
+ <% else%> +
+ Date: <%= @order.created_at.strftime("%I:%M %p") rescue '-'%>   +
+ <% end%>
-   Customer : <%= @sale.customer.name rescue "-" %> - + <% if @status == 'sale' %> +   Customer : <%= @sale.customer.name rescue "-" %> + <% else%> +   Customer : <%= @order.customer.name rescue "-" %> + <% end%>
@@ -58,55 +84,64 @@ - <% - sub_total = 0 + <% if @status == 'sale' %> + <% sub_total = 0 @sale.sale_items.each do |sale_item| - sub_total = sub_total + sale_item.price - %> - - <% #unless sale_item.price <= 0 %> - - <%= sale_item.product_name %> - <%= sale_item.qty %> - <%= sale_item.price %> - - <% - - #end - end - - %> + sub_total = sub_total + sale_item.price %> + + + <%= sale_item.product_name %> + <%= sale_item.qty %> + <%= sale_item.price %> + + <% end%> + <% else%> + <% sub_total = 0 + @order_items.each do |order_item| + sub_total = sub_total + order_item.price %> + + + <%= order_item.item_name %> + <%= order_item.qty %> + <%= order_item.price %> + + <% end%> + <% end%> +
@@ -115,8 +150,15 @@
+ <% if current_user.role != "waiter" || @status != "sale"%> - + <%end%> + <% if current_user.role != "waiter"%> + + <%end%> + <% if @status != "sale"%> + + <%end%>
@@ -135,7 +177,7 @@ $(document).ready(function(){ }); $('#addorder').on('click', function () { var table_id = "<%=@table_id%>"; - var booking_id = "<%=@booking%>"; + var booking_id = "<%=@bookings.booking_id%>"; if (table_id) { window.location.href = '/origami/quick_service/modify_order/' + table_id+"/"+$('#sale_id').val(); }else{ @@ -143,5 +185,23 @@ $(document).ready(function(){ } }); + // Bill Request + $('#request_bills').click(function () { + var order_id = $('#save_order_id').val(); + var ajax_url = "/origami/" + order_id + "/request_bills"; + $.ajax({ + type: "GET", + url: ajax_url, + // data: 'order_id='+ order_id, + success: function (result) { + if (!result.status) { + swal("Information!", result.error_message); + } + else { + location.reload(); + } + } + }); + }); });