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:
Thein Lin Kyaw
2019-11-25 23:17:53 +06:30
parent a36e170d94
commit 3c1cc737b5
71 changed files with 1338 additions and 1898 deletions

View File

@@ -1,19 +1,5 @@
<div class="container-fluid">
<div class="row">
<% if !@print_settings.nil? %>
<% 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
%>
<% end %>
<div class="col-lg-4 col-md-6 col-sm-6">
<!-- <div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;"> -->
@@ -89,7 +75,7 @@
<td><%= count %></td>
<td class='item-name'><%= sale_item.product_name %></td>
<td class='item-attr'><%= sale_item.qty %></td>
<td class='item-attr'><%= number_with_precision(sale_item.price, precision: precision.to_i ) %></td>
<td class='item-attr'><%= number_format(sale_item.price, precision: precision.to_i ) %></td>
</tr>
<%
# end
@@ -108,7 +94,7 @@
<td><%= count %></td>
<td class='item-name'><%= order_item.item_name %></td>
<td class='item-attr'><%= order_item.qty %></td>
<td class='item-attr'><%= number_with_precision(order_item.qty*order_item.price, precision: precision.to_i ) %></td>
<td class='item-attr'><%= number_format(order_item.qty*order_item.price, precision: precision.to_i ) %></td>
</tr>
<%
end
@@ -124,7 +110,7 @@
<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"><span id="sub_total"><%= number_with_precision(sub_total, precision: precision.to_i ) %></span></strong></td>
<td class="item-attr"><strong id="order-sub-total"><span id="sub_total"><%= number_format(sub_total, precision: precision.to_i ) %></span></strong></td>
</tr>
<tr>
<%if @sale.discount_type == 'member_discount'%>
@@ -132,19 +118,19 @@
<%else%>
<td class="charges-name"><strong>Discount:</strong></td>
<%end%>
<td class="item-attr"><strong id="order-discount">(<%= number_with_precision(@sale.total_discount, precision: precision.to_i ) rescue 0%>)</strong></td>
<td class="item-attr"><strong id="order-discount">(<%= number_format(@sale.total_discount, precision: precision.to_i ) rescue 0%>)</strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Tax:</strong></td>
<td class="item-attr"><strong id="order-Tax"><%= number_with_precision(@sale.total_tax, precision: precision.to_i ) rescue 0%></strong></td>
<td class="item-attr"><strong id="order-Tax"><%= number_format(@sale.total_tax, precision: precision.to_i ) rescue 0%></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Rounding Adj:</strong></td>
<td class="item-attr"><strong id="order-round-adj"><%= number_with_precision(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%></strong></td>
<td class="item-attr"><strong id="order-round-adj"><%= number_format(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Grand Total:</strong></td>
<td class="item-attr"><strong id="order-grand-total"><span id="grand_total"><%= number_with_precision(@sale.grand_total, precision: precision.to_i ) rescue 0%></span></strong></td>
<td class="item-attr"><strong id="order-grand-total"><span id="grand_total"><%= number_format(@sale.grand_total, precision: precision.to_i ) rescue 0%></span></strong></td>
</tr>
<tr class="rebate_amount"></tr>
</table>
@@ -163,7 +149,7 @@
<button type="button" class="btn btn-block bg-blue waves-effect" data-toggle="modal" data-target="#paymentModal">First Bill</button>
<%else%>
<button type="button" id="first_bill" class="btn btn-block bg-blue waves-effect">First Bill</button>
<%end%>
<%end%>
<% end %>
<button type="button" id="pay" class="btn bg-blue btn-block">Pay</button>
@@ -173,7 +159,7 @@
<% else %>
<button type="button" class="btn bg-deep-purple btn-block" data-toggle="modal" data-target="#focModal" <%= (can? :foc, :payment)? ' ': 'disabled=' %> active="true"> FOC </button>
<button type="button" data-toggle="modal" data-target="#voidModal" class="btn bg-danger btn-block" <%= (can? :overall_void, :void)? ' ': 'disabled=' %> > Void </button>
<% end %>
<% end %>
</div>
</div>
</div>
@@ -197,8 +183,8 @@
<%= pay.payment_method %>
</option>
<%end %>
</select>
</select>
</div>
<div class="modal-footer p-r-30">
<button type="button" class="btn btn-link btn-danger waves-effect" data-dismiss="modal">CLOSE</button>
@@ -228,7 +214,7 @@
<button type="button" class="btn btn-link p-t-5 p-b-5 bg-blue waves-effect" data-dismiss="modal">CLOSE</button>
</div>
</div>
</div>
</div>
</div>
@@ -252,7 +238,7 @@
<button type="button" class="btn btn-link bg-blue waves-effect" data-dismiss="modal">CLOSE</button>
</div>
</div>
</div>
</div>
</div>
@@ -266,7 +252,7 @@
<h4 class="modal-title" id="AccessCodeModalLabel">Enter Access Code</h4>
<button type="button" class="close" id="close" data-dismiss="modal" aria-hidden="true" style="font-size: 20px;color:#111;">&times;</button>
</div>
<div class="modal-body" style="padding: 0px 25px 15px 25px !important">
<div class="modal-body" style="padding: 0px 25px 15px 25px !important">
<input type="password" id="access_code" class="access_code form-control col-md-12 ">
<div class="row bottom p-l-15 p-r-15 m-t-10">
<div class="col-md-3 access_number border-top border-left" data-value="1" data-type="num">1</div>
@@ -285,7 +271,7 @@
<div class="col-md-3 access_number border-top border-left" data-value="0" data-type="num">0</div>
<div class="col-md-3 access_number border-top border-left orange" data-type="clr">Clr</div>
<div class="col-md-3 access_number ok border-top border-left blue" data-type="ok" data-action="">OK</div>
</div>
</div>
</div>
@@ -298,7 +284,7 @@ $(document).ready(function(){
if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
receipt_no = ($("#receipt_no").html()).trim();
}
discount="<%= @membership.discount%>"
if ($("#server_mode").val() != "cloud") { // first bill not used in cloud
if (discount) {
@@ -339,7 +325,7 @@ $(document).ready(function(){
// }
// location.reload();
// }
// });
// });
// });
// Print for first bill
@@ -376,9 +362,9 @@ $(document).ready(function(){
}
location.reload();
}
});
});
}
});
});
});
$(".choose_payment").on('click', function () {
@@ -389,10 +375,10 @@ $(document).ready(function(){
if(parseInt(jQuery.inArray("Credit", type)) == -1){
if (parseInt(jQuery.inArray("MPU", type)) != -1 || parseInt(jQuery.inArray("VISA", type)) != -1 || parseInt(jQuery.inArray("JCB", type)) != -1 || parseInt(jQuery.inArray("Master", type)) != -1 || parseInt(jQuery.inArray("UNIONPAY", type)) != -1 || parseInt(jQuery.inArray("Redeem", type)) != -1) {
calculate_member_discount(sale_id,"Card");
}else{
calculate_member_discount(sale_id,"Cash");
}
}
}
var ajax_url = "/origami/sale/" + sale_id + "/first_bill";
$.ajax({
@@ -411,7 +397,7 @@ $(document).ready(function(){
}
location.reload();
}
});
});
});
function calculate_member_discount(sale_id,type) {
@@ -426,7 +412,7 @@ $(document).ready(function(){
url: "/origami/" + sale_id + "/member_discount",
data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card },
async: false,
success:function(result){
success:function(result){
}
});
}
@@ -439,7 +425,7 @@ $('#pay').on('click',function() {
// $.ajax({
// type: "GET",
// url: url,
// success:function(result){
// success:function(result){
// // console.log(result);
// }
// });
@@ -453,7 +439,7 @@ $('#back').on('click',function(){
}else{
window.location.href = '/origami/table/<%= @table.id %>';
}
});
$('#void').on('click',function () {
@@ -487,7 +473,7 @@ $('#void').on('click',function () {
}
});
}
});
});
}else{
swal("Opps","You are not authorized for void","warning");
}
@@ -505,12 +491,12 @@ $('#foc').click(function() {
var params = { 'cash':cash,'sale_id':sale_id,'sub_total':sub_total,'remark':remark,'type':'cashier','access_code':access_code };
// console.log(sale_id);
if(sale_id != ''){
if ($(this).attr('active')=== "true") {
if ($(this).attr('active')=== "true") {
$.ajax({
type: "POST",
url: "/origami/payment/cashier/foc",
data: params,
success:function(result){
success:function(result){
if (cash >= 0) {
swal({
title: "Information!",
@@ -549,7 +535,7 @@ $(document).on('click', '.access_modal', function(event){
if (result.status == true) {
createAccessCode(code);
if (type == "edit") {
}else if(type == "void"){
$('#AccessCodeModal').modal('hide');
$('#voidModal').modal('show');