menu, table,rooms, orders structure

This commit is contained in:
Min Zeya Phyo
2017-04-03 21:26:22 +06:30
parent 40423c12d3
commit 30b4a0f5ff
60 changed files with 536 additions and 101 deletions

9
app/models/customer.rb Normal file
View File

@@ -0,0 +1,9 @@
class Customer < ApplicationRecord
has_many :orders
has_many :sales
validates_presence_of :name, :contact_no
validates :contact_no, uniqueness: true
end

View File

@@ -0,0 +1,2 @@
class DiningFacility < ApplicationRecord
end

4
app/models/dining_in.rb Normal file
View File

@@ -0,0 +1,4 @@
class DiningIn < ApplicationRecord
belongs_to :table
belongs_to :order
end

View File

@@ -1,5 +1,10 @@
class MenuCategory < ApplicationRecord
belongs_to :menu
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
validates_presence_of :name
end

7
app/models/menu_item.rb Normal file
View File

@@ -0,0 +1,7 @@
class MenuItem < ApplicationRecord
belongs_to :menu_category
has_many :menu_item_instances
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id"
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
end

View File

@@ -0,0 +1,4 @@
class MenuItemAttribute < ApplicationRecord
validates_presence_of :attribute_type, :name, :value
end

View File

@@ -0,0 +1,4 @@
class MenuItemInstance < ApplicationRecord
belongs_to :menu_item
end

View File

@@ -0,0 +1,4 @@
class MenuItemOption < ApplicationRecord
validates_presence_of :name, :value
end

12
app/models/order.rb Normal file
View File

@@ -0,0 +1,12 @@
class Order < ApplicationRecord
before_create :set_order_date
belongs_to :customer
has_many :order_items, inverse_of: :order
has_many :dining_ins
private
def set_order_date
self.date = Time.now.utc
end
end

10
app/models/order_item.rb Normal file
View File

@@ -0,0 +1,10 @@
class OrderItem < ApplicationRecord
#Associations
belongs_to :order
#Validation
validates_presence_of :item_code, :item_name, :qty
validates :qty, numericality: { :greater_than 0 }
validates_associated :orders
end

View File

@@ -1,6 +1,3 @@
class Room < ApplicationRecord
belongs_to :zone
validates_presence_of :name,:seater, :order_by, :created_by, :is_active
class Room < DiningFacility
end

View File

@@ -0,0 +1,2 @@
class RoomBooking < ApplicationRecord
end

4
app/models/room_order.rb Normal file
View File

@@ -0,0 +1,4 @@
class RoomOrder < ApplicationRecord
belongs_to :room
belongs_to :orders
end

View File

@@ -1,6 +0,0 @@
class SeatTable < ApplicationRecord
belongs_to :zone
# validations
validates_presence_of :name,:order_by, :created_by
end

View File

@@ -0,0 +1,3 @@
class SetMenuItem < MenuItem
end

View File

@@ -0,0 +1,3 @@
class SimpleMenuItem < MenuItem
end

4
app/models/table.rb Normal file
View File

@@ -0,0 +1,4 @@
class Table < DiningFacility
has_many :dining_ins
end

View File

@@ -1,6 +1,6 @@
class Zone < ApplicationRecord
# model association
has_many :seat_tables, dependent: :destroy
has_many :tables, dependent: :destroy
has_many :rooms, dependent: :destroy
# validations