improve receipt/details reports and implement number formatting
1) eager load reports for receipt/details 2) introduce number_format lookups to replace print_settings for number formatting 3) implement NumberFormattable concern, reference number_format lookups or print_settings if not exist, to get number format settings and number formatting 4) replace rails NumberHelper.number_with_precision with NumberFormattable.number_format hopefully to reduce overhead, formatting numbers for huge lists of data
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
<div class="col-md-12">
|
||||
<div class="text-right">
|
||||
<a href="javascript:export_to('<%=reports_product_sale_index_path%>.xls')" class = "btn btn-info wave-effects "><%= t("views.btn.exp_to_excel") %></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="margin-top-20">
|
||||
<div class="card">
|
||||
@@ -25,18 +25,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<% if @print_settings.precision.to_i > 0
|
||||
precision = @print_settings.precision
|
||||
else
|
||||
precision = 0
|
||||
end
|
||||
#check delimiter
|
||||
if @print_settings.delimiter
|
||||
delimiter = ","
|
||||
else
|
||||
delimiter = ""
|
||||
end %>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" id="items_table" border="0">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -47,7 +36,7 @@
|
||||
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
|
||||
<!-- <th><%= t("views.right_panel.detail.unit_price") %></th> -->
|
||||
<th><%= t("views.right_panel.detail.total") %></th>
|
||||
</tr>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbd_data">
|
||||
<% unless @sale_data.blank? %>
|
||||
@@ -57,7 +46,7 @@
|
||||
<% total_qty = 0 %>
|
||||
<% total_item = {} %>
|
||||
<% total_data = {} %>
|
||||
<% @sale_data.each do |sale|
|
||||
<% @sale_data.each do |sale|
|
||||
if !total_item.has_key?(sale.item_code)
|
||||
grand_total += sale.grand_total
|
||||
total_item[sale.item_code] = sale.total_item
|
||||
@@ -66,25 +55,25 @@
|
||||
if sale.status_type == "void"
|
||||
total_item[sale.item_code] += sale.total_item
|
||||
end
|
||||
if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc"
|
||||
if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc"
|
||||
total_data[sale.item_code] += sale.grand_total
|
||||
grand_total += sale.grand_total
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end %>
|
||||
|
||||
<% @sale_data.each do |sale| %>
|
||||
<% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion"
|
||||
total_qty += sale.total_item
|
||||
total_qty += sale.total_item
|
||||
end %>
|
||||
<% if sale.status_type == "foc" && sale.price > 0
|
||||
total_qty += sale.total_item
|
||||
end %>
|
||||
|
||||
|
||||
<% if sale.status_type != "Discount" && sale.price.to_f >= 0 %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<% if !cate_arr.include?(sale.menu_category_id) %>
|
||||
<% if !cate_arr.include?(sale.menu_category_id) %>
|
||||
<td><%= sale.menu_category_name %></td>
|
||||
<% cate_arr.push(sale.menu_category_id) %>
|
||||
<% else %>
|
||||
@@ -96,8 +85,8 @@
|
||||
<td><%= sale.item_code rescue '-' %></td>
|
||||
<td><%= sale.product_name rescue '-' %></td>
|
||||
<td><%= total_item[sale.item_code] rescue '-' %></td>
|
||||
<!-- <td><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> -->
|
||||
<td><%= number_with_precision(total_data[sale.item_code] , precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||
<!-- <td><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> -->
|
||||
<td><%= number_format(total_data[sale.item_code] , precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||
</tr>
|
||||
<!-- sub total -->
|
||||
<!-- end sub total -->
|
||||
@@ -107,9 +96,9 @@
|
||||
<td colspan="3"></td>
|
||||
<td><strong>Total</strong></td>
|
||||
<td><strong><%= total_qty %></strong></td>
|
||||
<td><strong><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></strong></td>
|
||||
<td><strong><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></strong></td>
|
||||
</tr>
|
||||
|
||||
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -123,9 +112,9 @@
|
||||
$(function(){
|
||||
$('#order_by').val('<%= @order_by %>');
|
||||
});
|
||||
|
||||
|
||||
$('#order_by').on('change', function(){
|
||||
var order_by = $("#order_by").val();
|
||||
window.location.href = "?order_by=" + order_by;
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user