diff --git a/README.md b/README.md index 54474f5e..62c69ed9 100755 --- a/README.md +++ b/README.md @@ -311,6 +311,9 @@ settings/lookups => {type:show_total_before_tax, name:Show Total Before Tax, val For Using Staff Meal settings/lookups => { type:customer_type, name: Staff, value:Staff } +For FoodCourt Cashier role +settings/lookups => { type:employee_roles, name: FoodCourt Cashier, value:foodcourt_cashier } + * ToDo list 1. Migration diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index d94dddb7..c40db476 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1655,4 +1655,32 @@ $(function() { //end is_sub_item false } } + $("#add_to_existing_order").on('click', function(e){ + $(this).attr('disabled', 'disabled'); + e.preventDefault(); + type = $("#link_type").val(); + $("#oqs_loading_wrapper").show(); + var ajax_url = 'addorders/add_to_existing_order'; + var table_type = $('#table_type').text(); + var table_id = $('#table_id').text(); + var customer_id = $('#customer_id').text(); + var booking_id = $('#booking_id').text(); + var sale_id = $('#sale_id').text(); + var order_items = JSON.stringify(get_order_item_rows()); + 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,'sale_id': sale_id,'create_type': "create_pay" }; + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + dataType: "json", + success:function(result){ + if (result.status) { + window.location.href = "/foodcourt/table/sale/" + sale_id + "/food_court/edit"; + } + } + }); + }); }); diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 0c512f5d..ec2f7eed 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -122,6 +122,9 @@ class Api::OrdersController < Api::ApiController end @status, @booking = @order.generate + if params[:order_source] != "app" + @order.process_order_queue(@order.order_id,@order.table_id,@order.source) + end if @order.table_id.to_i > 0 table = DiningFacility.find(@booking.dining_facility_id) type = 'order' diff --git a/app/controllers/foodcourt/addorders_controller.rb b/app/controllers/foodcourt/addorders_controller.rb index 2af43923..79ffdb37 100755 --- a/app/controllers/foodcourt/addorders_controller.rb +++ b/app/controllers/foodcourt/addorders_controller.rb @@ -305,5 +305,56 @@ class Foodcourt::AddordersController < BaseFoodcourtController return from end + def add_to_existing_order + if params[:booking_id].present? && params[:sale_id].present? + booking = Booking.find(params[:booking_id]) + saleobj =Sale.find(params[:sale_id]) + order =saleobj.orders[0] + items_arr = [] + JSON.parse(params[:order_items]).each { |i| + i["item_instance_code"] = i["item_instance_code"].downcase.to_s + if i["item_instance_code"].include? "ext" + is_extra_time = true + arr_exts = i["item_instance_code"].split("_") + if arr_exts[1].match(/^(\d)+$/) + time = arr_exts[1].to_i*60*i["quantity"].to_i + extra_time = Time.at(time) + end + end + if i["parent_order_item_id"]; + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])} + else + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])} + end + items_arr.push(items) + } + order.items = items_arr + order.new_booking = false + order.booking_id = booking.booking_id + @status, booking = order.generate + order_array = [] + items_arr.each do |item| + order_item =order.order_items.where("item_instance_code=?",item[:item_instance_code]).last + saleobj.add_item (order_item) + if !order_item.set_menu_items.nil? + saleobj.add_sub_item(order_item.set_menu_items) + end + end + # Re-compute for add + saleobj.compute(order.source) + saleobj.save + order.save + booking.save + order_array.push(order.order_id) + receipt_no = saleobj.receipt_no + action_by = current_user.name + type = "ADD_TO_EXISTING" + + remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no}" + sale_audit = SaleAudit.record_audit_sale(saleobj.sale_id,remark,action_by,type ) + end + result = {:status=> @status} + render :json => result.to_json + end end diff --git a/app/controllers/foodcourt/food_court_controller.rb b/app/controllers/foodcourt/food_court_controller.rb index 13f72dc3..f5d4b653 100644 --- a/app/controllers/foodcourt/food_court_controller.rb +++ b/app/controllers/foodcourt/food_court_controller.rb @@ -8,6 +8,15 @@ class Foodcourt::FoodCourtController < ApplicationController end def index + if params[:sale_id].present? + sale =Sale.find(params[:sale_id]) + if sale + @sale_id =sale.sale_id + @booking_id =sale.bookings[0].booking_id + end + end + + today = DateTime.now day = Date.today.wday @menus = [] diff --git a/app/controllers/foodcourt/sale_edit_controller.rb b/app/controllers/foodcourt/sale_edit_controller.rb index 9971e50d..9bebbe0e 100755 --- a/app/controllers/foodcourt/sale_edit_controller.rb +++ b/app/controllers/foodcourt/sale_edit_controller.rb @@ -38,19 +38,6 @@ class Foodcourt::SaleEditController < BaseFoodcourtController # re-calc tax saleObj = Sale.find(saleitemObj.sale_id) - - - # booking = Booking.find_by_sale_id(saleitemObj.sale_id) - # booking.booking_orders.each do |bo| - # order = Order.find(bo.order_id) - # order.order_items.each do |o| - # if saleitemObj.product_code == o.item_code - # o.qty = saleitemObj.qty * -1 - # o.price = saleitemObj.price * -1 - # o.save - # end - # end - # end # FOr Sale Audit action_by = current_user.name if access_code != "null" && current_user.role == "cashier" @@ -99,26 +86,6 @@ class Foodcourt::SaleEditController < BaseFoodcourtController ProductCommission.create_product_commission(@newsaleitem, saleitemObj) end - # def item_edit - # saleitemId = params[:sale_item_id] - # update_qty = params[:update_qty] - # update_price = params[:update_price] - # saleitemObj = SaleItem.find(saleitemId) - # saleitemObj.status = 'void' - # saleitemObj.save - # @newsaleitem = SaleItem.new - # @newsaleitem = saleitemObj.dup - # @newsaleitem.save - # @newsaleitem.qty = update_qty - # @newsaleitem.price = update_price - # @newsaleitem.unit_price = update_price - # @newsaleitem.taxable_price = update_price - # @newsaleitem.is_taxable = 0 - # @newsaleitem.remark = 'edit' - # @newsaleitem.product_name = saleitemObj.product_name + " - updated" - # @newsaleitem.save - # end - def item_edit saleitemId = params[:sale_item_id] update_qty = params[:update_qty] @@ -149,20 +116,6 @@ class Foodcourt::SaleEditController < BaseFoodcourtController saleitemObj.save - # re-calc tax - # saleObj = Sale.find(saleitemObj.sale_id) - - # order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id - # order = Order.find(order_id) - - # order.order_items.each do |o| - # if saleitemObj.product_code == o.item_code - # o.qty = update_qty - # o.price = update_price - # o.save - # end - # end - sale.compute_by_sale_items(sale.total_discount, nil, order_source) ProductCommission.edit_product_commission(saleitemObj,sale.shop_code) diff --git a/app/views/foodcourt/addorders/detail.html.erb b/app/views/foodcourt/addorders/detail.html.erb index 73ee792e..f02dfb88 100644 --- a/app/views/foodcourt/addorders/detail.html.erb +++ b/app/views/foodcourt/addorders/detail.html.erb @@ -151,63 +151,17 @@
- <% if type %> -
-
- ORDER DETAILS -
- <% if modify_order %> - <% if @table.nil? %> - -
Table :
- - - - <% else%> - -
Table : <%=@table.name%>
- - - - <% end%> - - - - - -
- -
- <% else%> - -
- -
-
- -
- <% end%> -
- <% else %>
- ORDER DETAILS | Table-<%=@table.name%> - - - - + ORDER DETAILS - - +
- <% end%>
@@ -237,7 +191,11 @@ - + <% if @sale_id.nil?%> + + <% else %> + + <% end %>
@@ -360,7 +318,7 @@
- +
@@ -727,4 +685,5 @@ var webview = <%= @webview %>; showHideNavbar(webview); <% end %> }); + diff --git a/app/views/foodcourt/sale_edit/edit.html.erb b/app/views/foodcourt/sale_edit/edit.html.erb index e1a8dd85..a97364f3 100755 --- a/app/views/foodcourt/sale_edit/edit.html.erb +++ b/app/views/foodcourt/sale_edit/edit.html.erb @@ -155,6 +155,7 @@
+
@@ -421,7 +422,7 @@ var access_code = localStorage.getItem("access_code"); } } - function checkPrice(obj_value,sale_item_id) { - - } + $('#add_order').on('click', function () { + window.location.href = '/foodcourt/food_court?sale_id=<%=@saleobj.sale_id %>'; + }); diff --git a/config/puma.rb b/config/puma.rb index f0013d25..d24425ae 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,11 +1,11 @@ -# application_path="#{File.expand_path("../..", __FILE__)}" -# directory application_path -# #environment ENV.fetch("RAILS_ENV") { "production" } -# environment "production" -# pidfile "#{application_path}/tmp/puma/pid" -# state_path "#{application_path}/tmp/puma/state" -# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" -# port ENV.fetch("PORT") { 62158 } -# workers 2 -# preload_app! -# threads 1,1 +application_path="#{File.expand_path("../..", __FILE__)}" +directory application_path +#environment ENV.fetch("RAILS_ENV") { "production" } +environment "production" +pidfile "#{application_path}/tmp/puma/pid" +state_path "#{application_path}/tmp/puma/state" +stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" +port ENV.fetch("PORT") { 62158 } +workers 2 +preload_app! +threads 1,1 diff --git a/config/routes.rb b/config/routes.rb index 8828b51f..630265ba 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -677,6 +677,7 @@ scope "(:locale)", locale: /en|mm/ do get '/:addorders/:id' => "addorders#detail" post '/:addorders/create' => "addorders#create",:as => "addorder_create", :defaults => { :format => 'json' } + post '/:addorders/add_to_existing_order' => "addorders#add_to_existing_order",:as => "add_to_existing_order", :defaults => { :format => 'json' } get '/addorders/get_item_instance/:id' => "addorders#get_item_instance",:as => "get_item_instance", :defaults => { :format => 'json' }