From b13b0afa6c4ef7331ffd07f3c8be07f40671fbd5 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 22 Jun 2017 11:31:05 +0630 Subject: [PATCH] discuont updated for show --- app/controllers/origami/discounts_controller.rb | 10 ++++------ app/views/origami/home/show.html.erb | 11 +++++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index a195bb6a..6c0a4c8d 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -20,9 +20,9 @@ class Origami::DiscountsController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) sale.total_discount = overall_discount.to_f - sale.total_amount = sub_total - sale.grand_total = (sub_total - overall_discount.to_f) + sale.total_tax; - + sale.total_amount = sub_total.to_f + sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; + sale.save if discount_items.length > 0 #save sale item for discount discount_items.each do |di| @@ -42,9 +42,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.price = di["price"] sale_item.save - end - - sale.save + end end end end diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 22e35765..139697e3 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -143,7 +143,10 @@ sub_total = sub_total + sale_item.price %> - <% unless sale_item.price <= 0 %> + <% + # Can't check for discount + unless sale_item.price == 0 + %> <%= count %> <%= sale_item.product_name %> @@ -151,7 +154,7 @@ <%= sale_item.price %> <% - end + end end end @@ -164,7 +167,7 @@ count += 1 sub_total = sub_total + order_item.price - unless order_item.price <= 0 %> + unless order_item.price == 0 %> <%= count %> <%= order_item.item_name %> @@ -188,7 +191,7 @@ Discount: - (<%= @obj_order.total_discount rescue 0%>) + (<%= @obj_sale.total_discount rescue 0%>) <% if @status_sale == "sale" %>