114 lines
3.9 KiB
Ruby
Executable File
114 lines
3.9 KiB
Ruby
Executable File
class Origami::RequestBillsController < ApplicationController
|
|
before_action :check_user
|
|
|
|
def check_user
|
|
if current_user.nil?
|
|
redirect_to root_path
|
|
end
|
|
end
|
|
# Print Request Bill and add to sale tables
|
|
def print
|
|
if !ShiftSale.current_shift.nil?
|
|
order_id = params[:id] # order_id
|
|
order = Order.find(order_id)
|
|
booking = order.booking
|
|
if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil?
|
|
@status = false
|
|
@error_message = "Operation failed, Could not request bill!"
|
|
else
|
|
table = DiningFacility.find_by(id: booking.dining_facility_id)
|
|
|
|
if sale_data = booking.sale
|
|
@status = true
|
|
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
|
|
@status = true
|
|
# in-duty update
|
|
in_duties = InDuty.where("booking_id=?", booking.id)
|
|
if !in_duties.empty?
|
|
in_duties.each do |in_duty|
|
|
induty = InDuty.find(in_duty.id)
|
|
induty.sale_id = sale_data.sale_id
|
|
induty.out_time = Time.now.utc
|
|
induty.save
|
|
end
|
|
end
|
|
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_data)
|
|
|
|
#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_data.sale_id }
|
|
render :json => result.to_json
|
|
else
|
|
#check checkInOut pdf print
|
|
checkout_time = Lookup.collection_of('checkout_time')
|
|
if !booking.dining_facility_id.nil?
|
|
terminal = DiningFacility.find_by_id(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, booking, table)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
@status = true
|
|
else
|
|
@status = false
|
|
@error_message = "No Current Open Shift for This Employee"
|
|
end
|
|
|
|
# Not Use for these printed bill cannot give customer
|
|
# unique_code = "ReceiptBillPdf"
|
|
# #shop detail
|
|
# shop_details = Shop.find(1)
|
|
# # customer= Customer.where('customer_id=' +.customer_id)
|
|
# customer= Customer.find(@sale_data.customer_id)
|
|
# # get member information
|
|
# member_info = Customer.get_member_account(customer)
|
|
# # get printer info
|
|
# print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
|
|
# # find order id by sale id
|
|
# # sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
|
|
|
|
# # Calculate price_by_accounts
|
|
# item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
|
|
|
|
# printer = Printer::ReceiptPrinter.new(print_settings)
|
|
|
|
|
|
# printer.print_receipt_bill(print_settings, false, nil,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
|
|
end
|
|
|
|
end
|