order api - WIP & db structure change
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@@ -1,3 +0,0 @@
|
||||
// Place all the styles related to the api/restaurant/zone controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@@ -1,10 +0,0 @@
|
||||
class Api::CustomersController < ActionController::API
|
||||
|
||||
#List all active customers by name
|
||||
def index
|
||||
end
|
||||
|
||||
#Show customer by ID
|
||||
def show
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
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
|
||||
@@ -5,5 +5,7 @@ class Customer < ApplicationRecord
|
||||
validates_presence_of :name, :contact_no
|
||||
validates :contact_no, uniqueness: true
|
||||
|
||||
|
||||
def lastest_invoices
|
||||
sales.where(:customer_id => self.id).order("created_at desc").limit(5)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
class DiningIn < ApplicationRecord
|
||||
belongs_to :table
|
||||
belongs_to :order
|
||||
end
|
||||
@@ -1,12 +1,86 @@
|
||||
class Order < ApplicationRecord
|
||||
before_create :set_order_date
|
||||
before_save :update_products_and_quantity_count
|
||||
|
||||
belongs_to :customer
|
||||
has_many :order_items, inverse_of: :order
|
||||
has_many :dining_ins
|
||||
|
||||
#internal references attributes for business logic control
|
||||
attr_accessor :items, :guest, :table_id, :new_booking, :booking_type
|
||||
|
||||
|
||||
#Main Controller method to create new order - validate all inputs and generate new order
|
||||
# order_item : {
|
||||
# order_item_code : "",
|
||||
# item_instance_code : "",
|
||||
# quantity : 0,
|
||||
# option_values : [],
|
||||
# sub_order_items : [],
|
||||
# }
|
||||
def generate
|
||||
if self.new_booking
|
||||
booking = Booking.create({:dining_facility_id => :table_id, })
|
||||
|
||||
self.adding_line_items
|
||||
self.save!
|
||||
else
|
||||
|
||||
|
||||
booking = Booking.find(self.booking_id)
|
||||
#Add Order Table and Room relation afrer order creation
|
||||
if booking.type = "Table"
|
||||
#add to table_booking_order
|
||||
tbo = TableBookingOrder.create({:table_booking => booking, :order => self})
|
||||
elsif booking.type = "Room"
|
||||
#add to room_booking_order
|
||||
rbo = RoomBookingOrder.create({:table_booking => booking, :order => self})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#Main Method - to update order / add items
|
||||
def modify
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
def validate_api_inputs
|
||||
|
||||
end
|
||||
|
||||
def adding_line_items
|
||||
|
||||
if self.items
|
||||
#loop to add all items to order
|
||||
self.items.each do |item|
|
||||
self.order_items.add( OrderItem.processs_item(item) )
|
||||
end
|
||||
else
|
||||
self.errors.add(:order_items, :blank, message: "Order items cannot be blank")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def set_order_date
|
||||
self.date = Time.now.utc
|
||||
end
|
||||
|
||||
#Update Items Count and Quantity changes whenever there is changes
|
||||
def update_products_and_quantity_count
|
||||
item_count = 0
|
||||
quantity_count = 0
|
||||
# Count number of different items
|
||||
self.item_count = item_count
|
||||
self.quantity_count = quantity_count
|
||||
# Counter number of quantity
|
||||
end
|
||||
|
||||
#Process order items and send to order queue
|
||||
def process_order_queue
|
||||
#Send to background job for processing
|
||||
OrderQueueProcessorJob.perform_later(:order_id => self.id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,28 @@ class OrderItem < ApplicationRecord
|
||||
|
||||
#Validation
|
||||
validates_presence_of :item_code, :item_name, :qty
|
||||
validates :qty, numericality: { :greater_than 0 }
|
||||
validates :qty, numericality: { :greater_than => 0 }
|
||||
validates_associated :orders
|
||||
|
||||
#This Method - handle how items is added into order
|
||||
# order_item : {
|
||||
# order_item_code : "",
|
||||
# item_instance_code : "",
|
||||
# quantity : 0,
|
||||
# option_values : [],
|
||||
# sub_order_items : [],
|
||||
# }
|
||||
def processs_item (item, item_order_by)
|
||||
OrderItem.new do |oitem|
|
||||
oitem.item_code = item.item_code
|
||||
oitem.item_name = item.name
|
||||
oitem.qty = item.qty
|
||||
oitem.option = item.option
|
||||
oitem.variants = item.variants
|
||||
oitem.set_order_items = item.sub_order_items
|
||||
oitem.item_order_by = item_order_by
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
class RoomBooking < ApplicationRecord
|
||||
class RoomBooking < Booking
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
class RoomOrder < ApplicationRecord
|
||||
belongs_to :room
|
||||
belongs_to :orders
|
||||
end
|
||||
@@ -2,7 +2,7 @@
|
||||
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">SXRestaurant</a>
|
||||
<a class="navbar-brand" href="#">H</a>
|
||||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item active">
|
||||
@@ -11,9 +11,7 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Link</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link disabled" href="#">Disabled</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -13,8 +13,15 @@ Rails.application.routes.draw do
|
||||
namespace :restaurant do
|
||||
get 'zones' => "zones#index"
|
||||
get 'tables' => "#index"
|
||||
|
||||
#Order Controller
|
||||
resources :orders, only: [:create, :show, :update]
|
||||
|
||||
|
||||
end
|
||||
|
||||
resources :customers, only: [:index, :show, :create]
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -3,13 +3,12 @@ class CreateOrderItems < ActiveRecord::Migration[5.0]
|
||||
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_order_by #person who order this
|
||||
t.string :item_code, :null => false
|
||||
t.string :item_name, :null => false
|
||||
t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||
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
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
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
|
||||
@@ -1,15 +0,0 @@
|
||||
class CreateRoomBookings < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :room_bookings do |t|
|
||||
t.references :room, :null => false
|
||||
t.datetime :checkin_at, :null => false
|
||||
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
|
||||
@@ -1,11 +0,0 @@
|
||||
class CreateRoomOrders < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :room_orders do |t|
|
||||
t.references :room
|
||||
t.references :orders, foreign_key: true
|
||||
t.string :order_by
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -35,10 +35,10 @@ menu_item_instance : {
|
||||
}
|
||||
|
||||
order_item : {
|
||||
order_item_code : "",
|
||||
item_instance_code : "",
|
||||
item_instance_price: "",
|
||||
quantity : 0,
|
||||
option_values : [],
|
||||
option_values : [{key,value},],
|
||||
sub_order_items : [],
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ customer {name, company, contact, email, member_id, member_type, member_authenti
|
||||
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}
|
||||
room-booking {room, check-in, check-out, reserved_by, status, orders}
|
||||
booking {dining_facility_id, type, checkin_at, checkout_at, checkout_by, reserved_at, reserved_by, status, is_currently_checkin}
|
||||
booking_order(booking, order)
|
||||
|
||||
order_queue_station {name, is_active, processing_items [product_code], print_copy: boolean, printer_name, font_size, cut_per_item, use_alternate_name}
|
||||
order_queue_log {order_id, job_status [new, completed], print_status [], header: {table name, order_type, order_date}, items :{name, comment, qty}}
|
||||
|
||||
10
db/seeds.rb
10
db/seeds.rb
@@ -47,11 +47,6 @@ menu_item_type = Lookup.create([{lookup_type:'menu_item_type', name: 'SIMPLE', v
|
||||
{lookup_type:'menu_item_type', name: 'Set Menu', value: 'set_menu'},
|
||||
{lookup_type:'menu_item_type', name: 'DIY', value: 'diy'}])
|
||||
|
||||
#dining_facilities:[available| reserved | occupied| cleaning]
|
||||
dining_facilities_status = Lookup.create([{lookup_type:'dining_facilities_status', name: 'Available', value: 'available'},
|
||||
{lookup_type:'dining_facilities_status', name: 'Reserved', value: 'reserved'},
|
||||
{lookup_type:'dining_facilities_status', name: 'Occupied', value: 'occupied'},
|
||||
{lookup_type:'dining_facilities_status', name: 'Cleaning', value: 'cleaning'}])
|
||||
|
||||
#Employee Roles
|
||||
employee_roles = Lookup.create([{lookup_type:'employee_roles', name: 'Cashier', value: 'cashier'},
|
||||
@@ -60,6 +55,11 @@ employee_roles = Lookup.create([{lookup_type:'employee_roles', name: 'Cashier',
|
||||
{lookup_type:'employee_roles', name: 'Manager', value: 'manager'},
|
||||
{lookup_type:'employee_roles', name: 'Administrator', value: 'Administrator'}])
|
||||
|
||||
#booking_status
|
||||
booking_status = Lookup.create([{lookup_type:'booking_status', name: 'Available', value: 'available'},
|
||||
{lookup_type:'booking_status', name: 'Reserved', value: 'reserved'},
|
||||
{lookup_type:'booking_status', name: 'Occupied', value: 'occupied'},
|
||||
{lookup_type:'booking_status', name: 'Cleaning', value: 'cleaning'}])
|
||||
|
||||
#WALK CUSTOMER - Default CUSTOMER (take key 1)
|
||||
customer = Customer.create({id:1, name:"WALK-IN", contact_no:"000000000"})
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiningIn, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RoomBooking, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -1,5 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RoomOrder, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Reference in New Issue
Block a user