diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb new file mode 100644 index 00000000..31aa674c --- /dev/null +++ b/app/controllers/api/bill_controller.rb @@ -0,0 +1,15 @@ +class Api::Restaurant::BillController < Api::ApiController + + + #Create invoice based on booking + #Output and invoice + def create + + end + + + private + def bill_params + params.permit(:booking_id, :order_id) + end +end diff --git a/app/controllers/api/move_controller.rb b/app/controllers/api/move_controller.rb new file mode 100644 index 00000000..29913e06 --- /dev/null +++ b/app/controllers/api/move_controller.rb @@ -0,0 +1,15 @@ +class Api::Restaurant::MoveController < Api::ApiController + + #Move between table + def update + end + + + + private + # Use callbacks to share common setup or constraints between actions. + def move_params + params.permit(:booking_id, :order_id) + end + +end diff --git a/app/controllers/api/restaurant/menu_categories.rb b/app/controllers/api/restaurant/menu_categories.rb new file mode 100644 index 00000000..fe7983ea --- /dev/null +++ b/app/controllers/api/restaurant/menu_categories.rb @@ -0,0 +1,37 @@ +class Api::Restaurant::MenuController < Api::ApiController + + #Description + # Pull the default menu details and also other available (active) menus + # Input Params - order_id + def index + @menus = Menu.all + @current_menu = Menu.current_menu + + end + + #Description + # This API show current order details + # Input Params - menu_id + def show + @menu = menu_detail(params[:id]) + end + + + private + def menu_detail (menu_id) + if (menu_id) + #Pull this menu + menu = Menu.find_by_id(menu_id) + return menu + else + Menu.current_menu + end + + end + + def menu_params() + params.permit(:id) + end + + +end diff --git a/app/controllers/api/restaurant/menu_controller.rb b/app/controllers/api/restaurant/menu_controller.rb index ea91dbc1..fe7983ea 100644 --- a/app/controllers/api/restaurant/menu_controller.rb +++ b/app/controllers/api/restaurant/menu_controller.rb @@ -4,7 +4,9 @@ class Api::Restaurant::MenuController < Api::ApiController # Pull the default menu details and also other available (active) menus # Input Params - order_id def index - @menu = menu_detail() + @menus = Menu.all + @current_menu = Menu.current_menu + end #Description @@ -22,8 +24,7 @@ class Api::Restaurant::MenuController < Api::ApiController menu = Menu.find_by_id(menu_id) return menu else - #Pull Default menu - + Menu.current_menu end end diff --git a/app/controllers/api/restaurant/menu_item_attributes_controller.rb b/app/controllers/api/restaurant/menu_item_attributes_controller.rb new file mode 100644 index 00000000..f2aead8f --- /dev/null +++ b/app/controllers/api/restaurant/menu_item_attributes_controller.rb @@ -0,0 +1,13 @@ +class Api::Restaurant::MenuItemAttributesController < Api::ApiController + + #Description + # Pull the default menu details and also other available (active) menus + # Input Params - order_id + def index + @menu_attributes = MenuItemAttribute.all + end + + + + +end diff --git a/app/controllers/api/restaurant/menu_item_options_controller.rb b/app/controllers/api/restaurant/menu_item_options_controller.rb new file mode 100644 index 00000000..cc898add --- /dev/null +++ b/app/controllers/api/restaurant/menu_item_options_controller.rb @@ -0,0 +1,13 @@ +class Api::Restaurant::MenuItemOptionsController < Api::ApiController + + #Description + # Pull the default menu details and also other available (active) menus + # Input Params - order_id + def index + @menu_options = MenuItemOption.all + end + + + + +end diff --git a/app/controllers/api/restaurant/menu_sold_out.rb b/app/controllers/api/restaurant/menu_sold_out.rb new file mode 100644 index 00000000..9c090428 --- /dev/null +++ b/app/controllers/api/restaurant/menu_sold_out.rb @@ -0,0 +1,12 @@ +class Api::Restaurant::MenuSoldOutController < Api::ApiController + + #Description + # Pull the default menu details and also other available (active) menus + # Input Params - order_id + def index + + end + + + +end diff --git a/app/models/employee.rb b/app/models/employee.rb index 7f7fc776..8f9dcf14 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -8,40 +8,49 @@ class Employee < ApplicationRecord def self.login(emp_id, password) - user = Employee.find_by_emp_id(emp_id).authenticate(password) - - Rails.logger.debug user - + user = Employee.find_by_emp_id(emp_id) if (user) - user.generate_token - user.session_expiry = DateTime.now.utc + 30.minutes - user.session_last_login = DateTime.now.utc - user.save + user.authenticate(password) - return user + if (user) + user.generate_token + user.session_expiry = DateTime.now.utc + 30.minutes + user.session_last_login = DateTime.now.utc + user.save + return user + end end + + return nil end def self.authenticate_by_token(session_token) - user = Employee.find_by_token_session(session_token) - if user && user.session_expiry.utc > DateTime.now.utc - #Extend the login time each time authenticatation take place - user.session_expiry = DateTime.now.utc + 30.minutes - user.save - return true - else - return false + + if (session_token) + user = Employee.find_by_token_session(session_token) + if user && user.session_expiry.utc > DateTime.now.utc + #Extend the login time each time authenticatation take place + user.session_expiry = DateTime.now.utc + 30.minutes + user.save + return true + else + return false + end end + + return false end def self.logout(session_token) - user = Employee.find_by_token_session(session_token) - if user - user.token_session = nil - user.session_expiry = nil - user.save + if (session_token) + user = Employee.find_by_token_session(session_token) + if user + user.token_session = nil + user.session_expiry = nil + user.save + end end end diff --git a/app/models/menu.rb b/app/models/menu.rb index e2933314..4f1608ad 100644 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -3,4 +3,23 @@ class Menu < ApplicationRecord validates_presence_of :name,:is_active, :valid_days, :valid_time_from, :valid_time_to + #Default Scope to pull the active version only + default_scope { where(is_active: true).order("created_at desc") } + + def self.current_menu + today = DateTime.now + day_of_week = today.wday + menus = Menu.where("is_active = true and '#{today.strftime("%H:%M")}' between TIME(valid_time_from) and TIME(valid_time_to)") + current_menu = nil + + #Loop through the menu which is valid days - get the first menu out and return result + menus.each do |menu| + if menu.valid_days.include?(day_of_week.to_s) + current_menu = menu + break + end + end + + return current_menu + end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index b42ea027..7b27388f 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,5 +1,5 @@ class MenuItem < ApplicationRecord - belongs_to :menu_category + belongs_to :menu_category, :optional => true has_many :menu_item_instances belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id" diff --git a/app/views/api/restaurant/orders/create.json.jbuilder b/app/views/api/orders/create.json.jbuilder similarity index 100% rename from app/views/api/restaurant/orders/create.json.jbuilder rename to app/views/api/orders/create.json.jbuilder diff --git a/app/views/api/restaurant/orders/show.json.jbuilder b/app/views/api/orders/show.json.jbuilder similarity index 100% rename from app/views/api/restaurant/orders/show.json.jbuilder rename to app/views/api/orders/show.json.jbuilder diff --git a/app/views/api/restaurant/orders/update.json.jbuilder b/app/views/api/orders/update.json.jbuilder similarity index 100% rename from app/views/api/restaurant/orders/update.json.jbuilder rename to app/views/api/orders/update.json.jbuilder diff --git a/app/views/api/restaurant/menu/_menu.json.jbuilder b/app/views/api/restaurant/menu/_menu.json.jbuilder new file mode 100644 index 00000000..43721ff0 --- /dev/null +++ b/app/views/api/restaurant/menu/_menu.json.jbuilder @@ -0,0 +1,20 @@ +json.id menu.id +json.name menu.name +json.is_active menu.is_active +json.valid_time_from menu.valid_time_from.strftime("%H:%M") +json.valid_time_to menu.valid_time_to.strftime("%H:%M") + +if (menu.menu_categories) + json.menu_categories menu.menu_categories do |category| + json.id category.id + json.name category.name + json.alt_name category.alt_name + + if category.menu_items + json.menu_items category.menu_items do |item| + json.partial! 'api/restaurant/menu/menu_item', item: item + end + end + end + +end diff --git a/app/views/api/restaurant/menu/_menu_item.json.jbuilder b/app/views/api/restaurant/menu/_menu_item.json.jbuilder new file mode 100644 index 00000000..c93c3b12 --- /dev/null +++ b/app/views/api/restaurant/menu/_menu_item.json.jbuilder @@ -0,0 +1,40 @@ + +#Menu Item Information +json.item_code item.item_code +json.name item.name +json.alt_name item.alt_name +json.type item.type +json.min_qty item.min_qty +json.min_selectable_item item.min_selectable_item +json.max_selectable_item item.max_selectable_item + +#Item instance +if item.menu_item_instances.count == 1 then + + item_instance = item.menu_item_instances[0] + json.price = item_instance.price + json.is_available = item_instance.is_available + json.is_on_promotion = item_instance.is_on_promotion + json.promotion_price = item_instance.promotion_price + json.item_attributes = item_instance.item_attributes + +elsif item.menu_item_instances.count > 1 then + + json.item_instances item.menu_item_instances do |is| + json.item_instance_item_code = is.item_instance_code + json.item_instance_name = is.item_instance_name + json.price = is.price + json.is_available = is.is_available + json.is_on_promotion = is.is_on_promotion + json.promotion_price = is.promotion_price + json.item_attributes = is.item_attributes + end + +end +#Child Menu items +if (item.children) then + json.set_items item.children.each do |item| + json.partial! 'api/restaurant/menu/menu_item', item: item + end + +end diff --git a/app/views/api/restaurant/menu/index.json.jbuilder b/app/views/api/restaurant/menu/index.json.jbuilder new file mode 100644 index 00000000..b4241854 --- /dev/null +++ b/app/views/api/restaurant/menu/index.json.jbuilder @@ -0,0 +1,12 @@ +json.array! @menus do |menu| + json.id menu.id + json.name menu.name + json.valid_days menu.valid_days + json.valid_time_from menu.valid_time_from.strftime("%H:%M") + json.valid_time_to menu.valid_time_to.strftime("%H:%M") + if (@current_menu) + json.current_menu do + json.partial! 'api/restaurant/menu/menu', menu: @current_menu + end + end +end diff --git a/app/views/api/restaurant/menu/show.json.jbuilder b/app/views/api/restaurant/menu/show.json.jbuilder new file mode 100644 index 00000000..4ea99fd0 --- /dev/null +++ b/app/views/api/restaurant/menu/show.json.jbuilder @@ -0,0 +1,3 @@ +if (@menu) + json.partial! 'api/restaurant/menu/menu', menu: @menu +end diff --git a/app/views/api/restaurant/menu_item_attributes/index.json.jbuilder b/app/views/api/restaurant/menu_item_attributes/index.json.jbuilder new file mode 100644 index 00000000..0dc729eb --- /dev/null +++ b/app/views/api/restaurant/menu_item_attributes/index.json.jbuilder @@ -0,0 +1,5 @@ +json.array! @menu_attributes do |attribute| + json.type attribute.attribute_type + json.name attribute.name + json.value attribute.value +end diff --git a/app/views/api/restaurant/menu_item_options/index.json.jbuilder b/app/views/api/restaurant/menu_item_options/index.json.jbuilder new file mode 100644 index 00000000..eae1c761 --- /dev/null +++ b/app/views/api/restaurant/menu_item_options/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array! @menu_options do |option| + json.name option.name + json.value option.value +end diff --git a/app/views/api/restaurant/zones/index.json.jbuilder b/app/views/api/restaurant/zones/index.json.jbuilder new file mode 100644 index 00000000..cbcf1424 --- /dev/null +++ b/app/views/api/restaurant/zones/index.json.jbuilder @@ -0,0 +1,42 @@ +if @zones + json.array! @zones do |zone| + json.id zone.id + json.name zone.name + #List all tables + json.tables zone.tables do |table| + json.id table.id + json.name table.name + json.status table.status + json.zone_id table.zone_id #Add this zone_id to keep data structure consistance + json.current_booking table.get_current_booking + end + + json.rooms zone.rooms do |room| + json.id room.id + json.name room.name + json.status room.status + json.zone_id room.zone_id #Add this zone_id to keep data structure consistance + json.current_booking room.get_current_booking + + end + end +else #list all tables and rooms with out zones + json.tables @all_tables do |table| + json.id table.id + json.name table.name + json.status table.status + json.zone_id table.zone_id #Add this zone_id to keep data structure consistance + json.current_booking table.get_current_booking + + end + + json.rooms @all_rooms do |room| + json.id room.id + json.name room.name + json.status room.status + json.zone_id room.zone_id #Add this zone_id to keep data structure consistance + json.current_booking room.get_current_booking + + + end +end diff --git a/config/routes.rb b/config/routes.rb index d6e0d305..76b0bb16 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,12 +18,13 @@ Rails.application.routes.draw do namespace :restaurant do get 'zones' => "zones#index" - get "menu" => "menu#index" - get "menu/:id" => "menu#show" + resources :menu, only:[:index, :show] resources :menu_categories, only: [:index] resources :menu_items, only: [:index, :show] - resources :menu_items_attributes, only: [:index] + resources :menu_item_attributes, only: [:index] + resources :menu_item_options, only: [:index] + resources :menu_sold_out, only: [:index] end diff --git a/db/migrate/20170331024749_create_menu_items.rb b/db/migrate/20170331024749_create_menu_items.rb index ae202501..979f51af 100644 --- a/db/migrate/20170331024749_create_menu_items.rb +++ b/db/migrate/20170331024749_create_menu_items.rb @@ -10,8 +10,6 @@ class CreateMenuItems < ActiveRecord::Migration[5.0] t.integer :min_qty, :null => false, :default => 1 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 :item_attributes #value IDS t.string :created_by t.timestamps diff --git a/db/migrate/20170402084230_create_menu_item_instances.rb b/db/migrate/20170402084230_create_menu_item_instances.rb index f4c8123d..d5effcbf 100644 --- a/db/migrate/20170402084230_create_menu_item_instances.rb +++ b/db/migrate/20170402084230_create_menu_item_instances.rb @@ -3,8 +3,8 @@ class CreateMenuItemInstances < ActiveRecord::Migration[5.0] create_table :menu_item_instances do |t| t.references :menu_item, :foreign_key => true, :null => false t.string :item_instance_code, :null => false - t.string :item_instance_name, :string, :null => false - t.json :attributes + t.string :item_instance_name, :null => false + t.json :item_attributes t.decimal :price,:precision => 10, :scale => 2, :null => false, :default => 0.00 t.boolean :is_on_promotion, :null => false, :default => false t.decimal :promotion_price, :precision => 10, :scale => 2, :null => false, :default => 0.00 diff --git a/db/seeds.rb b/db/seeds.rb index 88bddd44..ea396e1b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -46,8 +46,8 @@ order_type = Lookup.create([{lookup_type:'order_type', name: 'Dine-in', value: ' {lookup_type:'order_type', name: 'Delivery', value: 'delivery'}]) #menu_item_type:[simple| set| DIY] -menu_item_type = Lookup.create([{lookup_type:'menu_item_type', name: 'SIMPLE', value: 'simple'}, - {lookup_type:'menu_item_type', name: 'Set Menu', value: 'set_menu'}, +menu_item_type = Lookup.create([{lookup_type:'menu_item_type', name: 'SIMPLE', value: 'simpleItem'}, + {lookup_type:'menu_item_type', name: 'Set Menu', value: 'setMenu'}, {lookup_type:'menu_item_type', name: 'DIY', value: 'diy'}]) #menu_item_attribute:[size|] @@ -89,6 +89,9 @@ tax_profiles = TaxProfile.create({id:1, name: "Commerical Tax", rate:5.0, order_ #Default menu menu = Menu.create({name: "Default Menu", is_active: true, created_by: "SYSTEM DEFAULT"}) +menu_options = MenuItemOption.create([{name: "Less Spicy", value: "less_spicy"},{name: "Spicy", value: "spicy"},{name: "Super Spicy", value: "super_spicy"}]) +menu_options = MenuItemOption.create([{name: "Less Oil", value: "less_oil"},{name: "No MSG", value: "no_msg"},{name: "Less Sweet", value: "less_sweet"}]) + #Default Menu Category menu_category1 = MenuCategory.create({menu: menu, name: "Sample Menu Category 1", alt_name: "Sample Alternate Name 1", order_by: 1}) menu_category2 = MenuCategory.create({menu: menu, name: "Sample Menu Category 2", alt_name: "Sample Alternate Name 2", order_by: 2}) @@ -97,10 +100,12 @@ menu_category4 = MenuCategory.create({menu: menu, name: "Sample Menu Category 4" #Default Menu items menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"01001", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 }) -menu_item0_instance = MenuItemInstance.create([{item_instance_code:"01001", menu_item: menu_category1_menu_item0, }]) -menu_category1_menu_item1 = SimpleMenuItem.create({item_code:"01002", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 }) -menu_category1_menu_item2 = SimpleMenuItem.create({item_code:"01003", name: "Default Menu Item Name 2", alt_name: "Alternate Menu Item Name 2",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 }) -menu_category1_menu_item3 = SimpleMenuItem.create({item_code:"01004", name: "Default Menu Item Name 3", alt_name: "Alternate Menu Item Name 3",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 }) +menu_item0_instance = MenuItemInstance.create([{item_instance_name:"half portion",item_instance_code:"01001-1", menu_item: menu_category1_menu_item0, price:12.00, is_on_promotion:false}]) +menu_item0_instance = MenuItemInstance.create([{item_instance_name:"full portion",item_instance_code:"01001-2", menu_item: menu_category1_menu_item0, price:18.00, is_on_promotion:false}]) + +menu_category1_menu_item1 = SetMenuItem.create({item_code:"01002", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1 }) +menu_category1_menu_item2 = SetMenuItem.create({item_code:"01003", name: "Default Menu Item Name 2",parent: menu_category1_menu_item1, alt_name: "Alternate Menu Item Name 2", min_selectable_item: 1, max_selectable_item:1 }) +menu_category1_menu_item3 = SetMenuItem.create({item_code:"01004", name: "Default Menu Item Name 3",parent: menu_category1_menu_item1, alt_name: "Alternate Menu Item Name 3", min_selectable_item: 1, max_selectable_item:1 }) menu_category2_menu_item0 = SimpleMenuItem.create({item_code:"02005", name: "Default Menu Item Name 0", alt_name: "Alternate Menu Item Name 0",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 }) menu_category2_menu_item1 = SimpleMenuItem.create({item_code:"02006", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 })