merge with r-19

This commit is contained in:
NyanLinHtut
2020-01-11 11:08:33 +06:30
106 changed files with 2722 additions and 3024 deletions

View File

@@ -6,13 +6,62 @@ class Booking < ApplicationRecord
belongs_to :dining_facility, :optional => true
belongs_to :sale, :optional => true
has_one :cashier_terminal_by_dining_facility, through: :dining_facility, source: :cashier_terminal
has_one :current_shift_by_dining_facility, through: :dining_facility, source: :current_shift
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}")}
scope :shop, -> { where("bookings.shop_code=?",Shop.current_shop.shop_code) }
scope :assign, -> { where(booking_status: 'assign')}
scope :within_time_limit, -> { where(checkin_at: Lookup.get_checkin_time_limit.hours.ago..DateTime::Infinity.new) }
def self.sync_booking_records(bookings)
if !bookings.nil?