update room

This commit is contained in:
Aung Myo
2017-08-03 13:31:52 +06:30
parent 518314c772
commit e71ca0dee8
2 changed files with 52 additions and 42 deletions

View File

@@ -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

View File

@@ -119,9 +119,9 @@
<div class="col-lg-5 col-md-5 col-sm-5">
<div class="card" >
<div class="card-header">
<% if @status == 'order' %>
<div id="save_order_id" data-order="<%= @obj.order_id %>"><strong id="order-title">ORDER DETAILS </strong> | Table <%= @room.name rescue "" %></div>
<% elsif @status == 'sale' %>
<% if @status_order == 'order' %>
<div id="save_order_id" data-order="<%= @obj_order.order_id %>"><strong id="order-title">ORDER DETAILS </strong> | Table <%= @room.name rescue "" %></div>
<% elsif @status_sale == 'sale' %>
<div><strong id="order-title">INVOICE DETAILS </strong> | Table <%= @room.name rescue "" %></div>
<% end %>
@@ -130,21 +130,21 @@
<div class="card-title row">
<div class="col-lg-6 col-md-6 col-sm-6">
<p> Receipt No: <span id="receipt_no">
<% if @status == 'sale' %>
<%= @obj.receipt_no rescue '' %>
<% if @status_sale == 'sale' %>
<%= @obj_sale.receipt_no rescue '' %>
<% end %>
</span></p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
<p>Date: <span id="receipt_date"><%= @obj.created_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
<p>Date: <span id="receipt_date"><%= @obj_sale.created_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
</div>
</div>
<div class="card-title row customer_detail">
<div class="col-lg-6 col-md-6 col-sm-6">
<% if @status == 'sale' %>
<p class="hidden customer-id"><%= @obj.customer_id rescue '' %></p>
<p>Customer : <%= @obj.customer.name rescue '-' %></p>
<% if @status_sale == 'sale' %>
<p class="hidden customer-id"><%= @obj_sale_sale.customer_id rescue '' %></p>
<p>Customer : <%= @obj_sale_sale.customer.name rescue '-' %></p>
<%else%>
<p class="hidden customer-id"><%= @customer.customer_id rescue "" %></p>
<p>Customer : <%= @customer.name rescue "-" %></p>
@@ -156,6 +156,7 @@
<table class="table table-striped" id="order-items-table">
<thead>
<tr>
<th></th>
<th class="item-name">Items</th>
<th class="item-attr">QTY</td>
<th class="item-attr">Price</td>
@@ -163,35 +164,48 @@
</thead>
<tbody>
<%
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
%>
<input type="hidden" id="sale_id" value="<%= @obj.sale_id %>">
<% unless sale_item.price == 0 %>
<input type="hidden" id="sale_id" value="<%= @sale_array[0].sale_id %>">
<%
# Can't check for discount
unless sale_item.price == 0
count += 1
%>
<tr>
<td><%= count %></td>
<td class='item-name'><%= sale_item.product_name %></td>
<td class='item-attr'><%= sale_item.qty %></td>
<td class='item-attr'><%= sale_item.price %></td>
</tr>
<%
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 %>
<tr>
<td><%= count %></td>
<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
end
end
@@ -207,25 +221,26 @@
<td class="item-attr"><strong id="order-sub-total"><%= sub_total %></strong></td>
</tr>
<tr>
<%if @obj != nil && @status == 'sale' && @obj.discount_type == 'member_discount'%>
<%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%>
<td class="charges-name"><strong>Member Discount:</strong></td>
<%else%>
<td class="charges-name"><strong>Discount:</strong></td>
<%end%>
<td class="item-attr"><strong id="order-discount">(<%=@obj.total_discount rescue 0%>)</strong></td>
<td class="item-attr"><strong id="order-discount">(<%= @obj_sale.total_discount rescue 0%>)</strong></td>
</tr>
<% if @status == "sale" %>
<% if @status_sale == "sale" %>
<tr>
<td class="charges-name"><strong>Tax:</strong></td>
<td class="item-attr"><strong id="order-Tax"><%= @obj.total_tax rescue 0%></strong></td>
<td class="item-attr"><strong id="order-Tax"><%= @obj_sale.total_tax rescue 0%></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Rounding Adj:</strong></td>
<td class="item-attr"><strong id="order-round-adj"><%= @obj.rounding_adjustment rescue 0%></strong></td>
<td class="item-attr"><strong id="order-round-adj"><%= @obj_sale.rounding_adjustment rescue 0%></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Grand Total:</strong></td>
<td class="item-attr"><strong id="order-grand-total"><%= @obj.grand_total rescue 0%></strong></td>
<td class="item-attr"><strong id="order-grand-total"><%= @obj_sale.grand_total rescue 0%></strong></td>
</tr>
<% end %>
<tr class="rebate_amount"></tr>
@@ -233,7 +248,7 @@
</div>
<br>
<%
if @status == 'sale'
if @status_sale == 'sale'
unless @order_items.nil?
%>
Pending New Order
@@ -289,7 +304,7 @@
<button type="button" class="btn btn-primary btn-block" id='back' >Back</button>
<% if @room.bookings.length >= 1 %>
<% if @status == 'order' && @status != 'sale' %>
<% if @status_order == 'order' && @status_sale != 'sale' %>
<!-- <button type="button" class="btn btn-primary btn-block" >Add Order</button> -->
<button type="button" id="customer" class="btn btn-primary btn-block" disabled>Customer</button>
<button type="button" class="btn btn-primary btn-block" disabled >Edit</button>
@@ -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";
});