From ac2449931925a75d13d415f5a300c29793b1f2ed Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Tue, 10 Sep 2019 13:12:41 +0630 Subject: [PATCH] foc --- Gemfile.lock | 23 +++++++++---------- app/controllers/origami/void_controller.rb | 2 +- app/models/sale.rb | 26 +++++++++++----------- app/models/sale_item.rb | 6 +++-- app/models/sale_payment.rb | 3 ++- app/views/layouts/_left_sidebar.html.erb | 8 +++---- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1b1180a1..4c36f330 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,7 +47,7 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) aescrypt (1.0.0) - airbrussh (1.3.2) + airbrussh (1.3.3) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) axlsx (2.0.1) @@ -62,7 +62,7 @@ GEM builder (3.2.3) byebug (11.0.1) cancancan (1.17.0) - capistrano (3.11.0) + capistrano (3.11.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -99,8 +99,8 @@ GEM factory_girl_rails (4.9.0) factory_girl (~> 4.9.0) railties (>= 3.0.0) - faker (2.1.0) - i18n (>= 0.7) + faker (2.2.2) + i18n (~> 1.6.0) ffi (1.11.1) filterrific (5.2.1) font-awesome-rails (4.7.0.5) @@ -148,9 +148,9 @@ GEM material_icons (2.2.1) railties (>= 3.2) method_source (0.9.2) - mime-types (3.2.2) + mime-types (3.3) mime-types-data (~> 3.2015) - mime-types-data (3.2019.0331) + mime-types-data (3.2019.0904) mini_magick (4.9.5) mini_mime (1.0.2) mini_portile2 (2.4.0) @@ -163,8 +163,8 @@ GEM net-scp (2.0.0) net-ssh (>= 2.6.5, < 6.0.0) net-ssh (5.2.0) - nio4r (2.4.0) - nokogiri (1.10.3) + nio4r (2.5.1) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) pdf-core (0.7.0) pdfjs_viewer-rails (0.3.1) @@ -183,7 +183,7 @@ GEM puma (3.12.1) rack (2.0.7) rack-cors (1.0.3) - rack-protection (2.0.5) + rack-protection (2.0.7) rack rack-test (1.1.0) rack (>= 1.0, < 3) @@ -202,7 +202,7 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.1.0) + rails-html-sanitizer (1.2.0) loofah (~> 2.2, >= 2.2.2) railties (5.1.7) actionpack (= 5.1.7) @@ -251,9 +251,8 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.0.1) + sassc (2.2.0) ffi (~> 1.9) - rake schema_to_scaffold (0.8.0) activesupport (>= 3.2.1) shoulda-matchers (3.1.3) diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 980fd6bd..0523023e 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -8,7 +8,7 @@ class Origami::VoidController < BaseOrigamiController access_code = params[:access_code] if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - + puts sale.to_json if sale.discount_type == "member_discount" sale.update_attributes(total_discount: 0) sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) diff --git a/app/models/sale.rb b/app/models/sale.rb index 2c451b5b..95bbe525 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -461,7 +461,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil) + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil,type=nil) shop = Shop.first sale = Sale.find(sale_id) sales_items = sale_itemss @@ -473,20 +473,23 @@ class Sale < ApplicationRecord sales_items.each do |item| #compute each item and added to total - subtotal_price = subtotal_price + item.price + subtotal_price = subtotal_price + item.price # check for item is taxable and calculate if item.is_taxable total_taxable = total_taxable + item.taxable_price end end - compute_tax(sale, total_taxable, total_discount, order_source, tax_type) - 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 type =="foc" + sale.grand_total = 0 + else + sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax + sale.grand_total_round + end + if discount_type == "member_discount" sale.discount_type = discount_type end @@ -2955,13 +2958,10 @@ end #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 + print_settings = PrintSetting.get_precision_delimiter() + if !print_settings.nil? + self.grand_total =self.grand_total.round(print_settings.precision.to_i) + end end private diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index b8ada0ed..bd97e5c5 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -85,8 +85,10 @@ class SaleItem < ApplicationRecord # sale_item.is_taxable = 1 # sale_item.sale_id = sale_id # sale_item.save - sale = Sale.find(sale_id) - sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) + if type != "foc" + sale = Sale.find(sale_id) + sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) + end end def self.get_order_items_details(sale_id) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 42a4452c..2e1700f8 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -82,7 +82,6 @@ class SalePayment < ApplicationRecord amount_due = amount_due - payment.payment_amount end end - if (amount_due >= 0) payment_status = false membership_data = nil @@ -419,6 +418,8 @@ class SalePayment < ApplicationRecord sale_items.each do|item| SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) end + sale = Sale.find(self.sale.sale_id) + sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,'','','',"foc") self.payment_method = "foc" self.payment_amount = self.received_amount diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 4fee71b1..c948964d 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -103,9 +103,9 @@
  • Sale Items
  • -
  • + <% if order_reservation %>
  • <%= t("views.right_panel.detail.order_reservation") %> @@ -289,9 +289,9 @@
  • Hourly Sale Items
  • -
  • + <% if order_reservation %>
  • <%= t("views.right_panel.detail.order_reservation") %>