From e71ca0dee83771a3e33bfa123aa15d6defbe1bb1 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 3 Aug 2017 13:31:52 +0630 Subject: [PATCH] update room --- app/controllers/origami/rooms_controller.rb | 27 ++++----- app/views/origami/rooms/show.html.erb | 67 +++++++++++++-------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index de06ef62..23d64602 100644 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -1,7 +1,5 @@ class Origami::RoomsController < BaseOrigamiController - before_action :set_dining, only: [:show] - def index @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') @@ -16,18 +14,19 @@ class Origami::RoomsController < BaseOrigamiController @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('date desc') - # @room = DiningFacility.find(params[:room_id]) + @room = DiningFacility.find(params[:room_id]) - @status = "" + @status_order = "" + @status_sale = "" @sale_array = Array.new - @dining.bookings.active.each do |booking| + @room.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new booking.booking_orders.each do |booking_order| order = Order.find(booking_order.order_id) if (order.status == "new") - @obj = order + @obj_order = order @customer = order.customer @date = order.created_at order.order_items.each do |item| @@ -35,17 +34,18 @@ class Origami::RoomsController < BaseOrigamiController end end end - @status = 'order' + @status_order = 'order' else sale = Sale.find(booking.sale_id) if sale.sale_status != "completed" && sale.sale_status != 'void' + puts "enter" @sale_array.push(sale) - if @status == 'order' - @status = 'sale' + if @status_order == 'order' + @status_order = 'sale' end @date = sale.created_at - @status = 'sale' - @obj = sale + @status_sale = 'sale' + @obj_sale = sale @customer = sale.customer end end @@ -77,10 +77,5 @@ class Origami::RoomsController < BaseOrigamiController # end end - private - -def set_dining - @dining = DiningFacility.find(params[:room_id]) -end end diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index c72ded6e..39d55757 100644 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -119,9 +119,9 @@
- <% if @status == 'order' %> -
ORDER DETAILS | Table <%= @room.name rescue "" %>
- <% elsif @status == 'sale' %> + <% if @status_order == 'order' %> +
ORDER DETAILS | Table <%= @room.name rescue "" %>
+ <% elsif @status_sale == 'sale' %>
INVOICE DETAILS | Table <%= @room.name rescue "" %>
<% end %> @@ -130,21 +130,21 @@

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

-

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

+

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

- <% if @status == 'sale' %> - -

Customer : <%= @obj.customer.name rescue '-' %>

+ <% if @status_sale == 'sale' %> + +

Customer : <%= @obj_sale_sale.customer.name rescue '-' %>

<%else%>

Customer : <%= @customer.name rescue "-" %>

@@ -156,6 +156,7 @@ + <% + count = 0 sub_total = 0 - if @status == "sale" - @obj.sale_items.each do |sale_item| - sub_total = sub_total + sale_item.price + if @status_sale == "sale" + @sale_array[0].sale_items.each do |sale_item| + + sub_total = sub_total + sale_item.price %> - - <% unless sale_item.price == 0 %> + + <% + # Can't check for discount + unless sale_item.price == 0 + count += 1 + %> + + <% - end + + end end end - if @status == 'order' + if @status_order == 'order' && @status_sale != 'sale' unless @order_items.nil? + count = 0 @order_items.each do |order_item | + count += 1 sub_total = sub_total + (order_item.price * order_item.qty) unless order_item.price == 0 %> + <% + end end end @@ -207,25 +221,26 @@ - <%if @obj != nil && @status == 'sale' && @obj.discount_type == 'member_discount'%> + <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%> <%else%> <%end%> - + + - <% if @status == "sale" %> + <% if @status_sale == "sale" %> - + - + - + <% end %> @@ -233,7 +248,7 @@
<% - if @status == 'sale' + if @status_sale == 'sale' unless @order_items.nil? %> Pending New Order @@ -289,7 +304,7 @@ <% if @room.bookings.length >= 1 %> - <% if @status == 'order' && @status != 'sale' %> + <% if @status_order == 'order' && @status_sale != 'sale' %> @@ -520,7 +535,7 @@ $('#back').on('click',function(){ $('#add_invoice').on('click',function(){ var dining_id = "<%= @room.id %>" - var sale_id = "<%= @obj.sale_id rescue "" %>" + var sale_id = "<%= @obj_sale.sale_id rescue "" %>" var ajax_url = "/origami/sale/append_order"; $.ajax({ type: "POST", @@ -603,7 +618,7 @@ $('#add_invoice').on('click',function(){ $('#edit').on('click',function(){ var dining_id = "<%= @room.id %>" - var sale_id = "<%= @obj.sale_id rescue "" %>" + var sale_id = "<%= @obj_sale.sale_id rescue "" %>" window.location.href = '/origami/table/'+ dining_id + "/sale/"+ sale_id + "/edit"; });
Items QTY Price @@ -163,35 +164,48 @@
<%= count %> <%= sale_item.product_name %> <%= sale_item.qty %> <%= sale_item.price %>
<%= count %> <%= order_item.item_name %> <%= order_item.qty %> <%= order_item.qty*order_item.price %>
<%= sub_total %>
Member Discount:Discount:(<%=@obj.total_discount rescue 0%>)(<%= @obj_sale.total_discount rescue 0%>)
Tax:<%= @obj.total_tax rescue 0%><%= @obj_sale.total_tax rescue 0%>
Rounding Adj:<%= @obj.rounding_adjustment rescue 0%><%= @obj_sale.rounding_adjustment rescue 0%>
Grand Total:<%= @obj.grand_total rescue 0%><%= @obj_sale.grand_total rescue 0%>