promotion issue second item
This commit is contained in:
@@ -426,14 +426,30 @@ class Promotion < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.find_second_item_qty(sale_id, promo_item)
|
def self.find_second_item_qty(sale_id, promo_item)
|
||||||
|
array_same =[]
|
||||||
saleObj = Sale.find_by_sale_id(sale_id)
|
saleObj = Sale.find_by_sale_id(sale_id)
|
||||||
itemList = combine_item(saleObj)
|
itemList = combine_item(saleObj)
|
||||||
itemList.each do |item|
|
itemList.each do|list|
|
||||||
item.each do |i|
|
list.each do |l|
|
||||||
if i[0][0] == promo_item.downcase
|
array_same.push({
|
||||||
return i[1]
|
item_instance_code: l.item_instance_code,
|
||||||
|
order_id:l.order_id,
|
||||||
|
qty:l.qty
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
item_list =[]
|
||||||
|
array_same.group_by do |same|
|
||||||
|
same.values_at :item_instance_code
|
||||||
|
end.map do |(item_instance_code), array_same|
|
||||||
|
quantities = array_same.map { |p| p[:qty] }
|
||||||
|
qty = quantities.all? ? quantities.reduce(:+) : nil
|
||||||
|
item_list.push({ item_instance_code: item_instance_code, qty: qty })
|
||||||
|
end
|
||||||
|
item_list.each do |item|
|
||||||
|
if item[:item_instance_code] == promo_item.downcase
|
||||||
|
return item[:qty].to_i
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user