diff --git a/app/assets/javascripts/channels/checkin.js b/app/assets/javascripts/channels/checkin.js new file mode 100644 index 00000000..859cb733 --- /dev/null +++ b/app/assets/javascripts/channels/checkin.js @@ -0,0 +1,25 @@ +App.order = App.cable.subscriptions.create('CheckinChannel', { +// App.messages = App.cable.subscriptions.create('MessagesChannel', { + + connected: function() {}, + + disconnected: function() {}, + + received: function(data) { + if((data.table != undefined) && (data.table.length > 0)){ + $.each(data.table,function(key,value){ + if($('.table_'+value.table_id).hasClass('blue')){ + $('.table_'+value.table_id).removeClass('blue'); + $('.table_'+value.table_id).addClass('orange'); + } + else if($('.table_'+value.table_id).hasClass('red')){ + $('.table_'+value.table_id).removeClass('red'); + $('.table_'+value.table_id).addClass('orange'); + } + $('.new_text_'+value.table_id).removeClass('hide'); + }); + + } + } +}); + diff --git a/app/channels/checkin_channel.rb b/app/channels/checkin_channel.rb new file mode 100644 index 00000000..c2e78132 --- /dev/null +++ b/app/channels/checkin_channel.rb @@ -0,0 +1,10 @@ +class CheckinChannel < ApplicationCable::Channel + def subscribed + stream_from "checkin_channel" + end + + def unsubscribed + stop_all_streams + # Any cleanup needed when channel is unsubscribed + end +end diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index 979fdf02..f9688235 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -2,6 +2,8 @@ class BaseOrigamiController < ActionController::Base include LoginVerification layout "origami" + before_action :checkin_process + #before_action :check_installation protect_from_forgery with: :exception rescue_from CanCan::AccessDenied do |exception| @@ -13,4 +15,7 @@ class BaseOrigamiController < ActionController::Base @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end + def checkin_process + CheckinJob.set(wait: 30.seconds).perform_later() + end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 35308c5f..64a6c587 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -72,7 +72,7 @@ class HomeController < ApplicationController @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) - @employee_sales = Sale.employee_sales(today).sum(:grand_total) + @employee_sales = Sale.employee_sales(today).sum('total_amount') @inventories = StockJournal.inventory_balances(today).sum(:balance) @total_sale = Sale.total_sale(today) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index ae3d1073..51a1f7db 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -37,7 +37,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.qty = 1 sale_item.unit_price = di["price"] sale_item.taxable_price = di["price"] * 1 - sale_item.is_taxable = 1 + sale_item.is_taxable = di["is_taxable"] sale_item.account_id = 0 sale_item.price = di["price"] * 1 diff --git a/app/jobs/checkin_job.rb b/app/jobs/checkin_job.rb new file mode 100644 index 00000000..3a0d329f --- /dev/null +++ b/app/jobs/checkin_job.rb @@ -0,0 +1,10 @@ +class CheckinJob < ApplicationJob + queue_as :default + + def perform() + table = DiningFacility.get_checkin_booking + ActionCable.server.broadcast "checkin_channel",table: table + end + + +end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 9948ec48..d3e05582 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -96,4 +96,26 @@ class DiningFacility < ApplicationRecord end end end + + def self.get_checkin_booking + bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null") + arr_booking = Array.new + if bookings + bookings.each do |booking| + now = Time.now.utc.getlocal + hr = (now.strftime("%H").to_i).to_int + min = (now.strftime("%M").to_i).to_int + if !booking.checkout_at.nil? + checkout_at = booking.checkout_at.utc.getlocal + checkout_at_hr = (checkout_at.strftime("%H").to_i).to_int + checkout_at_min = (checkout_at.strftime("%M").to_i).to_int + checkout_at_min -= min + if (checkout_at_hr <= hr) && (checkout_at_min <= 15) + arr_booking.push({'table_id' => booking.dining_facility_id}) + end + end + end + end + return arr_booking + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 3db6efb1..c28a382c 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -984,7 +984,7 @@ end end def self.employee_sales(today) - query = Sale.select("e.name as employee_name,grand_total") + query = Sale.select("e.name as employee_name,(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE sp.payment_amount END) as total_amount") .where('sales.payment_status="paid" and sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) .joins("join employees e on e.id=sales.cashier_id") .joins("join sale_payments sp on sp.sale_id=sales.sale_id") @@ -1103,7 +1103,7 @@ end .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .group("a.product_code") - .order("SUM(a.price) DESC") + .order("SUM(a.qty) DESC") .first() end diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb index 5b677d3e..0317d120 100755 --- a/app/views/origami/other_charges/index.html.erb +++ b/app/views/origami/other_charges/index.html.erb @@ -8,7 +8,7 @@
<%=@sale_data.sale_id %>
Receipt No: <%=@sale_data.receipt_no rescue ' '%>
@@ -95,12 +95,16 @@