From fa309fb89a8c6c6448459b51075da7e8bf5eb58e Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 21 Jun 2017 05:36:58 +0630 Subject: [PATCH] move whole table --- .../origami/moveroom_controller.rb | 37 ++++ .../origami/movetable_controller.rb | 49 +++++ app/models/booking.rb | 13 ++ app/models/dining_facility.rb | 10 + app/views/origami/home/show.html.erb | 15 +- .../origami/moveroom/move_dining.html.erb | 207 ++++++++++++++++++ .../origami/movetable/move_dining.html.erb | 207 ++++++++++++++++++ .../origami/movetable/moving.json.jbuilder | 2 + app/views/origami/orders/show.html.erb | 5 +- app/views/origami/rooms/show.html.erb | 11 +- app/views/origami/sales/show.html.erb | 5 +- config/routes.rb | 5 +- 12 files changed, 558 insertions(+), 8 deletions(-) create mode 100644 app/controllers/origami/moveroom_controller.rb create mode 100644 app/controllers/origami/movetable_controller.rb create mode 100644 app/views/origami/moveroom/move_dining.html.erb create mode 100644 app/views/origami/movetable/move_dining.html.erb create mode 100644 app/views/origami/movetable/moving.json.jbuilder diff --git a/app/controllers/origami/moveroom_controller.rb b/app/controllers/origami/moveroom_controller.rb new file mode 100644 index 00000000..c51fcbb1 --- /dev/null +++ b/app/controllers/origami/moveroom_controller.rb @@ -0,0 +1,37 @@ +class Origami::MoveroomController < BaseOrigamiController + + def move_dining + @tables = Table.all.active.order('status desc') + @rooms = Room.all.active.order('status desc') + @complete = Sale.all + @orders = Order.all.order('date desc') + + @status_order = "" + @dining = DiningFacility.find(params[:dining_id]) + @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 + @date = order.created_at + order.order_items.each do |item| + @order_items.push(item) + end + end + @status_order = 'order' + else + sale = Sale.find(booking.sale_id) + if sale.sale_status != "completed" + if @status_order == 'order' + @status_order = 'sale' + end + @date = sale.created_at + @status_sale = 'sale' + @obj_sale = sale + end + end + end + end + +end diff --git a/app/controllers/origami/movetable_controller.rb b/app/controllers/origami/movetable_controller.rb new file mode 100644 index 00000000..8199411c --- /dev/null +++ b/app/controllers/origami/movetable_controller.rb @@ -0,0 +1,49 @@ +class Origami::MovetableController < BaseOrigamiController + + def move_dining + @tables = Table.all.active.order('status desc') + @rooms = Room.all.active.order('status desc') + @complete = Sale.all + @orders = Order.all.order('date desc') + + @status_order = "" + @dining = DiningFacility.find(params[:dining_id]) + @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 + @date = order.created_at + order.order_items.each do |item| + @order_items.push(item) + end + end + @status_order = 'order' + else + sale = Sale.find(booking.sale_id) + if sale.sale_status != "completed" + if @status_order == 'order' + @status_order = 'sale' + end + @date = sale.created_at + @status_sale = 'sale' + @obj_sale = sale + end + end + end + end + + def moving + change_to = params[:change_to] #new + change_from = params[:change_from] #original + bookings = Booking.where('dining_facility_id=?',change_from) + booking_array = Array.new + bookings.each do | booking | + if booking.sale_id.nil? || booking.sale.sale_status != 'completed' + booking_array.push(booking) + end + end + @get_type = Booking.update_dining_facility(booking_array,change_to,change_from) + end +end diff --git a/app/models/booking.rb b/app/models/booking.rb index 01cf0f46..79fbad4a 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -10,6 +10,19 @@ class Booking < ApplicationRecord has_many :booking_orders has_many :orders, :through => :booking_orders + def self.update_dining_facility(booking_arr, newd, old) + booking_arr.each do |booking| + booking.dining_facility_id = newd + booking.save + end + new_dining = DiningFacility.find(newd) + new_dining.make_occupied + old_dining = DiningFacility.find(old) + old_dining.make_available + + return new_dining.type + end + private def generate_custom_id self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI") diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 65c337e4..c699a534 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -8,6 +8,16 @@ class DiningFacility < ApplicationRecord scope :active, -> {where(is_active: true)} + def make_available + self.status = 'available' + self.save + end + + def make_occupied + self.status = 'occupied' + self.save + 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) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 1e2acba0..07d0fa99 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -228,12 +228,12 @@
- + - + - <% if @status == 'order' %> + <% if @status_order == 'order' %> <% else %> @@ -282,4 +282,13 @@ $('#request_bills').click(function() { } }); }); + +$('#move').on('click',function(){ + var dining_id = "<%= @dining.id %>" + window.location.href = '/origami/table/'+ dining_id + "/movetable"; +}) + +$('#back').on('click',function(){ + window.location.href = '/origami/'; +}) diff --git a/app/views/origami/moveroom/move_dining.html.erb b/app/views/origami/moveroom/move_dining.html.erb new file mode 100644 index 00000000..495e1514 --- /dev/null +++ b/app/views/origami/moveroom/move_dining.html.erb @@ -0,0 +1,207 @@ +
+ +
+ + + + + +
+ + + + +
+
+ <% @tables.each do |table| %> + <% if table.status == 'occupied' %> +
+
+ <%= table.name %> +
+
+ <% else %> +
+
+ <%= table.name %> +
+
+ <% end %> + <% end %> +
+
+ + +
+
+ <% @rooms.each do |room| %> + <% if room.status == 'occupied' %> +
+
+ <%= room.name %> +
+
+ <% else %> +
+
+ <%= room.name %> +
+
+ <% end %> + <% end %> +
+
+ + + + +
+ +
+ + + +
+
+
+
MOVE --> ' <%= @dining.name %>' to
+ +
+
+
+
+

Receipt No: + <% if @status_sale == 'sale' %> + <%= @obj_sale.receipt_no rescue '' %> + <% end %> +

+
+
+

Date: <%= @date.utc.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

+
+
+
+
+

Customer :

+
+ +
+
+ + + + + + + + <% + sub_total = 0 + if @status_sale == "sale" + @obj_sale.sale_items.each do |sale_item| + sub_total = sub_total + sale_item.price + %> + + <% unless sale_item.price <= 0 %> + + + + + + <% + end + end + end + + if @status_order == 'order' + unless @order_items.nil? + @order_items.each do |order_item | + sub_total = sub_total + order_item.price + + unless order_item.price <= 0 %> + + + + + + <% + end + end + end + end + %> + +
ItemsQTY + Price +
<%= sale_item.product_name %><%= sale_item.qty %><%= sale_item.price %>
<%= order_item.item_name %><%= order_item.qty %><%= order_item.qty*order_item.price %>
+
+
+
+
MOVE TABLE
+
+
+
+
+
+ + +
+ + + + +
+
+ diff --git a/app/views/origami/movetable/move_dining.html.erb b/app/views/origami/movetable/move_dining.html.erb new file mode 100644 index 00000000..ad69b653 --- /dev/null +++ b/app/views/origami/movetable/move_dining.html.erb @@ -0,0 +1,207 @@ +
+ +
+ + + + + +
+ + + + +
+
+ <% @tables.each do |table| %> + <% if table.status == 'occupied' %> +
+
+ <%= table.name %> +
+
+ <% else %> +
+
+ <%= table.name %> +
+
+ <% end %> + <% end %> +
+
+ + +
+
+ <% @rooms.each do |room| %> + <% if room.status == 'occupied' %> +
+
+ <%= room.name %> +
+
+ <% else %> +
+
+ <%= room.name %> +
+
+ <% end %> + <% end %> +
+
+ + + + +
+ +
+ + + +
+
+
+
MOVE --> ' <%= @dining.name %> ' to
+ +
+
+
+
+

Receipt No: + <% if @status_sale == 'sale' %> + <%= @obj_sale.receipt_no rescue '' %> + <% end %> +

+
+
+

Date: <%= @date.utc.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

+
+
+
+
+

Customer :

+
+ +
+
+ + + + + + + + <% + sub_total = 0 + if @status_sale == "sale" + @obj_sale.sale_items.each do |sale_item| + sub_total = sub_total + sale_item.price + %> + + <% unless sale_item.price <= 0 %> + + + + + + <% + end + end + end + + if @status_order == 'order' + unless @order_items.nil? + @order_items.each do |order_item | + sub_total = sub_total + order_item.price + + unless order_item.price <= 0 %> + + + + + + <% + end + end + end + end + %> + +
ItemsQTY + Price +
<%= sale_item.product_name %><%= sale_item.qty %><%= sale_item.price %>
<%= order_item.item_name %><%= order_item.qty %><%= order_item.qty*order_item.price %>
+
+
+
+
MOVE TABLE
+
+
+
+
+
+ + +
+ + + + +
+
+ diff --git a/app/views/origami/movetable/moving.json.jbuilder b/app/views/origami/movetable/moving.json.jbuilder new file mode 100644 index 00000000..8030f9fe --- /dev/null +++ b/app/views/origami/movetable/moving.json.jbuilder @@ -0,0 +1,2 @@ +json.status true +json.get_type @get_type diff --git a/app/views/origami/orders/show.html.erb b/app/views/origami/orders/show.html.erb index d15870b1..dccb3401 100644 --- a/app/views/origami/orders/show.html.erb +++ b/app/views/origami/orders/show.html.erb @@ -164,7 +164,7 @@
- +
@@ -191,4 +191,7 @@ $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); window.location.href = '/origami/sale/'+ sale_id + "/payment"; }); +$('#back').on('click',function(){ + window.location.href = '/origami/'; +}) diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index c1a03461..c1797158 100644 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -228,10 +228,10 @@
- + - + @@ -264,4 +264,11 @@ $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); window.location.href = '/origami/sale/'+ sale_id + "/payment"; }); +$('#move').on('click',function(){ + var dining_id = "<%= @room.id %>" + window.location.href = '/origami/table/'+ dining_id + "/moveroom"; +}) +$('#back').on('click',function(){ + window.location.href = '/origami/'; +}) diff --git a/app/views/origami/sales/show.html.erb b/app/views/origami/sales/show.html.erb index 626d6256..81face96 100644 --- a/app/views/origami/sales/show.html.erb +++ b/app/views/origami/sales/show.html.erb @@ -174,7 +174,7 @@
- +
@@ -203,4 +203,7 @@ $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); window.location.href = '/origami/sale/'+ sale_id + "/payment"; }); +$('#back').on('click',function(){ + window.location.href = '/origami/'; +}) diff --git a/config/routes.rb b/config/routes.rb index de7b2a6f..8f9b7dea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -73,10 +73,13 @@ Rails.application.routes.draw do namespace :origami do root "home#index" get "table/:dining_id" => "home#show" do #origami/:booking_id will show - # resources :discounts, only: [:index,:new, :create ] #add discount type resources :customers #add customer type end + post 'moving' => "movetable#moving" + + get 'table/:dining_id/movetable' => "movetable#move_dining" + get 'table/:dining_id/moveroom' => "moveroom#move_dining" get 'sale/:sale_id' => 'sales#show' get 'room/:room_id' => 'rooms#show' get 'order/:order_id' => "orders#show"