From 2f024e86915b6f8324c4c6e1b7b7ac47bcf4c03d Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 1 Feb 2018 10:29:24 +0630 Subject: [PATCH 01/37] update qurick raw --- app/assets/javascripts/addorder.js | 124 +++++++-- app/assets/stylesheets/addorder.scss | 9 +- app/controllers/api/bill_controller.rb | 3 +- .../api/call_waiters_controller.rb | 3 +- app/controllers/base_origami_controller.rb | 3 +- app/controllers/home_controller.rb | 3 +- .../origami/addorders_controller.rb | 9 + .../origami/dashboard_controller.rb | 59 +++++ .../origami/quick_service_controller.rb | 42 +++ app/models/order.rb | 2 - app/models/sale.rb | 35 +++ app/models/sale_payment.rb | 2 +- app/views/origami/addorders/detail.html.erb | 92 +++++-- app/views/origami/dashboard/index.html.erb | 245 ++++++++++++++++++ app/views/origami/home/index.html.erb | 6 +- .../origami/quick_service/index.html.erb | 0 app/views/origami/shifts/new.html.erb | 2 +- config/routes.rb | 6 +- 18 files changed, 585 insertions(+), 60 deletions(-) create mode 100644 app/controllers/origami/dashboard_controller.rb create mode 100644 app/controllers/origami/quick_service_controller.rb create mode 100644 app/views/origami/dashboard/index.html.erb create mode 100644 app/views/origami/quick_service/index.html.erb diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 4b158946..60bcbcc3 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -83,9 +83,12 @@ $(function() { //show menu item list when click menu category function show_menu_item_list(url_item){ - var menu_list = $('.menu_items_list'); menu_list.empty(); + if ($('#type').val() == 'true') { + url_item = 'addorders/'+url_item + } + //Start Ajax $.ajax({ type: "GET", @@ -702,26 +705,41 @@ $(function() { } } - // Pay Discount for Payment + // Create Order $("#create_order").on('click', function(e){ + $(this).attr('disabled', 'disabled'); e.preventDefault(); $("#oqs_loading_wrapper").show(); - var table_id = $('#table_id').text(); - var customer_id = $('#customer_id').text(); - var booking_id = $('#booking_id').text(); + + type = $('#type').val(); + if (type == 'true') { + type = 'cashier' + + var table_type = $('#table_id').find("option:selected").data('type'); + var table_id = $('#table_id').val(); + var customer_id = $('#customer_id').val(); + var booking_id = $('#booking_id').text(); + var ajax_url = 'addorders/create'; + }else{ + type = 'cashier' + 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 ajax_url = '../addorders/create'; + } if (!booking_id.length > 0) { - var params = {'order_source': "cashier", 'order_type': "dine_in", + 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 table_type = $('#table_type').text(); + var order_items = JSON.stringify(get_order_item_rows()); - var ajax_url = '../addorders/create'; - var params = {'order_source': "cashier", 'order_type': "dine_in", + var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, 'order_items': order_items }; @@ -731,27 +749,61 @@ $(function() { data: params, dataType: "json", success:function(result){ - // $("#oqs_loading_wrapper").hide(); - // swal({ - // title: "Information !", - // text: 'Order has been successfully created', - // confirmButtonColor: "green", - // confirmButtonText: "Yes!", - // closeOnConfirm: false, - // }, function (isConfirm) { - // if (isConfirm) { + if(table_type == "Table"){ window.location.href = "/origami/table/" + table_id } else { window.location.href = "/origami/room/" + table_id - } - // } - // }); + } } }); }); + + // Pay Discount for Payment + $("#create_pay_order").on('click', function(e){ + + $(this).attr('disabled', 'disabled'); + e.preventDefault(); + $("#oqs_loading_wrapper").show(); + + type = $('#type').val(); + type = 'quick_service' + var table_type = $('#table_id').find("option:selected").data('type'); + var table_id = $('#table_id').val(); + var customer_id = $('#customer_id').val(); + var booking_id = $('#booking_id').text(); + var ajax_url = 'addorders/create'; + + 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", + 'customer_id': customer_id, 'guest_info': "", + 'table_id': table_id, + 'order_items': order_items }; + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + dataType: "json", + success:function(result){ + console.log(result) + if (result.status) { + window.location.href = "/origami/sale/"+result.data["sale_id"]+"/payment" + } + // window.location.href = "/origami/quick_service" + } + }); + }); + //click item row for update qty $('.summary-items').on('click', '.item_box', function(){ $(this).attr('data-active',true); @@ -863,11 +915,21 @@ $(function() { $("#back").on("click", function(){ var table_id = $('#table_id').text(); var table_type = $('#table_type').text(); - if(table_type == "Table"){ - window.location.href = "/origami/table/" + table_id - }else { - window.location.href = "/origami/room/" + table_id - } + type = $('#type').val(); + if (type == 'true') { + var table_type = $('#table_id').find("option:selected").data('type'); + var table_id = $('#table_id').val(); + window.location.href = "/origami/dashboard" + }else{ + var table_type = $('#table_type').text(); + var table_id = $('#table_id').text(); + + if(table_type == "Table"){ + window.location.href = "/origami/table/" + table_id + }else { + window.location.href = "/origami/room/" + table_id + } + } }); // Get Selected Class @@ -970,6 +1032,9 @@ $(function() { $(".sub_click").on("click", function(){ var menu_id = $(this).attr("data-id"); var url = "get_menu_sub_category/"+menu_id; + if ($('#type').val() == 'true') { + url = 'addorders/'+url + } sub_category = $(this).find('.sub_category_list'); show_sub_category_list(url,sub_category); }); @@ -992,7 +1057,12 @@ $(function() { data = data.sub_category; if (data.length>0) { - $(sub_category).removeClass('hidden'); + if ((sub_category.hasClass('hidden'))) { + $(sub_category).removeClass('hidden'); + }else{ + $(sub_category).addClass('hidden'); + } + for(var i in data) { row = '
  • - + monetization_on <%= t :origami %> diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 2c23b37b..8c6a5974 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -5,7 +5,9 @@ <% type = request.path_info.include?('quick_service')%> +<% modify_order = request.path_info.include?('modify_order')%> +
    <% else %>
    @@ -125,24 +132,13 @@ <% if type %> - - + + + <% end %> + <% if !modify_order %> - + <% end %>
    @@ -333,7 +329,7 @@ - <% if type %> + <% if type && !modify_order%> -
    +
    arrow_forward From 08e372cfb516d3df27898b243c100ae4716f18a7 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 14 Feb 2018 13:46:22 +0630 Subject: [PATCH 18/37] udpdate qs --- .../origami/addorders_controller.rb | 20 +++++--- app/models/order.rb | 17 +++++-- app/models/sale.rb | 51 ------------------- 3 files changed, 26 insertions(+), 62 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 500e1ff8..9da6b7a6 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -102,9 +102,13 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController if !params["booking_id"].nil? # check booking id is already completed. booking = Booking.find(params[:booking_id]) - + if !params[:table_id].nil? + 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 @@ -115,17 +119,21 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController @order.booking_id = params[:booking_id] end else + if !params[:table_id].nil? 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].nil? + 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 diff --git a/app/models/order.rb b/app/models/order.rb index 0ca06316..5b022b57 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -25,23 +25,30 @@ class Order < ApplicationRecord booking = nil if self.new_booking + if !self.table_id.nil? + table_id = self.table_id + else + table_id = nil + end #add extra time if self.is_extra_time && self.extra_time - booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", + booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking", :checkin_at => Time.now.utc,:checkout_at => Time.now.utc + self.extra_time.to_i, :checkin_by => self.employee_name, :booking_status => "assign" }) else - booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", + booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking", :checkin_at => Time.now.utc, :checkin_by => self.employee_name, :booking_status => "assign" }) end #end extra time + if !self.table_id.nil? + table = DiningFacility.find(self.table_id) + table.status = "occupied" + table.save + end - table = DiningFacility.find(self.table_id) - table.status = "occupied" - table.save else booking = Booking.find(self.booking_id) #add extra time diff --git a/app/models/sale.rb b/app/models/sale.rb index 6c6f5795..f42b62a0 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1225,57 +1225,6 @@ end return query 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") - .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.add_to_existing_pending_invoice(dining,sale_id) - puts sale_id - table = DiningFacility.find(dining) - existing_booking = Booking.find_by_sale_id(sale_id) - puts existing_booking.to_json - table.bookings.each do |booking| - # if !booking.checkout_at.nil? - # existing_booking.update_attributes(checkout_at: checkout_at) - # end - - if booking.sale_id.nil? - puts booking.to_json - 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) - puts "saleobj" - puts saleobj.to_json - 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 - private def generate_custom_id From b2cec950641b986d640bbaae79965cbb7dc03110 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 14 Feb 2018 14:26:36 +0630 Subject: [PATCH 19/37] test no table --- app/controllers/origami/addorders_controller.rb | 6 +++--- app/controllers/origami/payments_controller.rb | 2 ++ app/models/order.rb | 17 +++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 9da6b7a6..ab481fc3 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -102,7 +102,7 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController if !params["booking_id"].nil? # check booking id is already completed. booking = Booking.find(params[:booking_id]) - if !params[:table_id].nil? + if params[:table_id].to_i > 0 table_status = booking.dining_facility_id.to_i == params[:table_id].to_i else table_status = true @@ -119,7 +119,7 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController @order.booking_id = params[:booking_id] end else - if !params[:table_id].nil? + 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") @@ -128,7 +128,7 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController end end #booking exists else - if !params[:table_id].nil? + if params[:table_id].to_i > 0 sale_status = check_order_with_table(params[:table_id]) if sale_status # return false , @message = "bill requested" diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 8beede44..7b97ea45 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -220,6 +220,8 @@ class Origami::PaymentsController < BaseOrigamiController #end customer amount @sale_data.bookings.each do |sbk| + puts "sssssssssss" + puts sbk.dining_facility_id df = DiningFacility.find(sbk.dining_facility_id) @table_no = df.type + ' ' + df.name @checkin_time = sbk.checkin_at diff --git a/app/models/order.rb b/app/models/order.rb index 5b022b57..15ce56c3 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -23,9 +23,8 @@ class Order < ApplicationRecord def generate booking = nil - if self.new_booking - if !self.table_id.nil? + if self.table_id.to_i > 0 table_id = self.table_id else table_id = nil @@ -43,7 +42,7 @@ class Order < ApplicationRecord end #end extra time - if !self.table_id.nil? + if self.table_id.to_i > 0 table = DiningFacility.find(self.table_id) table.status = "occupied" table.save @@ -324,11 +323,13 @@ class Order < ApplicationRecord #send order items and send to order queue def send_order_broadcast(booking) - table = DiningFacility.find(booking.dining_facility_id) - type = 'order' - #Send to background job for processing - # OrderBroadcastJob.perform_later(table,type) - ActionCable.server.broadcast "order_channel",table: table,type:type + if self.table_id.to_i > 0 + table = DiningFacility.find(booking.dining_facility_id) + type = 'order' + #Send to background job for processing + # OrderBroadcastJob.perform_later(table,type) + ActionCable.server.broadcast "order_channel",table: table,type:type + end end #Origami: Cashier : to view order Table From 80ab7e7c1224f8c3e7a10a6ea4285b4dc421219c Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 14 Feb 2018 14:33:30 +0630 Subject: [PATCH 20/37] test no table --- app/controllers/origami/payments_controller.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 7b97ea45..2d3618b5 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -220,13 +220,17 @@ class Origami::PaymentsController < BaseOrigamiController #end customer amount @sale_data.bookings.each do |sbk| - puts "sssssssssss" - puts sbk.dining_facility_id - df = DiningFacility.find(sbk.dining_facility_id) - @table_no = df.type + ' ' + df.name - @checkin_time = sbk.checkin_at - @dining = df - break + if sbk.dining_facility_id.to_i >0 + df = DiningFacility.find(sbk.dining_facility_id) + @table_no = df.type + ' ' + df.name + @checkin_time = sbk.checkin_at + @dining = df + break + else + @table_no = nil + @checkin_time = nil + @dining = nil + end end @sale_data.sale_payments.each do |spay| From a5c72b6540edf8c597bef1ad80448d776b9cfefa Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 14 Feb 2018 14:40:28 +0630 Subject: [PATCH 21/37] test no table --- app/views/origami/payments/show.html.erb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index c86c0284..c97e9abe 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -19,7 +19,8 @@
    Customer : <%= @sale_data.customer.name%>
    -
    Checkin Time : <%= @checkin_time.utc.getlocal.strftime("%I:%M %p") %>
    +
    Checkin Time : <%if !@checkin_time.nil?%><%= @checkin_time.utc.getlocal.strftime("%I:%M %p") %> + <%end%>
    @@ -368,7 +369,9 @@ var cashier_type = "<%= @cashier_type %>"; if (sale) { var sale_id = sale } else { - var sale_id = "<%= @dining.id %>"; + if (cashier_type != "quick_service") { + var sale_id = "<%= @dining.id %>"; + } } //var table_id = $('.tables').attr("data-id"); window.location.href = '/origami/' + sale_id +"/"+ cashier_type + "/surveys" @@ -425,7 +428,10 @@ var cashier_type = "<%= @cashier_type %>"; }); $('#edit').on('click', function () { + if (cashier_type != "quick_service") { + console.log(cashier_type) var dining_id = "<%= @dining.id %>" + } var sale_id = $('#sale_id').text(); if ($(this).attr('active')=== "true") { window.location.href = '/origami/table/' + dining_id + "/sale/" + sale_id + "/"+cashier_type+"/edit"; From a2e7ebd27a7cb906aa17065f79dc065fc23a0e69 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 14 Feb 2018 15:00:16 +0630 Subject: [PATCH 22/37] update payment show --- app/views/origami/payments/show.html.erb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index c97e9abe..b6d08ed0 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -13,6 +13,7 @@
    Table No : <%=@table_no%>
    +
    Sale ID : <% if @sale_data %><%=@sale_data.sale_id %><% end %>
    @@ -369,9 +370,7 @@ var cashier_type = "<%= @cashier_type %>"; if (sale) { var sale_id = sale } else { - if (cashier_type != "quick_service") { - var sale_id = "<%= @dining.id %>"; - } + var sale_id = $('#dining').text(); } //var table_id = $('.tables').attr("data-id"); window.location.href = '/origami/' + sale_id +"/"+ cashier_type + "/surveys" @@ -428,10 +427,7 @@ var cashier_type = "<%= @cashier_type %>"; }); $('#edit').on('click', function () { - if (cashier_type != "quick_service") { - console.log(cashier_type) - var dining_id = "<%= @dining.id %>" - } + 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"; From 47ffc5fa51046173ef9c6a6b5b399ee67ea1b993 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 14 Feb 2018 18:21:10 +0630 Subject: [PATCH 23/37] update no table quick srevice --- app/controllers/application_controller.rb | 10 +-- .../origami/customers_controller.rb | 7 +- .../origami/other_charges_controller.rb | 30 +++++-- .../origami/payments_controller.rb | 84 ++++++++++++------- app/controllers/origami/sales_controller.rb | 9 +- app/controllers/origami/surveys_controller.rb | 15 +++- app/models/sale_payment.rb | 42 +++++----- app/pdf/receipt_bill_pdf.rb | 13 ++- app/views/origami/customers/index.html.erb | 22 +++-- .../origami/other_charges/index.html.erb | 6 +- app/views/origami/surveys/_form.html.erb | 16 +++- app/views/origami/surveys/new.html.erb | 9 -- 12 files changed, 173 insertions(+), 90 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4dafef41..3a35a15b 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,11 +38,11 @@ class ApplicationController < ActionController::Base end else # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index b0056fb2..db89b1d0 100755 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -53,7 +53,12 @@ class Origami::CustomersController < BaseOrigamiController if(@sale_id[0,3] == "SAL") @booking = Booking.find_by_sale_id(@sale_id) - @dining_facility = DiningFacility.find(@booking.dining_facility_id) + if @booking.dining_facility_id.to_i > 0 + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + else + @dining_facility = nil + end + else @booking_order = BookingOrder.find_by_order_id(@sale_id) @booking = Booking.find(@booking_order.booking_id) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 7ed087d4..d15edb5e 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -6,7 +6,12 @@ class Origami::OtherChargesController < BaseOrigamiController @cashier_type = params[:type] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) - @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + if @sale_data.bookings[0].dining_facility_id.to_i > 0 + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + else + @table = nil + end + end end @@ -17,8 +22,14 @@ class Origami::OtherChargesController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) - table_id = sale.bookings[0].dining_facility_id - table = DiningFacility.find(table_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table_id = nil + table = nil + end + # sale.total_amount = sub_total.to_f # sale.grand_total = sub_total.to_f + sale.total_tax; @@ -45,7 +56,12 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.save action_by = current_user.id - remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->#{table.name}" + if table.nil? + remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->" + else + remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->#{table.name}" + end + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"ADDOTHERCHARGES" ) end @@ -54,9 +70,11 @@ class Origami::OtherChargesController < BaseOrigamiController # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) end - - dining = {:table_id => table_id, :table_type => table.type } + if !table.nil? + dining = {:table_id => table_id, :table_type => table.type } render :json => dining.to_json + end + end #Shop Name in Navbor diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 2d3618b5..fe384a89 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -11,15 +11,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking - table = DiningFacility.find(bookings[0].dining_facility_id) - else - table = DiningFacility.find(bookings[0].dining_facility_id) - end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end if ENV["SERVER_MODE"] != "cloud" #no print in cloud server # Print for First Bill to Customer @@ -94,15 +100,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking - table = DiningFacility.find(bookings[0].dining_facility_id) - else - table = DiningFacility.find(bookings[0].dining_facility_id) - end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end # For Print if ENV["SERVER_MODE"] != "cloud" #no print in cloud server @@ -264,15 +276,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking - table = DiningFacility.find(bookings[0].dining_facility_id) - else - table = DiningFacility.find(bookings[0].dining_facility_id) - end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end if ENV["SERVER_MODE"] != "cloud" #no print in cloud server unique_code = "ReceiptBillPdf" @@ -333,15 +351,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end + if bookings[0].dining_facility_id.to_i > 0 table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) else - table = DiningFacility.find(bookings[0].dining_facility_id) + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) end - - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + # Re-call Sale Data saleObj = Sale.find(sale_id) diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index c522f9e7..513bdb2c 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -7,8 +7,13 @@ class Origami::SalesController < 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) + 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 def add_to_existing_invoice diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index d7f97a6e..4ecdf95f 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -9,8 +9,14 @@ class Origami::SurveysController < BaseOrigamiController @receipt_no = @sale.receipt_no @grand_total = @sale.grand_total @booking = Booking.find_by_sale_id(@id) - @dining_facility = DiningFacility.find(@booking.dining_facility_id) - @table_type = @dining_facility.type + if @booking.dining_facility_id.to_i>0 + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + @table_type = @dining_facility.type + else + @dining_facility = nil + @table_type = nil + end + else @dining_facility = DiningFacility.find(@id) @table_type = @dining_facility.type @@ -20,8 +26,9 @@ class Origami::SurveysController < BaseOrigamiController end def create - @dining_facility = DiningFacility.find(params[:table_id]) - + if params[:table_id].to_i>0 + @dining_facility = DiningFacility.find(params[:table_id]) + end @type = params[:cashier_type] @sale_id = params[:sale_id] if @type == "quick_service" diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 661eb57b..c2fce169 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -385,32 +385,34 @@ class SalePayment < ApplicationRecord sale_count = 0 booking = Booking.find_by_sale_id(sale_obj.id) if booking - table = DiningFacility.find(booking.dining_facility_id) - bookings = table.bookings - bookings.each do |tablebooking| - if tablebooking.booking_status != 'moved' - if tablebooking.sale_id - if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + if booking.dining_facility_id.to_i > 0 + table = DiningFacility.find(booking.dining_facility_id) + bookings = table.bookings + bookings.each do |tablebooking| + if tablebooking.booking_status != 'moved' + if tablebooking.sale_id + if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + status = false + sale_count += 1 + else + status = true + end + else status = false sale_count += 1 - else - status = true end - else - status = false - sale_count += 1 end end - end - if status && sale_count == 0 - table.status = "available" - table.save - end + if status && sale_count == 0 + table.status = "available" + table.save + end - type = 'payment' - #Send to background job for processing - # OrderBroadcastJob.perform_later(table,type) - ActionCable.server.broadcast "order_channel",table: table,type:type + type = 'payment' + #Send to background job for processing + # OrderBroadcastJob.perform_later(table,type) + ActionCable.server.broadcast "order_channel",table: table,type:type + end end end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index d2ad0260..dece55cb 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -104,9 +104,12 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do + if sale_data.bookings[0].dining_facility_id.to_i > 0 + bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end end + move_down 5 y_position = cursor @@ -119,8 +122,14 @@ class ReceiptBillPdf < Prawn::Document move_down 5 y_position = cursor + if sale_data.bookings[0].dining_facility_id.to_i > 0 + time =sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")" + else + time = time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p') + end + bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do - text "Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left + text "Date : #{ time }",:size => self.item_font_size,:align => :left end diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 88f4646d..eebaabbf 100755 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -32,7 +32,6 @@
    -
    @@ -115,8 +114,13 @@ + <%if !@dining_facility.nil?%> + <%else%> + + + <%end%> <%= f.error_notification %> <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
    @@ -417,6 +421,7 @@ if(customer_name != ""){ customer = '(' + customer_name + ')'; } + swal({ title: "Confirmation !", text: 'Are You Sure to assign this customer' + customer + '!', @@ -437,7 +442,6 @@ var id = $("#table_id").val(); var type = $("#type").val(); if (cashier_type == "quick_service") { - window.location.href = '/origami/table/'+id window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/'; }else{ if (type=="Table") { @@ -458,11 +462,17 @@ $('#back').on('click',function(){ var id = $("#table_id").val() var type = $("#type").val() - if (type=="Table") { - window.location.href = '/origami/table/'+id + var sale_id = $("#sale_id").val() + if (cashier_type == "quick_service") { + window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/'; }else{ - window.location.href = '/origami/room/'+id - } + if (type=="Table") { + window.location.href = '/origami/table/'+id + }else{ + window.location.href = '/origami/room/'+id + } + } + }) diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb index 9e3b7c3f..a194e03a 100755 --- a/app/views/origami/other_charges/index.html.erb +++ b/app/views/origami/other_charges/index.html.erb @@ -197,7 +197,11 @@
    - + <%if !@table.nil?%> + + <%else%> + + <%end%>
    diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index 9f2b5d06..47cb08d0 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -41,10 +41,18 @@
    - + <%if !@dining_facility.nil?%> + + + <%= f.input :dining_name, :as => :hidden, :input_html => { :value => @dining_facility.name } %> + <%else%> + + + <%= f.input :dining_name, :as => :hidden, :input_html => { :value => 0 } %> + <%end%> - <%= f.input :dining_name, :as => :hidden, :input_html => { :value => @dining_facility.name } %> + <%= f.input :created_by, :as => :hidden, :input_html => { :value => current_login_employee.name } %> <%= f.input :receipt_no, :as => :hidden, :input_html => { :value => @receipt_no} %> <%= f.input :total_amount, :as => :hidden, :input_html => { :value => @grand_total } %> @@ -228,8 +236,8 @@ var cashier_type = "<%= @cashier_type %>"; }); // click back button for redirect $('#back').on('click',function(){ - table_type = '<%=@table_type%>'; - table_id = '<%=@dining_facility.id%>'; + table_type = $('#table_type').val() + table_id = $('#table_id').val() if (cashier_type == "quick_service") { window.location.href = '/origami/sale/<%= @id %>/<%= @cashier_type %>/payment/'; diff --git a/app/views/origami/surveys/new.html.erb b/app/views/origami/surveys/new.html.erb index bee0f843..ee4d9a57 100755 --- a/app/views/origami/surveys/new.html.erb +++ b/app/views/origami/surveys/new.html.erb @@ -1,12 +1,3 @@ - <%= render 'form', survey: @survey %> From 0d515d9c93f53874e087b99f497a208ffbc96774 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Feb 2018 10:27:00 +0630 Subject: [PATCH 24/37] paending order sale model --- app/models/sale.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/sale.rb b/app/models/sale.rb index f42b62a0..a5ffa8d9 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1225,6 +1225,13 @@ end return query 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") + .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 + private def generate_custom_id From a2bd8795ccec9c0b23132c08bfdc60f74e0b6ff4 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Feb 2018 11:23:40 +0630 Subject: [PATCH 25/37] update discount for qs --- .../origami/discounts_controller.rb | 26 +++++++++++++++---- app/views/origami/discounts/index.html.erb | 6 +++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index bea6e381..1905fd9a 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -7,7 +7,11 @@ class Origami::DiscountsController < BaseOrigamiController @cashier_type = params[:type] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) - @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + if @sale_data.bookings[0].dining_facility_id.to_i > 0 + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + else + @table = nil + end end @member_discount = MembershipSetting.find_by_discount(1) @@ -23,8 +27,15 @@ class Origami::DiscountsController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) - table_id = sale.bookings[0].dining_facility_id - table = DiningFacility.find(table_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table = nil + table_id = nil + end + + # sale.total_discount = overall_discount.to_f # sale.total_amount = sub_total.to_f # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; @@ -34,7 +45,6 @@ class Origami::DiscountsController < BaseOrigamiController #save sale item for discount discount_items.each do |di| origin_sale_item = SaleItem.find(di["id"]) - puts origin_sale_item.to_json sale_item = SaleItem.new sale_item.sale_id = sale_id @@ -55,6 +65,7 @@ class Origami::DiscountsController < BaseOrigamiController action_by = current_user.id remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} " + sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_id, action_by,remark,"ITEMDISCOUNT" ) end @@ -63,7 +74,12 @@ class Origami::DiscountsController < BaseOrigamiController # Re-calc All Amount in Sale if overall_discount.to_f > 0 action_by = current_user.id - remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + if table.nil? + remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + else + remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + end + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" ) end sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 33141666..ba03f8d7 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -13,8 +13,14 @@
    + <%if !@table.nil?%> + <%else%> + + + <%end%> +

    Receipt No: <%=@sale_data.receipt_no rescue ' '%>

    From a8fdf2ec30598815e073d0281afe2f121ce6f67f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Feb 2018 11:49:01 +0630 Subject: [PATCH 26/37] update discount for qs --- .../origami/discounts_controller.rb | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 1905fd9a..4b8c18f0 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -75,7 +75,7 @@ class Origami::DiscountsController < BaseOrigamiController if overall_discount.to_f > 0 action_by = current_user.id if table.nil? - remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- no Table " else remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " end @@ -83,9 +83,17 @@ class Origami::DiscountsController < BaseOrigamiController sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" ) end sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) - result = {:status=> "Success", :table_id => table_id, :table_type => table.type } + if !table.nil? + result = {:status=> "Success", :table_id => table_id, :table_type => table.type } + else + result = {:status=> "Success" } + end else - result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } + if !table.nil? + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } + else + result = {:status=> "Please, Check Again!" } + end end @@ -97,9 +105,15 @@ class Origami::DiscountsController < BaseOrigamiController sale_id = params[:sale_id] discount_items = JSON.parse(params[:discount_items]) if Sale.exists?(sale_id) - sale = Sale.find(sale_id) - table_id = sale.bookings[0].dining_facility_id - table = DiningFacility.find(table_id) + sale = Sale.find(sale_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table_id = nil + table = nil + end + if discount_items.length > 0 #destroy sale item for discount @@ -108,7 +122,11 @@ class Origami::DiscountsController < BaseOrigamiController sale.total_amount = (sale.total_amount + sale_item.price.abs) action_by = current_user.id - remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} " + if table.nil? + remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- No Table " + else + remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} " + end sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEITEMDISCOUNT" ) sale_item.destroy @@ -119,9 +137,19 @@ class Origami::DiscountsController < BaseOrigamiController # sale.save # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) - result = {:status=> "Success", :table_id => table_id, :table_type => table.type } + if table.nil? + result = {:status=> "Success"} + else + result = {:status=> "Success", :table_id => table_id, :table_type => table.type } + end + else - result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } + if table.nil? + result = {:status=> "Please, Check Again!"} + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } + end + end render :json => result.to_json From cf644892c92094b61ba5e611c3090014562f6559 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Feb 2018 15:26:34 +0630 Subject: [PATCH 27/37] 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" From 2f7f412150a7da5c0f1410a47d10825efde1dde0 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 16 Feb 2018 09:46:55 +0630 Subject: [PATCH 28/37] update addorder move + and box --- app/assets/javascripts/addorder.js | 35 ++++++---- app/models/sale.rb | 3 +- app/views/origami/addorders/detail.html.erb | 76 +++++++++++++-------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index bebc6f99..bc0b2721 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -164,29 +164,33 @@ $(function() { }else{ image_path = "/image/logo.png"; } + if (menu_item_box == "set_item_box") { + add_icon = "set_item_box" + }else{ + add_icon = "add_icon" + } row = '
    ' +'
    ' +'
    '+ menu_items[field].name +'
    ' - +"
    " - +"" - +add+ '' - +'
    ' - +'
    ' - - +"
    " + +JSON.stringify(menu_items[field].item_sets)+"' data-toggle='modal' data-target='."+data_target+"' >" + +"" + +add+ '' + +'
    ' + +'
    ' + +"
    " +"
    " +"" @@ -434,7 +438,8 @@ $(function() { change_qty_plus_minus("count","plus","minus"); - data = $(this).parent().children().children('.add_icon'); + // data = $(this).parent().children().children('.add_icon'); + data = $(this).parent().siblings('.add_icon'); $('#total_price').text(data.attr('data-price')); attributes = $(this).data('id'); diff --git a/app/models/sale.rb b/app/models/sale.rb index 680f37b6..8979f452 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1226,9 +1226,10 @@ end 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 = DiningFacility.find(dining) table.bookings.each do |booking| # if !booking.checkout_at.nil? # existing_booking.update_attributes(checkout_at: checkout_at) diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 7c8d0324..36f45b74 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -65,15 +65,28 @@
    - - <% if type %> - - <% end%> + + <% if type && modify_order%> + + + <%elsif !modify_order && type%> + + + Select + + <%else%> + + <%end%>
    <% if type %> @@ -81,19 +94,23 @@
    ORDER DETAILS
    + <% if modify_order %> -
    Table : <%=@table.name%>
    - - + <% if @table.nil? %> +
    Table :
    + + + <% else%> +
    Table : <%=@table.name%>
    + + + <% end%> + <% else%> -
    Table
    -
    - Select - -
    + <% end%>
    <% else %> @@ -123,23 +140,28 @@
    -