Files
sx-fc/app/views/origami/home/show.html.erb
2017-06-24 11:12:30 +06:30

459 lines
16 KiB
Plaintext

<div class="row">
<!-- Column One -->
<div class="col-lg-6 col-md-6 col-sm-6">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" id="mytab">
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#completed" role="tab">Completed</a>
</li>
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#tables" role="tab">Tables</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#rooms" role="tab">Rooms</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#orders" role="tab">Orders</a>
</li>
</ul>
<!-- Nav tabs - End -->
<div class="tab-content" style="max-height:670px; overflow:auto">
<!--- Panel 0 - Completed Orders -->
<div class="tab-pane" id="completed" role="tabpanel">
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
<% @complete.each do |sale| %>
<div class="card sales red text-white" data-id = "<%= sale.sale_id %>">
<div class="card-block">
<%= sale.receipt_no %>
</div>
</div>
<% end %>
</div>
</div>
<!--- Panel 1 - Table Orders -->
<div class="tab-pane active" id="tables" role="tabpanel">
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
<% @tables.each do |table| %>
<% if table.status == 'occupied' %>
<div class="card tables red text-white" data-id="<%= table.id %>">
<div class="card-block">
<%= table.name %>
<% if table.get_booking.nil? %>
<span style="font-size:12px;float:right;line-height:inherit;"> billed</span>
<% else %>
<span style="font-size:12px;float:right;line-height:inherit;"> new</span>
<% end %>
</div>
</div>
<% else %>
<div class="card tables green text-white" data-id="<%= table.id %>">
<div class="card-block">
<%= table.name %>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
<!--- Panel 2 - Room Orders -->
<div class="tab-pane" id="rooms" role="tabpanel">
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
<% @rooms.each do |room| %>
<% if room.status == 'occupied' %>
<div class="card rooms red text-white" data-id="<%= room.id %>">
<div class="card-block">
<%= room.name %>
<% if room.get_booking.nil? %>
<span style="font-size:12px;float:right;line-height:inherit;"> billed</span>
<% else %>
<span style="font-size:12px;float:right;line-height:inherit;"> new</span>
<% end %>
</div>
</div>
<% else %>
<div class="card rooms green text-white" data-id="<%= room.id %>">
<div class="card-block">
<%= room.name %>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
<!--- Panel 3 - Orders -->
<div class="tab-pane" id="orders" role="tabpanel">
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
<% @orders.each do |order| %>
<div class="card orders red text-white" data-id = "<%= order.order_id %>">
<div class="card-block">
<%= order.order_id %>
</div>
</div>
<% end %>
</div>
</div>
</div>
<!-- tabs - End -->
</div>
<!-- Column One -->
<!-- Column Two -->
<div class="col-lg-5 col-md-5 col-sm-5">
<div class="card" >
<div class="card-header">
<% if @status_order == 'order' && @status_sale != 'sale' %>
<div id="save_order_id" data-order="<%= @obj_order.order_id %>"><strong id="order-title">ORDER DETAILS </strong></div>
<% elsif @status_sale == 'sale' %>
<div><strong id="order-title">INVOICE DETAILS </strong></div>
<% end %>
</div>
<div class="card-block">
<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 == 'sale' %>
<%= @sale_array[0].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"><%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
</div>
</div>
<div class="card-title row">
<div class="col-lg-6 col-md-6 col-sm-6">
<p class="hidden customer-id"><%= @customer.customer_id %></p>
<p>Customer : <%= @customer.name %></p>
</div>
</div>
<div class="card-text">
<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>
</tr>
</thead>
<tbody>
<%
count = 0
sub_total = 0
if @status_sale == "sale"
@sale_array[0].sale_items.each do |sale_item|
count += 1
sub_total = sub_total + sale_item.price
%>
<input type="hidden" id="sale_id" value="<%= @sale_array[0].sale_id %>">
<%
# Can't check for discount
unless sale_item.price == 0
%>
<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
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
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
end
%>
</tbody>
</table>
</div>
<div class="card-footer">
<table class="table" id="order-charges-table" border="0">
<tr>
<td class="charges-name"><strong>Sub Total:</strong></td>
<td class="item-attr"><strong id="order-sub-total"><%= sub_total %></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Discount:</strong></td>
<td class="item-attr"><strong id="order-discount">(<%= @obj_sale.total_discount rescue 0%>)</strong></td>
</tr>
<% if @status_sale == "sale" %>
<tr>
<td class="charges-name"><strong>Tax:</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>Grand Total:</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>
</table>
</div>
<br>
<%
if @status_sale == 'sale'
unless @order_items.nil?
%>
Pending New Order
<table class="table table-striped">
<%
count = 0
@order_items.each do |order_item |
count += 1
%>
<tr>
<td><%= count %>
<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
%>
</table>
<button class='btn btn-primary' id='add_invoice'> Add to existing invoice </button>
<%
end
@sale_array.each do |sale|
if @sale_array.size > 1
unless sale.receipt_no == @sale_array[0].receipt_no
%>
<br><br>
Pending Payment
<table class="table table-striped">
<tr>
<td>Receipt No - <%= sale.receipt_no %></td>
<td><button class='btn btn-sm btn-primary '>Show Detail </button></td>
</tr>
</table>
<%
end
end
end
end
%>
</div>
</div>
</div>
<!-- Column Three -->
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- Waiter Buttons -->
<button type="button" class="btn btn-primary btn-block" id='back' >Back</button>
<% if @dining.bookings.length >= 1 %>
<button type="button" id="customer" class="btn btn-primary btn-block" >Customer</button>
<% 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" disabled >Edit</button>
<button type="button" id="discount" class="btn btn-primary btn-block" disabled >Discount</button>
<button type="button" class="btn btn-primary btn-block" id='move'>Move</button>
<button type="button" id="request_bills" class="btn btn-primary btn-block">Req.Bill</button>
<button type="button" id="pay" class="btn btn-primary btn-block" disabled>Pay</button>
<button type="button" class="btn btn-primary btn-block" disabled=""> Void </button>
<% else %>
<button type="button" class="btn btn-primary btn-block" disabled>Add Order</button>
<button type="button" class="btn btn-primary btn-block" id='edit'>Edit</button>
<button type="button" id="discount" class="btn btn-primary btn-block" >Discount</button>
<button type="button" class="btn btn-primary btn-block" id='move' disabled="">Move</button>
<button type="button" id="request_bills" class="btn btn-primary btn-block" disabled> Req.Bill</button>
<button type="button" id="pay" class="btn btn-primary btn-block">Pay</button>
<button type="button" class="btn btn-primary btn-block" > Void </button>
<% end %>
<!-- Cashier Buttons -->
<!-- <button type="button" id="re-print" class="btn btn-primary btn-block" >Re.Print</button> -->
<% end %>
</div>
</div>
<script>
$(document).ready(function(){
$(".tables").on('click', function(){
var customer_id=$(".customer-id").text();
show_customer_details(customer_id);
var dining_id = $(this).attr("data-id");
window.location.href = '/origami/table/' + dining_id;
});
$(".sales").on('click',function(){
var customer_id=$(".customer-id").text();
show_customer_details(customer_id);
var sale_id = $(this).attr("data-id");
window.location.href = '/origami/sale/' + sale_id;
});
$(".rooms").on('click', function(){
var customer_id=$(".customer-id").text();
show_customer_details(customer_id);
var dining_id = $(this).attr("data-id");
window.location.href = '/origami/room/' + dining_id;
});
$(".orders").on('click',function(){
var customer_id=$(".customer-id").text();
show_customer_details(customer_id);
var order_id = $(this).attr("data-id");
window.location.href = '/origami/order/' + order_id;
});
// bind customer to order or sale
$("#customer").on('click', function(){
var sale = $('#sale_id').val();
if (sale) {
var sale_id = sale
}else{
var sale_id = $('#save_order_id').attr('data-order');
}
var table_id = $('.tables').attr("data-id");
window.location.href = '/origami/'+ sale_id + "/customers"
});
// Discount for Payment
$('#discount').click(function() {
var sale = $('#sale_id').val();
if (sale!="") {
var sale_id = sale
}else{
var sale_id = $('#save_order_id').attr('data-order');
}
if(sale_id!=""){
window.location.href = '/origami/' + sale_id + '/discount'
}
else {
alert("Please select an table!");
}
return false;
});
});
$('#pay').on('click',function() {
var sale_id = $('#sale_id').val();
window.location.href = '/origami/sale/'+ sale_id + "/payment";
});
// Bill Request
$('#request_bills').click(function() {
var order_id = $('#save_order_id').attr('data-order');
var ajax_url = "/origami/" + order_id + "/request_bills";
$.ajax({
type: "POST",
url: ajax_url,
data: 'order_id='+ order_id,
success:function(result){
location.reload();
}
});
});
$('#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/';
})
$('#add_invoice').on('click',function(){
var dining_id = "<%= @dining.id %>"
var sale_id = "<%= @obj_sale.sale_id rescue "" %>"
var ajax_url = "/origami/sale/append_order";
$.ajax({
type: "POST",
url: ajax_url,
data: 'dining_id='+ dining_id + "&sale_id=" + sale_id,
success:function(result){
alert("Invoice updated")
window.location.reload();
}
});
})
//show cusotmer rebate amount
function show_customer_details(customer_id){
var url = '<%= @show_customer_details_path %>'
//Start Ajax
$.ajax({
type: "GET",
url: url,
data: {},
dataType: "json",
success: function(data) {
$("#customer_name").text(data["customer"].name);
if (data["response_data"]["data"].length) {
$.each(data["response_data"]["data"], function (i) {
if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){
var balance = data["response_data"]["data"][i]["balance"];
if (data["response_data"]["status"]==true) {
$('.rebate_amount').removeClass('hide');
row =
'<td class="charges-name">' + "Rebate Balance" +'</td>'
+'<td class="item-attr">' + balance + '</td>';
$(".rebate_amount").html(row);
}
}
});
}else{
$('.rebate_amount').addClass('hide');
}
}
});
//End Ajax
}
$('#edit').on('click',function(){
var dining_id = "<%= @dining.id %>"
var sale_id = "<%= @obj_sale.sale_id rescue "" %>"
window.location.href = '/origami/table/'+ dining_id + "/sale/"+ sale_id + "/edit";
})
</script>