move table
This commit is contained in:
@@ -9,15 +9,17 @@ class Api::BillController < Api::ApiController
|
||||
#create Bill by Booking ID
|
||||
if (params[:booking_id])
|
||||
booking = Booking.find(params[:booking_id])
|
||||
if booking
|
||||
if booking.sale_id.nil?
|
||||
@sale = Sale.new
|
||||
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee)
|
||||
else
|
||||
@status = true
|
||||
@sale_id = booking.sale_id
|
||||
|
||||
if booking
|
||||
if booking.sale_id.nil?
|
||||
@sale = Sale.new
|
||||
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee)
|
||||
else
|
||||
@status = true
|
||||
@sale_id = booking.sale_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elsif (params[:order_id])
|
||||
@sale = Sale.new
|
||||
@status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee)
|
||||
|
||||
@@ -6,11 +6,9 @@ class Api::BookingsController < Api::ApiController
|
||||
end
|
||||
|
||||
def show
|
||||
@booking = Booking.find(params[:id])
|
||||
booking = Booking.find(params[:id])
|
||||
if booking.dining_facility_id.to_i == params[:table_id].to_i
|
||||
@booking = booking
|
||||
end
|
||||
end
|
||||
|
||||
# private
|
||||
# def Bookings_params
|
||||
# params.permit(:id, :order_id)
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -7,11 +7,45 @@ class Api::OrdersController < Api::ApiController
|
||||
order = Order.find(params[:order_id])
|
||||
order.order_items
|
||||
end
|
||||
|
||||
def get_order
|
||||
order = Order.find(params[:order_id])
|
||||
order.order_items
|
||||
end
|
||||
|
||||
# API - This api will retrive current booking for android with table or room id
|
||||
def view_orders
|
||||
booking_id = params[:booking_id]
|
||||
table_id = params[:table_id]
|
||||
if Booking.exists?(booking_id)
|
||||
booking = Booking.find(booking_id)
|
||||
|
||||
if booking
|
||||
if booking.dining_facility_id.to_i == table_id.to_i
|
||||
@booking = booking
|
||||
else
|
||||
table = DiningFacility.find(table_id)
|
||||
booking = table.get_current_booking
|
||||
if booking
|
||||
if booking.dining_facility_id.to_i == table_id.to_i
|
||||
@booking = booking
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
puts "only table"
|
||||
table = DiningFacility.find(table_id)
|
||||
booking = table.get_current_booking
|
||||
puts booking
|
||||
if booking
|
||||
if booking.dining_facility_id.to_i == table_id.to_i
|
||||
@booking = booking
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Description
|
||||
# This API allow new order creation
|
||||
# Input Params
|
||||
@@ -38,18 +72,50 @@ class Api::OrdersController < Api::ApiController
|
||||
if !params["booking_id"].nil?
|
||||
# check booking id is already completed.
|
||||
booking = Booking.find(params[:booking_id])
|
||||
if !booking.sale_id.nil?
|
||||
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
|
||||
@order.new_booking = true
|
||||
if booking
|
||||
if booking.dining_facility_id.to_i == params[:table_id].to_i
|
||||
if !booking.sale_id.nil?
|
||||
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
|
||||
@order.new_booking = true
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = params[:booking_id]
|
||||
end
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = params[:booking_id]
|
||||
puts "booking sale is null"
|
||||
end
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = params[:booking_id]
|
||||
# booking.table id not equal current table
|
||||
table = DiningFacility.find(params[:table_id])
|
||||
if table
|
||||
booking = table.get_current_booking
|
||||
if booking
|
||||
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
|
||||
@order.new_booking = true
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = booking.booking_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = params[:booking_id]
|
||||
puts "booking sale is null"
|
||||
end
|
||||
end #booking exists
|
||||
else
|
||||
#no booking id
|
||||
table = DiningFacility.find(params[:table_id])
|
||||
if table
|
||||
booking = table.get_current_booking
|
||||
if booking
|
||||
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
|
||||
@order.new_booking = true
|
||||
else
|
||||
@order.new_booking = false
|
||||
@order.booking_id = booking.booking_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@status, @booking = @order.generate
|
||||
|
||||
@@ -15,9 +15,10 @@ class Origami::HomeController < BaseOrigamiController
|
||||
@complete = Sale.all
|
||||
@orders = Order.all.order('date desc')
|
||||
@status_order = ""
|
||||
@order_items = Array.new
|
||||
@dining.bookings.each do |booking|
|
||||
if booking.sale_id.nil?
|
||||
@order_items = Array.new
|
||||
|
||||
booking.booking_orders.each do |booking_order|
|
||||
order = Order.find(booking_order.order_id)
|
||||
@obj_order = order
|
||||
|
||||
@@ -8,9 +8,10 @@ class Origami::MovetableController < BaseOrigamiController
|
||||
|
||||
@status_order = ""
|
||||
@dining = DiningFacility.find(params[:dining_id])
|
||||
@order_items = Array.new
|
||||
@dining.bookings.each do |booking|
|
||||
if booking.sale_id.nil?
|
||||
@order_items = Array.new
|
||||
|
||||
booking.booking_orders.each do |booking_order|
|
||||
order = Order.find(booking_order.order_id)
|
||||
@obj_order = order
|
||||
|
||||
@@ -4,7 +4,12 @@ class Origami::OrdersController < BaseOrigamiController
|
||||
@tables = Table.all.active.order('status desc')
|
||||
@rooms = Room.all.active.order('status desc')
|
||||
@complete = Sale.all
|
||||
@orders = Order.all.order('date desc')
|
||||
@orders = Order.all.order('status desc')
|
||||
@order = Order.find(params[:order_id])
|
||||
sale_order = SaleOrder.find_by_order_id(@order.order_id)
|
||||
if sale_order
|
||||
sale = Sale.find(sale_order.sale_id)
|
||||
@sale_status = sale.sale_status
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,6 +15,19 @@ class Booking < ApplicationRecord
|
||||
booking.dining_facility_id = newd
|
||||
booking.save
|
||||
end
|
||||
table = DiningFacility.find(newd)
|
||||
if table
|
||||
booking = table.get_current_booking
|
||||
if booking
|
||||
newtablebookingID= booking.booking_id
|
||||
booking_arr.each do |booking|
|
||||
booking.booking_orders.each do |booking_order|
|
||||
booking_order.booking_id = newtablebookingID
|
||||
booking_order.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
new_dining = DiningFacility.find(newd)
|
||||
new_dining.make_occupied
|
||||
old_dining = DiningFacility.find(old)
|
||||
|
||||
@@ -19,11 +19,10 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_current_booking
|
||||
puts "enter booking"
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
|
||||
|
||||
if booking.count > 0 then
|
||||
return booking[0].booking_id
|
||||
return booking[0]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class Order < ApplicationRecord
|
||||
#primary key - need to be unique
|
||||
before_create :generate_custom_id
|
||||
before_create :set_order_date
|
||||
|
||||
has_many :sale_orders
|
||||
belongs_to :customer
|
||||
has_many :order_items, autosave: true , inverse_of: :order
|
||||
has_many :assigned_order_items
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
if (@booking)
|
||||
json.success true
|
||||
json.id @booking.booking_id
|
||||
json.status @booking.booking_status
|
||||
if Sale.exists?(@booking.sale_id)
|
||||
@@ -43,5 +44,6 @@ if (@booking)
|
||||
json.sub_total @total_amount
|
||||
json.commerical_tax @total_amount * 0.05
|
||||
json.total @total_amount + (@total_amount * 0.05)
|
||||
|
||||
else
|
||||
json.success false
|
||||
end
|
||||
|
||||
49
app/views/api/orders/view_orders.json.jbuilder
Normal file
49
app/views/api/orders/view_orders.json.jbuilder
Normal file
@@ -0,0 +1,49 @@
|
||||
if (@booking)
|
||||
json.success true
|
||||
json.booking_id @booking.booking_id
|
||||
json.status @booking.booking_status
|
||||
if Sale.exists?(@booking.sale_id)
|
||||
json.sale_status Sale.find(@booking.sale_id).sale_status
|
||||
else
|
||||
json.sale_status ""
|
||||
end
|
||||
json.checkin_at @booking.checkin_at.strftime("%d-%m-%Y")
|
||||
json.checkin_by @booking.checkin_by
|
||||
json.table_name @booking.dining_facility.name
|
||||
|
||||
if @booking.type == "TableBooking"
|
||||
json.table_id @booking.dining_facility_id
|
||||
else
|
||||
json.room_id @booking.dining_facility_id
|
||||
end
|
||||
@total_amount = 0.00
|
||||
@total_tax = 0.00
|
||||
|
||||
if @booking.booking_orders
|
||||
order_items = []
|
||||
@booking.booking_orders.each do |bo|
|
||||
order = Order.find(bo.order_id)
|
||||
#if (order.status == "new")
|
||||
order_items = order_items + order.order_items
|
||||
#end
|
||||
end
|
||||
|
||||
json.order_items order_items do |item|
|
||||
json.item_instance_code item.item_code
|
||||
json.item_name item.item_name
|
||||
json.price item.price
|
||||
json.qty item.qty
|
||||
json.options item.options
|
||||
json.remark item.remark
|
||||
json.item_status item.order_item_status
|
||||
@total_amount = @total_amount + (item.price * item.qty)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
json.sub_total @total_amount
|
||||
json.commerical_tax @total_amount * 0.05
|
||||
json.total @total_amount + (@total_amount * 0.05)
|
||||
else
|
||||
json.success false
|
||||
end
|
||||
@@ -8,7 +8,7 @@ if @zones
|
||||
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
|
||||
json.current_booking table.get_current_booking.booking_id rescue ""
|
||||
end
|
||||
|
||||
json.rooms zone.rooms do |room|
|
||||
@@ -16,7 +16,7 @@ if @zones
|
||||
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
|
||||
json.current_booking room.get_current_booking.booking_id rescue ""
|
||||
|
||||
end
|
||||
end
|
||||
@@ -26,7 +26,7 @@ else #list all tables and rooms with out zones
|
||||
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
|
||||
json.current_booking table.get_current_booking.booking_id rescue ""
|
||||
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ else #list all tables and rooms with out zones
|
||||
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
|
||||
json.current_booking room.get_current_booking.booking_id rescue ""
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -229,6 +229,7 @@
|
||||
<div class="col-lg-1 col-md-1 col-sm-1">
|
||||
<!-- Waiter Buttons -->
|
||||
<button type="button" class="btn btn-primary btn-block" id='back' >Back</button>
|
||||
<% if @dining.bookings.length >= 1 %>
|
||||
<button type="button" class="btn btn-primary btn-block" disabled>Add Order</button>
|
||||
<button type="button" class="btn btn-primary btn-block" disabled>Edit</button>
|
||||
<button type="button" class="btn btn-primary btn-block" id='move'>Move</button>
|
||||
@@ -243,6 +244,7 @@
|
||||
<!-- Cashier Buttons -->
|
||||
<button type="button" id="discount" class="btn btn-primary btn-block" >Discount</button>
|
||||
<button type="button" id="re-print" class="btn btn-primary btn-block" >Re.Print</button>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
@@ -143,6 +143,30 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<%
|
||||
if @status_sale == 'sale'
|
||||
unless @order_items.nil?
|
||||
%>
|
||||
Pending New Order
|
||||
<table class="table table-striped">
|
||||
<%
|
||||
@order_items.each do |order_item |
|
||||
%>
|
||||
|
||||
<tr>
|
||||
<td class='item-name'><%= order_item.item_name %></td>
|
||||
<td class='item-attr'><%= order_item.qty %></td>
|
||||
<td class='item-attr'><%= order_item.qty*order_item.price %></td>
|
||||
</tr>
|
||||
|
||||
<%
|
||||
end
|
||||
%>
|
||||
</table>
|
||||
<%
|
||||
end
|
||||
end
|
||||
%>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="pay purple" id="move_table">MOVE TABLE</div>
|
||||
|
||||
@@ -81,7 +81,20 @@
|
||||
<% @orders.each do |order| %>
|
||||
<div class="card orders red text-white" data-id = "<%= order.order_id %>">
|
||||
<div class="card-block">
|
||||
<%= order.order_id %>
|
||||
<%
|
||||
order_status = ""
|
||||
sale_order = SaleOrder.find_by_order_id(order)
|
||||
if sale_order
|
||||
sale = Sale.find(sale_order.sale_id)
|
||||
order_status = sale.sale_status
|
||||
if order_status == 'new'
|
||||
order_status = order.status
|
||||
end
|
||||
else
|
||||
order_status = order.status
|
||||
end
|
||||
%>
|
||||
<%= order.order_id %> | <%= order_status %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -137,10 +150,8 @@
|
||||
<td class='item-attr'><%= sale_item.price %></td>
|
||||
</tr>
|
||||
<%
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
%>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -165,6 +176,9 @@
|
||||
<!-- Column Three -->
|
||||
<div class="col-lg-1 col-md-1 col-sm-1">
|
||||
<button type="button" class="btn btn-primary btn-block" id='back'>Back</button>
|
||||
<% if @sale_status != 'completed' %>
|
||||
<button type="button" class="btn btn-primary btn-block" id='move'>MOVE</button>
|
||||
<% end %>
|
||||
<button type="button" id="re-print" class="btn btn-primary btn-block">Re.Print</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -193,5 +207,8 @@ $('#pay').on('click',function() {
|
||||
});
|
||||
$('#back').on('click',function(){
|
||||
window.location.href = '/origami/';
|
||||
})
|
||||
$('#move').on('click',function(){
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user