Promotion Tax bug fix

This commit is contained in:
Phyo
2017-08-24 18:31:53 +06:30
parent 9327cb7169
commit 8b33a94d93
2 changed files with 11 additions and 3 deletions

View File

@@ -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

View File

@@ -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