From ee17ddac92bd6e0a0a0ef298905da4f0c350fac2 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 31 Jan 2018 17:47:06 +0630 Subject: [PATCH] add rounding adj for table invoices --- .../origami/table_invoices_controller.rb | 30 +++++++++++++++++-- .../origami/table_invoices/index.html.erb | 4 +-- .../origami/table_invoices/show.html.erb | 4 +-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index 4571ba87..655083df 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -1,6 +1,7 @@ class Origami::TableInvoicesController < BaseOrigamiController def index @table = DiningFacility.find(params[:table_id]) + shop = Shop::ShopDetail puts "table bookig lenght" @sale_array = Array.new @table.bookings.each do |booking| @@ -9,7 +10,18 @@ class Origami::TableInvoicesController < BaseOrigamiController if booking.sale_id.nil? else sale = Sale.find(booking.sale_id) - + # rounding adjustment + if shop.is_rounding_adj + a = sale.grand_total % 25 # Modulus + b = sale.grand_total / 25 # Division + #not calculate rounding if modulus is 0 and division is even + #calculate rounding if modulus is zero or not zero and division are not even + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + new_total = Sale.get_rounding_adjustment(sale.grand_total) + sale.rounding_adjustment = new_total-sale.grand_total + end + end + #end rounding adjustment if sale.sale_status != "completed" @sale_array.push(sale) end @@ -19,12 +31,24 @@ class Origami::TableInvoicesController < BaseOrigamiController def show @table = DiningFacility.find(params[:table_id]) + shop = Shop::ShopDetail @sale_array = Array.new @table.bookings.each do |booking| if booking.sale_id.nil? else - sale = Sale.find(booking.sale_id) - + sale = Sale.find(booking.sale_id) + # rounding adjustment + if shop.is_rounding_adj + a = sale.grand_total % 25 # Modulus + b = sale.grand_total / 25 # Division + #not calculate rounding if modulus is 0 and division is even + #calculate rounding if modulus is zero or not zero and division are not even + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + new_total = Sale.get_rounding_adjustment(sale.grand_total) + sale.rounding_adjustment = new_total-sale.grand_total + end + end + #end rounding adjustment if sale.sale_status != "completed" && sale.sale_status != 'void' @sale_array.push(sale) end diff --git a/app/views/origami/table_invoices/index.html.erb b/app/views/origami/table_invoices/index.html.erb index eb98b9c0..b0c328be 100755 --- a/app/views/origami/table_invoices/index.html.erb +++ b/app/views/origami/table_invoices/index.html.erb @@ -75,8 +75,8 @@
- - +
diff --git a/app/views/origami/table_invoices/show.html.erb b/app/views/origami/table_invoices/show.html.erb index 5270202d..b70c2ffc 100755 --- a/app/views/origami/table_invoices/show.html.erb +++ b/app/views/origami/table_invoices/show.html.erb @@ -125,7 +125,7 @@ Rounding Adj: - <%= @obj_sale.rounding_adjustment rescue 0%> + <%= @sale.rounding_adjustment rescue 0%> Grand Total: @@ -140,7 +140,7 @@
- +