Merge branch 'split_bill' of bitbucket.org:code2lab/sxrestaurant into quick_service

This commit is contained in:
Aung Myo
2018-02-21 16:12:46 +06:30
8 changed files with 178 additions and 90 deletions

View File

@@ -192,9 +192,21 @@ class Origami::PaymentsController < BaseOrigamiController
@table_no = ''
@dining = ''
@shop = Shop::ShopDetail
@shop = Shop::ShopDetail #show shop info
saleObj = Sale.find(sale_id)
#total customer with individual total amount
survey = nil
@individual_total = Array.new
if !@sale_data.nil?
survey = Survey.find_by_receipt_no(@sale_data.receipt_no)
if !survey.nil?
per_person_amount = saleObj.grand_total.to_f / survey.total_customer.to_i
@individual_total.push({'total_customer' => survey.total_customer, 'per_person_amount' => per_person_amount.to_f })
end
end
# rounding adjustment
if @shop.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus
@@ -211,7 +223,9 @@ class Origami::PaymentsController < BaseOrigamiController
@rounding_adj = @sale_data.rounding_adjustment
end
#end rounding adjustment
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
#get customer amount
@customer = Customer.find(@sale_data.customer_id)

View File

@@ -97,11 +97,11 @@ class Origami::SplitBillController < BaseOrigamiController
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
else
table = nil
cashier_zone = nil
end
# 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)
get_cashier_by_terminal = current_user
if booking
if booking.sale_id.nil?
@@ -208,17 +208,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
# begin
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 = order_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.save!
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
@@ -260,17 +250,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
# begin
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 = order_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.save!
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
@@ -297,17 +277,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
# begin
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 = order_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.save!
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
@@ -319,17 +289,12 @@ class Origami::SplitBillController < BaseOrigamiController
end
sale = Sale.new
status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, get_cashier_by_terminal)
sale_data = Sale.find_by_sale_id(sale_id)
status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user)
end
# Bind shift sale id to sale
# sale_data.shift_sale_id = shift_by_terminal.id
# sale_data.save
Promotion.promo_activate(sale)
BillBroadcastJob.perform_later(table)
ActionCable.server.broadcast "bill_channel",table: table
render :json => { status: status }
else
@@ -337,9 +302,36 @@ class Origami::SplitBillController < BaseOrigamiController
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.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
"[{\"item_instance_code\":\"psi002in001\",\"quantity\":\"2\",\"price\":\"5500.0\"}]"
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
end
OrderItem.processs_item(orderItem.item_code,
orderItem.item_instance_code,
orderItem.item_name,
@@ -348,7 +340,7 @@ class Origami::SplitBillController < BaseOrigamiController
order_item['qty'],
orderItem.price,
orderItem.options,
orderItem.set_menu_items,
set_menu_items_obj.to_json,
order_id,
orderItem.item_order_by,
orderItem.taxable)

View File

@@ -86,9 +86,10 @@ class Origami::SurveysController < BaseOrigamiController
def create_survey
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
@type = params[:cashier_type]
@sale_id = params[:sale_id]
sale = Sale.find(@sale_id)
@type = params[:cashier_type]
@sale_id = params[:sale_id]
sale = Sale.find(@sale_id)
receipt_no = params[:receipt_no]
if @type != "quick_service"
dining_facility = DiningFacility.find(params[:dining_id])
@@ -102,27 +103,43 @@ class Origami::SurveysController < BaseOrigamiController
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_terminal_id,nil)
if @type != "quick_service"
survey = Survey.find_by_dining_name(dining_facility.name)
survey = Survey.find_by_dining_name_and_receipt_no(dining_facility.name,receipt_no)
else
survey = nil
end
if survey.nil?
survey = Survey.new
if @type != "quick_service"
survey.dining_name = dining_facility.name
survey = Survey.find_by_dining_name_and_receipt_no(dining_facility.name,nil)
if survey.nil?
survey = Survey.new
survey.dining_name = dining_facility.name
survey.receipt_no = params[:receipt_no]
survey.shift_id = shift_by_terminal.id
survey.created_by = current_user.name
survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save!
else
survey.receipt_no = params[:receipt_no]
survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save!
end
else
survey = Survey.new
survey.receipt_no = params[:receipt_no]
survey.shift_id = shift_by_terminal.id
survey.created_by = current_user.name
survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save!
end
survey.receipt_no = params[:receipt_no]
survey.shift_id = shift_by_terminal.id
survey.created_by = current_user.name
survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save!
else
survey.receipt_no = params[:receipt_no]
survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save!
end
render :json => {status: true}
@@ -131,6 +148,22 @@ class Origami::SurveysController < BaseOrigamiController
end
end
def get_survey
dining_id = params[:dining_id]
receipt_no = params[:receipt_no]
table = DiningFacility.find_by_id(dining_id)
survey = Survey.find_by_dining_name_and_receipt_no(table.name,receipt_no)
if survey.nil?
survey = Survey.find_by_dining_name_and_receipt_no(table.name,nil)
end
if !survey.nil?
render :json => { status: true, survey: survey }
else
render :json => { status: false }
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.