From 317a79446f240cf9b6f77bb71c03957c2a6049dd Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 21 Feb 2018 11:17:25 +0630 Subject: [PATCH] add precision in payment page --- .../origami/payments_controller.rb | 4 +- app/views/origami/payments/show.html.erb | 86 ++++++++++++------- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 28a82d83..ebdb80b0 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -217,7 +217,9 @@ class Origami::PaymentsController < BaseOrigamiController @rounding_adj = @sale_data.rounding_adjustment end #end rounding adjustment - + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() #get customer amount @customer = Customer.find(@sale_data.customer_id) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index eb8ed1ee..fa4167b2 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -2,6 +2,21 @@ + <% 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 %> +
@@ -56,9 +71,9 @@ <% sub_total += sale_item.price%> <%= count %> - <%=sale_item.product_name%>@<%=sale_item.unit_price%> + <%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%> <%=sale_item.qty%> - <%=(sale_item.price)%> + <%=(number_with_precision(sale_item.price, precision: precision.to_i ))%> <%end %> @@ -71,7 +86,7 @@ Sub Total - <%=sub_total%> + <%=number_with_precision(sub_total, precision: precision.to_i)%> <%if @sale_data.discount_type == 'member_discount'%> @@ -79,7 +94,7 @@ <%else%> (Discount) <%end%> - (<%=@sale_data.total_discount rescue 0%>) + (<%= number_with_precision(@sale_data.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>) Tax @@ -91,28 +106,28 @@ <%end%> <%end %>) - <%=@sale_data.total_tax rescue 0%> + <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> Rounding Adj: - <%= @sale_data.rounding_adjustment rescue 0%> + <%= number_with_precision(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> Grand Total - <%=@sale_data.grand_total rescue 0%> + <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> <%if @balance > 0%> <%= @accountable_type %> - <%=@balance%> + <%=number_with_precision(@balance, precision: precision.to_i )%> <% end %> - <% if !@individual_total.nil? %> + <% if !@individual_total[0].nil? %> Individual amount for <%= @individual_total[0]['total_customer'] %> persons - <%=@individual_total[0]['per_person_amount']%> + <%= number_with_precision(@individual_total[0]['per_person_amount'], precision: precision.to_i )%> <% end %> @@ -132,24 +147,24 @@
Amount Due
- - <%= @sale_data.grand_total rescue 0%> + + <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
Cash
-
<%= @cash %>
+
<%= number_with_precision(@cash, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
Credit
-
<%= @credit %>
+
<%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0%>
Other Payments
-
<%= @other %>
+
<%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %>
<% else %>
@@ -164,13 +179,13 @@
MPU
-
<%= @other %>
+
<%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %> <% end %> @@ -178,13 +193,13 @@
Redeem
-
<%= @ppamount %>
+
<%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %> <% end %> @@ -192,13 +207,13 @@
VISA
-
<%= @visacount %>
+
<%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %> <% end %> @@ -206,13 +221,13 @@
JCB
-
<%= @jcbcount %>
+
<%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %> <% end %> @@ -220,13 +235,13 @@
MASTER
-
<%= @mastercount %>
+
<%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %> <% end %> @@ -235,18 +250,18 @@
UNIONPAY
-
<%= @unionpaycount %>
+
<%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
<% else %> <% end %>
Balance
-
<%= @sale_data.grand_total rescue 0 %>
+
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
@@ -496,8 +511,13 @@ console.log("fffffffffffff") var unionpay1 = $('#unionpaycount').text(); var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1); var total = $('#amount_due').text(); - var amt = parseFloat(total) - parseFloat(othertotal); - $('#cash').text(parseFloat(amt).toFixed(1)); + var amt = 0; + <% if precision.to_i > 0 %>; + amt = parseFloat(parseFloat(total) - parseFloat(othertotal)).toFixed(<%= precision %>); + <% else %> + amt = parseFloat(parseFloat(total) - parseFloat(othertotal)); + <% end %> + $('#cash').text(amt); update_balance(); break; } @@ -662,7 +682,11 @@ console.log("fffffffffffff") var amount_due = $('#amount_due').text(); var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) var result = parseFloat(amount_due) - parseFloat(total); - $('#balance').text(result.toFixed(2)); + <% if precision.to_i > 0 %> + $('#balance').text(parseFloat(result).toFixed(<%= precision %>)); + <% else %> + $('#balance').text(parseFloat(result)); + <% end %> } $('#foc').click(function() {