From 0ff10f2f32684af9bf2951a5aafa86bf83a687c1 Mon Sep 17 00:00:00 2001 From: Nweni Date: Thu, 22 Jun 2017 05:51:42 +0630 Subject: [PATCH] move multiple order and sales --- app/controllers/origami/home_controller.rb | 3 +- .../origami/movetable_controller.rb | 9 ++-- app/models/booking.rb | 13 ------ app/views/origami/home/show.html.erb | 23 +++++++---- .../origami/movetable/move_dining.html.erb | 41 ++++++++++++++----- 5 files changed, 53 insertions(+), 36 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index dc61f7fb..4c35a918 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -19,8 +19,9 @@ class Origami::HomeController < BaseOrigamiController @sale_array = Array.new @dining.bookings.each do |booking| if booking.sale_id.nil? + @order_items = Array.new booking.booking_orders.each do |booking_order| - @order_items = Array.new + order = Order.find(booking_order.order_id) @obj_order = order @date = order.created_at diff --git a/app/controllers/origami/movetable_controller.rb b/app/controllers/origami/movetable_controller.rb index c5b2b2fc..cc6281ce 100644 --- a/app/controllers/origami/movetable_controller.rb +++ b/app/controllers/origami/movetable_controller.rb @@ -5,14 +5,14 @@ class Origami::MovetableController < BaseOrigamiController @rooms = Room.all.active.order('status desc') @complete = Sale.all @orders = Order.all.order('date desc') + @dining = DiningFacility.find(params[:dining_id]) @status_order = "" - @dining = DiningFacility.find(params[:dining_id]) - @order_items = Array.new + @status_sale = "" + @sale_array = 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) @@ -26,6 +26,7 @@ class Origami::MovetableController < BaseOrigamiController else sale = Sale.find(booking.sale_id) if sale.sale_status != "completed" + @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' end diff --git a/app/models/booking.rb b/app/models/booking.rb index 4aa177fc..79fbad4a 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -15,19 +15,6 @@ 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) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index d1629a04..b6398686 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -108,7 +108,7 @@

Receipt No: <% if @status_sale == 'sale' %> - <%= @obj_sale.receipt_no rescue '' %> + <%= @sale_array[0].receipt_no rescue '' %> <% end %>

@@ -126,6 +126,7 @@ + <% + count = 0 sub_total = 0 if @status_sale == "sale" - @obj_sale.sale_items.each do |sale_item| + puts @sale_array[0] + @sale_array[0].sale_items.each do |sale_item| + count += 1 sub_total = sub_total + sale_item.price %> - + <% unless sale_item.price <= 0 %> + @@ -152,11 +157,16 @@ if @status_order == 'order' && @status_sale != 'sale' unless @order_items.nil? + count = 0 @order_items.each do |order_item | + puts @order_items.size + puts "view" + count += 1 sub_total = sub_total + order_item.price unless order_item.price <= 0 %> + @@ -220,14 +230,13 @@ else @sale_array.each do |sale| if @sale_array.size > 1 + unless sale.receipt_no == @sale_array[0].receipt_no %> Pending New Invoice - <% - unless sale.receipt_no == @obj_sale.receipt_no - %>
# Items QTY Price @@ -133,14 +134,18 @@
<%= 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 %>
- + +
<%= sale.receipt_no %>Receipt No - <%= sale.receipt_no %>
<% diff --git a/app/views/origami/movetable/move_dining.html.erb b/app/views/origami/movetable/move_dining.html.erb index 7874f42b..83419ca0 100644 --- a/app/views/origami/movetable/move_dining.html.erb +++ b/app/views/origami/movetable/move_dining.html.erb @@ -81,7 +81,7 @@

Receipt No: <% if @status_sale == 'sale' %> - <%= @obj_sale.receipt_no rescue '' %> + <%= @sale_array[0].receipt_no rescue '' %> <% end %>

@@ -110,11 +110,12 @@ count = 0 sub_total = 0 if @status_sale == "sale" - @obj_sale.sale_items.each do |sale_item| + puts @sale_array[0] + @sale_array[0].sale_items.each do |sale_item| + count += 1 sub_total = sub_total + sale_item.price - count += 1 %> - + <% unless sale_item.price <= 0 %> <%= count %> @@ -126,12 +127,16 @@ end end end - count = 0 - if @status_order == 'order' && @status_sale != 'sale' + + if @status_order == 'order' && @status_sale != 'sale' unless @order_items.nil? + count = 0 @order_items.each do |order_item | + puts @order_items.size + puts "view" + count += 1 sub_total = sub_total + order_item.price - count += 1 + unless order_item.price <= 0 %> <%= count %> @@ -155,13 +160,10 @@ Pending New Order <% - count = 0 @order_items.each do |order_item | - count += 1 %> - @@ -171,9 +173,26 @@ end %>
<%= count %> <%= order_item.item_name %> <%= order_item.qty %> <%= order_item.qty*order_item.price %>
+ <% + else + @sale_array.each do |sale| + if @sale_array.size > 1 + unless sale.receipt_no == @sale_array[0].receipt_no + %> + Pending New Invoice + + + + + +
Receipt No - <%= sale.receipt_no %>
+ <% + end + end + end + end end - end %>