tables origami

This commit is contained in:
Cherry
2017-05-31 18:19:17 +06:30
parent b3b2e9bd8d
commit 44e7d2452f
2 changed files with 34 additions and 26 deletions

View File

@@ -8,18 +8,16 @@ class Origami::HomeController < BaseOrigamiController
left join order_items on order_items.order_id = orders.id") left join order_items on order_items.order_id = orders.id")
.where("orders.order_type=? and dining_facilities.is_active=?","dine_in",true) .where("orders.order_type=? and dining_facilities.is_active=?","dine_in",true)
.group("orders.id") .group("orders.id")
end end
def show def show
@order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price") @order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price")
.joins("left join orders on orders.id = order_items.order_id") .joins("left join orders on orders.id = order_items.order_id")
.where("order_items.order_id=?",params[:order_id]) .where("order_items.order_id=?",params[:order_id])
respond_to do |format| # render :json => @order_details.to_json
format.html str = []
format.json{ @order_details.each do |ord_detail|
render :json => @order_details.to_json str.push(ord_detail)
} end
end render :json => str.to_json
end end
end end

View File

@@ -196,23 +196,18 @@
<div id="table-details" class="card-text" style="min-height:400px; max-height:400px; overflow-x:scroll"> <div id="table-details" class="card-text" style="min-height:400px; max-height:400px; overflow-x:scroll">
<table class="table"> <table class="table">
<tbody> <tbody>
<% sub_total = 0%>
<% if @order_details%>
<% @order_details.each do |order_detail| %>
<tr> <tr>
<td style="width:60%; text-align:left"> <td style="width:60%; text-align:left">
<%=order_detail.item_name%> @ <%=order_detail.price%> <span id="item-name-price"></span>
</td> </td>
<td style="width:20%; text-align:right"> <td style="width:20%; text-align:right">
<%=order_detail.qty%> <span id="item-qty"></span>
</td> </td>
<td style="width:20%; text-align:right"> <td style="width:20%; text-align:right">
<%=order_detail.total_price%> <span id="item-total-price"></span>
<%sub_total+=order_detail.total_price%>
</td> </td>
</tr> </tr>
<% end %>
<% end %>
</tbody> </tbody>
</table> </table>
</div> </div>
@@ -220,13 +215,13 @@
<table class="table" style="margin-bottom:0px"> <table class="table" style="margin-bottom:0px">
<tfooter> <tfooter>
<tr> <tr>
<td style="width:80%; text-align:left; border-top:none"><strong>Total Amount</strong></td> <td style="width:80%; text-align:left; border-top:none"><strong>Sub Total</strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><%=sub_total%></strong></td> <td style="width:20%; text-align:right; border-top:none"><strong><span id="sub-total"></span></strong></td>
</tr> </tr>
<!-- <!--
<tr> <tr>
<td style="width:80%; text-align:left; border-top:none"><strong>Sub Total</strong></td> <td style="width:80%; text-align:left; border-top:none"><strong>Sub Total</strong></td>
<td style="width:20%; text-align:right; border-top:none"><strong><%=sub_total%></strong></td> <td style="width:20%; text-align:right; border-top:none"><strong>0</strong></td>
</tr> </tr>
<tr> <tr>
<td style="width:80%; text-align:left">Discounts</td> <td style="width:80%; text-align:left">Discounts</td>
@@ -269,12 +264,27 @@
</div> </div>
<script> <script>
function callOrderDetails(order_id){ function callOrderDetails(order_id){
$("#item-name-price").html("")
$("#item-qty").html("")
$("#item-total-price").html("")
$("#sub-total").html("")
url = "origami/"+order_id url = "origami/"+order_id
$.ajax({type: "GET", $.ajax({type: "GET",
url: url, url: url,
data: { order_id: order_id}, data: { order_id: order_id},
success:function(result){ success:function(result){
alert('ok'+result); var sub_total = 0
for (i = 0; i < result.length; i++) {
var data = JSON.stringify(result[i]);
// console.log(parse_data)
var parse_data = JSON.parse(data)
sub_total += (parse_data.qty*parse_data.price)
$("#item-name-price").append(parse_data.item_name+"@"+parse_data.price+"<br/>")
$("#item-qty").append(parse_data.qty+"<br/>")
$("#item-total-price").append((parse_data.qty*parse_data.price)+"<br/>")
}
$("#sub-total").append((sub_total)+"<br/>")
}, },
error:function(result){ error:function(result){
alert('error'); alert('error');