add channel for checkin process
This commit is contained in:
25
app/assets/javascripts/channels/checkin.js
Normal file
25
app/assets/javascripts/channels/checkin.js
Normal file
@@ -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');
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
10
app/channels/checkin_channel.rb
Normal file
10
app/channels/checkin_channel.rb
Normal file
@@ -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
|
||||||
@@ -2,6 +2,8 @@ class BaseOrigamiController < ActionController::Base
|
|||||||
include LoginVerification
|
include LoginVerification
|
||||||
layout "origami"
|
layout "origami"
|
||||||
|
|
||||||
|
before_action :checkin_process
|
||||||
|
|
||||||
#before_action :check_installation
|
#before_action :check_installation
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
rescue_from CanCan::AccessDenied do |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]
|
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def checkin_process
|
||||||
|
CheckinJob.set(wait: 30.seconds).perform_later()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class HomeController < ApplicationController
|
|||||||
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
|
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
|
||||||
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
||||||
# .sum(:grand_total)
|
# .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)
|
@inventories = StockJournal.inventory_balances(today).sum(:balance)
|
||||||
|
|
||||||
@total_sale = Sale.total_sale(today)
|
@total_sale = Sale.total_sale(today)
|
||||||
|
|||||||
10
app/jobs/checkin_job.rb
Normal file
10
app/jobs/checkin_job.rb
Normal file
@@ -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
|
||||||
@@ -96,4 +96,26 @@ class DiningFacility < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -979,11 +979,11 @@ end
|
|||||||
def self.hourly_sales(today)
|
def self.hourly_sales(today)
|
||||||
query= Sale.select("grand_total")
|
query= Sale.select("grand_total")
|
||||||
.where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
.where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||||
.group("date_format(receipt_date, '%I %p')")
|
.group("date_format(convert_tz(receipt_date,'+00:00','+06:30'), '%I:%p')")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.employee_sales(today)
|
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)
|
.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 employees e on e.id=sales.cashier_id")
|
||||||
.joins("join sale_payments sp on sp.sale_id=sales.sale_id")
|
.joins("join sale_payments sp on sp.sale_id=sales.sale_id")
|
||||||
@@ -1102,7 +1102,7 @@ end
|
|||||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
.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)
|
.where("sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||||
.group("a.product_code")
|
.group("a.product_code")
|
||||||
.order("SUM(a.price) DESC")
|
.order("SUM(a.qty) DESC")
|
||||||
.first()
|
.first()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
5
spec/jobs/checkin_job_spec.rb
Normal file
5
spec/jobs/checkin_job_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe CheckinJob, type: :job do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user