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:
@@ -34,43 +34,30 @@
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<th><b><%= t("views.right_panel.detail.shift_name") %></b></th>
|
||||
<th><b><%= t("views.right_panel.detail.table") %></b></th>
|
||||
<th><b><%= t("views.right_panel.detail.receipt_no") %></b></th>
|
||||
<th><b><%= t :cashier %> <%= t("views.right_panel.detail.name") %></b></th>
|
||||
<th><b><%= t("views.right_panel.detail.revenue") %></b></th>
|
||||
<th><b><%= t("views.right_panel.detail.shift_name") %></b></th>
|
||||
<th><b><%= t("views.right_panel.detail.table") %></b></th>
|
||||
<th><b><%= t("views.right_panel.detail.receipt_no") %></b></th>
|
||||
<th><b><%= t :cashier %> <%= t("views.right_panel.detail.name") %></b></th>
|
||||
<th><b><%= t("views.right_panel.detail.revenue") %></b></th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% 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
|
||||
%>
|
||||
<% grand_total = 0 %>
|
||||
<% @sale_data.each do |result| %>
|
||||
<% table_name=nil
|
||||
table_type =nil
|
||||
if result.table_id.to_i>0
|
||||
table = DiningFacility.find(result.table_id)
|
||||
if table = result.bookings[0].dining_facility
|
||||
table_type = table.type
|
||||
table_name = table.name
|
||||
end %>
|
||||
<% grand_total = grand_total.to_f + result.grand_total.to_f%>
|
||||
<% grand_total = grand_total + result.grand_total %>
|
||||
<tr style="border-top:4px double #666;">
|
||||
<td><%= @shift_from %> - <%= @shift_to %></td>
|
||||
<td><%= table_type %> - <%= table_name %></td>
|
||||
<td><%= result.receipt_no rescue '-' %> </td>
|
||||
<td><%= result.cashier_name rescue '-' %></td>
|
||||
<td><%= number_with_precision(result.grand_total, precision:precision.to_i,delimiter:delimiter) %></td>
|
||||
<td><%= number_format(result.grand_total, precision: precision, delimiter: delimiter) %></td>
|
||||
<!-- <td> </td> -->
|
||||
</tr>
|
||||
|
||||
@@ -85,8 +72,8 @@
|
||||
<% result.sale_items.each do |item|%>
|
||||
<tr>
|
||||
<td>
|
||||
<% if item.price.to_i < 0.to_i %>
|
||||
<% if item.qty.to_i < 0.to_i%>
|
||||
<% if item.price < 0 %>
|
||||
<% if item.qty < 0 %>
|
||||
[PROMO QTY]<%= item.product_name rescue '-' %>
|
||||
<% else %>
|
||||
[PROMO PRICE]<%= item.product_name rescue '-' %>
|
||||
@@ -96,15 +83,15 @@
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= item.qty rescue '-' %></td>
|
||||
<td><%= number_with_precision(item.unit_price, precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||
<td><%= number_with_precision(item.price, precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||
<td><%=l item.created_at.utc.getlocal, :format => :short rescue '-' %> </td>
|
||||
<td><%= number_format(item.unit_price, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) rescue '-' %></td>
|
||||
<td><%= number_format(item.price, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) rescue '-' %></td>
|
||||
<td><%=l item.created_at.getlocal, :format => :short rescue '-' %> </td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<tr><td colspan="5"> </td></tr>
|
||||
|
||||
<%survey = Survey.find_by_receipt_no(result.receipt_no)%>
|
||||
<%survey = result.survey%>
|
||||
<% if !survey.nil?%>
|
||||
<tr>
|
||||
<td> </td>
|
||||
@@ -120,19 +107,19 @@
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></td>
|
||||
<td><%= number_with_precision(result.total_amount, precision:precision.to_i,delimiter:delimiter) %></td>
|
||||
<td><%= number_format(result.total_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% if result.total_discount.to_f > 0 %>
|
||||
<% if result.total_discount > 0 %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td><%= t("views.right_panel.detail.total") %>
|
||||
<%= t("views.right_panel.detail.discount") %>
|
||||
<%= t("views.right_panel.detail.amount") %></td>
|
||||
<td> - <%= number_with_precision(result.total_discount, precision:precision.to_i,delimiter:delimiter) %> </td>
|
||||
<td> - <%= number_format(result.total_discount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -142,39 +129,38 @@
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td>Tax Amount </td>
|
||||
<td><%= number_with_precision(result.total_tax, precision:precision.to_i,delimiter:delimiter) %> </td>
|
||||
<td><%= number_format(result.total_tax, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% sale_payments = SalePayment.get_sale_payments(result) %>
|
||||
<% sale_payments = result.sale_payments %>
|
||||
<% if sale_payments.length > 0%>
|
||||
<% sale_payments.each do |rec| %>
|
||||
<%if rec.payment_amount.to_f > 0 %>
|
||||
<% next if rec.payment_method == 'credit_note' && result.payments_for_credits_amount < rec.payment_amount %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td>Payment <%= rec.payment_method.upcase %></td>
|
||||
<td><%= number_format(rec.payment_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> ( <%= rec.payment_status %> )</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
|
||||
<% if !rec.payment_reference.nil? %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td>Payment <%= rec.payment_method.upcase %></td>
|
||||
<td><%= number_with_precision(rec.payment_amount, precision:precision.to_i,delimiter:delimiter) %> ( <%= rec.payment_status %> )</td>
|
||||
<td>Payment Ref.</td>
|
||||
<td><%= rec.payment_reference %></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
|
||||
<% if !rec.payment_reference.nil? %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td>Payment Ref.</td>
|
||||
<td><%= rec.payment_reference %></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if result.amount_changed != 0 && !result.amount_changed.nil? %>
|
||||
<% if result.amount_changed != 0 %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td><%= t("views.right_panel.detail.change") %> <%= t("views.right_panel.detail.amount") %></td>
|
||||
<td><%= number_with_precision(result.amount_changed, precision:precision.to_i,delimiter:delimiter) %></td>
|
||||
<td><%= number_format(result.amount_changed, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -196,7 +182,7 @@
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td><b>Total Nett</b> - <b><%= number_with_precision(grand_total, precision:precision.to_i,delimiter:delimiter) %></b></td>
|
||||
<td><b>Total Nett</b> - <b><%= number_format(grand_total, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %></b></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user