From cf644892c92094b61ba5e611c3090014562f6559 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Feb 2018 15:26:34 +0630 Subject: [PATCH] update pending and quick service --- .../origami/discounts_controller.rb | 33 +++++++-- .../origami/pending_order_controller.rb | 11 ++- .../origami/quick_service_controller.rb | 41 ++++++++--- .../origami/sale_edit_controller.rb | 7 +- app/models/sale.rb | 69 +++++++++++++++++++ app/views/origami/addorders/detail.html.erb | 7 +- app/views/origami/payments/show.html.erb | 10 ++- app/views/origami/pending_order/show.html.erb | 11 ++- config/routes.rb | 2 + 9 files changed, 164 insertions(+), 27 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 4b8c18f0..46dd65d0 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -161,9 +161,16 @@ class Origami::DiscountsController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) - table_id = sale.bookings[0].dining_facility_id - dining = DiningFacility.find(table_id) - table_type = dining.type + + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + table_type = table.type + else + table_id = nil + table = nil + table_type = nil + end discount_items = [] #destroy all discount sale item @@ -182,14 +189,28 @@ class Origami::DiscountsController < BaseOrigamiController sale.sale_items.destroy(discount_items) action_by = current_user.id - remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- #{dining.name} " + if table.nil? + remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- No Table" + else + remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + end sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEALLDISCOUNT" ) # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, 0) - result = {:status=> "Success", :table_id => table_id, :dining => dining.name, :table_type => table_type } + if table.nil? + result = {:status=> "Success"} + else + result = {:status=> "Success", :table_id => table_id, :dining => table.name, :table_type => table_type } + end + else - result = {:status=> "Please, Check Again!", :table_id => table_id, :dining => dining.name, :table_type => table_type } + if table.nil? + result = {:status=> "Please, Check Again!"} + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :dining => table.name, :table_type => table_type } + end + end render :json => result.to_json diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 766c7e47..dd2f4cc7 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -9,8 +9,15 @@ class Origami::PendingOrderController < BaseOrigamiController @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 - @table_id = Booking.find(@booking).dining_facility_id - @dining = DiningFacility.find(@table_id) + puts "sssssssssss" + puts @booking + if Booking.find(@booking).dining_facility_id.to_i > 0 + @table_id = Booking.find(@booking).dining_facility_id + @dining = DiningFacility.find(@table_id) + else + @table_id = nil + @dining = nil + end end helper_method :shop_detail def shop_detail diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 0c90530f..8dfc901c 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -16,10 +16,18 @@ class Origami::QuickServiceController < ApplicationController def modify_order @menu = MenuCategory.all.active - @table_id = params[:id] + if(params[:id][0,3] == "BKI") + @table_id = nil + @table = nil + @booking = Booking.find(params[:id]) + else + @table_id = params[:id] + @table = DiningFacility.find(@table_id) + @booking = @table.get_booking + end + @sale_id = params[:sale_id] - @table = DiningFacility.find(@table_id) - @booking = @table.get_booking + if @booking @booking_id = @booking.booking_id @order_items = Array.new @@ -84,9 +92,13 @@ class Origami::QuickServiceController < ApplicationController if !params["booking_id"].nil? # check booking id is already completed. booking = Booking.find(params[:booking_id]) - + if params[:table_id].to_i > 0 + table_status = booking.dining_facility_id.to_i == params[:table_id].to_i + else + table_status = true + end if booking - if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved' + if table_status && booking.booking_status != 'moved' if !booking.sale_id.nil? sale_status = check_order_with_booking(booking) if sale_status @@ -97,17 +109,21 @@ class Origami::QuickServiceController < ApplicationController @order.booking_id = params[:booking_id] end else + if params[:table_id].to_i > 0 sale_status = check_order_with_table(params[:table_id]) if sale_status return return_json_status_with_code(400, "bill requested") end + end end end #booking exists else - sale_status = check_order_with_table(params[:table_id]) - if sale_status - # return false , @message = "bill requested" - return return_json_status_with_code(400, "bill requested") + if params[:table_id].to_i > 0 + sale_status = check_order_with_table(params[:table_id]) + if sale_status + # return false , @message = "bill requested" + return return_json_status_with_code(400, "bill requested") + end end end @@ -116,7 +132,12 @@ class Origami::QuickServiceController < ApplicationController if @status && @booking && @order.source == 'quick_service' if params[:sale_id] @sale = Sale.find(params[:sale_id]) - update = Sale.add_to_existing_pending_invoice(@order.table_id,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 result = {:status=> true, :data => @sale } diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index fa40e41f..f78c0f53 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -3,7 +3,12 @@ class Origami::SaleEditController < BaseOrigamiController # Index for sale item void OR edit def edit sale_id = params[:sale_id] - @table_id = params[:table_id] + if params[:table_id] + @table_id = params[:table_id] + else + @table_id = nil + end + @cashier_type = params[:type] @saleobj = Sale.find(sale_id) end diff --git a/app/models/sale.rb b/app/models/sale.rb index a5ffa8d9..680f37b6 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1225,6 +1225,75 @@ end return query end + def self.add_to_existing_pending_invoice(dining,sale_id,booking) + table = DiningFacility.find(dining) + existing_booking = Booking.find_by_sale_id(sale_id) + if dining.to_i > 0 + table.bookings.each do |booking| + # if !booking.checkout_at.nil? + # existing_booking.update_attributes(checkout_at: checkout_at) + # end + if booking.sale_id.nil? + booking.booking_orders.each do |booking_order| + + booking.booking_status = 'moved' + order = Order.find(booking_order.order_id) + order.status = 'billed' + order.order_items.each do |item| + item.order_item_status = 'billed' + end + # create sale item + saleobj = Sale.find(sale_id) + order.order_items.each do |orer_item| + saleobj.add_item (orer_item) + end + + # Re-compute for add + saleobj.compute + saleobj.save + order.save + booking.save + end + + booking_order = BookingOrder.where('booking_id=?',booking) + booking_order.each do |bo| + bo.booking_id = existing_booking.booking_id + bo.save + end + end + end + else + if booking.sale_id.nil? + booking.booking_orders.each do |booking_order| + + booking.booking_status = 'moved' + order = Order.find(booking_order.order_id) + order.status = 'billed' + order.order_items.each do |item| + item.order_item_status = 'billed' + end + # create sale item + saleobj = Sale.find(sale_id) + order.order_items.each do |orer_item| + saleobj.add_item (orer_item) + end + + # Re-compute for add + saleobj.compute + saleobj.save + order.save + booking.save + end + + booking_order = BookingOrder.where('booking_id=?',booking) + booking_order.each do |bo| + bo.booking_id = existing_booking.booking_id + bo.save + end + end + end + end + def self.pending_order query = Sale.all query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id") diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 8c6a5974..7c8d0324 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -11,6 +11,9 @@
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index b6d08ed0..8c275785 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -326,9 +326,10 @@ var cashier_type = "<%= @cashier_type %>"; payment_type = ''; if ($("#server_mode").val() != "cloud") { // first bill not used in cloud + console.log("ssssssssssss") payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment") if (member_id && member_discount) { - +console.log("fffffffffffff") if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){ $("#credit_payment").hide(); } else{ @@ -430,7 +431,12 @@ var cashier_type = "<%= @cashier_type %>"; var dining_id = $('#dining').text(); var sale_id = $('#sale_id').text(); if ($(this).attr('active')=== "true") { - window.location.href = '/origami/table/' + dining_id + "/sale/" + sale_id + "/"+cashier_type+"/edit"; + if (dining_id) { + window.location.href = '/origami/table/' + dining_id + "/sale/" + sale_id + "/"+cashier_type+"/edit"; + }else{ + window.location.href = "/origami/table/sale/" + sale_id + "/"+cashier_type+"/edit"; + } + }else{ swal("Opps","You are not authorized for void","warning") } diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index 3b0aad83..c7233400 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -42,7 +42,7 @@
- Customer : <%= @sale.customer.name rescue "-" %> +   Customer : <%= @sale.customer.name rescue "-" %>
@@ -112,7 +112,6 @@
-
@@ -136,7 +135,13 @@ $(document).ready(function(){ }); $('#addorder').on('click', function () { var table_id = "<%=@table_id%>"; - window.location.href = '/origami/quick_service/modify_order/' + table_id+"/"+$('#sale_id').val(); + var booking_id = "<%=@booking%>"; + if (table_id) { + window.location.href = '/origami/quick_service/modify_order/' + table_id+"/"+$('#sale_id').val(); + }else{ + window.location.href = '/origami/quick_service/modify_order/'+ booking_id+"/" +$('#sale_id').val(); + } + }); }); diff --git a/config/routes.rb b/config/routes.rb index 141220a6..2b563b69 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -92,6 +92,7 @@ scope "(:locale)", locale: /en|mm/ do get "quick_service/pending_order/:sale_id" => "pending_order#show" get "quick_service/modify_order/:id/:sale_id" => "quick_service#modify_order" + get "quick_service/modify_order/:sale_id" => "quick_service#modify_order" post 'quick_service/update_modify_order' => "quick_service#update_modify_order", :defaults => { :format => 'json' } @@ -104,6 +105,7 @@ scope "(:locale)", locale: /en|mm/ do end post 'moving' => "movetable#moving" get "/table/:table_id/sale/:sale_id/:type/edit" => "sale_edit#edit" + get "/table/sale/:sale_id/:type/edit" => "sale_edit#edit" post 'item_void' => "sale_edit#item_void" post 'item_foc' => "sale_edit#item_foc" post 'item_edit' => "sale_edit#item_edit"