merge with r-19
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user