merge with r-19
This commit is contained in:
@@ -6,10 +6,11 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
if check_mobile
|
||||
@webview = true
|
||||
end
|
||||
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
|
||||
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
|
||||
@all_table = Table.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc')
|
||||
@all_room = Room.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc')
|
||||
|
||||
@tables = Table.active.order('zone_id asc').group("zone_id")
|
||||
@rooms = Room.active.order('zone_id asc').group("zone_id")
|
||||
@all_table = Table.active.order('status desc')
|
||||
@all_room = Room.active.order('status desc')
|
||||
end
|
||||
|
||||
def detail
|
||||
@@ -33,10 +34,11 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
@booking = @table.get_booking
|
||||
if @booking
|
||||
@booking_id = @booking.booking_id
|
||||
@obj_order = @booking.orders.first
|
||||
@customer = @obj_order.customer
|
||||
@date = @obj_order.created_at
|
||||
@order_items = @booking.order_items
|
||||
if @obj_order = @booking.orders.first
|
||||
@customer = @obj_order.customer
|
||||
@date = @obj_order.created_at
|
||||
@order_items = @booking.order_items
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -98,87 +100,85 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
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)+$/)
|
||||
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
|
||||
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
|
||||
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)
|
||||
}
|
||||
# begin
|
||||
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
|
||||
customer_id = "CUS-000000000002" # for no customer id from mobile
|
||||
customer_id = takeaway.customer_id # for no customer id from mobile
|
||||
else
|
||||
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
|
||||
customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
|
||||
end
|
||||
|
||||
@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.shop_code = @shop.shop_code
|
||||
@order.is_extra_time = is_extra_time
|
||||
@order.extra_time = extra_time
|
||||
|
||||
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
|
||||
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
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = booking.booking_id
|
||||
end
|
||||
@order.waiters = current_login_employee.name
|
||||
@order.employee_name = current_login_employee.name
|
||||
|
||||
@status, @booking = @order.generate
|
||||
|
||||
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.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 @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
|
||||
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
|
||||
# Order.send_customer_view(@booking)
|
||||
|
||||
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
||||
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
|
||||
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)
|
||||
@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
|
||||
# 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
|
||||
result = {:status=> @status, :data => @sale }
|
||||
render :json => result.to_json
|
||||
end
|
||||
#end
|
||||
result = {:status=> @status, :data => @sale }
|
||||
else
|
||||
result = {:status=> @status, :data => 0 }
|
||||
render :json => result.to_json
|
||||
end
|
||||
else
|
||||
result = {:status=> @status, :data => 0 }
|
||||
render :json => result.to_json
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# render json for http status code
|
||||
@@ -220,66 +220,29 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
|
||||
def process_order_queue(order_id,table_id,order_source)
|
||||
print_status = nil
|
||||
cup_status = nil
|
||||
#Send to background job for processing
|
||||
order = Order.find(order_id)
|
||||
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code)
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
def process_order_queue(order_id, table_id, order_source)
|
||||
#Send to background job for processing
|
||||
order = Order.find(order_id)
|
||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
if Printer::PrinterWorker.printers.blank?
|
||||
msg = 'Print Error ! Please contact to service'
|
||||
ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: ''
|
||||
end
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, order_source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_start = `#{"sudo service cups start"}`
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, order_source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
from = ""
|
||||
msg = ' Print Error ! Please contact to service'
|
||||
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error',from:from
|
||||
end
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, order_source)
|
||||
end
|
||||
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
||||
end
|
||||
end
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, order_source)
|
||||
end
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
ActionCable.server.broadcast "order_queue_station_channel", order: assign_order, from: from
|
||||
end
|
||||
end
|
||||
|
||||
def check_cup_status(status)
|
||||
|
||||
@@ -55,7 +55,7 @@ class Origami::CustomersController < BaseOrigamiController
|
||||
@cashier_type = params[:type]
|
||||
@page = params[:dir_page]
|
||||
|
||||
if(@sale_id[0,3] == "SAL")
|
||||
if @sale_id.include? "SAL"
|
||||
@booking = Booking.find_by_sale_id(@sale_id)
|
||||
if @booking.dining_facility_id.to_i > 0
|
||||
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
|
||||
@@ -117,7 +117,7 @@ class Origami::CustomersController < BaseOrigamiController
|
||||
|
||||
def update_sale_by_customer
|
||||
|
||||
id = params[:sale_id][0,3]
|
||||
id = params[:sale_id]
|
||||
customer_id = params[:customer_id]
|
||||
customer = Customer.find(customer_id)
|
||||
order_source = params[:type]
|
||||
@@ -129,7 +129,7 @@ class Origami::CustomersController < BaseOrigamiController
|
||||
# end
|
||||
# end
|
||||
|
||||
if(id == "SAL")
|
||||
if id.include? "SAL"
|
||||
sale = Sale.find(params[:sale_id])
|
||||
status = sale.update_attributes(customer_id: customer_id)
|
||||
sale.sale_orders.each do |sale_order|
|
||||
@@ -153,7 +153,7 @@ class Origami::CustomersController < BaseOrigamiController
|
||||
|
||||
if status == true
|
||||
render json: JSON.generate({:status => true})
|
||||
if(id == "SAL")
|
||||
if id.include? "SAL"
|
||||
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
|
||||
end
|
||||
else
|
||||
|
||||
@@ -104,9 +104,7 @@ class Origami::DashboardController < BaseOrigamiController
|
||||
end
|
||||
|
||||
def get_all_menu
|
||||
|
||||
@menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.shop
|
||||
|
||||
@menus = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
|
||||
@item_attributes = MenuItemAttribute.all.load
|
||||
@item_options = MenuItemOption.all.load
|
||||
end
|
||||
|
||||
@@ -22,7 +22,6 @@ class Origami::FoodCourtController < ApplicationController
|
||||
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
|
||||
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
|
||||
@cashier_type = "food_court"
|
||||
|
||||
display_type = Lookup.find_by_lookup_type("display_type")
|
||||
if !display_type.nil? && display_type.value.to_i ==2
|
||||
@display_type = display_type.value
|
||||
@@ -57,7 +56,7 @@ class Origami::FoodCourtController < ApplicationController
|
||||
# @menus = Menu.all
|
||||
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
|
||||
# end
|
||||
if(params[:id][0,3] == "BKI")
|
||||
if params[:id].include? "BKI"
|
||||
@table_id = nil
|
||||
@table = nil
|
||||
@booking = Booking.find(params[:id])
|
||||
@@ -114,7 +113,7 @@ class Origami::FoodCourtController < ApplicationController
|
||||
order = Order.new
|
||||
order.source = params[:order_source]
|
||||
order.order_type = params[:order_type]
|
||||
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
|
||||
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
|
||||
|
||||
@@ -4,10 +4,8 @@ class Origami::HomeController < BaseOrigamiController
|
||||
|
||||
def index
|
||||
@webview = check_mobile
|
||||
|
||||
|
||||
@tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc')
|
||||
@rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc')
|
||||
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active.order('status desc')
|
||||
@rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active.order('status desc')
|
||||
@complete = Sale.completed_sale("cashier")
|
||||
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
|
||||
|
||||
@@ -23,9 +21,8 @@ class Origami::HomeController < BaseOrigamiController
|
||||
@print_settings = PrintSetting.get_precision_delimiter()
|
||||
@webview = check_mobile
|
||||
|
||||
|
||||
@tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc')
|
||||
@rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc')
|
||||
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
|
||||
@rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
|
||||
@complete = Sale.completed_sale("cashier")
|
||||
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
|
||||
|
||||
@@ -36,77 +33,44 @@ class Origami::HomeController < BaseOrigamiController
|
||||
@status_sale = ""
|
||||
@sale_array = Array.new
|
||||
|
||||
@membership = MembershipSetting.find_by_shop_code(@shop.shop_code)
|
||||
@payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'")
|
||||
@dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ")
|
||||
#@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'")
|
||||
@order_items = Array.new
|
||||
@shop = shop_detail
|
||||
@membership = MembershipSetting::MembershipSetting
|
||||
@payment_methods = PaymentMethodSetting.all
|
||||
@dining_booking = @dining.current_bookings
|
||||
|
||||
@order_items = Array.new
|
||||
@dining_booking.each do |booking|
|
||||
if booking.sale_id.nil? && booking.booking_status != 'moved'
|
||||
@order_items = Array.new
|
||||
# @assigned_order_items = Array.new
|
||||
if booking.booking_orders.empty?
|
||||
@booking = booking
|
||||
else
|
||||
booking.booking_orders.each do |booking_order|
|
||||
order = Order.find(booking_order.order_id)
|
||||
if (order.status == "new")
|
||||
@obj_order = order
|
||||
@customer = order.customer
|
||||
@date = order.created_at
|
||||
@booking= booking
|
||||
order.order_items.each do |item|
|
||||
@order_items.push(item)
|
||||
# assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id)
|
||||
# if !assigned_order_items.nil?
|
||||
# @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id})
|
||||
# end
|
||||
end
|
||||
@account_arr = Array.new
|
||||
if @customer.tax_profiles
|
||||
accounts = @customer.tax_profiles
|
||||
@account_arr =[]
|
||||
accounts.each do |acc|
|
||||
account = TaxProfile.find_by_id(acc)
|
||||
if !account.nil?
|
||||
@account_arr.push(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@status_order = 'order'
|
||||
else
|
||||
sale = Sale.find(booking.sale_id)
|
||||
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste'
|
||||
@sale_array.push(sale)
|
||||
if @status_order == 'order'
|
||||
@status_order = 'sale'
|
||||
end
|
||||
@booking= booking
|
||||
@date = sale.created_at
|
||||
@status_sale = 'sale'
|
||||
@obj_sale = sale
|
||||
@customer = sale.customer
|
||||
accounts = @customer.tax_profiles
|
||||
@account_arr =[]
|
||||
accounts.each do |acc|
|
||||
account = TaxProfile.find_by_id(acc)
|
||||
if !account.nil?
|
||||
@account_arr.push(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
@sale_taxes = []
|
||||
sale_taxes = SaleTax.where("sale_id = ?", sale.sale_id)
|
||||
if !sale_taxes.empty?
|
||||
sale_taxes.each do |sale_tax|
|
||||
@sale_taxes.push(sale_tax)
|
||||
end
|
||||
end
|
||||
if @obj_sale || @booking.blank?
|
||||
@booking = booking
|
||||
end
|
||||
|
||||
if booking.sale_id
|
||||
@obj_sale = booking.sale
|
||||
@sale_array.push(@obj_sale)
|
||||
@sale_taxes = @obj_sale.sale_taxes
|
||||
@status_sale = 'sale'
|
||||
else
|
||||
@order_items += booking.order_items
|
||||
@obj_order = booking.orders.first
|
||||
end
|
||||
|
||||
if @obj_sale || @customer.blank?
|
||||
if obj = @obj_sale || @obj_order
|
||||
@customer = obj.customer
|
||||
@date = obj.created_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @obj_sale
|
||||
@status_order = 'sale'
|
||||
else
|
||||
@status_order = 'order'
|
||||
end
|
||||
|
||||
if (@obj_sale || @account_arr.blank?) && @customer
|
||||
@account_arr = TaxProfile.find_by(id: @customer.tax_profiles)
|
||||
end
|
||||
end
|
||||
|
||||
#for bank integration
|
||||
@checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
class Origami::HomeController < ApplicationController
|
||||
def index
|
||||
if params[:booking_id] != nil
|
||||
type=params[:booking_id].split('-')[0];
|
||||
# Sale
|
||||
if type == "SAL"
|
||||
if params[:booking_id].include? "SAL"
|
||||
@selected_item = Sale.find(params[:booking_id])
|
||||
@selected_item_type="Sale"
|
||||
# Booking
|
||||
@@ -25,9 +24,8 @@ class Origami::HomeController < ApplicationController
|
||||
|
||||
def selection(selected_id, is_ajax)
|
||||
str = []
|
||||
type=selected_id.split('-')[0];
|
||||
# Sale
|
||||
if type == "SAL"
|
||||
if selected_id.include? "SAL"
|
||||
@order_details = SaleItem.get_order_items_details(params[:booking_id])
|
||||
@order_details.each do |ord_detail|
|
||||
str.push(ord_detail)
|
||||
@@ -48,9 +46,7 @@ class Origami::HomeController < ApplicationController
|
||||
end
|
||||
|
||||
def update_sale_by_customer
|
||||
|
||||
id = params[:sale_id][0,3]
|
||||
if(id == "SAL")
|
||||
if id.inlude? "SAL"
|
||||
sale = Sale.find(params[:sale_id])
|
||||
else
|
||||
sale = Order.find(params[:sale_id])
|
||||
|
||||
@@ -10,121 +10,73 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
member_info = nil
|
||||
|
||||
# For Cashier by Zone
|
||||
booking = Booking.find_by_sale_id(sale_id)
|
||||
# if bookings.count > 1
|
||||
# # for Multiple Booking
|
||||
# table = DiningFacility.find(bookings[0].dining_facility_id)
|
||||
# else
|
||||
# table = DiningFacility.find(bookings[0].dining_facility_id)
|
||||
# end
|
||||
shift = ShiftSale.current_open_shift(current_user)
|
||||
if !shift.nil?
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
else
|
||||
if booking.dining_facility_id.to_i > 0
|
||||
table = DiningFacility.find(booking.dining_facility_id)
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
||||
else
|
||||
shift = ShiftSale.find(sale_data.shift_sale_id)
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
booking = sale_data.booking
|
||||
|
||||
if current_user.role == 'cashier'
|
||||
cashier_terminal = current_user.cashier_terminal
|
||||
elsif booking.dining_facility
|
||||
cashier_terminal = booking.cashier_terminal_by_dining_facility
|
||||
end
|
||||
|
||||
cashier_terminal ||= sale_data.cashier_terminal_by_shift_sale
|
||||
|
||||
customer = sale_data.customer
|
||||
|
||||
#record for sale audit
|
||||
action_by = current_user.name
|
||||
type = "FIRST_BILL"
|
||||
|
||||
remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}"
|
||||
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
|
||||
# get member information
|
||||
rebate = MembershipSetting.find_by_rebate(1)
|
||||
if customer.membership_id != nil && rebate
|
||||
# member_info = Customer.get_member_account(customer)
|
||||
# current_balance = SaleAudit.paymal_search(sale_id)
|
||||
current_balance = 0
|
||||
end
|
||||
|
||||
# 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)
|
||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
|
||||
|
||||
other_amount = SaleItem.calculate_other_charges(sale_items)
|
||||
|
||||
print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
|
||||
#TODO :: KBZPAY ( QR )
|
||||
# On/Off setting ( show or not qr )
|
||||
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
|
||||
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
|
||||
|
||||
status = false
|
||||
qr = nil
|
||||
|
||||
if !kbz_pay_method.nil?
|
||||
if kbz_pay_method.is_active == true
|
||||
sale_payment = SalePayment.new
|
||||
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
|
||||
|
||||
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
|
||||
end
|
||||
end
|
||||
|
||||
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
||||
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
||||
# Print for First Bill to Customer
|
||||
unique_code = "ReceiptBillPdf"
|
||||
print_settings = PrintSetting.all
|
||||
if !print_settings.nil?
|
||||
print_settings.each do |setting|
|
||||
if setting.unique_code == 'ReceiptBillPdf'
|
||||
unique_code = "ReceiptBillPdf"
|
||||
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
||||
unique_code = "ReceiptBillStarPdf"
|
||||
end
|
||||
end
|
||||
end
|
||||
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil)
|
||||
|
||||
if !receipt_bill_a5_pdf.empty?
|
||||
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
||||
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
||||
if receipt_bilA5[1] == '1'
|
||||
unique_code = "ReceiptBillA5Pdf"
|
||||
else
|
||||
unique_code = unique_code#{}"ReceiptBillPdf"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
result = {
|
||||
:filepath => filename,
|
||||
:printer_model => print_settings.brand_name,
|
||||
:printer_url => print_settings.api_settings
|
||||
}
|
||||
|
||||
#shop detail
|
||||
## shop_detail = @shop
|
||||
# customer= Customer.where('customer_id=' +.customer_id)
|
||||
customer = Customer.find(sale_data.customer_id)
|
||||
# rounding adjustment
|
||||
if @shop.is_rounding_adj
|
||||
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
||||
rounding_adj = new_total - sale_data.grand_total
|
||||
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
|
||||
end
|
||||
#end rounding adjustment
|
||||
#record for sale audit
|
||||
action_by = current_user.name
|
||||
type = "FIRST_BILL"
|
||||
# status, qr = KbzPay.query(sale_payment.sale_payment_id)
|
||||
|
||||
remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}"
|
||||
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
|
||||
# get member information
|
||||
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
|
||||
if customer.membership_id != nil && rebate
|
||||
# member_info = Customer.get_member_account(customer)
|
||||
# current_balance = SaleAudit.paymal_search(sale_id)
|
||||
current_balance = 0
|
||||
end
|
||||
# get printer info
|
||||
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_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)
|
||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
|
||||
|
||||
other_amount = SaleItem.calculate_other_charges(sale_items)
|
||||
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
|
||||
#TODO :: KBZPAY ( QR )
|
||||
# On/Off setting ( show or not qr )
|
||||
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
|
||||
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => @shop.shop_code).last
|
||||
|
||||
status = false
|
||||
qr = nil
|
||||
|
||||
if !kbz_pay_method.nil?
|
||||
if kbz_pay_method.is_active == true
|
||||
sale_payment = SalePayment.new
|
||||
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
|
||||
|
||||
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
|
||||
end
|
||||
end
|
||||
|
||||
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, @shop, "Frt",current_balance,nil,other_amount,nil,nil,nil,nil)
|
||||
|
||||
result = {
|
||||
:filepath => filename,
|
||||
:printer_model => print_settings.brand_name,
|
||||
:printer_url => print_settings.api_settings
|
||||
}
|
||||
|
||||
# status, qr = KbzPay.query(sale_payment.sale_payment_id)
|
||||
|
||||
# Mobile Print
|
||||
render :json => result.to_json
|
||||
# Mobile Print
|
||||
render :json => result.to_json
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -138,25 +90,9 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
latest_order_no = nil
|
||||
is_kbz = params[:is_kbz]
|
||||
|
||||
if(Sale.exists?(sale_id))
|
||||
saleObj = Sale.find(sale_id)
|
||||
if saleObj = Sale.find(sale_id)
|
||||
sale_items = SaleItem.get_all_sale_items(sale_id)
|
||||
#shop_detail = @shop
|
||||
# rounding adjustment
|
||||
if !path.include? ("credit_payment")
|
||||
if @shop.is_rounding_adj
|
||||
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
||||
rounding_adj = new_total - saleObj.grand_total
|
||||
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
|
||||
end
|
||||
end
|
||||
#end rounding adjustment
|
||||
|
||||
# if pay_from = 'kbzpay'
|
||||
# salePayment = SalePayment.find(sale_payment_id)
|
||||
# salePayment.process_kbz_payment(salePayment.sale_id, sale_data.grand_total, cash, 'paid')
|
||||
# else
|
||||
sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last
|
||||
if is_kbz == 'false'
|
||||
Rails.logger.info '################ CASH PAYMENT #################'
|
||||
sale_payment = SalePayment.new
|
||||
@@ -166,134 +102,110 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
||||
end
|
||||
else
|
||||
sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last
|
||||
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
|
||||
end
|
||||
|
||||
# end
|
||||
|
||||
if !path.include? ("credit_payment")
|
||||
rebate_amount = nil
|
||||
|
||||
# For Cashier by Zone
|
||||
# bookings = Booking.where("sale_id='#{sale_id}'")
|
||||
bookings = saleObj.bookings[0]
|
||||
booking = saleObj.booking
|
||||
|
||||
shift = ShiftSale.current_open_shift(current_user)
|
||||
if !shift.nil?
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
else
|
||||
if bookings.dining_facility_id.to_i > 0
|
||||
table = bookings.dining_facility
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
||||
if current_user.role == 'cashier'
|
||||
cashier_terminal = current_user.cashier_terminal
|
||||
elsif booking.dining_facility
|
||||
cashier_terminal = booking.cashier_terminal_by_dining_facility
|
||||
end
|
||||
|
||||
type = 'payment'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
else
|
||||
shift = ShiftSale.find(saleObj.shift_sale_id)
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
end
|
||||
cashier_terminal ||= saleObj.cashier_terminal_by_shift_sale
|
||||
|
||||
if booking.dining_facility
|
||||
ActionCable.server.broadcast(
|
||||
"order_channel",
|
||||
table: booking.dining_facility,
|
||||
type: 'payment',
|
||||
from: getCloudDomain
|
||||
)
|
||||
end
|
||||
|
||||
# For Print
|
||||
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
||||
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
||||
unique_code = "ReceiptBillPdf"
|
||||
print_settings = PrintSetting.all
|
||||
if !print_settings.nil?
|
||||
print_settings.each do |setting|
|
||||
if setting.unique_code == 'ReceiptBillPdf'
|
||||
unique_code = "ReceiptBillPdf"
|
||||
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
||||
unique_code = "ReceiptBillStarPdf"
|
||||
end
|
||||
end
|
||||
if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
|
||||
unique_code = "ReceiptBillA5Pdf"
|
||||
else
|
||||
unique_code = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code
|
||||
end
|
||||
|
||||
customer = saleObj.customer
|
||||
|
||||
# get member information
|
||||
rebate = MembershipSetting.find_by_rebate(1)
|
||||
credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
|
||||
|
||||
if customer.membership_id != nil && rebate && credit_data.nil?
|
||||
member_info = Customer.get_member_account(customer)
|
||||
|
||||
if member_info["status"] == true
|
||||
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
|
||||
current_balance = SaleAudit.paymal_search(sale_id)
|
||||
end
|
||||
end
|
||||
|
||||
#orders print out
|
||||
if type == "quick_service"
|
||||
if booking.dining_facility_id.present?
|
||||
table_id = booking.dining_facility_id
|
||||
else
|
||||
table_id = 0
|
||||
end
|
||||
|
||||
if !receipt_bill_a5_pdf.empty?
|
||||
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
||||
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
||||
if receipt_bilA5[1] == '1'
|
||||
unique_code = "ReceiptBillA5Pdf"
|
||||
# else
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
|
||||
if !latest_order.nil?
|
||||
latest_order_no = latest_order.order_id
|
||||
end
|
||||
|
||||
customer= Customer.find(saleObj.customer_id)
|
||||
booking.booking_orders.each do |order|
|
||||
# Order.pay_process_order_queue(order.order_id, table_id)
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.pay_process_order_queue(order.order_id, table_id)
|
||||
|
||||
# get member information
|
||||
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
|
||||
credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
|
||||
|
||||
if customer.membership_id != nil && rebate && credit_data.nil?
|
||||
member_info = Customer.get_member_account(customer)
|
||||
|
||||
if member_info["status"] == true
|
||||
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
|
||||
current_balance = SaleAudit.paymal_search(sale_id)
|
||||
end
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
||||
end
|
||||
|
||||
#orders print out
|
||||
if type == "quick_service"
|
||||
booking = Booking.find_by_sale_id(sale_id)
|
||||
if booking.dining_facility_id.to_i>0
|
||||
table_id = booking.dining_facility_id
|
||||
else
|
||||
table_id = 0
|
||||
end
|
||||
|
||||
latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
|
||||
if !latest_order.nil?
|
||||
latest_order_no = latest_order.order_id
|
||||
end
|
||||
|
||||
booking.booking_orders.each do |order|
|
||||
# Order.pay_process_order_queue(order.order_id, table_id)
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.pay_process_order_queue(order.order_id, table_id)
|
||||
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
||||
end
|
||||
end
|
||||
|
||||
#for card sale data
|
||||
card_data = Array.new
|
||||
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
|
||||
if !card_sale_trans_ref_no.nil?
|
||||
card_sale_trans_ref_no.each do |cash_sale_trans|
|
||||
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
|
||||
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
|
||||
card_no = cash_sale_trans.pan.last(4)
|
||||
card_no = card_no.rjust(19,"**** **** **** ")
|
||||
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
|
||||
end
|
||||
end
|
||||
|
||||
#for card sale data
|
||||
card_data = Array.new
|
||||
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
|
||||
if !card_sale_trans_ref_no.nil?
|
||||
card_sale_trans_ref_no.each do |cash_sale_trans|
|
||||
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
|
||||
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
|
||||
card_no = cash_sale_trans.pan.last(4)
|
||||
card_no = card_no.rjust(19,"**** **** **** ")
|
||||
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
|
||||
end
|
||||
end
|
||||
#card_balance amount for Paymal payment
|
||||
card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
|
||||
|
||||
#card_balance amount for Paymal payment
|
||||
card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id)
|
||||
# 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(saleObj.sale_items)
|
||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
|
||||
other_amount = SaleItem.calculate_other_charges(sale_items)
|
||||
|
||||
# get printer info
|
||||
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
|
||||
# Calculate Food and Beverage Total
|
||||
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
|
||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
|
||||
other_amount = SaleItem.calculate_other_charges(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_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref)
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
|
||||
|
||||
#end
|
||||
end
|
||||
logger.debug 'saleObj++++++++++++++++++++++++++'
|
||||
logger.debug saleObj.to_json
|
||||
if !saleObj.nil?
|
||||
# InventoryJob.perform_now(self.id)
|
||||
# InventoryDefinition.calculate_product_count(saleObj)
|
||||
@@ -330,7 +242,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
end
|
||||
|
||||
if path.include? ("credit_payment")
|
||||
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id)
|
||||
@sale_payment = SalePayment.where(sale_id: sale_id, payment_method: 'creditnote').select("SUM(payment_amount) as payment_amount")
|
||||
end
|
||||
|
||||
@member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code)
|
||||
@@ -381,7 +293,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
|
||||
# @shop = shop_detail #show shop info
|
||||
|
||||
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")
|
||||
@customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"])
|
||||
|
||||
saleObj = Sale.find(sale_id)
|
||||
|
||||
@@ -636,11 +548,14 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
current_balance = nil
|
||||
order_source = params[:type]
|
||||
|
||||
if(Sale.exists?(sale_id))
|
||||
if Sale.exists?(sale_id)
|
||||
saleObj = Sale.find(sale_id)
|
||||
#calculate cash acmount
|
||||
cash = saleObj.total_amount
|
||||
|
||||
sale_payment = SalePayment.new
|
||||
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
|
||||
|
||||
if saleObj.discount_type == "member_discount"
|
||||
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
||||
saleObj.compute_by_sale_items(0, nil, order_source)
|
||||
@@ -648,9 +563,6 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
|
||||
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
||||
|
||||
sale_payment = SalePayment.new
|
||||
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
|
||||
|
||||
bookings = Booking.where("sale_id='#{sale_id}'")
|
||||
if bookings[0].dining_facility_id.to_i > 0
|
||||
table = DiningFacility.find(bookings[0].dining_facility_id)
|
||||
@@ -659,8 +571,6 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
end
|
||||
|
||||
|
||||
|
||||
# For Cashier by Zone
|
||||
bookings = Booking.where("sale_id='#{sale_id}'")
|
||||
|
||||
@@ -795,7 +705,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
# get printer info
|
||||
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
|
||||
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)
|
||||
|
||||
@@ -817,8 +727,10 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
sale_id = params[:sale_id]
|
||||
order_source = params[:cashier_type]
|
||||
tax_type = params[:tax_type]
|
||||
remark = "Change tax to #{tax_type.upcase} for Sale ID #{sale_id} By #{current_login_employee.name}"
|
||||
sale = Sale.find(sale_id)
|
||||
sale.compute_by_sale_items(sale.total_discount, nil, order_source, tax_type)
|
||||
SaleAudit.record_audit_change_tax(sale_id,remark,current_login_employee.name)
|
||||
|
||||
render json: JSON.generate({:status => true})
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ class Origami::PendingOrderController < BaseOrigamiController
|
||||
|
||||
def show
|
||||
id = params[:sale_id]
|
||||
if id.start_with?("SAL")
|
||||
if id.include? "SAL"
|
||||
@sale = Sale.find(id)
|
||||
if @sale.sale_status == "new"
|
||||
@bookings = @sale.bookings.first
|
||||
@@ -22,7 +22,7 @@ class Origami::PendingOrderController < BaseOrigamiController
|
||||
else
|
||||
redirect_to "/origami/#{params[:type]}" and return
|
||||
end
|
||||
elsif (id.start_with?("BKI") || id.start_with?("CBKI"))
|
||||
elsif id.include? "BKI"
|
||||
@bookings = Booking.find(id)
|
||||
@order = @bookings.orders.where(status: "new").first
|
||||
@order_items = @bookings.order_items
|
||||
|
||||
@@ -10,24 +10,27 @@ class Origami::QuickServiceController < ApplicationController
|
||||
def index
|
||||
today = DateTime.now
|
||||
day = Date.today.wday
|
||||
# if params[:menu] == "true"
|
||||
|
||||
@menus = []
|
||||
@menu = []
|
||||
@zone = Zone.all
|
||||
@customer = Customer.all
|
||||
@tables = Table.all.active.order('status desc')
|
||||
@rooms = Room.all.active.order('status desc')
|
||||
@tables = Table.active.order('status desc')
|
||||
@rooms = Room.active.order('status desc')
|
||||
@cashier_type = "quick_service"
|
||||
display_type = Lookup.find_by_lookup_type("display_type")
|
||||
if !display_type.nil? && display_type.value.to_i ==2
|
||||
if !display_type.nil? && display_type.value.to_i == 2
|
||||
@display_type = display_type.value
|
||||
else
|
||||
@display_type = nil
|
||||
end
|
||||
|
||||
#checked quick_service only
|
||||
@quick_service_only = false
|
||||
lookup_dine_in = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quickservice_add_order')
|
||||
@quick_service_only = Lookup.collection_of('quickservice_add_order').any? { |x| x == ["quickserviceaddorder", "1"] }
|
||||
|
||||
lookup_dine_in = Lookup.collection_of('quickservice_add_order')
|
||||
# puts 'lookup_dine_in!!!!'
|
||||
# puts lookup_dine_in
|
||||
if !lookup_dine_in.empty?
|
||||
lookup_dine_in.each do |dine_in|
|
||||
if dine_in[0].downcase == "quickserviceaddorder"
|
||||
@@ -37,7 +40,23 @@ class Origami::QuickServiceController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
divided_value =0
|
||||
exclusive =0
|
||||
tax_profiles = TaxProfile.where(group_type: "quick_service")
|
||||
if !tax_profiles.empty?
|
||||
tax_profiles.each do |tax|
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
tax_incl_exec = "inclusive"
|
||||
rate = tax.rate
|
||||
divided_value += (100 + rate)/rate
|
||||
else
|
||||
exclusive +=tax.rate / 100
|
||||
end
|
||||
end
|
||||
end
|
||||
@inclusive_tax =divided_value
|
||||
@exclusive_tax =exclusive
|
||||
render "origami/addorders/detail"
|
||||
end
|
||||
|
||||
@@ -52,7 +71,7 @@ class Origami::QuickServiceController < ApplicationController
|
||||
# @menus = Menu.all
|
||||
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
|
||||
# end
|
||||
if(params[:id][0,3] == "BKI")
|
||||
if params[:id].include? "BKI"
|
||||
@table_id = nil
|
||||
@table = nil
|
||||
@booking = Booking.find(params[:id])
|
||||
@@ -109,7 +128,7 @@ class Origami::QuickServiceController < ApplicationController
|
||||
order = Order.new
|
||||
order.source = params[:order_source]
|
||||
order.order_type = params[:order_type]
|
||||
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
|
||||
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
|
||||
|
||||
@@ -18,96 +18,78 @@ class Origami::RequestBillsController < ApplicationController
|
||||
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.where("shop_code='#{@shop.shop_code}'").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_and_shop_code(unique_code,@shop.shop_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)
|
||||
if booking.sale_id.nil?
|
||||
if sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
|
||||
# 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
|
||||
|
||||
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 ["quick_service", "cashier"].include? order.source
|
||||
ActionCable.server.broadcast "bill_channel", table: table, from: from
|
||||
end
|
||||
|
||||
unless ["quick_service", "food_court"].include? order.source
|
||||
#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
|
||||
@status = true
|
||||
sale_id = sale_data.sale_id
|
||||
else
|
||||
@status = false
|
||||
sale_id = nil
|
||||
end
|
||||
else
|
||||
@status = true
|
||||
sale_id = booking.sale_id
|
||||
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
|
||||
# # 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)
|
||||
if ["quick_service", "food_court"].include? order.source
|
||||
result = {:status=> @status, :data => sale_data.sale_id }
|
||||
render :json => result.to_json
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -27,52 +27,33 @@ class Origami::SalesController < BaseOrigamiController
|
||||
dining = params[:dining_id]
|
||||
sale_id = params[:sale_id]
|
||||
tax_type = params[:tax_type]
|
||||
sale_data = []
|
||||
table = DiningFacility.find(dining)
|
||||
existing_booking = Booking.find_by_sale_id(sale_id)
|
||||
table.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ").each do |booking|
|
||||
if booking.sale_id.nil?
|
||||
order_array = []
|
||||
booking.booking_orders.each do |booking_order|
|
||||
|
||||
booking.booking_status = 'moved'
|
||||
order = Order.find(booking_order.order_id)
|
||||
order.status = 'billed'
|
||||
order.order_items.each do |item|
|
||||
item.order_item_status = 'billed'
|
||||
end
|
||||
# create sale item
|
||||
saleobj = Sale.find(sale_id)
|
||||
order.order_items.each do |orer_item|
|
||||
saleobj.add_item (orer_item)
|
||||
if !orer_item.set_menu_items.nil?
|
||||
saleobj.add_sub_item(orer_item.set_menu_items)
|
||||
end
|
||||
sale_data.push(orer_item)
|
||||
end
|
||||
Sale.transaction do
|
||||
table = DiningFacility.find(dining)
|
||||
booking = table.current_checkin_booking
|
||||
|
||||
# Re-compute for add
|
||||
saleobj.compute(order.source,tax_type)
|
||||
saleobj.save
|
||||
order.save
|
||||
booking.save
|
||||
sale = Sale.find(sale_id)
|
||||
existing = sale.booking
|
||||
|
||||
order_array.push(order.order_id)
|
||||
end
|
||||
sale.sale_items << booking.order_items.to_sale_items
|
||||
sale.orders << booking.orders
|
||||
|
||||
receipt_no = Sale.find(sale_id).receipt_no
|
||||
action_by = current_user.name
|
||||
type = "ADD_TO_EXISTING"
|
||||
sale.compute(booking.orders[0].source, tax_type)
|
||||
|
||||
remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no} in #{table.name}"
|
||||
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
|
||||
type = "ADD_TO_EXISTING"
|
||||
receipt_no = sale.receipt_no
|
||||
action_by = current_user.name
|
||||
order_ids = booking.orders.map(&:order_id)
|
||||
|
||||
booking_order = BookingOrder.where('booking_id=?',booking)
|
||||
booking_order.each do |bo|
|
||||
bo.booking_id = existing_booking.booking_id
|
||||
bo.save
|
||||
end
|
||||
end
|
||||
remark = "#{action_by} add to existing order #{order_ids.to_s} to Receipt No=>#{receipt_no} in #{table.name}"
|
||||
sale_audit = SaleAudit.record_audit_sale(sale_id, remark, action_by, type)
|
||||
|
||||
booking.orders.update_all(status: "billed")
|
||||
booking.order_items.update_all(order_item_status: "billed")
|
||||
BookingOrder.where(booking_id: booking.booking_id).update_all(booking_id: existing)
|
||||
|
||||
booking.booking_status = "moved"
|
||||
booking.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,377 +16,118 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
@sale_data = Array.new
|
||||
@current_user = current_user
|
||||
|
||||
table_bookings = Booking.where("dining_facility_id = #{dining_id} and sale_id IS NOT NULL")
|
||||
if !table_bookings.nil?
|
||||
table_bookings.each do |table_booking|
|
||||
if table_booking.sale.sale_status != 'waste' && table_booking.sale.sale_status != 'spoile'
|
||||
@sale_data.push(table_booking.sale)
|
||||
end
|
||||
end
|
||||
end
|
||||
@sale_data = @table.current_sales
|
||||
|
||||
if @booking
|
||||
@booking.booking_orders.each do |booking_order|
|
||||
arr_order_items = Array.new
|
||||
@order = Order.find(booking_order.order_id)
|
||||
if (@order.status == "new")
|
||||
@orders.push(@order)
|
||||
@orders = @booking.orders
|
||||
@order = @orders[0]
|
||||
@order_items = []
|
||||
order_items = []
|
||||
|
||||
@order.order_items.each do |item|
|
||||
if !item.set_menu_items.nil?
|
||||
instance_item_sets = JSON.parse(item.set_menu_items)
|
||||
arr_instance_item_sets = Array.new
|
||||
instance_item_sets.each do |instance_item|
|
||||
item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
|
||||
item.price = item.price.to_f + instance_item["price"].to_f
|
||||
arr_instance_item_sets.push(item_instance_name)
|
||||
end
|
||||
item.set_menu_items = arr_instance_item_sets
|
||||
end
|
||||
@booking.order_items.each do |item|
|
||||
if item.set_menu_items.present?
|
||||
set_menu_items = JSON.parse(item.set_menu_items)
|
||||
item.set_menu_items = set_menu_items.map { |x| x["item_instance_name"] }
|
||||
item.price = item.price + set_menu_items.inject(0.0) { |sum, x| sum + x["item_instance_name"].to_f }
|
||||
end
|
||||
|
||||
arr_item = Hash.new
|
||||
if item.qty.to_i > 1
|
||||
i = 1
|
||||
while i <= item.qty.to_i do
|
||||
arr_item = {'order_items_id' => item.order_items_id,
|
||||
'order_id' => item.order_id,
|
||||
'order_item_status' => item.order_item_status,
|
||||
'item_order_by' => item.item_order_by,
|
||||
'item_code' => item.item_code,
|
||||
'item_instance_code' => item.item_instance_code,
|
||||
'item_name' => item.item_name,
|
||||
'alt_name' => item.alt_name,
|
||||
'account_id' => item.account_id,
|
||||
'qty' => '1.0',
|
||||
'price' => item.price,
|
||||
'remark' => item.remark,
|
||||
'options' => item.options,
|
||||
'set_menu_items' => item.set_menu_items,
|
||||
'taxable' => item.taxable,
|
||||
'completed_by' => item.completed_by,
|
||||
'created_at' => item.created_at,
|
||||
'updated_at' => item.updated_at}
|
||||
i += 1
|
||||
@order_items.push({@order.order_id => arr_item})
|
||||
arr_order_items.push(arr_item)
|
||||
end
|
||||
else
|
||||
arr_order_items.push(item)
|
||||
@order_items.push({@order.order_id => item})
|
||||
end
|
||||
end
|
||||
@order_items.push({'all_order' => arr_order_items})
|
||||
end
|
||||
end
|
||||
else
|
||||
@booking = nil
|
||||
end
|
||||
@order_items += item.qty.to_i.times.map { i = item.as_json; i["qty"] = 1; order_items << i; { item.order_id => i } }
|
||||
end
|
||||
|
||||
@order_items << { 'all_order' => order_items }
|
||||
else
|
||||
@booking = nil
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
cashier_type = params[:cashier_type]
|
||||
dining_id = params[:dining_id]
|
||||
order_ids = params[:order_ids]
|
||||
arr_order_ids = nil
|
||||
if !params[:arr_order_ids].nil?
|
||||
arr_order_ids = JSON.parse(params[:arr_order_ids])
|
||||
end
|
||||
orders = nil
|
||||
if !params[:orders].empty?
|
||||
orders = JSON.parse(params[:orders])
|
||||
end
|
||||
order_items = nil
|
||||
if !params[:order_items].empty?
|
||||
order_items = JSON.parse(params[:order_items])
|
||||
end
|
||||
arr_order_ids = JSON.parse(params[:arr_order_ids]) if params[:arr_order_ids].present?
|
||||
orders = JSON.parse(params[:orders]) if params[:orders].present?
|
||||
order_items = JSON.parse(params[:order_items]) if params[:order_items].present?
|
||||
|
||||
status = false
|
||||
if !ShiftSale.current_shift.nil?
|
||||
#create Bill by Booking ID
|
||||
table = 0
|
||||
if !params[:booking_id].empty?
|
||||
booking = Booking.find(params[:booking_id])
|
||||
# for Multiple Cashier by Zone
|
||||
if booking.dining_facility_id.to_i>0
|
||||
table = DiningFacility.find(booking.dining_facility_id)
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
else
|
||||
table = nil
|
||||
cashier_zone = nil
|
||||
end
|
||||
#create Bill by Booking ID
|
||||
table = DiningFacility.find_by(id: params[:dining_id]) if params[:dining_id].present?
|
||||
|
||||
# shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
|
||||
# get_cashier_by_terminal = Employee.find(shift_by_terminal.employee_id)
|
||||
|
||||
if sale_data = booking.sale
|
||||
status = true
|
||||
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type,params[:current_checkin_induties_count])
|
||||
status = true
|
||||
Booking.transaction do
|
||||
if params[:booking_id].present?
|
||||
booking = Booking.find(params[:booking_id])
|
||||
else
|
||||
status = false
|
||||
end
|
||||
else
|
||||
if params[:type] == "Table"
|
||||
type = "TableBooking"
|
||||
else
|
||||
type = "RoomBooking"
|
||||
end
|
||||
type = "TableBooking" if params[:type] == "Table"
|
||||
type ||= "RoomBooking"
|
||||
|
||||
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type,
|
||||
:checkin_at => Time.now.utc, :checkin_by => current_user.name,
|
||||
:booking_status => "assign",
|
||||
:shop_code =>@shop.shop_code})
|
||||
split_orders = []
|
||||
new_order = nil
|
||||
|
||||
if !orders.nil?
|
||||
orders.each do |order|
|
||||
BookingOrder.find_by_order_id(order["id"]).delete
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order["id"]})
|
||||
booking = Booking.create({:dining_facility_id => table.id, :type => type, :checkin_at => Time.now.utc, :checkin_by => current_user.name, :booking_status => "assign" })
|
||||
|
||||
if orders.present?
|
||||
split_orders += orders.map { |x| x["id"] }
|
||||
end
|
||||
elsif !order_items.nil?
|
||||
order_item_count = 0
|
||||
order_id_count = 0
|
||||
order_id = nil
|
||||
|
||||
arr_order_ids.each do |order|
|
||||
order.each do |odr|
|
||||
data = Order.find(odr[0])
|
||||
if data.order_items.count == odr[1]
|
||||
order_id = odr[0]
|
||||
order_id_count += 1
|
||||
if order_items.present?
|
||||
order_items = order_items.inject([]) do |arr, v|
|
||||
v["qty"] = v["qty"].to_i
|
||||
if i = arr.find { |x| x["id"] == v["id"] }
|
||||
i["qty"] = i["qty"] + v["qty"]
|
||||
else
|
||||
order_item_count += 1
|
||||
arr << v
|
||||
end
|
||||
arr
|
||||
end
|
||||
|
||||
Order.includes(:order_items).where(order_id: order_ids).each do |order|
|
||||
if order.order_items.any? { |x| order_items.none? { |y| x.order_items_id == y["id"] && x.qty == y["qty"] } }
|
||||
new_order ||= Order.create({ source: "cashier", order_type: order.order_type, customer_id: order.customer_id, item_count: order_items.length, waiters: current_user.name })
|
||||
order.order_items.each do |order_item|
|
||||
if split_item = order_items.find { |x| x["id"] == order_item.order_items_id }
|
||||
if split_item["qty"] == order_item.qty
|
||||
new_order.order_items << order_item
|
||||
else
|
||||
order_item.qty = order_item.qty - split_item["qty"]
|
||||
order_item.save
|
||||
order_item_dup = order_item.dup
|
||||
order_item_dup.qty = split_item["qty"]
|
||||
new_order.order_items << order_item_dup
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
split_orders << order
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if !order_id.nil?
|
||||
if order_id_count > 1
|
||||
|
||||
updated_order_id = Array.new
|
||||
arr_order_ids.each do |order|
|
||||
order.each do |odr|
|
||||
data = Order.find(odr[0])
|
||||
if data.order_items.count != odr[1]
|
||||
updated_order_id.push(odr[0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if !updated_order_id.empty?
|
||||
order_ids.each do |odr_id|
|
||||
unless updated_order_id.include?(odr_id)
|
||||
BookingOrder.find_by_order_id(odr_id).delete
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
|
||||
end
|
||||
end
|
||||
|
||||
order_items.each do |order_item|
|
||||
if updated_order_id.include?(order_item["order_id"])
|
||||
update_order_item(order_id, order_item)
|
||||
end
|
||||
end
|
||||
else
|
||||
order_ids.each do |odr_id|
|
||||
new_order_status = true
|
||||
order_items.each do |order_item|
|
||||
orderItem = OrderItem.find_by_order_id(odr_id)
|
||||
if !orderItem.nil?
|
||||
if order_item["id"] == orderItem.order_items_id
|
||||
if orderItem.qty.to_f != order_item['qty'].to_f
|
||||
new_order_status = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if new_order_status
|
||||
BookingOrder.find_by_order_id(odr_id).delete
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
|
||||
else
|
||||
customer = Customer.find(params[:customer_id])
|
||||
order_type = "dine_in"
|
||||
if !customer.nil?
|
||||
if customer.customer_type == "Takeaway"
|
||||
order_type = "takeaway"
|
||||
elsif customer.customer_type == "Delivery"
|
||||
order_type = "delivery"
|
||||
end
|
||||
end
|
||||
|
||||
# begin
|
||||
order = create_order(params,order_type,order_items.count,current_user)
|
||||
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
|
||||
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order.order_id, order_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
new_order_status = true
|
||||
order_items.each do |order_item|
|
||||
orderItem = OrderItem.find(order_item["id"])
|
||||
if !orderItem.nil?
|
||||
if order_item["id"] == orderItem.order_items_id
|
||||
if orderItem.qty.to_f != order_item['qty'].to_f
|
||||
new_order_status = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if new_order_status
|
||||
BookingOrder.find_by_order_id(order_id).delete
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order_id, order_item)
|
||||
end
|
||||
else
|
||||
customer = Customer.find(params[:customer_id])
|
||||
order_type = "dine_in"
|
||||
if !customer.nil?
|
||||
if customer.customer_type == "Takeaway"
|
||||
order_type = "takeaway"
|
||||
elsif customer.customer_type == "Delivery"
|
||||
order_type = "delivery"
|
||||
end
|
||||
end
|
||||
|
||||
# begin
|
||||
order = create_order(params,order_type,order_items.count,current_user)
|
||||
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
|
||||
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order.order_id, order_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if order_ids.count == 1 && order_item_count == 1
|
||||
if order_id_count == 0
|
||||
customer = Customer.find(params[:customer_id])
|
||||
order_type = "dine_in"
|
||||
if !customer.nil?
|
||||
if customer.customer_type == "Takeaway"
|
||||
order_type = "takeaway"
|
||||
elsif customer.customer_type == "Delivery"
|
||||
order_type = "delivery"
|
||||
end
|
||||
end
|
||||
|
||||
# begin
|
||||
order = create_order(params,order_type,order_items.count,current_user)
|
||||
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
|
||||
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order.order_id, order_item)
|
||||
end
|
||||
else
|
||||
BookingOrder.find_by_order_id(order_ids[0]).delete
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order_ids[0], order_item)
|
||||
end
|
||||
end
|
||||
else
|
||||
customer = Customer.find(params[:customer_id])
|
||||
order_type = "dine_in"
|
||||
if !customer.nil?
|
||||
if customer.customer_type == "Takeaway"
|
||||
order_type = "takeaway"
|
||||
elsif customer.customer_type == "Delivery"
|
||||
order_type = "delivery"
|
||||
end
|
||||
end
|
||||
|
||||
# begin
|
||||
order = create_order(params,order_type,order_items.count,current_user)
|
||||
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
|
||||
|
||||
order_items.each do |order_item|
|
||||
update_order_item(order.order_id, order_item)
|
||||
end
|
||||
end
|
||||
if new_order.present?
|
||||
booking.orders << new_order
|
||||
end
|
||||
end
|
||||
|
||||
if sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type ,params[:current_checkin_induties_count])
|
||||
status = true
|
||||
end
|
||||
end
|
||||
|
||||
Promotion.promo_activate(sale_data)
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "bill_channel",table: table,from:from
|
||||
|
||||
render :json => { status: status }
|
||||
else
|
||||
render :json => { status: false, error_message: 'No Current Open Shift!'}
|
||||
end
|
||||
end
|
||||
|
||||
def create_order(params,order_type,items_count,current_user)
|
||||
order = Order.new
|
||||
order.source = "cashier"
|
||||
order.order_type = order_type
|
||||
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
|
||||
order.item_count = items_count
|
||||
order.status = "new"
|
||||
order.table_id = params[:dining_id] # this is dining facilities's id
|
||||
order.waiters = current_user.name
|
||||
order.employee_name = current_user.name
|
||||
order.guest_info = nil
|
||||
order.shop_code = @shop.shop_code
|
||||
order.save!
|
||||
|
||||
return order
|
||||
end
|
||||
|
||||
def update_order_item(order_id, order_item)
|
||||
orderItem = OrderItem.find(order_item["id"])
|
||||
if orderItem.qty.to_f != order_item['qty'].to_f
|
||||
set_menu_items_obj = Array.new
|
||||
if !orderItem.set_menu_items.nil?
|
||||
instance_item_sets = JSON.parse(orderItem.set_menu_items)
|
||||
instance_item_sets.each_with_index do |instance_item, instance_index|
|
||||
instance_item_sets[instance_index]["quantity"] = (instance_item["quantity"].to_i - order_item['qty'].to_i).to_s
|
||||
set_menu_items_obj.push({'item_instance_code' => instance_item["item_instance_code"], 'quantity' => order_item['qty'].to_i, 'price' => instance_item["price"]})
|
||||
end
|
||||
orderItem.set_menu_items = instance_item_sets.to_json
|
||||
if split_orders.present?
|
||||
BookingOrder.where(order_id: split_orders).update_all(booking_id: booking.booking_id)
|
||||
end
|
||||
end
|
||||
|
||||
same_order = OrderItem.find_by_order_id(order_id)
|
||||
if same_order.nil?
|
||||
OrderItem.processs_item(orderItem.item_code,
|
||||
orderItem.item_instance_code,
|
||||
orderItem.item_name,
|
||||
orderItem.alt_name,
|
||||
orderItem.account_id,
|
||||
order_item['qty'],
|
||||
orderItem.price,
|
||||
orderItem.options,
|
||||
set_menu_items_obj.to_json,
|
||||
order_id,
|
||||
orderItem.item_order_by,
|
||||
orderItem.taxable)
|
||||
else
|
||||
same_order.qty = same_order.qty.to_f + order_item['qty'].to_f
|
||||
same_order.set_menu_items = set_menu_items_obj.to_json
|
||||
same_order.save
|
||||
end
|
||||
orderItem.qty = orderItem.qty.to_f - order_item['qty'].to_f
|
||||
else
|
||||
orderItem.order_id = order_id
|
||||
end
|
||||
orderItem.save!
|
||||
if booking.sale.nil?
|
||||
sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type, params[:current_checkin_induties_count])
|
||||
Promotion.promo_activate(sale_data)
|
||||
end
|
||||
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
|
||||
ActionCable.server.broadcast "bill_channel", table: table, from:from
|
||||
|
||||
render :json => { status: true }
|
||||
end
|
||||
else
|
||||
render :json => { status: false, error_message: 'No Current Open Shift!'}
|
||||
end
|
||||
end
|
||||
|
||||
def update_sale
|
||||
|
||||
@@ -9,7 +9,7 @@ class Origami::SurveysController < BaseOrigamiController
|
||||
@id = params[:id]
|
||||
@cashier_type = params[:type]
|
||||
|
||||
if(@id[0,3] == "SAL")
|
||||
if @id.include? "SAL"
|
||||
@sale = Sale.find(@id)
|
||||
@receipt_no = @sale.receipt_no
|
||||
@grand_total = @sale.grand_total
|
||||
@@ -33,7 +33,7 @@ class Origami::SurveysController < BaseOrigamiController
|
||||
@table_type = @dining_facility.type
|
||||
@receipt_no = nil
|
||||
@grand_total = nil
|
||||
@survey_data = Survey.find_by_dining_name_and_receipt_no_and_shop_code(@dining_facility.name,nil,@shop.shop_code)
|
||||
@survey_data = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name,nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Origami::TableInvoicesController < BaseOrigamiController
|
||||
def index
|
||||
@table = DiningFacility.find(params[:table_id])
|
||||
shop = Shop.current_shop
|
||||
@sale_array = Array.new
|
||||
@table.bookings.each do |booking|
|
||||
|
||||
@@ -31,29 +32,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
|
||||
|
||||
@membership = MembershipSetting::MembershipSetting
|
||||
@payment_methods = PaymentMethodSetting.all
|
||||
@sale_array = Array.new
|
||||
@table.bookings.each do |booking|
|
||||
if booking.sale_id.nil?
|
||||
else
|
||||
sale = Sale.find(booking.sale_id)
|
||||
# rounding adjustment
|
||||
if @shop.is_rounding_adj
|
||||
a = sale.grand_total % 25 # Modulus
|
||||
b = sale.grand_total / 25 # Division
|
||||
#not calculate rounding if modulus is 0 and division is even
|
||||
#calculate rounding if modulus is zero or not zero and division are not even
|
||||
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
||||
new_total = Sale.get_rounding_adjustment(sale.grand_total)
|
||||
sale.rounding_adjustment = new_total-sale.grand_total
|
||||
sale.update_attributes(grand_total: new_total,old_grand_total: sale.grand_total,rounding_adjustment:sale.rounding_adjustment)
|
||||
end
|
||||
end
|
||||
#end rounding adjustment
|
||||
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != "waste" && sale.sale_status != "spoile"
|
||||
@sale_array.push(sale)
|
||||
end
|
||||
end
|
||||
end
|
||||
@sale_array = @table.current_sales
|
||||
|
||||
@sale = Sale.find(params[:invoice_id])
|
||||
@date = @sale.created_at
|
||||
|
||||
Reference in New Issue
Block a user