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 class Origami::RoomsController < BaseOrigamiController
before_action :set_dining, only: [:show]
def index def index
@tables = Table.all.active.order('status desc') @tables = Table.all.active.order('status desc')
@rooms = Room.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'") @complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('date desc') @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 @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' if booking.sale_id.nil? && booking.booking_status != 'moved'
@order_items = Array.new @order_items = Array.new
booking.booking_orders.each do |booking_order| booking.booking_orders.each do |booking_order|
order = Order.find(booking_order.order_id) order = Order.find(booking_order.order_id)
if (order.status == "new") if (order.status == "new")
@obj = order @obj_order = order
@customer = order.customer @customer = order.customer
@date = order.created_at @date = order.created_at
order.order_items.each do |item| order.order_items.each do |item|
@@ -35,17 +34,18 @@ class Origami::RoomsController < BaseOrigamiController
end end
end end
end end
@status = 'order' @status_order = 'order'
else else
sale = Sale.find(booking.sale_id) sale = Sale.find(booking.sale_id)
if sale.sale_status != "completed" && sale.sale_status != 'void' if sale.sale_status != "completed" && sale.sale_status != 'void'
puts "enter"
@sale_array.push(sale) @sale_array.push(sale)
if @status == 'order' if @status_order == 'order'
@status = 'sale' @status_order = 'sale'
end end
@date = sale.created_at @date = sale.created_at
@status = 'sale' @status_sale = 'sale'
@obj = sale @obj_sale = sale
@customer = sale.customer @customer = sale.customer
end end
end end
@@ -77,10 +77,5 @@ class Origami::RoomsController < BaseOrigamiController
# end # end
end end
private
def set_dining
@dining = DiningFacility.find(params[:room_id])
end
end end

View File

@@ -119,9 +119,9 @@
<div class="col-lg-5 col-md-5 col-sm-5"> <div class="col-lg-5 col-md-5 col-sm-5">
<div class="card" > <div class="card" >
<div class="card-header"> <div class="card-header">
<% if @status == 'order' %> <% if @status_order == 'order' %>
<div id="save_order_id" data-order="<%= @obj.order_id %>"><strong id="order-title">ORDER DETAILS </strong> | Table <%= @room.name rescue "" %></div> <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' %> <% elsif @status_sale == 'sale' %>
<div><strong id="order-title">INVOICE DETAILS </strong> | Table <%= @room.name rescue "" %></div> <div><strong id="order-title">INVOICE DETAILS </strong> | Table <%= @room.name rescue "" %></div>
<% end %> <% end %>
@@ -130,21 +130,21 @@
<div class="card-title row"> <div class="card-title row">
<div class="col-lg-6 col-md-6 col-sm-6"> <div class="col-lg-6 col-md-6 col-sm-6">
<p> Receipt No: <span id="receipt_no"> <p> Receipt No: <span id="receipt_no">
<% if @status == 'sale' %> <% if @status_sale == 'sale' %>
<%= @obj.receipt_no rescue '' %> <%= @obj_sale.receipt_no rescue '' %>
<% end %> <% end %>
</span></p> </span></p>
</div> </div>
<div class="col-lg-6 col-md-6 col-sm-6 text-right"> <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> </div>
<div class="card-title row customer_detail"> <div class="card-title row customer_detail">
<div class="col-lg-6 col-md-6 col-sm-6"> <div class="col-lg-6 col-md-6 col-sm-6">
<% if @status == 'sale' %> <% if @status_sale == 'sale' %>
<p class="hidden customer-id"><%= @obj.customer_id rescue '' %></p> <p class="hidden customer-id"><%= @obj_sale_sale.customer_id rescue '' %></p>
<p>Customer : <%= @obj.customer.name rescue '-' %></p> <p>Customer : <%= @obj_sale_sale.customer.name rescue '-' %></p>
<%else%> <%else%>
<p class="hidden customer-id"><%= @customer.customer_id rescue "" %></p> <p class="hidden customer-id"><%= @customer.customer_id rescue "" %></p>
<p>Customer : <%= @customer.name rescue "-" %></p> <p>Customer : <%= @customer.name rescue "-" %></p>
@@ -156,6 +156,7 @@
<table class="table table-striped" id="order-items-table"> <table class="table table-striped" id="order-items-table">
<thead> <thead>
<tr> <tr>
<th></th>
<th class="item-name">Items</th> <th class="item-name">Items</th>
<th class="item-attr">QTY</td> <th class="item-attr">QTY</td>
<th class="item-attr">Price</td> <th class="item-attr">Price</td>
@@ -163,35 +164,48 @@
</thead> </thead>
<tbody> <tbody>
<% <%
count = 0
sub_total = 0 sub_total = 0
if @status == "sale" if @status_sale == "sale"
@obj.sale_items.each do |sale_item| @sale_array[0].sale_items.each do |sale_item|
sub_total = sub_total + sale_item.price
sub_total = sub_total + sale_item.price
%> %>
<input type="hidden" id="sale_id" value="<%= @obj.sale_id %>"> <input type="hidden" id="sale_id" value="<%= @sale_array[0].sale_id %>">
<% unless sale_item.price == 0 %> <%
# Can't check for discount
unless sale_item.price == 0
count += 1
%>
<tr> <tr>
<td><%= count %></td>
<td class='item-name'><%= sale_item.product_name %></td> <td class='item-name'><%= sale_item.product_name %></td>
<td class='item-attr'><%= sale_item.qty %></td> <td class='item-attr'><%= sale_item.qty %></td>
<td class='item-attr'><%= sale_item.price %></td> <td class='item-attr'><%= sale_item.price %></td>
</tr> </tr>
<% <%
end
end
end end
end end
if @status == 'order' if @status_order == 'order' && @status_sale != 'sale'
unless @order_items.nil? unless @order_items.nil?
count = 0
@order_items.each do |order_item | @order_items.each do |order_item |
count += 1
sub_total = sub_total + (order_item.price * order_item.qty) sub_total = sub_total + (order_item.price * order_item.qty)
unless order_item.price == 0 %> unless order_item.price == 0 %>
<tr> <tr>
<td><%= count %></td>
<td class='item-name'><%= order_item.item_name %></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 %></td>
<td class='item-attr'><%= order_item.qty*order_item.price %></td> <td class='item-attr'><%= order_item.qty*order_item.price %></td>
</tr> </tr>
<% <%
end end
end end
end end
@@ -207,25 +221,26 @@
<td class="item-attr"><strong id="order-sub-total"><%= sub_total %></strong></td> <td class="item-attr"><strong id="order-sub-total"><%= sub_total %></strong></td>
</tr> </tr>
<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> <td class="charges-name"><strong>Member Discount:</strong></td>
<%else%> <%else%>
<td class="charges-name"><strong>Discount:</strong></td> <td class="charges-name"><strong>Discount:</strong></td>
<%end%> <%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> </tr>
<% if @status == "sale" %> <% if @status_sale == "sale" %>
<tr> <tr>
<td class="charges-name"><strong>Tax:</strong></td> <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>
<tr> <tr>
<td class="charges-name"><strong>Rounding Adj:</strong></td> <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>
<tr> <tr>
<td class="charges-name"><strong>Grand Total:</strong></td> <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> </tr>
<% end %> <% end %>
<tr class="rebate_amount"></tr> <tr class="rebate_amount"></tr>
@@ -233,7 +248,7 @@
</div> </div>
<br> <br>
<% <%
if @status == 'sale' if @status_sale == 'sale'
unless @order_items.nil? unless @order_items.nil?
%> %>
Pending New Order Pending New Order
@@ -289,7 +304,7 @@
<button type="button" class="btn btn-primary btn-block" id='back' >Back</button> <button type="button" class="btn btn-primary btn-block" id='back' >Back</button>
<% if @room.bookings.length >= 1 %> <% 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" 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" id="customer" class="btn btn-primary btn-block" disabled>Customer</button>
<button type="button" class="btn btn-primary btn-block" disabled >Edit</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(){ $('#add_invoice').on('click',function(){
var dining_id = "<%= @room.id %>" 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"; var ajax_url = "/origami/sale/append_order";
$.ajax({ $.ajax({
type: "POST", type: "POST",
@@ -603,7 +618,7 @@ $('#add_invoice').on('click',function(){
$('#edit').on('click',function(){ $('#edit').on('click',function(){
var dining_id = "<%= @room.id %>" 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"; window.location.href = '/origami/table/'+ dining_id + "/sale/"+ sale_id + "/edit";
}); });