From a2bd8795ccec9c0b23132c08bfdc60f74e0b6ff4 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Feb 2018 11:23:40 +0630 Subject: [PATCH] update discount for qs --- .../origami/discounts_controller.rb | 26 +++++++++++++++---- app/views/origami/discounts/index.html.erb | 6 +++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index bea6e381..1905fd9a 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -7,7 +7,11 @@ class Origami::DiscountsController < BaseOrigamiController @cashier_type = params[:type] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) - @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + if @sale_data.bookings[0].dining_facility_id.to_i > 0 + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + else + @table = nil + end end @member_discount = MembershipSetting.find_by_discount(1) @@ -23,8 +27,15 @@ class Origami::DiscountsController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) - table_id = sale.bookings[0].dining_facility_id - table = DiningFacility.find(table_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table = nil + table_id = nil + end + + # sale.total_discount = overall_discount.to_f # sale.total_amount = sub_total.to_f # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; @@ -34,7 +45,6 @@ class Origami::DiscountsController < BaseOrigamiController #save sale item for discount discount_items.each do |di| origin_sale_item = SaleItem.find(di["id"]) - puts origin_sale_item.to_json sale_item = SaleItem.new sale_item.sale_id = sale_id @@ -55,6 +65,7 @@ class Origami::DiscountsController < BaseOrigamiController action_by = current_user.id remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} " + sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_id, action_by,remark,"ITEMDISCOUNT" ) end @@ -63,7 +74,12 @@ class Origami::DiscountsController < BaseOrigamiController # Re-calc All Amount in Sale if overall_discount.to_f > 0 action_by = current_user.id - remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + if table.nil? + remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + else + remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + end + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" ) end sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 33141666..ba03f8d7 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -13,8 +13,14 @@
+ <%if !@table.nil?%> + <%else%> + + + <%end%> +

Receipt No: <%=@sale_data.receipt_no rescue ' '%>