diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 87b90613..282d6798 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -120,6 +120,10 @@ class Promotion < ApplicationRecord def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id) puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty + foc_qty = find_second_item_qty(sale_id, promo_product) + if (foc_qty < promotion_qty) + promotion_qty = foc_qty + end item = OrderItem.find_by_item_code(promo_product) update_existing_item(promotion_qty, item, sale_id, "promotion", item.price) end @@ -135,13 +139,15 @@ class Promotion < ApplicationRecord sale_item.qty = foc_qty * (-1) sale_item.unit_price = item_price * (-1) - sale_item.taxable_price = item_price + sale_item.taxable_price = item_price * (-1) sale_item.price = foc_qty * item_price * (-1) - sale_item.is_taxable = item.taxable + sale_item.is_taxable = false 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) end diff --git a/app/models/sale.rb b/app/models/sale.rb index 9927251d..500e28ef 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -183,6 +183,7 @@ class Sale < ApplicationRecord sale_item.sale_id = self.id sale_item.price = diningprice sale_item.save + self.compute end def update_item (item) @@ -214,10 +215,11 @@ class Sale < ApplicationRecord sales_items.each do |item| #compute each item and added to total + puts "item.sales_item_id ddd" + puts item.sale_item_id subtotal_price = subtotal_price + item.price total_taxable = total_taxable + (item.taxable_price * item.qty) end - apply_tax (total_taxable) self.total_amount = subtotal_price self.total_discount = total_discount