From 258aba669bdf32a954371897e0967bb04d683bf9 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Thu, 5 Sep 2019 18:12:17 +0630 Subject: [PATCH] precision --- .../origami/discounts_controller.rb | 2 ++ app/controllers/origami/home_controller.rb | 3 ++- app/models/sale.rb | 15 +++++++++++ app/views/origami/discounts/index.html.erb | 26 ++++++++++++++----- app/views/origami/home/show.html.erb | 24 +++++++++++++---- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 22092a50..cd73d174 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -3,6 +3,8 @@ class Origami::DiscountsController < BaseOrigamiController #discount page show from origami index with selected order def index + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() @webview = false if check_mobile @webview = true diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 2ba8cd3e..fe074210 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -17,7 +17,8 @@ class Origami::HomeController < BaseOrigamiController # origami table detail def show - + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() @webview = check_mobile @tables = Table.unscoped.all.active.order('status desc') diff --git a/app/models/sale.rb b/app/models/sale.rb index 8f5c7eb0..2c451b5b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -452,6 +452,7 @@ class Sale < ApplicationRecord self.total_amount = subtotal_price self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax + self.grand_total_round #compute rounding adjustment adjust_rounding @@ -461,6 +462,7 @@ class Sale < ApplicationRecord #compute - invoice total def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil) + shop = Shop.first sale = Sale.find(sale_id) sales_items = sale_itemss @@ -484,6 +486,7 @@ class Sale < ApplicationRecord sale.total_amount = subtotal_price sale.total_discount = total_discount sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax + sale.grand_total_round if discount_type == "member_discount" sale.discount_type = discount_type end @@ -519,6 +522,7 @@ class Sale < ApplicationRecord self.total_amount = subtotal_price self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax + self.grand_total_round #compute rounding adjustment adjust_rounding @@ -2948,6 +2952,17 @@ end # End hourly sale item report + +#not to show decimal in grand total +def grand_total_round + shop =Shop.first + print_settings = PrintSetting.get_precision_delimiter() + if !print_settings.nil? + self.grand_total =self.grand_total.round(print_settings.precision.to_i) + puts self.grand_total + puts "Hello grand_total_round" + end +end private def generate_custom_id diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 55144c41..cb7fe255 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -2,6 +2,20 @@ + <% 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 %>
@@ -72,7 +86,7 @@ - +
@@ -350,7 +364,7 @@
Sub Total:<%=sub_total%><%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
- + <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%> @@ -359,7 +373,7 @@ <%end%> - + <% if @status_sale == "sale" %> @@ -382,15 +396,15 @@ <% end %> - + - + - + <% end %>
Sub Total:<%= sub_total %><%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
Discount:(<%= @obj_sale.total_discount rescue 0%>)(<%= number_with_precision(@obj_sale.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>)
<%= @obj_sale.total_tax rescue 0%><%= number_with_precision(@obj_sale.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%>
Rounding Adj:<%= @obj_sale.rounding_adjustment rescue 0%><%= number_with_precision(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%>
Grand Total:<%= @obj_sale.grand_total rescue 0%><%= number_with_precision(@obj_sale.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>