rounding decimal to print_settings precision

This commit is contained in:
Thein Lin Kyaw
2019-11-06 17:34:42 +06:30
parent 33670b450e
commit 155cb0a9eb
11 changed files with 467 additions and 802 deletions

View File

@@ -57,13 +57,16 @@ class Origami::DiscountsController < BaseOrigamiController
sale_item = SaleItem.new sale_item = SaleItem.new
if !origin_sale_item.nil? # if !origin_sale_item.nil?
menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items # menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items
if !menu_category.nil? # if !menu_category.nil?
sale_item.menu_category_code = menu_category.code # sale_item.menu_category_code = menu_category.code
sale_item.menu_category_name = menu_category.name # sale_item.menu_category_name = menu_category.name
end # end
end # end
sale_item.menu_category_code = origin_sale_item.menu_category_code
sale_item.menu_category_name = origin_sale_item.menu_category_name
sale_item.sale_id = sale_id sale_item.sale_id = sale_id
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
@@ -73,7 +76,7 @@ class Origami::DiscountsController < BaseOrigamiController
sale_item.status = "Discount" sale_item.status = "Discount"
sale_item.qty = -1 sale_item.qty = -1
sale_item.unit_price = di["price"].to_f * (-1) sale_item.unit_price = di["price"].to_f * -1
sale_item.taxable_price = di["price"] sale_item.taxable_price = di["price"]
sale_item.is_taxable = 1 sale_item.is_taxable = 1
sale_item.account_id = origin_sale_item.account_id sale_item.account_id = origin_sale_item.account_id

View File

@@ -64,15 +64,9 @@ class Origami::PaymentsController < BaseOrigamiController
customer = Customer.find(sale_data.customer_id) customer = Customer.find(sale_data.customer_id)
# rounding adjustment # rounding adjustment
if shop_detail.is_rounding_adj if shop_detail.is_rounding_adj
a = sale_data.grand_total % 25 # Modulus
b = sale_data.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(sale_data.grand_total) new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
rounding_adj = new_total-sale_data.grand_total rounding_adj = new_total - sale_data.grand_total
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
end
end end
#end rounding adjustment #end rounding adjustment
#record for sale audit #record for sale audit
@@ -151,15 +145,9 @@ class Origami::PaymentsController < BaseOrigamiController
# rounding adjustment # rounding adjustment
if !path.include? ("credit_payment") if !path.include? ("credit_payment")
if shop_detail.is_rounding_adj if shop_detail.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus
b = saleObj.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(saleObj.grand_total) new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
rounding_adj = new_total-saleObj.grand_total rounding_adj = new_total - saleObj.grand_total
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
end
end end
end end
#end rounding adjustment #end rounding adjustment

View File

@@ -72,7 +72,7 @@ class Origami::SaleEditController < BaseOrigamiController
saleitemObj.status = 'foc' saleitemObj.status = 'foc'
saleitemObj.remark = remark saleitemObj.remark = remark
saleitemObj.save saleitemObj.save
@newsaleitem = SaleItem.new
@newsaleitem = saleitemObj.dup @newsaleitem = saleitemObj.dup
@newsaleitem.qty = saleitemObj.qty * -1 @newsaleitem.qty = saleitemObj.qty * -1
@newsaleitem.unit_price = saleitemObj.unit_price * 1 @newsaleitem.unit_price = saleitemObj.unit_price * 1
@@ -143,7 +143,7 @@ class Origami::SaleEditController < BaseOrigamiController
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMEDIT" ) sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMEDIT" )
# saleitemObj.remark = 'edit' # saleitemObj.remark = 'edit'
unless saleitemObj.product_name.include? 'updated' unless saleitemObj.product_name.include? 'UPDATED'
saleitemObj.product_name = saleitemObj.product_name + ' (UPDATED)' saleitemObj.product_name = saleitemObj.product_name + ' (UPDATED)'
end end

View File

@@ -11,37 +11,23 @@ class Promotion < ApplicationRecord
PROMO_TYPE3 = "Net_price" # 1800 => 1000 => 1000 PROMO_TYPE3 = "Net_price" # 1800 => 1000 => 1000
PROMO_TYPE4 = "Percentage" PROMO_TYPE4 = "Percentage"
def is_promo_day
promo_day.include? Date.today.wday.to_s
end
def self.promo_activate(saleObj) def self.promo_activate(saleObj)
array_same =[]
current_day = Time.now.strftime("%Y-%m-%d") current_day = Time.now.strftime("%Y-%m-%d")
current_time = Time.now.strftime('%H:%M:%S') current_time = Time.now.strftime('%H:%M:%S')
day = Date.today.wday day = Date.today.wday
promoList = is_between_promo_datetime(current_day,current_time) promoList = is_between_promo_datetime(current_day,current_time)
puts "promoList - " + promoList.size.to_s
if promoList.size > 0
itemList = combine_item(saleObj)
itemList.each do|list|
list.each do |l|
array_same.push({
item_instance_code: l.item_instance_code,
order_id:l.order_id,
qty:l.qty
})
end
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
Rails.logger.debug "-------promo_activate array_same-------"
puts item_list.to_json
is_promo_day(promoList,day, item_list, saleObj.sale_id)
promoList.each do |promo|
if promo.is_promo_day
if item = saleObj.qty_of(promo.original_product)
check_promo_type(promo, item, saleObj)
end
end
end
end end
def self.is_between_promo_datetime(current_day,current_time) #database is not local time def self.is_between_promo_datetime(current_day,current_time) #database is not local time
@@ -49,45 +35,7 @@ class Promotion < ApplicationRecord
return promoList return promoList
end end
def self.combine_item(saleObj) def self.check_promo_type(promo, orderitem, saleObj)
# order_id = saleObj.sale_orders[0][0].order_id
# itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
# array_same =[]
itemList = []
saleObj.sale_orders.each do |so|
# itemList << OrderItem.where("order_id = ?",so.order_id).group(["item_instance_code", "order_id"]).sum(:qty)
itemList << OrderItem.where("order_id = ?",so.order_id).select(:item_instance_code,:order_id,:qty)
end
return itemList
end
def self.is_promo_day(promoList, day, orderitemList, sale_id)
puts "Today date - " + day.to_s
promoList.each do |promo|
dayresult = promo.promo_day.include?(day.to_s)
if dayresult
orderitemList.each do |item|
find_promo_item(promo, item, sale_id)
end
end
end
end
def self.find_promo_item(promo, orderitem, sale_id)
item_code = OrderItem.find_by_item_instance_code(orderitem[:item_instance_code]).item_code
# orderitem.each do |odr_item|
if promo.original_product.downcase.to_s == orderitem[:item_instance_code]
if promo.min_qty.to_i > orderitem[:qty].to_i
return false
else
check_promo_type(promo,orderitem, sale_id)
end
end
# end
end
def self.check_promo_type(promo, orderitem, sale_id)
promo.promotion_products.each do |promo_product| promo.promotion_products.each do |promo_product|
if promo_product.item_code.downcase == orderitem[:item_instance_code] if promo_product.item_code.downcase == orderitem[:item_instance_code]
same = true same = true
@@ -98,19 +46,19 @@ class Promotion < ApplicationRecord
# same, promo_product = check_giveaway_product(promo, orderitem[0][0]) # same, promo_product = check_giveaway_product(promo, orderitem[0][0])
if promo.promo_type == Promotion::PROMO_TYPE1 if promo.promo_type == Promotion::PROMO_TYPE1
if same if same
give_promotion_same_product(orderitem[:qty], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code) give_promotion_same_product(orderitem[:qty], promo.min_qty, promo_product.min_qty, orderitem, saleObj, promo_product.item_code)
else else
give_promotion_second_product(orderitem[:qty], promo.min_qty, promo_product.item_code, orderitem, sale_id) give_promotion_second_product(orderitem[:qty], promo.min_qty, promo_product.item_code, orderitem, saleObj)
end end
elsif promo.promo_type == Promotion::PROMO_TYPE2 elsif promo.promo_type == Promotion::PROMO_TYPE2
give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, sale_id) give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, saleObj)
elsif promo.promo_type == Promotion::PROMO_TYPE3 elsif promo.promo_type == Promotion::PROMO_TYPE3
give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, sale_id) give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, saleObj)
elsif promo.promo_type == Promotion::PROMO_TYPE4 elsif promo.promo_type == Promotion::PROMO_TYPE4
give_promotion_discount(same,promo_product,promo.min_qty, orderitem, sale_id) give_promotion_discount(same,promo_product,promo.min_qty, orderitem, saleObj)
end end
end end
end end
@@ -128,8 +76,7 @@ class Promotion < ApplicationRecord
# end # end
end end
def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, sale_id,promo_product) def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, saleObj,promo_product)
item =''
puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s
multiple = qty.to_i / promoqty.to_i # loop count multiple = qty.to_i / promoqty.to_i # loop count
charge_qty = 0 charge_qty = 0
@@ -156,76 +103,37 @@ class Promotion < ApplicationRecord
else else
charge_qty += qty charge_qty += qty
end end
sale_order =SaleOrder.where("sale_id=?",sale_id)
price =0
source =''
sale_order.each do|order|
source = Order.find(order.order_id).source
end
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first price = 0
item ={ source = saleObj.orders.first.source
item_code:item.item_code, item = saleObj.order_items.where(item_instance_code: promo_product).first
item_instance_code:item.item_instance_code,
item_name:item.item_name,
alt_name:item.alt_name,
account_id:item.account_id,
price:item.price
}
if promo_product.downcase != item[:item_instance_code]
sale_order.each do|order|
source = Order.find(order.order_id).source
end
item = OrderItem.where("item_code = ?",promo_product).order("order_items_id DESC").first
item ={
item_code:item.item_code,
item_instance_code:item.item_instance_code,
item_name:item.item_name,
alt_name:item.alt_name,
account_id:item.account_id,
price:item.price
}
end
if !item.nil? if !item.nil?
update_existing_item(foc_qty, item, sale_id, "promotion", item[:price],source) update_existing_item(foc_qty, item, sale_id, "promotion", item[:price], source)
end end
end end
# AA - 10 # 3 # BB # orderList, #S34345 # AA - 10 # 3 # BB # orderList, #S34345
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id) def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, saleObj)
source =''
item =''
puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s 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 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) foc_qty = saleObj.qty_of(promo_product).qty rescue 0
if (foc_qty < promotion_qty) if (foc_qty < promotion_qty)
promotion_qty = foc_qty promotion_qty = foc_qty
end end
# item = OrderItem.find_by_item_instance_code(promo_product) # item = OrderItem.find_by_item_instance_code(promo_product)
sale_order =SaleOrder.where("sale_id=?",sale_id)
price =0 price = 0
sale_order.each do|order| source = saleObj.orders.first.source
source = Order.find(order.order_id).source item = saleObj.order_items.where(item_instance_code: promo_product).first
end
item = OrderItem.where("item_instance_code = ?",promo_product).order("order_items_id DESC").first
item ={
item_code:item.item_code,
item_instance_code:item.item_instance_code,
item_name:item.item_name,
alt_name:item.alt_name,
account_id:item.account_id,
price:item.price
}
# item = OrderItem.where("item_instance_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first
if !item.nil? if !item.nil?
# source = Order.find(item.order_id).source
update_existing_item(promotion_qty, item, sale_id, "promotion", item[:price],source) update_existing_item(promotion_qty, item, sale_id, "promotion", item[:price],source)
end end
end end
def self.update_existing_item(qty, item, saleObj, type, item_price,source)
def self.update_existing_item(qty, item, sale_id, type, item_price,source) if qty > 0
if qty >0
menu_category = MenuCategory.get_menu_category(item[:item_code]) #get menu category for menu items menu_category = MenuCategory.get_menu_category(item[:item_code]) #get menu category for menu items
sale_item = SaleItem.new sale_item = SaleItem.new
@@ -247,216 +155,84 @@ class Promotion < ApplicationRecord
sale_item.price = qty * item_price * (-1) sale_item.price = qty * item_price * (-1)
sale_item.is_taxable = 1 sale_item.is_taxable = 1
sale_item.sale_id = sale_id sale_item.sale = saleObj
sale_item.save sale_item.save
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,nil,source) saleObj.compute_by_sale_items(saleObj.id, saleObj.sale_items, saleObj.total_discount,nil,source)
end end
end end
def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, sale_id) def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, saleObj)
item =''
source =''
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
sale_order =SaleOrder.where("sale_id=?",sale_id)
if same
foc_qty = orderitem[:qty].to_i / foc_min_qty foc_qty = orderitem[:qty].to_i / foc_min_qty
# item = OrderItem.find_by_item_instance_code(orderitem[0][0]) if !same
order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0
price =0
sale_order.each do|order|
source = Order.find(order.order_id).source
end
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
item ={
item_code:item.item_code,
item_instance_code:item.item_instance_code,
item_name:item.item_name,
alt_name:item.alt_name,
account_id:item.account_id,
price:item.price
}
# item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
if !item.nil?
# source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
end
else
foc_qty = orderitem[:qty].to_i / foc_min_qty
# foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
# item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
sale_order.each do|order|
source = Order.find(order.order_id).source
end
item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first
item ={
item_code:item.item_code,
item_instance_code:item.item_instance_code,
item_name:item.item_name,
alt_name:item.alt_name,
account_id:item.account_id,
price:item.price
}
if !item.nil?
# source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
end
end
end
def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id)
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
sale_order =SaleOrder.where("sale_id=?",sale_id)
source =''
item =''
if same
foc_qty = orderitem[:qty].to_i / foc_min_qty
# item = OrderItem.find_by_item_instance_code(orderitem[0][0]) # need to specify with menu item instance
# item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
sale_order.each do|order|
source = Order.find(order.order_id).source
end
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
item ={
item_code:item.item_code,
item_instance_code:item.item_instance_code,
item_name:item.item_name,
alt_name:item.alt_name,
account_id:item.account_id,
price:item.price
}
if !item.nil?
price = item[:price].to_i - promo_product.net_price.to_i
# source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
end
else
order_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty
foc_qty = orderitem[:qty].to_i / foc_min_qty foc_qty = orderitem[:qty].to_i / foc_min_qty
if foc_qty > order_qty if foc_qty > order_qty
foc_qty = order_qty foc_qty = order_qty
end end
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
# item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
sale_order.each do|order|
source = Order.find(order.order_id).source
end end
item = OrderItem.where("item_instance_code",promo_product.item_code).order("order_items_id DESC").first
item ={ source = saleObj.orders.first.source
item_code:item.item_code, item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first
item_instance_code:item.item_instance_code,
item_name:item.item_name, if !item.nil?
alt_name:item.alt_name, update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
account_id:item.account_id, end
price:item.price end
}
def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, saleObj)
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
foc_qty = orderitem[:qty].to_i / foc_min_qty
if !same
order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0
foc_qty = orderitem[:qty].to_i / foc_min_qty
if foc_qty > order_qty
foc_qty = order_qty
end
end
source = saleObj.orders.first.source
item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first
if !item.nil? if !item.nil?
price = item[:price].to_i - promo_product.net_price.to_i price = item[:price].to_i - promo_product.net_price.to_i
# source = Order.find(item.order_id).source update_existing_item(foc_qty, item, saleObj, "promotion nett price", price,source)
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
end
end end
end end
def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, sale_id) def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, saleObj)
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
sale_order =SaleOrder.where("sale_id=?",sale_id)
source =''
item =''
if same
foc_qty = orderitem[:qty].to_i / foc_min_qty foc_qty = orderitem[:qty].to_i / foc_min_qty
# item = OrderItem.find_by_item_instance_code(orderitem[0][0]) if !same
# item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0
sale_order.each do|order| foc_qty = orderitem[:qty].to_i / foc_min_qty
source = Order.find(order.order_id).source
if foc_qty > order_qty
foc_qty = order_qty
end end
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first end
item ={
item_code:item.item_code, source = saleObj.orders.first.source
item_instance_code:item.item_instance_code, item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first
item_name:item.item_name, puts saleObj
alt_name:item.alt_name, puts item
account_id:item.account_id,
price:item.price
}
# total = orderitem[1].to_i * item.price # total = orderitem[1].to_i * item.price
if !item.nil? if item
total = item[:price] total = item[:price]
price = calculate_discount(total, promo_product.percentage) price = calculate_discount(total, promo_product.percentage)
# source = Order.find(item.order_id).source # source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) update_existing_item(foc_qty, item, saleObj, "promotion discount", price,source)
end end
else
order_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check
foc_qty = orderitem[:qty].to_i / foc_min_qty
# give total qty is 1
#foc_qty = (foc_qty - foc_qty) + 1
if foc_qty > order_qty
foc_qty = order_qty
end
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
# item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
sale_order.each do|order|
source = Order.find(order.order_id).source
end
item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first
item ={
item_code:item.item_code,
item_instance_code:item.item_instance_code,
item_name:item.item_name,
alt_name:item.alt_name,
account_id:item.account_id,
price:item.price
}
# total = item.price * foc_qty
if !item.nil?
total = item[:price]
price = calculate_discount(total, promo_product.percentage)
# source = Order.find(item.order_id).source
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
end
end
end
def self.find_second_item_qty(sale_id, promo_item)
array_same =[]
saleObj = Sale.find_by_sale_id(sale_id)
itemList = combine_item(saleObj)
itemList.each do|list|
list.each do |l|
array_same.push({
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
return 0
end end
def self.calculate_discount(total, percentage) def self.calculate_discount(total, percentage)
return (total.to_i * percentage.to_i) / 100 return (total * percentage) / 100
end end
end end

View File

@@ -14,14 +14,20 @@ class Sale < ApplicationRecord
has_many :sale_payments has_many :sale_payments
has_many :sale_orders has_many :sale_orders
has_many :orders, through: :sale_orders has_many :orders, through: :sale_orders
has_many :order_items, through: :sale_orders
has_many :bookings has_many :bookings
has_many :product_commissions has_many :product_commissions
before_validation :round_to_precision
after_update :update_stock_journal after_update :update_stock_journal
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") } scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") }
def qty_of(item_instance_code)
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
end
REPORT_TYPE = { REPORT_TYPE = {
"daily" => 0, "daily" => 0,
"monthly" => 1, "monthly" => 1,
@@ -418,11 +424,11 @@ class Sale < ApplicationRecord
apply_tax(total_taxable, order_source, tax_type) apply_tax(total_taxable, order_source, tax_type)
self.total_amount = subtotal_price self.total_amount = subtotal_price
self.total_discount = total_discount # self.total_discount = total_discount
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
self.grand_total_round # self.grand_total_round
#compute rounding adjustment #compute rounding adjustment
adjust_rounding # adjust_rounding
self.save! self.save!
@@ -455,7 +461,7 @@ class Sale < ApplicationRecord
sale.grand_total = 0 sale.grand_total = 0
else else
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
sale.grand_total_round # sale.grand_total_round
end end
if discount_type == "member_discount" if discount_type == "member_discount"
@@ -463,7 +469,6 @@ class Sale < ApplicationRecord
end end
#compute rounding adjustment #compute rounding adjustment
# adjust_rounding # adjust_rounding
sale.rounding_adjustment = compute_adjust_rounding(sale.grand_total)
sale.save! sale.save!
end end
@@ -491,11 +496,11 @@ class Sale < ApplicationRecord
apply_tax(total_taxable, order_source) apply_tax(total_taxable, order_source)
self.total_amount = subtotal_price self.total_amount = subtotal_price
self.total_discount = total_discount # self.total_discount = total_discount
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
self.grand_total_round # self.grand_total_round
#compute rounding adjustment #compute rounding adjustment
adjust_rounding # adjust_rounding
self.save! self.save!
end end
@@ -509,37 +514,23 @@ class Sale < ApplicationRecord
# #delete existing and create new # #delete existing and create new
# existing_tax.delete # existing_tax.delete
# end # end
taxes = SaleTax.where("sale_id='#{sale.sale_id}'").pluck(:sale_tax_id) taxes = SaleTax.where("sale_id='#{self.sale_id}'").destroy_all
SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all
total_tax_amount = 0 total_tax_amount = 0
tax_incl_exec = "exclusive" tax_incl_exec = "exclusive"
#tax_profile - list by order_by #tax_profile - list by order_by
# tax_profiles = TaxProfile.all.order("order_by asc") # tax_profiles = TaxProfile.all.order("order_by asc")
# customer = Customer.find(sale.customer_id) # customer = Customer.find(sale.customer_id)
arr_tax = []
arr_tax = unique_tax_profiles(order_source, self.customer_id)
if !arr_tax.empty?
if tax_type.nil?
tax_profiles = TaxProfile.where(:id => arr_tax)
else
tax_profiles = TaxProfile.where("group_type=?",order_source)
end
else
tax_profiles = TaxProfile.where("group_type=?",order_source)
end
# #Creat new tax records
if order_source.to_s == "emenu" if order_source.to_s == "emenu"
order_source = "cashier" order_source = "cashier"
end end
tax_profiles = unique_tax_profiles(order_source, self.customer_id)
# #Creat new tax records
if sale.payment_status != 'foc' if sale.payment_status != 'foc'
tax_profiles.each do |tax| tax_profiles.each do |tax|
if tax.group_type.to_s == order_source.to_s
if tax_type
if tax_type.to_s == tax.name.to_s || tax_type == 'all'
sale_tax = SaleTax.new(:sale => sale) sale_tax = SaleTax.new(:sale => sale)
sale_tax.tax_name = tax.name sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate sale_tax.tax_rate = tax.rate
@@ -563,36 +554,6 @@ class Sale < ApplicationRecord
sale_tax.inclusive = tax.inclusive sale_tax.inclusive = tax.inclusive
sale_tax.save sale_tax.save
end end
else
# customer.tax_profiles.each do |cus_tax|
# if cus_tax.to_i == tax.id
sale_tax = SaleTax.new(:sale => sale)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
# substract , to give after discount
total_tax = total_taxable - total_discount
#include or execulive
if tax.inclusive
tax_incl_exec = "inclusive"
rate = tax.rate
divided_value = (100 + rate)/rate
sale_tax.tax_payable_amount = total_tax / divided_value
else
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
end
#new taxable amount is standard rule for step by step
if shop.calc_tax_order
total_taxable = total_taxable + sale_tax.tax_payable_amount
end
sale_tax.inclusive = tax.inclusive
sale_tax.save
# end
# end
end
end
end
end end
sale.tax_type = tax_incl_exec sale.tax_type = tax_incl_exec
sale.total_tax = total_tax_amount sale.total_tax = total_tax_amount
@@ -608,8 +569,7 @@ class Sale < ApplicationRecord
# existing_tax.delete # existing_tax.delete
# end # end
taxes = SaleTax.where("sale_id='#{self.sale_id}'").pluck(:sale_tax_id) taxes = SaleTax.where("sale_id='#{self.sale_id}'").destroy_all
SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all
total_tax_amount = 0 total_tax_amount = 0
tax_incl_exec = "exclusive" tax_incl_exec = "exclusive"
@@ -622,49 +582,10 @@ class Sale < ApplicationRecord
# tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id) # tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id)
# customer = Customer.find(self.customer_id).tax_profiles # customer = Customer.find(self.customer_id).tax_profiles
arr_tax = [] tax_profiles = unique_tax_profiles(order_source, self.customer_id)
arr_tax = unique_tax_profiles(order_source, self.customer_id)
if !arr_tax.empty?
if tax_type.nil?
tax_profiles = TaxProfile.where(:id => arr_tax)
else
tax_profiles = TaxProfile.where("group_type=?",order_source)
end
else
tax_profiles = TaxProfile.where("group_type=?",order_source)
end
#Create new tax records #Create new tax records
tax_profiles.each do |tax| tax_profiles.each do |tax|
if tax.group_type.to_s == order_source.to_s
if tax_type
if tax_type.to_s == tax.name.to_s || tax_type == 'all'
sale_tax = SaleTax.new(:sale => self)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
# substract , to give after discount
total_tax = total_taxable - total_discount
#include or execulive
if tax.inclusive
tax_incl_exec = "inclusive"
rate = tax.rate
divided_value = (100 + rate)/rate
sale_tax.tax_payable_amount = total_tax / divided_value
else
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
end
#new taxable amount is standard rule for step by step
if shop.calc_tax_order
total_taxable = total_taxable + sale_tax.tax_payable_amount
end
sale_tax.inclusive = tax.inclusive
sale_tax.save
end
else
# customer.tax_profiles.each do |cus_tax|
# if cus_tax.to_i == tax.id
sale_tax = SaleTax.new(:sale => self) sale_tax = SaleTax.new(:sale => self)
sale_tax.tax_name = tax.name sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate sale_tax.tax_rate = tax.rate
@@ -689,10 +610,6 @@ class Sale < ApplicationRecord
sale_tax.inclusive = tax.inclusive sale_tax.inclusive = tax.inclusive
sale_tax.save sale_tax.save
# end
# end
end
end
end end
self.tax_type = tax_incl_exec self.tax_type = tax_incl_exec
self.total_tax = total_tax_amount self.total_tax = total_tax_amount
@@ -727,42 +644,16 @@ class Sale < ApplicationRecord
shop_details = Shop.first shop_details = Shop.first
# rounding adjustment # rounding adjustment
if shop_details.is_rounding_adj if shop_details.is_rounding_adj
a = self.grand_total % 25 # Modulus
b = self.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(self.grand_total) new_total = Sale.get_rounding_adjustment(self.grand_total)
self.rounding_adjustment = new_total - self.grand_total self.rounding_adjustment = new_total - self.grand_total
else self.old_grand_total = self.grand_total
self.rounding_adjustment = 0.00 self.grand_total = new_total
end
else else
self.rounding_adjustment = 0.00 self.rounding_adjustment = 0.00
end end
end end
def compute_adjust_rounding(grand_total)
shop_details = Shop.first
# rounding adjustment
if shop_details.is_rounding_adj
a = grand_total % 25 # Modulus
b = grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(grand_total)
rounding_adjustment = new_total - grand_total
else
rounding_adjustment = 0.00
end
else
rounding_adjustment = 0.00
end
return rounding_adjustment
end
#Generate new Receipt No when it is not assigned #Generate new Receipt No when it is not assigned
def generate_receipt_no def generate_receipt_no
#shop_code and client_code #shop_code and client_code
@@ -857,36 +748,16 @@ class Sale < ApplicationRecord
# if get_rounded_amt == true # if get_rounded_amt == true
value = 0 value = 0
num = num.to_f.round # num = num.to_f.round
get_last_no = num.to_s.last(2).to_f mod = num % 50
if get_last_no.between?(0,25) if mod > 0 && mod <= 25
## down to 0 num -= mod
num -= get_last_no elsif mod > 25
else num += 50 - mod
if get_last_no.between?(26,50)
## up to 50
value = 50 - get_last_no.to_f
num += value
puts 'up to 50'
else
if get_last_no.between?(51, 75)
## down to 50
value = get_last_no.to_f - 50
num -= value
puts 'down to 50'
else
## up to 100
value = 100 - get_last_no.to_f
num += value
puts 'up to 100'
end end
end
end
# end
return num return num
end end
def self.daily_sales_list(from,to) def self.daily_sales_list(from,to)
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN
(SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount)) ELSE 0 END) (SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount)) ELSE 0 END)
@@ -2646,20 +2517,15 @@ def self.get_sale_data_for_other_payment_credit(sale_id)
end end
def unique_tax_profiles(order_source, customer_id) def unique_tax_profiles(order_source, customer_id)
tax_data = TaxProfile.where("group_type='#{order_source}'").pluck(:id) tax_data = TaxProfile
customer_tax_profiles = Customer.find(customer_id).tax_profiles .where(group_type: order_source)
arr_data = [] customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first
if !customer_tax_profiles.empty? if customer_tax_profiles.present?
customer_tax_profiles.each do |value1| tax_data = tax_data.where(id: customer_tax_profiles.tax_profiles)
if tax_data.include? value1.to_i
arr_data.push(value1.to_i)
end end
end
return arr_data
else
return tax_data return tax_data
end
end end
def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
@@ -2892,6 +2758,20 @@ private
end end
end end
def round_to_precision
if (self.total_amount != self.total_amount_was || self.total_discount != self.total_discount_was || self.total_tax != self.total_tax_was)
if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0)
precision = PrintSetting.get_precision_delimiter().precision.to_i
self.total_amount = self.total_amount.round(precision)
self.total_discount = self.total_discount.round(precision)
self.total_tax = self.total_tax.round(precision)
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
end
adjust_rounding
end
end
def update_stock_journal def update_stock_journal
if self.sale_status == "void" && self.sale_status_before_last_save != "void" if self.sale_status == "void" && self.sale_status_before_last_save != "void"
self.sale_items.each do |item| self.sale_items.each do |item|

View File

@@ -11,6 +11,7 @@ class SaleItem < ApplicationRecord
def compute_item def compute_item
end end
before_validation :round_to_precision
after_update :update_stock_journal after_update :update_stock_journal
# Add Sale Items # Add Sale Items
@@ -231,6 +232,24 @@ class SaleItem < ApplicationRecord
end end
end end
def round_to_precision
unit_price_fraction = self.unit_price % 1
price_fraction = self.unit_price % 1
# is_dining_charge = self.menu_category_code == 'DingingCharge'
if self.unit_price != self.unit_price_was || self.price != self.price_was
if unit_price_fraction > 0 || price_fraction > 0
if ['Discount', 'promotion'].include?(self.status)
precision = PrintSetting.get_precision_delimiter().precision.to_i
self.unit_price = self.unit_price.round(precision)
self.price = (self.unit_price * self.qty).round(precision)
self.taxable_price = self.price
end
end
end
end
def update_stock_journal def update_stock_journal
is_void = self.status == "void" && self.status_before_last_save != "void" is_void = self.status == "void" && self.status_before_last_save != "void"
cancel_void = self.status_before_last_save == "void" && self.status.nil? cancel_void = self.status_before_last_save == "void" && self.status.nil?

View File

@@ -6,6 +6,7 @@ class SaleOrder < ApplicationRecord
belongs_to :sale belongs_to :sale
belongs_to :order belongs_to :order
has_many :order_items, foreign_key: "order_id", primary_key: "order_id"
def create_sale_order(sale_id, order_id) def create_sale_order(sale_id, order_id)
# sale_order = SaleOrder.new # sale_order = SaleOrder.new

View File

@@ -5,6 +5,8 @@ class SaleTax < ApplicationRecord
before_create :generate_custom_id before_create :generate_custom_id
belongs_to :sale belongs_to :sale
before_validation :round_to_precision
def self.sync_sale_tax_records(sale_taxes) def self.sync_sale_tax_records(sale_taxes)
if !sale_taxes.nil? if !sale_taxes.nil?
sale_taxes.each do |t| sale_taxes.each do |t|
@@ -38,4 +40,13 @@ class SaleTax < ApplicationRecord
self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI") self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI")
end end
end end
def round_to_precision
if self.tax_payable_amount != self.tax_payable_amount_was
if self.tax_payable_amount % 1 > 0
precision = PrintSetting.get_precision_delimiter().precision.to_i
self.tax_payable_amount = self.tax_payable_amount.round(precision)
end
end
end
end end

View File

@@ -707,7 +707,7 @@ function calculate_overall_discount(type, amount){
// For Net Pay // For Net Pay
if(type == 0){ if(type == 0){
total_discount = amount; total_discount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
} }
// For Percentage Pay // For Percentage Pay
@@ -722,7 +722,7 @@ function calculate_overall_discount(type, amount){
}); });
} }
else{ else{
total_discount = (origin_sub_total * amount)/100; total_discount = Math.round(origin_sub_total * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision);
} }
} }
@@ -736,12 +736,13 @@ function calculate_item_discount(type, amount, sale_items, account_types){
var sub_total = 0; var sub_total = 0;
var total_discount = 0; var total_discount = 0;
var arrItemName = ""; var arrItemName = "";
var precision = <%= precision %>;
$("#discount_itemsErr").html(""); $("#discount_itemsErr").html("");
$("#discount-amountErr").html(""); $("#discount-amountErr").html("");
// For Net Pay // For Net Pay
if(origin_sub_total > 0){ if(origin_sub_total > 0){
if(type == 0){ if(type == 0){
dis_amount = (0 - amount); dis_amount = -Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
if(sale_items.length > 0){ if(sale_items.length > 0){
for(var i=0;i < sale_items.length;i++){ for(var i=0;i < sale_items.length;i++){
// if(account_types.length > 0){ // if(account_types.length > 0){
@@ -835,7 +836,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){
// } // }
// } // }
// else { // else {
dis_amount = 0 - ((sale_items[i].price * amount)/100); dis_amount = -Math.round(sale_items[i].price * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision);
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
total_discount = total_discount + dis_amount; total_discount = total_discount + dis_amount;

View File

@@ -98,8 +98,8 @@
<%if !@sale_data.nil? %> <%if !@sale_data.nil? %>
<% @sale_data.each do |result| %> <% @sale_data.each do |result| %>
<% grand_total +=result.grand_total.to_f %> <% grand_total += result.grand_total.to_f %>
<% old_grand_total += result.grand_total_after_rounding() %> <% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %>
<% total_tax += result.total_tax.to_f %> <% total_tax += result.total_tax.to_f %>
<% total_sum += result.total_amount.to_f %> <% total_sum += result.total_amount.to_f %>
<% discount_amt += result.total_discount.to_f %> <% discount_amt += result.total_discount.to_f %>
@@ -127,47 +127,35 @@
<td><%= number_with_precision(result.total_amount, precision: precision.to_i ,delimiter: delimiter) %></td> <td><%= number_with_precision(result.total_amount, precision: precision.to_i ,delimiter: delimiter) %></td>
<td><%= number_with_precision(result.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue '0' %> <td><%= number_with_precision(result.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue '0' %>
</td> </td>
<!-- <%if result.customer.customer_type == "Takeaway"%>
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
<%end%> -->
<% if !result.sale_taxes.empty? %> <% if !result.sale_taxes.empty? %>
<% num = 1 <% num = 1 %>
if tax_flag && tax_count > 0 %> <% if tax_flag && tax_count > 0 %>
<% while num <= tax_count %> <% while num <= tax_count %>
<td> <td>0</td>
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> <% num += 1 %>
</td> <% end %>
<% num += 1
end %>
<% end %> <% end %>
<% result.sale_taxes.each do |tax| %> <% result.sale_taxes.each do |tax| %>
<td> <td>
<%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %>
</td> </td>
<%end%> <%end%>
<% num = 1 <% num = 1 %>
if tax_flag==false && tax_count > 0 %> <% if !tax_flag && tax_count > 0 %>
<% while num <= tax_count %> <% while num <= tax_count %>
<td> <td>0</td>
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> <% num += 1 %>
</td> <% end %>
<% num += 1
end %>
<% end %> <% end %>
<% else %> <% else %>
<% @tax_profiles.each do |tax| %> <% @tax_profiles.each do |tax| %>
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td> <td>0</td>
<% end %> <% end %>
<%end%> <%end%>
<% if result.old_grand_total.nil? %> <td><%= number_with_precision(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td> <td><%= number_with_precision(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
<%else%> <td><%= number_with_precision(result.grand_total, precision: precision.to_i, delimiter: delimiter) %></td>
<td><%= number_with_precision(result.old_grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
<%end%>
<td><%= result.rounding_adjustment.to_f rescue '-' %></td>
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %></td>
<% if @lookup.value.to_i == 1 %> <% if @lookup.value.to_i == 1 %>
<td> <td>
<!-- ############### Need to Check SyncStatus ############# --> <!-- ############### Need to Check SyncStatus ############# -->

View File

@@ -65,8 +65,8 @@
<%if @sale_data %> <%if @sale_data %>
<% @sale_data.each do |result| %> <% @sale_data.each do |result| %>
<% grand_total = grand_total.to_f + result.grand_total.to_f %> <% grand_total += result.grand_total.to_f %>
<% old_grand_total = old_grand_total.to_f + result.old_grand_total.to_f %> <% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %>
<% total_tax += result.total_tax.to_f %> <% total_tax += result.total_tax.to_f %>
<% total_sum += result.total_amount.to_f %> <% total_sum += result.total_amount.to_f %>
<% discount_amt += result.total_discount.to_f %> <% discount_amt += result.total_discount.to_f %>
@@ -91,9 +91,7 @@
<td><%= result.cashier_name rescue '-' %></td> <td><%= result.cashier_name rescue '-' %></td>
<td><%= result.total_amount rescue '-' %></td> <td><%= result.total_amount rescue '-' %></td>
<td><%= result.total_discount rescue '-' %></td> <td><%= result.total_discount rescue '-' %></td>
<!-- <%if result.customer.customer_type == "Takeaway"%>
<td>0.0</td>
<%end%> -->
<% if !result.sale_taxes.empty? %> <% if !result.sale_taxes.empty? %>
<% num = 1 <% num = 1
if tax_flag && tax_count > 0 %> if tax_flag && tax_count > 0 %>
@@ -120,9 +118,9 @@
<% end %> <% end %>
<%end%> <%end%>
<td><%= result.grand_total %></td> <td><%= result.grand_total - result.rounding_adjustment %></td>
<td><%= result.rounding_adjustment.to_f rescue '-' %></td> <td><%= result.rounding_adjustment.to_f rescue '-' %></td>
<td><%= result.grand_total_after_rounding() rescue '-'%></td> <td><%= result.grand_total rescue '-'%></td>
</tr> </tr>
<% end %> <% end %>