change future checkin time flow
This commit is contained in:
@@ -11,39 +11,44 @@ class Api::BillController < Api::ApiController
|
|||||||
table = 0
|
table = 0
|
||||||
if (params[:booking_id])
|
if (params[:booking_id])
|
||||||
booking = Booking.find(params[:booking_id])
|
booking = Booking.find(params[:booking_id])
|
||||||
# for Multiple Cashier by Zone
|
if booking.checkin_at.utc.strftime("%Y-%m-%d %H:%M") > Time.now.utc.strftime("%Y-%m-%d %H:%M") && booking.checkout_at.nil?
|
||||||
table = DiningFacility.find(booking.dining_facility_id)
|
@status = false
|
||||||
|
@error_message = "Operation failed, Could not request bill!"
|
||||||
bk_order = BookingOrder.find_by_booking_id(booking.booking_id)
|
|
||||||
order = Order.find(bk_order.order_id)
|
|
||||||
|
|
||||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
|
||||||
|
|
||||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
|
|
||||||
|
|
||||||
#for multiple zone with terminal
|
|
||||||
if !shift.nil?
|
|
||||||
cashier = Employee.find(shift.employee_id)
|
|
||||||
else
|
else
|
||||||
multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}")
|
# for Multiple Cashier by Zone
|
||||||
multiple_zone.each do |zone|
|
table = DiningFacility.find(booking.dining_facility_id)
|
||||||
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
|
|
||||||
if !shift.nil? then
|
bk_order = BookingOrder.find_by_booking_id(booking.booking_id)
|
||||||
cashier = Employee.find(shift.employee_id)
|
order = Order.find(bk_order.order_id)
|
||||||
break
|
|
||||||
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||||
|
|
||||||
|
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
|
||||||
|
|
||||||
|
#for multiple zone with terminal
|
||||||
|
if !shift.nil?
|
||||||
|
cashier = Employee.find(shift.employee_id)
|
||||||
|
else
|
||||||
|
multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}")
|
||||||
|
multiple_zone.each do |zone|
|
||||||
|
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
|
||||||
|
if !shift.nil? then
|
||||||
|
cashier = Employee.find(shift.employee_id)
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if booking
|
if booking
|
||||||
if booking.sale_id.nil?
|
if booking.sale_id.nil?
|
||||||
@sale = Sale.new
|
@sale = Sale.new
|
||||||
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, cashier, order.source)
|
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, cashier, order.source)
|
||||||
@sale_data = Sale.find_by_sale_id(@sale_id)
|
@sale_data = Sale.find_by_sale_id(@sale_id)
|
||||||
else
|
else
|
||||||
@status = true
|
@status = true
|
||||||
@sale_id = booking.sale_id
|
@sale_id = booking.sale_id
|
||||||
@sale_data = Sale.find_by_sale_id(@sale_id)
|
@sale_data = Sale.find_by_sale_id(@sale_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif (params[:order_id])
|
elsif (params[:order_id])
|
||||||
@@ -59,35 +64,36 @@ class Api::BillController < Api::ApiController
|
|||||||
# Bind shift sale id to sale
|
# Bind shift sale id to sale
|
||||||
# @sale_data.shift_sale_id = shift_by_terminal.id
|
# @sale_data.shift_sale_id = shift_by_terminal.id
|
||||||
# @sale_data.save
|
# @sale_data.save
|
||||||
|
if @status
|
||||||
|
#check checkInOut pdf print
|
||||||
|
check_booking = Booking.find_by_sale_id(@sale_id)
|
||||||
|
checkout_time = Lookup.collection_of('checkout_time')
|
||||||
|
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
|
||||||
|
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
||||||
|
|
||||||
#check checkInOut pdf print
|
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
|
||||||
check_booking = Booking.find_by_sale_id(@sale_id)
|
|
||||||
checkout_time = Lookup.collection_of('checkout_time')
|
unique_code = "CheckInOutPdf"
|
||||||
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
|
printer = PrintSetting.find_by_unique_code(unique_code)
|
||||||
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
|
||||||
|
|
||||||
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
|
# print when complete click
|
||||||
|
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
||||||
unique_code = "CheckInOutPdf"
|
|
||||||
printer = PrintSetting.find_by_unique_code(unique_code)
|
|
||||||
|
|
||||||
# print when complete click
|
if !printer.nil?
|
||||||
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
order_queue_printer.print_check_in_out(printer,cashier_terminal , check_booking, table)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if !printer.nil?
|
Promotion.promo_activate(@sale)
|
||||||
order_queue_printer.print_check_in_out(printer,cashier_terminal , check_booking, table)
|
|
||||||
|
#BillBroadcastJob.perform_later(table)
|
||||||
|
if ENV["SERVER_MODE"] == 'cloud'
|
||||||
|
from = request.subdomain + "." + request.domain
|
||||||
|
else
|
||||||
|
from = ""
|
||||||
end
|
end
|
||||||
end
|
ActionCable.server.broadcast "bill_channel",table: table, from: from
|
||||||
|
end
|
||||||
Promotion.promo_activate(@sale)
|
|
||||||
|
|
||||||
#BillBroadcastJob.perform_later(table)
|
|
||||||
if ENV["SERVER_MODE"] == 'cloud'
|
|
||||||
from = request.subdomain + "." + request.domain
|
|
||||||
else
|
|
||||||
from = ""
|
|
||||||
end
|
|
||||||
ActionCable.server.broadcast "bill_channel",table: table, from: from
|
|
||||||
else
|
else
|
||||||
@status = false
|
@status = false
|
||||||
@error_message = "No Current Open Shift"
|
@error_message = "No Current Open Shift"
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
def check_in_process
|
def check_in_process
|
||||||
if params[:dining_id]
|
if params[:dining_id]
|
||||||
dining_facility = DiningFacility.find(params[:dining_id])
|
dining_facility = DiningFacility.find(params[:dining_id])
|
||||||
if dining_facility.status == "available"
|
if dining_facility.is_active && dining_facility.status == "available"
|
||||||
if params[:checkin_time]
|
if params[:checkin_time]
|
||||||
checkin_at = nil
|
checkin_at = nil
|
||||||
if !params[:checkin_time].empty?
|
if !params[:checkin_time].empty?
|
||||||
|
|||||||
@@ -16,78 +16,83 @@ class Origami::RequestBillsController < ApplicationController
|
|||||||
bk_order = BookingOrder.find_by_order_id(order_id)
|
bk_order = BookingOrder.find_by_order_id(order_id)
|
||||||
order = Order.find(order_id)
|
order = Order.find(order_id)
|
||||||
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
||||||
if check_booking.dining_facility_id.to_i > 0
|
if check_booking.checkin_at.utc.strftime("%Y-%m-%d %H:%M") > Time.now.utc.strftime("%Y-%m-%d %H:%M") && check_booking.checkout_at.nil?
|
||||||
table = DiningFacility.find(check_booking.dining_facility_id)
|
@status = false
|
||||||
|
@error_message = "Operation failed, Could not request bill!"
|
||||||
else
|
else
|
||||||
table = nil
|
if check_booking.dining_facility_id.to_i > 0
|
||||||
end
|
table = DiningFacility.find(check_booking.dining_facility_id)
|
||||||
|
else
|
||||||
if check_booking.sale_id.nil?
|
table = nil
|
||||||
# Create Sale if it doesn't exist
|
|
||||||
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source)
|
|
||||||
@sale_data = Sale.find_by_sale_id(@sale_id)
|
|
||||||
@sale_items = SaleItem.where("sale_id=?",@sale_id)
|
|
||||||
|
|
||||||
# in-duty update
|
|
||||||
in_duties = InDuty.where("booking_id=?",bk_order.booking_id)
|
|
||||||
if !in_duties.empty?
|
|
||||||
in_duties.each do |in_duty|
|
|
||||||
induty = InDuty.find(in_duty.id)
|
|
||||||
induty.sale_id = @sale_id
|
|
||||||
induty.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
|
if check_booking.sale_id.nil?
|
||||||
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
|
# Create Sale if it doesn't exist
|
||||||
end
|
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source)
|
||||||
|
@sale_data = Sale.find_by_sale_id(@sale_id)
|
||||||
|
@sale_items = SaleItem.where("sale_id=?",@sale_id)
|
||||||
|
|
||||||
# Bind shift sale id to sale
|
# in-duty update
|
||||||
# @sale_data.shift_sale_id = shift.id
|
in_duties = InDuty.where("booking_id=?",bk_order.booking_id)
|
||||||
# @sale_data.save
|
if !in_duties.empty?
|
||||||
|
in_duties.each do |in_duty|
|
||||||
action_by = current_user.name
|
induty = InDuty.find(in_duty.id)
|
||||||
type = "REQUEST_BILL"
|
induty.sale_id = @sale_id
|
||||||
|
induty.save
|
||||||
remark = "Request bill Receipt No #{@sale_data.receipt_no}"
|
|
||||||
sale_audit = SaleAudit.record_audit_sale(@sale_data.sale_id,remark,action_by,type )
|
|
||||||
|
|
||||||
# Promotion Activation
|
|
||||||
Promotion.promo_activate(@sale)
|
|
||||||
|
|
||||||
#bill channel
|
|
||||||
if ENV["SERVER_MODE"] == 'cloud'
|
|
||||||
from = request.subdomain + "." + request.domain
|
|
||||||
else
|
|
||||||
from = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
if order.source == "cashier" || order.source == "quick_service"
|
|
||||||
ActionCable.server.broadcast "bill_channel",table: table, from: from
|
|
||||||
end
|
|
||||||
if order.source == "quick_service" || order.source == "food_court"
|
|
||||||
result = {:status=> @status, :data => @sale.sale_id }
|
|
||||||
render :json => result.to_json
|
|
||||||
else
|
|
||||||
#check checkInOut pdf print
|
|
||||||
check_booking = Booking.find_by_sale_id(@sale_id)
|
|
||||||
checkout_time = Lookup.collection_of('checkout_time')
|
|
||||||
if !check_booking.dining_facility_id.nil?
|
|
||||||
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
|
|
||||||
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
|
||||||
|
|
||||||
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
|
|
||||||
unique_code = "CheckInOutPdf"
|
|
||||||
printer = PrintSetting.find_by_unique_code(unique_code)
|
|
||||||
|
|
||||||
# print when complete click
|
|
||||||
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
|
||||||
|
|
||||||
if !printer.nil?
|
|
||||||
order_queue_printer.print_check_in_out(printer, cashier_terminal, check_booking, table)
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
|
||||||
|
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Bind shift sale id to sale
|
||||||
|
# @sale_data.shift_sale_id = shift.id
|
||||||
|
# @sale_data.save
|
||||||
|
|
||||||
|
action_by = current_user.name
|
||||||
|
type = "REQUEST_BILL"
|
||||||
|
|
||||||
|
remark = "Request bill Receipt No #{@sale_data.receipt_no}"
|
||||||
|
sale_audit = SaleAudit.record_audit_sale(@sale_data.sale_id,remark,action_by,type )
|
||||||
|
|
||||||
|
# Promotion Activation
|
||||||
|
Promotion.promo_activate(@sale)
|
||||||
|
|
||||||
|
#bill channel
|
||||||
|
if ENV["SERVER_MODE"] == 'cloud'
|
||||||
|
from = request.subdomain + "." + request.domain
|
||||||
|
else
|
||||||
|
from = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
if order.source == "cashier" || order.source == "quick_service"
|
||||||
|
ActionCable.server.broadcast "bill_channel",table: table, from: from
|
||||||
|
end
|
||||||
|
if order.source == "quick_service" || order.source == "food_court"
|
||||||
|
result = {:status=> @status, :data => @sale.sale_id }
|
||||||
|
render :json => result.to_json
|
||||||
|
else
|
||||||
|
#check checkInOut pdf print
|
||||||
|
check_booking = Booking.find_by_sale_id(@sale_id)
|
||||||
|
checkout_time = Lookup.collection_of('checkout_time')
|
||||||
|
if !check_booking.dining_facility_id.nil?
|
||||||
|
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
|
||||||
|
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
|
||||||
|
|
||||||
|
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
|
||||||
|
unique_code = "CheckInOutPdf"
|
||||||
|
printer = PrintSetting.find_by_unique_code(unique_code)
|
||||||
|
|
||||||
|
# print when complete click
|
||||||
|
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
||||||
|
|
||||||
|
if !printer.nil?
|
||||||
|
order_queue_printer.print_check_in_out(printer, cashier_terminal, check_booking, table)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@status = false
|
@status = false
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ class DiningFacility < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_current_booking
|
def get_current_booking
|
||||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null
|
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null
|
||||||
|
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null
|
||||||
if booking.count > 0 then
|
if booking.count > 0 then
|
||||||
return booking[0]
|
return booking[0]
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1078,7 +1078,19 @@
|
|||||||
// data: 'order_id='+ order_id,
|
// data: 'order_id='+ order_id,
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (!result.status) {
|
if (!result.status) {
|
||||||
swal("Information!", result.error_message);
|
swal({
|
||||||
|
title: 'Oops',
|
||||||
|
text: result.error_message,
|
||||||
|
type: 'error',
|
||||||
|
html: true,
|
||||||
|
closeOnConfirm: false,
|
||||||
|
closeOnCancel: false,
|
||||||
|
allowOutsideClick: false
|
||||||
|
}, function (isConfirm) {
|
||||||
|
if(isConfirm){
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
location.reload();
|
location.reload();
|
||||||
|
|||||||
@@ -1146,7 +1146,19 @@ $('#request_bills').click(function() {
|
|||||||
// data: 'order_id='+ order_id,
|
// data: 'order_id='+ order_id,
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (!result.status) {
|
if (!result.status) {
|
||||||
swal("Information!", result.error_message);
|
swal({
|
||||||
|
title: 'Oops',
|
||||||
|
text: result.error_message,
|
||||||
|
type: 'error',
|
||||||
|
html: true,
|
||||||
|
closeOnConfirm: false,
|
||||||
|
closeOnCancel: false,
|
||||||
|
allowOutsideClick: false
|
||||||
|
}, function (isConfirm) {
|
||||||
|
if(isConfirm){
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
location.reload();
|
location.reload();
|
||||||
|
|||||||
Reference in New Issue
Block a user