update order and request bill
This commit is contained in:
@@ -8,7 +8,53 @@ class Booking < ApplicationRecord
|
||||
belongs_to :sale, :optional => true
|
||||
has_many :booking_orders
|
||||
has_many :orders, :through => :booking_orders
|
||||
has_many :order_items, :through => :orders
|
||||
has_many :order_items, :through => :orders do
|
||||
def to_sale_items
|
||||
sale_items = []
|
||||
proxy_association.load_target.select(&:order_items_id).each do |order_item|
|
||||
menu_category = order_item.menu_category || OpenStruct.new(name: 'Product', code: '') #get menu category for menu items
|
||||
|
||||
sale_items << SaleItem.new({
|
||||
menu_category_name: menu_category.name,
|
||||
menu_category_code: menu_category.code,
|
||||
product_name: order_item.item_name,
|
||||
product_code: order_item.item_code,
|
||||
product_alt_name: order_item.alt_name,
|
||||
account_id: order_item.account_id,
|
||||
is_taxable: order_item.taxable,
|
||||
item_instance_code: order_item.item_instance_code,
|
||||
qty: order_item.qty,
|
||||
unit_price: order_item.price,
|
||||
price: order_item.qty * order_item.price,
|
||||
taxable_price: order_item.qty * order_item.price,
|
||||
status: order_item.remark
|
||||
})
|
||||
|
||||
if order_item.set_menu_items
|
||||
JSON.parse(order_item.set_menu_items).each do |item|
|
||||
instance = MenuItemInstance.find_by_item_instance_code(item["item_instance_code"])
|
||||
menu_item = instance.menu_item
|
||||
menu_category = menu_item.menu_category #get menu category for menu items
|
||||
sale_items << SaleItem.new({
|
||||
menu_category_name: menu_category.name,
|
||||
menu_category_code: menu_category.code,
|
||||
product_name: instance.item_instance_name,
|
||||
product_code: menu_item.item_code,
|
||||
product_alt_name: menu_item.alt_name,
|
||||
account_id: menu_item.account_id,
|
||||
is_taxable: menu_item.taxable,
|
||||
item_instance_code: item["item_instance_code"],
|
||||
qty: item["quantity"],
|
||||
unit_price: item["price"],
|
||||
price: item["quantity"].to_f * item["price"].to_f,
|
||||
taxable_price: item["quantity"].to_f * item["price"].to_f
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
sale_items
|
||||
end
|
||||
end
|
||||
|
||||
scope :active, -> {where("booking_status != 'moved'")}
|
||||
scope :today, -> {where("created_at >= #{Time.now.utc}")}
|
||||
|
||||
Reference in New Issue
Block a user