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

View File

@@ -0,0 +1,9 @@
class Api::AuthenticateController < ActionController::API
def create
end
def destroy
end
end

View File

@@ -0,0 +1,10 @@
class Api::CustomersController < ActionController::API
#List all active customers by name
def index
end
#Show customer by ID
def show
end
end

View File

@@ -0,0 +1,24 @@
class Api::Restaurant::InvoiceController < ActionController::API
before :authenticate_token
#Description
# This API show current order details
# Input Params - order_id
def show
order = Order.find(params[:order_id])
order.order_items
end
# Description
# This API allow new invoice creation
# Input Params
# order_id
# Output Params
# Status [Success | Error | System Error] , order_id, error_message (*)
def create
end
end

View File

@@ -0,0 +1,29 @@
class Api::Restaurant::MenuController < ActionController::API
before :authenticate_token
#Description
# Pull the default menu details and also other available (active) menus
# Input Params - order_id
def index
menu_detail()
end
#Description
# This API show current order details
# Input Params - menu_id
def show
menu_detail(params[:menu_id])
end
private
def menu_detail
if (menu_id)
#Pull this menu
else
#Pull Default menu
end
end
end

View File

@@ -0,0 +1,36 @@
class Api::Restaurant::OrderController < ActionController::API
before :authenticate_token
#Description
# This API show current order details
# Input Params - order_id
def show
order = Order.find(params[:order_id])
order.order_items
end
# Description
# This API allow new order creation
# Input Params
# order_source [* default - emenu] | table_id (*require for Dine-In) | order_type [* Default - Dine-in]
# | guest_info (optional) | customer_id (optional)
# order_items {[item_code, item_instance_code , qty, option, variants]}
# Output Params
# Status [Success | Error | System Error] , order_id, error_message (*)
def create
end
# Description
# This API - allow order to add new items to existing orders, does not allow you to remove confirm items
# Update customer info, Guest Info
# Input Params
# order_id , order_items {[item_code, item_instance_code , qty, option, variants]}
def update
end
end

View File

@@ -0,0 +1,21 @@
class Api::Restaurant::RoomsController < ActionController::API
def index
render json: SeatTable.order("order_by")
end
# Description
# This API full the current status of table and if there is order attached to this table - Order_ID will be return
# Output
# status: {available, cleaning, occupied, reserved}, order_id : <current_order_id>
def show
end
#Input Params
# table_id: table_id
# Output
# status: error | success, error_message: <Problem with moving table>
def update
end
end

View File

@@ -1,5 +0,0 @@
class Api::Restaurant::SeatTablesController < ActionController::API
def index
render json: SeatTable.order("order_by")
end
end

View File

@@ -0,0 +1,21 @@
class Api::Restaurant::SeatingsController < ActionController::API
def index
render json: Zone.order("order_by")
end
# Description
# This API full the current status of table and if there is order attached to this table - Order_ID will be return
# Output
# status: {available, cleaning, occupied, reserved}, order_id : <current_order_id>
def show
end
#Input Params
# table_id: table_id
# Output
# status: error | success, error_message: <Problem with moving table>
def update
end
end

View File

@@ -0,0 +1,21 @@
class Api::Restaurant::TakeawaysController < ActionController::API
def index
render json: SeatTable.order("order_by")
end
# Description
# This API full the current status of table and if there is order attached to this table - Order_ID will be return
# Output
# status: {available, cleaning, occupied, reserved}, order_id : <current_order_id>
def show
end
#Input Params
# table_id: table_id
# Output
# status: error | success, error_message: <Problem with moving table>
def update
end
end

View File

@@ -1,4 +1,5 @@
class Api::Restaurant::ZonesController < ActionController::API
def index
render json: Zone.where("is_active = true")
end

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

View File

@@ -1,9 +1,16 @@
Rails.application.routes.draw do
namespace :api, :defaults => { :format => 'json' } do
#Session Login and Logout
post 'autheticate' => "autheticate#create"
delete 'autheticate' => "autheticate#destroy"
namespace :restaurant do
get 'zones' => "zones#index"
get 'seat_tables' => "seat_tables#index"
get 'tables' => "#index"
end
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

View File

@@ -1,15 +0,0 @@
class CreateSeatTables < ActiveRecord::Migration[5.0]
def change
create_table :seat_tables do |t|
t.references :zone, foreign_key: true
t.string :name, :null => false
t.integer :order_by
t.integer :no_of_seater, :null => false, :default => 2
t.string :table_type, :null => false, :default => "square"
t.float :position_x, :null => false, :default => 0.0
t.float :position_y, :null => false, :default => 0.0
t.string :created_by
t.timestamps
end
end
end

View File

@@ -1,13 +0,0 @@
class CreateRooms < ActiveRecord::Migration[5.0]
def change
create_table :rooms do |t|
t.string :name, :null => false
t.integer :seater, :null => false, :default => 4
t.string :created_by
t.boolean :is_active, :null => false, :default => true
t.integer :order_by
t.references :zone
t.timestamps
end
end
end

View File

@@ -2,7 +2,7 @@ class CreateMenus < ActiveRecord::Migration[5.0]
def change
create_table :menus do |t|
t.string :name
t.boolean :is_active, :null => false
t.boolean :is_active, :null => false, :deafult => true
t.string :valid_days, :null => false, :default => "1,2,3,4,5,6,7"
t.time :valid_time_from, :null => false, :default => "00:00:00"
t.time :valid_time_to, :null => false, :default => "23:59:59"

View File

@@ -5,7 +5,7 @@ class CreateMenuCategories < ActiveRecord::Migration[5.0]
t.string :name, :null => false
t.string :alt_name
t.integer :order_by
t.integer :parent_category_id
t.references :menu_category, :null => true
t.timestamps
end

View File

@@ -0,0 +1,19 @@
class CreateMenuItems < ActiveRecord::Migration[5.0]
def change
create_table :menu_items do |t|
t.string :item_code, :null => false
t.string :name, :null => false
t.string :alt_name
t.string :type, :null => false, :default => "SimpleMenuItem"
t.references :menu_category, foreign_key: true
t.references :menu_item, foreign_key: true
t.integer :min_selectable_item, :null => false, :default => 1
t.integer :max_selectable_item, :null => false, :default => 1
t.json :options #save value
t.json :attributes #value IDS
t.string :created_by
t.timestamps
end
end
end

View File

@@ -0,0 +1,11 @@
class CreateMenuItemAttributes < ActiveRecord::Migration[5.0]
def change
create_table :menu_item_attributes do |t|
t.string :attribute_type, :null => false
t.string :name, :null => false
t.string :value, :null => false
t.timestamps
end
end
end

View File

@@ -0,0 +1,10 @@
class CreateMenuItemOptions < ActiveRecord::Migration[5.0]
def change
create_table :menu_item_options do |t|
t.string :name, :null => false
t.string :value, :null => false
t.timestamps
end
end
end

View File

@@ -0,0 +1,14 @@
class CreateMenuItemInstances < ActiveRecord::Migration[5.0]
def change
create_table :menu_item_instances do |t|
t.references :menu_item, :foreign_key => true, :null => false
t.string :item_instance_code, :null => false
t.json :attributes
t.decimal :price, :null => false
t.boolean :is_available, :null => false, :default => true
t.boolean :is_on_promotion, :null => false, :default => false
t.decimal :promotion_price, :null => false, :default => false
t.timestamps
end
end
end

View File

@@ -0,0 +1,15 @@
class CreateCustomers < ActiveRecord::Migration[5.0]
def change
create_table :customers do |t|
t.string :name, :null => false
t.string :company
t.string :contact_no
t.string :email
t.string :membership_id
t.string :membership_type
t.string :membership_authentication_code
t.timestamps
end
end
end

View File

@@ -0,0 +1,17 @@
class CreateOrders < ActiveRecord::Migration[5.0]
def change
create_table :orders do |t|
t.datetime :date, :null => false
t.string :source, :null => false, :default => "emenu"
t.string :order_type, :null => false, :default => "dine-in"
t.references :customer, foreign_key: true
t.integer :item_count, :null => false, :default => 0
t.integer :quantity_count, :null => false, :default => 0
t.string :status, :null => false, :default => "new"
t.json :waiters
t.json :guest_info
t.timestamps
end
end
end

View File

@@ -0,0 +1,18 @@
class CreateOrderItems < ActiveRecord::Migration[5.0]
def change
create_table :order_items do |t|
t.references :order, foreign_key: true, :null => false
t.string :order_item_status, :null => false, :default => "new"
t.string :item_code, :null => false
t.string :item_name, :null => false
t.integer :qty, :null => false
t.string :item_order_by #person who order this
t.string :remark
t.string :options
t.string :variants
t.json :set_menu_items #this parameter is require to route the items correctly
t.timestamps
end
end
end

View File

@@ -0,0 +1,16 @@
class CreateDiningFacilities < ActiveRecord::Migration[5.0]
def change
create_table :dining_facilities do |t|
t.references :zone, foreign_key: true
t.string :name, :null => false
t.string :type, :null => false, :default => "table"
t.integer :seater, :null => false, :default => 2
t.integer :order_by
t.string :created_by
t.boolean :is_active, :null => false, :default => true
t.timestamps
end
end
end

View File

@@ -0,0 +1,11 @@
class CreateDiningIns < ActiveRecord::Migration[5.0]
def change
create_table :dining_ins do |t|
t.references :table
t.references :order
t.boolean :currently_occupied, :default => false #there will only be 1 true - where table_id+order_id
t.timestamps
end
end
end

View File

@@ -0,0 +1,15 @@
class CreateRoomBookings < ActiveRecord::Migration[5.0]
def change
create_table :room_bookings do |t|
t.references :room, :null => false
t.datetime :checkin_at
t.datetime :checkout_at
t.string :checkout_by
t.datetime :reserved_at
t.string :reserved_by
t.string :status, :null => false, :default => "new"
t.boolean :is_currently_checkin, :default => false, :null => true
t.timestamps
end
end
end

View File

@@ -0,0 +1,11 @@
class CreateRoomOrders < ActiveRecord::Migration[5.0]
def change
create_table :room_orders do |t|
t.references :room, foreign_key: true
t.references :orders, foreign_key: true
t.string :order_by
t.timestamps
end
end
end

View File

@@ -1,14 +1,53 @@
zone {name}
seat_tables {table_name, seater, table_type:[square, round, ], position-x, position-y}
room {Name, seater, created_by, is_active, order_by}
room {name, seater, created_by, is_active, order_by}
menu {name, is_active, valid_days, valid_time_from, valid_time_to}
menu_category {menu, name, alt_name, order_no, parent_category_id}
menu_items { menu_category, order_no, product_code, picture, menu_name, alt_menu_name, price, menu_item_type:[simple| set| DIY], available_size:[],
variants:[{product_code, name, picture, add_on_price}], allow_multiple_variants_selection: boolean, set_menu_items:[menu_items], is_sold_out, is_on_promotion
promotion_price, promotion_qty}
menu_category {menu, name, alt_name, order_by, parent_category_id}
order { id, date, order_source [tablet, order_station, emenu, api], order_type [dine-in, takeaway, delivery], item_count, quantity_count, status [new, processing, fulfilled], waiters[], guest_info: {customer_id, membership_id, }}
menu_item_attributes: {attribute_type, name, value}
menu_item_options: {option_type, name, value}
menu_item : {
category_code : "",
item_code : "",
name : "",
alt_name : "",
type : "[SIMPLE | SET | DIY]",
attributes : [],
parent_items : [],
child_items : [],
min_selectable_item : 0,
max_selectable_item : 0,
menu_item_instances : [],
options : [],
}
menu_item_instance : {
item_instance_code : "",
menu_item_attribute_values : [],
item_code : "",
parent_item_code : "",
price : 0.00,
is_available : t/f,
is_on_promotion : t/f,
promotion_price : 0.00,
}
order_item : {
order_item_code : "",
item_instance_code : "",
quantity : 0,
option_values : [],
sub_order_items : [],
}
menu_items { menu_category, order_by, product_code, picture, menu_name, alt_menu_name, price, menu_item_type:[simple| set| DIY], available_size:[small: {product_code, price}, medium: {product_code, price}, large: {product_code, price}],
variants:[{product_code, name, picture, add_on_price, options {option_name, option_value} }], max_variants_selection: integer, set_menu_items:[menu_items], is_sold_out, is_on_promotion
promotion_price, options {option_name, option_value}}
order { id, date, order_ref, order_source [tablet, order_station, emenu, api], order_type [dine-in, takeaway, delivery],customer_id, item_count, quantity_count, status [new, processing, fulfilled], waiters[], guest_info: {adult_count, child_count, woman_count, man_count}}
order_items { order_item_status, product_code, name, qty, price, remark, options , variants: [], set_menu_items :[]}
order_delivery_info {name, address, contact_no, delivery-by [InHouse | YDoor2Door | Food2U], tracker-id, sale}
dine-in-table {table, order, status}

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Customer, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe DiningFacility, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe DiningIn, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -4,4 +4,19 @@ RSpec.describe MenuCategory, type: :model do
it { should validate_presence_of(:name) }
it { should belong_to(:menu) }
describe ' #parent & #children' do
it 'should be able to do parent tree' do
menu = Menu.new(:name => "Test Category Menu", :is_active => true )
menu.save!
c1 = MenuCategory.new(:name =>"Parent Category", :menu => menu)
c1.save!
c2 = MenuCategory.new(:name =>"Child Category", :menu => menu, :parent => c1)
c2.save
expect(c1.children).to include(c2)
expect(c2.parent).to eq c1
end
end
end

View File

@@ -0,0 +1,7 @@
require 'rails_helper'
RSpec.describe MenuItemAttribute, type: :model do
it { should validate_presence_of(:attribute_type) }
it { should validate_presence_of(:name) }
it { should validate_presence_of(:value) }
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe MenuItemInstance, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,6 @@
require 'rails_helper'
RSpec.describe MenuItemOption, type: :model do
it { should validate_presence_of(:name) }
it { should validate_presence_of(:value) }
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe MenuItem, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe OrderItem, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Order, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe RoomBooking, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe RoomOrder, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -1,10 +0,0 @@
require 'rails_helper'
RSpec.describe Room, type: :model do
it { should belong_to(:zone) }
it { should validate_presence_of(:name) }
it { should validate_presence_of(:seater) }
it { should validate_presence_of(:is_active) }
end

View File

@@ -1,13 +0,0 @@
require 'rails_helper'
RSpec.describe SeatTable, type: :model do
# Association test
# ensure an item record belongs to a single todo record
it { should belong_to(:zone) }
# Validation test
# ensure column name is present before saving
it { should validate_presence_of(:name) }
it { should validate_presence_of(:order_by) }
it { should validate_presence_of(:created_by) }
end

View File

@@ -1,25 +0,0 @@
require 'rails_helper'
RSpec.describe 'Seat Table API', type: :request do
# initialize test data
let!(:seat_table) { create_list(:seat_table, 10) }
let(:seat_table_id) { seat_tables.first.id }
# Test suite for GET /todos
describe 'GET /api/restaurant/seat_tables' do
# make HTTP get request before each example
before { get '/api/restaurant/seat_tables' }
it 'returns Seat Tables' do
# Note `json` is a custom helper to parse JSON responses
expect(json).not_to be_empty
expect(json.size).to eq(10)
end
it 'returns status code 200' do
expect(response).to have_http_status(200)
end
end
end