fix foodcourt sales transaction
This commit is contained in:
@@ -87,8 +87,6 @@ class Foodcourt::AddordersController < BaseFoodcourtController
|
||||
end
|
||||
|
||||
def create
|
||||
new_booking =true
|
||||
booking_id =nil
|
||||
if params[:booking_id].present?
|
||||
booking = Booking.find(params[:booking_id])
|
||||
end
|
||||
@@ -105,82 +103,64 @@ class Foodcourt::AddordersController < BaseFoodcourtController
|
||||
items_arr = []
|
||||
JSON.parse(params[:order_items]).each { |i|
|
||||
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
|
||||
if i["item_instance_code"].include? "ext"
|
||||
is_extra_time = true
|
||||
arr_exts = i["item_instance_code"].split("_")
|
||||
if arr_exts[1].match(/^(\d)+$/)
|
||||
time = arr_exts[1].to_i*60*i["quantity"].to_i
|
||||
extra_time = Time.at(time)
|
||||
end
|
||||
end
|
||||
if i["parent_order_item_id"];
|
||||
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
|
||||
else
|
||||
if i["parent_order_item_id"];
|
||||
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
|
||||
else
|
||||
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
|
||||
end
|
||||
items_arr.push(items)
|
||||
end
|
||||
items_arr.push(items)
|
||||
}
|
||||
|
||||
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
|
||||
customer_id = takeaway.customer_id # for no customer id from mobile
|
||||
else
|
||||
customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id # for no customer id from mobile
|
||||
end
|
||||
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
|
||||
new_booking = true
|
||||
else
|
||||
new_booking = false
|
||||
booking_id = booking.booking_id
|
||||
end
|
||||
@order =Order.create(source: params[:order_source],
|
||||
order_type: params[:order_type],
|
||||
customer_id: customer_id,
|
||||
items: items_arr,
|
||||
guest: params[:guest_info],
|
||||
table_id: params[:table_id],
|
||||
new_booking: new_booking,
|
||||
waiters: current_login_employee.name,
|
||||
employee_name: current_login_employee.name,
|
||||
is_extra_time: is_extra_time,
|
||||
extra_time: extra_time,
|
||||
booking_id: booking_id
|
||||
)
|
||||
@status, @booking = @order.generate
|
||||
customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id
|
||||
|
||||
if @status && @booking
|
||||
#send order broadcast to order_channel
|
||||
if @order.table_id.to_i > 0
|
||||
table = DiningFacility.find(@booking.dining_facility_id)
|
||||
type = 'order'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
Order.transaction do
|
||||
@order = Order.new
|
||||
@order.source = params[:order_source]
|
||||
@order.order_type = params[:order_type]
|
||||
@order.customer_id = customer_id
|
||||
@order.items = items_arr
|
||||
@order.guest = params[:guest_info]
|
||||
@order.table_id = params[:table_id] # this is dining facilities's id
|
||||
@order.new_booking = true
|
||||
@order.waiters = current_login_employee.name
|
||||
@order.employee_name = current_login_employee.name
|
||||
|
||||
@order.is_extra_time = is_extra_time
|
||||
@order.extra_time = extra_time
|
||||
|
||||
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
|
||||
@order.new_booking = true
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = booking.booking_id
|
||||
end
|
||||
|
||||
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
|
||||
process_order_queue(@order.order_id,@order.table_id,@order.source)
|
||||
end
|
||||
end
|
||||
@status, @booking = @order.generate
|
||||
|
||||
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
||||
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
|
||||
|
||||
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
|
||||
|
||||
# for second display
|
||||
if @order.source == 'quick_service'
|
||||
if @status && @booking
|
||||
#send order broadcast to order_channel
|
||||
if @order.table_id.to_i > 0
|
||||
table = DiningFacility.find(@booking.dining_facility_id)
|
||||
type = 'order'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
end
|
||||
#end
|
||||
result = {:status=> @status, :data => @sale ,:current_user_role =>current_user.role}
|
||||
render :json => result.to_json
|
||||
end
|
||||
else
|
||||
result = {:status=> @status, :data => 0 }
|
||||
render :json => result.to_json
|
||||
end
|
||||
|
||||
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
||||
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
|
||||
|
||||
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
|
||||
|
||||
# for second display
|
||||
if @order.source == 'quick_service'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
|
||||
end
|
||||
#end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# render json for http status code
|
||||
|
||||
@@ -9,51 +9,49 @@ class Foodcourt::FoodCourtController < ApplicationController
|
||||
|
||||
def index
|
||||
if !ShiftSale.current_shift.nil?
|
||||
if params[:sale_id].present?
|
||||
sale =Sale.find(params[:sale_id])
|
||||
if sale
|
||||
@sale_id =sale.sale_id
|
||||
@booking_id =sale.bookings[0].booking_id
|
||||
if params[:sale_id].present?
|
||||
sale =Sale.find(params[:sale_id])
|
||||
if sale
|
||||
@sale_id =sale.sale_id
|
||||
@booking_id =sale.bookings[0].booking_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@zone = Zone.all
|
||||
@tables = Table.active.order('status desc')
|
||||
@rooms = Room.active.order('status desc')
|
||||
@zone = Zone.all.includes(:tables, :rooms).where("is_active= true")
|
||||
|
||||
today = Time.current
|
||||
day = Date.today.wday
|
||||
@menus = []
|
||||
@menu = []
|
||||
@cashier_type = "food_court"
|
||||
#checked quick_service only
|
||||
today = Time.current
|
||||
day = Date.today.wday
|
||||
@menus = []
|
||||
@menu = []
|
||||
@cashier_type = "food_court"
|
||||
#checked quick_service only
|
||||
|
||||
display_type = Lookup.find_by_lookup_type("display_type")
|
||||
if !display_type.nil? && display_type.value.to_i ==2
|
||||
@display_type = display_type.value
|
||||
else
|
||||
@display_type = nil
|
||||
end
|
||||
display_type = Lookup.find_by_lookup_type("display_type")
|
||||
if !display_type.nil? && display_type.value.to_i ==2
|
||||
@display_type = display_type.value
|
||||
else
|
||||
@display_type = nil
|
||||
end
|
||||
|
||||
@quick_service_only = true
|
||||
lookup_dine_in = Lookup.collection_of('dinein_cashier')
|
||||
if !lookup_dine_in.empty?
|
||||
lookup_dine_in.each do |dine_in|
|
||||
if dine_in[0].downcase == "dineincashier"
|
||||
if dine_in[1] == '1'
|
||||
@quick_service_only = false
|
||||
@quick_service_only = true
|
||||
lookup_dine_in = Lookup.collection_of('dinein_cashier')
|
||||
if !lookup_dine_in.empty?
|
||||
lookup_dine_in.each do |dine_in|
|
||||
if dine_in[0].downcase == "dineincashier"
|
||||
if dine_in[1] == '1'
|
||||
@quick_service_only = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@app_order_new_count = Booking.select("bookings.*,customers.*")
|
||||
@app_order_new_count = Booking.select("bookings.*,customers.*")
|
||||
.joins(" JOIN sales ON bookings.sale_id=sales.sale_id")
|
||||
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
|
||||
.joins("JOIN orders ON orders.order_id=booking_orders.order_id")
|
||||
.joins("JOIN order_items ON orders.order_id=order_items.order_id")
|
||||
.joins("JOIN customers ON orders.customer_id=customers.customer_id")
|
||||
.where("bookings.booking_status !=? and sales.sale_status =? and sales.payment_status =? and orders.source='app' and DATE(bookings.created_at)=?",'completed','completed','paid',Date.today).order("bookings.created_at desc").uniq.length
|
||||
render "foodcourt/addorders/detail"
|
||||
render "foodcourt/addorders/detail"
|
||||
else
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager'
|
||||
redirect_to origami_dashboard_path
|
||||
|
||||
@@ -64,7 +64,6 @@ class Foodcourt::OrdersController < BaseFoodcourtController
|
||||
@booking_id =@booking.booking_id
|
||||
@order_id =@booking.order_id
|
||||
@sale_data = Sale.find_by_sale_id(@booking.sale_id)
|
||||
|
||||
elsif params[:pending_id]
|
||||
id = params[:pending_id]
|
||||
if id.include? "SAL"
|
||||
@@ -166,40 +165,46 @@ class Foodcourt::OrdersController < BaseFoodcourtController
|
||||
}
|
||||
|
||||
# begin
|
||||
order = Order.new
|
||||
order.source = params[:order_source]
|
||||
order.order_type = params[:order_type]
|
||||
# order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
|
||||
order.items = items_arr
|
||||
order.guest = params[:guest_info]
|
||||
order.table_id = params[:table_id] # this is dining facilities's id
|
||||
order.waiters = current_login_employee.name
|
||||
order.employee_name = current_login_employee.name
|
||||
Order.transaction do
|
||||
order = Order.new
|
||||
order.source = params[:order_source]
|
||||
order.order_type = params[:order_type]
|
||||
# order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
|
||||
order.items = items_arr
|
||||
order.guest = params[:guest_info]
|
||||
order.table_id = params[:table_id] # this is dining facilities's id
|
||||
order.waiters = current_login_employee.name
|
||||
order.employee_name = current_login_employee.name
|
||||
|
||||
order.is_extra_time = is_extra_time
|
||||
order.extra_time = extra_time
|
||||
order.is_extra_time = is_extra_time
|
||||
order.extra_time = extra_time
|
||||
|
||||
order.new_booking = false
|
||||
order.booking_id = booking.booking_id
|
||||
order.new_booking = false
|
||||
order.booking_id = booking.booking_id
|
||||
|
||||
if order.generate
|
||||
if sale
|
||||
Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking)
|
||||
render :json => { :status => true, :data => sale }
|
||||
if order.generate
|
||||
if sale
|
||||
Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking)
|
||||
render :json => { :status => true, :data => sale }
|
||||
else
|
||||
render :json => { :status => true, :data => 'OK' }
|
||||
end
|
||||
else
|
||||
render :json => { :status => true, :data => 'OK' }
|
||||
render :json => { :status => false }
|
||||
end
|
||||
else
|
||||
render :json => { :status => false }
|
||||
end
|
||||
end
|
||||
|
||||
def request_bill
|
||||
sale_data =[]
|
||||
customer_id = params[:customer_id]
|
||||
if !ShiftSale.current_shift.nil?
|
||||
order_id = params[:order_id] # order_id
|
||||
order_id = params[:order_id]
|
||||
order = Order.find(order_id)
|
||||
booking = order.booking
|
||||
if Customer.exists?(customer_id: customer_id)
|
||||
booking.orders.update_all(customer_id: customer_id)
|
||||
end
|
||||
if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil?
|
||||
@status = false
|
||||
@error_message = "Operation failed, Could not request bill!"
|
||||
@@ -295,7 +300,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController
|
||||
|
||||
def cancel_order
|
||||
order_id = params[:order_id]
|
||||
|
||||
|
||||
if order_id.present?
|
||||
order = Order.find(order_id)
|
||||
booking = order.booking
|
||||
@@ -321,5 +326,5 @@ class Foodcourt::OrdersController < BaseFoodcourtController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,19 +1,37 @@
|
||||
class Foodcourt::PaymalController < BaseFoodcourtController
|
||||
|
||||
def create
|
||||
cash = params[:payment_amount]
|
||||
sale_id = params[:sale_id]
|
||||
transaction_ref = params[:transaction_ref]
|
||||
account_no = params[:account_no]
|
||||
if(Sale.exists?(sale_id))
|
||||
cash = params[:payment_amount]
|
||||
sale_id = params[:sale_id]
|
||||
transaction_ref = params[:transaction_ref]
|
||||
account_no = params[:account_no]
|
||||
if(Sale.exists?(sale_id))
|
||||
Sale.transaction do
|
||||
saleObj = Sale.find(sale_id)
|
||||
booking = saleObj.booking
|
||||
|
||||
sale_payment = SalePayment.new
|
||||
status, @sale, @membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal",account_no)
|
||||
status, @sale, @membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal", account_no)
|
||||
|
||||
if status == true && @membership_data["status"] == true
|
||||
PrintOrderQueueJob.perform_later(current_shop.shop_code, booking.booking_id)
|
||||
PrintReceiptJob.perform_later(current_shop.shop_code, sale_id)
|
||||
|
||||
@out = true, "Success!"
|
||||
else
|
||||
@out = false, @membership_data["message"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def getCloudDomain
|
||||
from = ""
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain.to_s + "." + request.domain.to_s
|
||||
end
|
||||
|
||||
return from
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,19 +9,20 @@ class Foodcourt::SecondDisplayController < BaseFoodcourtController
|
||||
|
||||
def customer_view
|
||||
display_type = Lookup.find_by_lookup_type("display_type")
|
||||
if !display_type.nil? && display_type.value.to_i == 2
|
||||
if params[:status]!= "billed"
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
else
|
||||
tax_profiles = nil
|
||||
end
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.host
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from
|
||||
end
|
||||
if !display_type.nil? && display_type.value.to_i == 2
|
||||
if params[:status]!= "billed"
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
else
|
||||
tax_profiles = nil
|
||||
end
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.host
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from
|
||||
end
|
||||
head :no_content
|
||||
# end
|
||||
end
|
||||
#Shop Name in Navbor
|
||||
|
||||
@@ -34,6 +34,15 @@ class Foodcourt::VoidController < BaseFoodcourtController
|
||||
sale.sale_status = 'void'
|
||||
sale.save
|
||||
|
||||
#call paymal to void
|
||||
if !sale.sale_payments.nil?
|
||||
membership_response = sale.paymal_payment_void
|
||||
Rails.logger.debug "---------Paymal Payment Void response in VoidController"
|
||||
Rails.logger.debug membership_response.to_json
|
||||
end
|
||||
|
||||
PrintReceiptJob.perform_later(current_shop.shop_code, sale.sale_id)
|
||||
|
||||
if table = sale.booking.dining_facility
|
||||
unless table.current_bookings.exists?
|
||||
table.update_attributes(status: 'available')
|
||||
@@ -49,73 +58,6 @@ class Foodcourt::VoidController < BaseFoodcourtController
|
||||
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
|
||||
sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,"SALEVOID" )
|
||||
|
||||
#call paymal to void
|
||||
if !sale.sale_payments.nil?
|
||||
membership_response =sale.paymal_payment_void
|
||||
Rails.logger.debug "---------Paymal Payment Void response in VoidController"
|
||||
Rails.logger.debug membership_response.to_json
|
||||
end
|
||||
|
||||
# For Print
|
||||
member_info = nil
|
||||
rebate_amount = nil
|
||||
current_balance = nil
|
||||
|
||||
if sale.booking.dining_facility_id.to_i > 0
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
||||
else
|
||||
shift = ShiftSale.find(sale.shift_sale_id)
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
end
|
||||
|
||||
customer= Customer.find(sale.customer_id)
|
||||
|
||||
#shop detail
|
||||
shop_details = Shop.current_shop
|
||||
# get member information
|
||||
rebate = MembershipSetting.find_by_rebate(1)
|
||||
if customer.membership_id != nil && rebate
|
||||
member_info = Customer.get_member_account(customer)
|
||||
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
|
||||
# current_balance = SaleAudit.paymal_search(sale_id)
|
||||
current_balance = 0
|
||||
end
|
||||
|
||||
printer = PrintSetting.all
|
||||
|
||||
unique_code="ReceiptBillPdf"
|
||||
if !printer.empty?
|
||||
printer.each do |printer_setting|
|
||||
if printer_setting.unique_code == 'ReceiptBillPdf'
|
||||
unique_code="ReceiptBillPdf"
|
||||
elsif printer_setting.unique_code == 'ReceiptBillA5Pdf'
|
||||
unique_code="ReceiptBillA5Pdf"
|
||||
elsif printer_setting.unique_code == 'ReceiptBillStarPdf'
|
||||
unique_code="ReceiptBillStarPdf"
|
||||
end
|
||||
end
|
||||
end
|
||||
# get printer info
|
||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||
# Calculate Food and Beverage Total
|
||||
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
|
||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
|
||||
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil)
|
||||
result = {
|
||||
:filepath => filename,
|
||||
:printer_model => print_settings.brand_name,
|
||||
:printer_url => print_settings.api_settings
|
||||
}
|
||||
|
||||
# Mobile Print
|
||||
render :json => result.to_json
|
||||
# end
|
||||
|
||||
#end print
|
||||
|
||||
# update complete order items in oqs
|
||||
SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
|
||||
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
|
||||
@@ -124,6 +66,6 @@ class Foodcourt::VoidController < BaseFoodcourtController
|
||||
end
|
||||
end
|
||||
end
|
||||
head :no_content
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user