add precision in payment page

This commit is contained in:
phyusin
2018-02-21 11:17:25 +06:30
parent 28252e9e87
commit 317a79446f
2 changed files with 58 additions and 32 deletions

View File

@@ -218,6 +218,8 @@ class Origami::PaymentsController < BaseOrigamiController
end end
#end rounding adjustment #end rounding adjustment
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
#get customer amount #get customer amount
@customer = Customer.find(@sale_data.customer_id) @customer = Customer.find(@sale_data.customer_id)

View File

@@ -2,6 +2,21 @@
<div id="loading_wrapper" style="display:none;"> <div id="loading_wrapper" style="display:none;">
<div id="loading"></div> <div id="loading"></div>
</div> </div>
<% 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="row clearfix"> <div class="row clearfix">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<div class="card"> <div class="card">
@@ -56,9 +71,9 @@
<% sub_total += sale_item.price%> <% sub_total += sale_item.price%>
<tr> <tr>
<td><%= count %></td> <td><%= count %></td>
<td class="item-name"><%=sale_item.product_name%>@<%=sale_item.unit_price%></td> <td class="item-name"><%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%></td>
<td class="item-attr"><%=sale_item.qty%></td> <td class="item-attr"><%=sale_item.qty%></td>
<td class="item-attr"><%=(sale_item.price)%></td> <td class="item-attr"><%=(number_with_precision(sale_item.price, precision: precision.to_i ))%></td>
</tr> </tr>
<%end %> <%end %>
</tbody> </tbody>
@@ -71,7 +86,7 @@
<tfooter> <tfooter>
<tr> <tr>
<td class="charges-name"><strong>Sub Total</strong></td> <td class="charges-name"><strong>Sub Total</strong></td>
<td class="item-attr"><strong><span id="sub-total"><%=sub_total%></span></strong></td> <td class="item-attr"><strong><span id="sub-total"><%=number_with_precision(sub_total, precision: precision.to_i)%></span></strong></td>
</tr> </tr>
<tr> <tr>
<%if @sale_data.discount_type == 'member_discount'%> <%if @sale_data.discount_type == 'member_discount'%>
@@ -79,7 +94,7 @@
<%else%> <%else%>
<td class="charges-name"><strong>(Discount)</strong></td> <td class="charges-name"><strong>(Discount)</strong></td>
<%end%> <%end%>
<td class="item-attr"><strong><span>(<%=@sale_data.total_discount rescue 0%>)</span></strong></td> <td class="item-attr"><strong><span>(<%= number_with_precision(@sale_data.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>)</span></strong></td>
</tr> </tr>
<tr> <tr>
<td class="charges-name"><strong>Tax <td class="charges-name"><strong>Tax
@@ -91,28 +106,28 @@
<%end%> <%end%>
<%end %>) <%end %>)
</strong></td> </strong></td>
<td class="item-attr"><strong><span><%=@sale_data.total_tax rescue 0%></span></strong></td> <td class="item-attr"><strong><span><%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%></span></strong></td>
</tr> </tr>
<tr> <tr>
<td class="charges-name"><strong>Rounding Adj:</strong></td> <td class="charges-name"><strong>Rounding Adj:</strong></td>
<td class="item-attr"><strong><%= @sale_data.rounding_adjustment rescue 0%></strong></td> <td class="item-attr"><strong><%= number_with_precision(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%></strong></td>
</tr> </tr>
<tr> <tr>
<td class="charges-name"><strong>Grand Total</strong></td> <td class="charges-name"><strong>Grand Total</strong></td>
<td class="item-attr"><strong><span><%=@sale_data.grand_total rescue 0%></span></strong></td> <td class="item-attr"><strong><span><%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%></span></strong></td>
</tr> </tr>
<%if @balance > 0%> <%if @balance > 0%>
<tr> <tr>
<td class="charges-name"><strong><%= @accountable_type %></strong></td> <td class="charges-name"><strong><%= @accountable_type %></strong></td>
<td class="item-attr"><strong><span><%=@balance%></span></strong></td> <td class="item-attr"><strong><span><%=number_with_precision(@balance, precision: precision.to_i )%></span></strong></td>
</tr> </tr>
<% end %> <% end %>
<% if !@individual_total.nil? %> <% if !@individual_total[0].nil? %>
<tr> <tr>
<td class="charges-name"> <td class="charges-name">
<strong>Individual amount for <%= @individual_total[0]['total_customer'] %> persons</strong> <strong>Individual amount for <%= @individual_total[0]['total_customer'] %> persons</strong>
</td> </td>
<td class="item-attr"><strong><span><%=@individual_total[0]['per_person_amount']%></span></strong></td> <td class="item-attr"><strong><span><%= number_with_precision(@individual_total[0]['per_person_amount'], precision: precision.to_i )%></span></strong></td>
</tr> </tr>
<% end %> <% end %>
</tfooter> </tfooter>
@@ -132,24 +147,24 @@
<div class="col-md-8"><strong>Amount Due</strong></div> <div class="col-md-8"><strong>Amount Due</strong></div>
<div class="col-md-4"> <div class="col-md-4">
<strong> <strong>
<span id="grand_total" class="hidden"><%= @sale_data.grand_total rescue 0%></span> <span id="grand_total" class="hidden"><%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%></span>
<span id="amount_due"><%= @sale_data.grand_total rescue 0%></span></strong> <span id="amount_due"><%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></span></strong>
</div> </div>
</div> </div>
<div class="row payment cash-color p-l-5 p-r-5"> <div class="row payment cash-color p-l-5 p-r-5">
<div class="col-md-8">Cash</div> <div class="col-md-8">Cash</div>
<div class="col-md-4" id="cash" ><%= @cash %></div> <div class="col-md-4" id="cash" ><%= number_with_precision(@cash, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<div class="row payment credit-color p-l-5 p-r-5" id="credit_payment" > <div class="row payment credit-color p-l-5 p-r-5" id="credit_payment" >
<div class="col-md-8">Credit</div> <div class="col-md-8">Credit</div>
<div class="col-md-4" id="credit"><%= @credit %></div> <div class="col-md-4" id="credit"><%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0%> <% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0%>
<div class="row payment other-payment-color" id="card_payment" > <div class="row payment other-payment-color" id="card_payment" >
<div class="col-md-8">Other Payments</div> <div class="col-md-8">Other Payments</div>
<div class="col-md-4" id="others"><%= @other %></div> <div class="col-md-4" id="others"><%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %></div>
</div> </div>
<% else %> <% else %>
<div class="row payment other-payment-color" id="card_payment" > <div class="row payment other-payment-color" id="card_payment" >
@@ -164,13 +179,13 @@
<div class="row payment others-color"> <div class="row payment others-color">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">MPU</div> <div class="col-md-3">MPU</div>
<div class="col-md-4 mpu is_card" id="others"><%= @other %></div> <div class="col-md-4 mpu is_card" id="others"><%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% else %> <% else %>
<div class="row hidden"> <div class="row hidden">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">MPU</div> <div class="col-md-3">MPU</div>
<div class="col-md-4" id="others">0.0</div> <div class="col-md-4" id="others"><%= number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% end %> <% end %>
<!-- paypar --> <!-- paypar -->
@@ -178,13 +193,13 @@
<div class="row payment others-color"> <div class="row payment others-color">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">Redeem</div> <div class="col-md-3">Redeem</div>
<div class="col-md-4" id="ppamount"><%= @ppamount %></div> <div class="col-md-4" id="ppamount"><%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% else %> <% else %>
<div class="row hidden"> <div class="row hidden">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">Redeem</div> <div class="col-md-3">Redeem</div>
<div class="col-md-4" id="ppamount">0.0</div> <div class="col-md-4" id="ppamount"><%= number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% end %> <% end %>
<!-- Visa --> <!-- Visa -->
@@ -192,13 +207,13 @@
<div class="row payment others-color"> <div class="row payment others-color">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">VISA</div> <div class="col-md-3">VISA</div>
<div class="col-md-4 visa is_card" id="visacount"><%= @visacount %></div> <div class="col-md-4 visa is_card" id="visacount"><%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% else %> <% else %>
<div class="row hidden"> <div class="row hidden">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">VISA</div> <div class="col-md-3">VISA</div>
<div class="col-md-4" id="visacount">0.0</div> <div class="col-md-4" id="visacount"><%= number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% end %> <% end %>
<!-- JCB --> <!-- JCB -->
@@ -206,13 +221,13 @@
<div class="row payment others-color"> <div class="row payment others-color">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">JCB</div> <div class="col-md-3">JCB</div>
<div class="col-md-4 jcb is_card" id="jcbcount"><%= @jcbcount %></div> <div class="col-md-4 jcb is_card" id="jcbcount"><%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% else %> <% else %>
<div class="row hidden"> <div class="row hidden">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">JCB</div> <div class="col-md-3">JCB</div>
<div class="col-md-4" id="jcbcount">0.0</div> <div class="col-md-4" id="jcbcount"><%= number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% end %> <% end %>
<!-- Master --> <!-- Master -->
@@ -220,13 +235,13 @@
<div class="row payment others-color"> <div class="row payment others-color">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">MASTER</div> <div class="col-md-3">MASTER</div>
<div class="col-md-4 master is_card" id="mastercount"><%= @mastercount %></div> <div class="col-md-4 master is_card" id="mastercount"><%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% else %> <% else %>
<div class="row hidden"> <div class="row hidden">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">MASTER</div> <div class="col-md-3">MASTER</div>
<div class="col-md-4" id="mastercount">0.0</div> <div class="col-md-4" id="mastercount"><%= number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% end %> <% end %>
<!-- <br> --> <!-- <br> -->
@@ -235,18 +250,18 @@
<div class="row payment others-color"> <div class="row payment others-color">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">UNIONPAY</div> <div class="col-md-3">UNIONPAY</div>
<div class="col-md-4 master is_card" id="unionpaycount"><%= @unionpaycount %></div> <div class="col-md-4 master is_card" id="unionpaycount"><%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% else %> <% else %>
<div class="row hidden"> <div class="row hidden">
<div class="col-md-5"></div> <div class="col-md-5"></div>
<div class="col-md-3">UNIONPAY</div> <div class="col-md-3">UNIONPAY</div>
<div class="col-md-4" id="unionpaycount">0.0</div> <div class="col-md-4" id="unionpaycount"><%= number_with_precision(0, precision: precision.to_i ) %></div>
</div> </div>
<% end %> <% end %>
<div class="row m-l-5 m-r-5"> <div class="row m-l-5 m-r-5">
<div class="col-md-8"><strong>Balance</strong></div> <div class="col-md-8"><strong>Balance</strong></div>
<div class="col-md-4"><strong><span id='balance'><%= @sale_data.grand_total rescue 0 %></span></strong></div> <div class="col-md-4"><strong><span id='balance'><%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %></span></strong></div>
</div> </div>
<!-- <br> --> <!-- <br> -->
</div> </div>
@@ -496,8 +511,13 @@ console.log("fffffffffffff")
var unionpay1 = $('#unionpaycount').text(); var unionpay1 = $('#unionpaycount').text();
var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1); var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1);
var total = $('#amount_due').text(); var total = $('#amount_due').text();
var amt = parseFloat(total) - parseFloat(othertotal); var amt = 0;
$('#cash').text(parseFloat(amt).toFixed(1)); <% 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(); update_balance();
break; break;
} }
@@ -662,7 +682,11 @@ console.log("fffffffffffff")
var amount_due = $('#amount_due').text(); 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 total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay)
var result = parseFloat(amount_due) - parseFloat(total); 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() { $('#foc').click(function() {