Files
sx-fc/app/views/api/orders/view_orders.json.jbuilder
Myat Zin Wai Maw c606ca73db foodcourt
2019-12-10 13:37:06 +06:30

133 lines
3.7 KiB
Ruby
Executable File

if (@booking)
json.success true
json.booking_id @booking.booking_id
json.status @booking.booking_status
if Sale.exists?(@booking.sale_id)
json.sale_status Sale.find(@booking.sale_id).sale_status
else
json.sale_status ""
end
json.checkin_at @booking.checkin_at.strftime("%d-%m-%Y")
json.checkin_by @booking.checkin_by
json.table_name @booking.dining_facility.name
if @booking.type == "TableBooking"
json.table_id @booking.dining_facility_id
else
json.room_id @booking.dining_facility_id
end
@total_amount = 0.00
@total_tax = 0.00
# For YGN BBQ
adult_count = 0
child_count = 0
adult_spent = 0
child_spent = 0
# End YGN BBQ
if @booking.booking_orders
order_items = []
@booking.booking_orders.each do |bo|
order = Order.find(bo.order_id)
if (order.status == "new")
order_items = order_items + order.order_items
end
end
json.order_items order_items do |item|
total_set_menu = 0
# For YGN BBQ
if item.item_code.include? ("PSA_")
adult_count += item.qty
adult_spent += (item.price * item.qty)
end
if item.item_code.include? ("PSC_")
child_count += item.qty
child_spent += (item.price * item.qty)
end
# End YGN BBQ
json.order_items_id item.order_items_id
json.order_id item.order_id
json.item_code item.item_code
json.item_instance_code item.item_instance_code
json.item_name item.item_name
json.set_menu_items item.set_menu_items
json.price item.price
json.qty item.qty
json.options item.options
json.remark item.remark
json.item_status item.order_item_status
#start set menu item price
if !item.set_menu_items.nil? && item.set_menu_items != '[]'
JSON.parse(item.set_menu_items).each do |item_instance|
total_set_menu += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f
end
end
#end set menu item price
@total_amount = @total_amount + (item.price * item.qty) + total_set_menu
end
end
# For YGN BBQ
# if adult_count > 0
# json.per_adult_spent adult_spent + ((adult_spent/adult_count) * 0.05)
# else
json.per_adult_spent 0
# end
# if child_count > 0
# json.per_child_spent child_spent + ((child_spent/child_count) * 0.05)
# else
json.per_child_spent 0
# end
# End YGN BBQ
#total tax calculation
@total_tax_amount = 0
@service_rate = 0
@commercial_rate = 0
@service_charges = 0.00
@commercial_tax = 0.00
@total_taxable = @total_amount
if !@tax_profile.nil?
@tax_profile.each do |tax|
total_tax_amount = 0
if tax.inclusive
total_tax_amount = (@total_taxable / ((100 + tax.rate)/ tax.rate))
else
total_tax_amount = (@total_taxable * tax.rate / 100)
end
if @shop.calc_tax_order
@total_taxable = @total_taxable + total_tax_amount
end
if tax.name.strip.downcase.include? ("service")
@service_rate = tax.rate.to_i
@service_charges = total_tax_amount
else
@commercial_rate = tax.rate.to_i
@commercial_tax = total_tax_amount
end
end
@total_tax_amount = @service_charges + @commercial_tax
end
#total tax calculation
json.sub_total @total_amount
if @service_rate.to_i > 0
json.service_rate @service_rate
json.service_charges @service_charges
end
if @commercial_rate.to_i > 0
json.commercial_rate @commercial_rate
json.commercial_tax @commercial_tax
end
json.total @total_amount + @total_tax_amount
else
json.success false
end