class OrderReservationItem < ApplicationRecord
	self.primary_key = "order_reservation_items_id"

	#primary key - need to be unique
  	before_create :generate_custom_id

	belongs_to :order_reservation, autosave: true

	def self.process_order_reservation_item (item_code, instance_code, menu_name, alt_name, account_id, qty, price, unit_price, options, set_menu_items, order_reservation_id)
	    orderreservationitem = OrderReservationItem.create do |oitem|
	      oitem.order_reservation_id = order_reservation_id
	      oitem.item_code = item_code
	      oitem.item_instance_code = instance_code
	      oitem.item_name = menu_name
	      oitem.alt_name = alt_name ? alt_name : ""
	      oitem.account_id = account_id
	      oitem.qty       = qty
	      oitem.unit_price = unit_price
	      oitem.price   = price
	      oitem.options     = options
	      oitem.set_menu_items = set_menu_items
	    end

	    #logger.debug orderitem.to_yml
	    orderreservationitem.save!
	end

	private
		def generate_custom_id
			self.order_reservation_items_id = SeedGenerator.generate_id(self.class.name, "ODRSI")
		end
end
