api discount and change tax

This commit is contained in:
Thein Lin Kyaw
2023-10-17 16:52:12 +06:30
parent 81eb30c03a
commit 3441811bb0
27 changed files with 1225 additions and 1067 deletions

View File

@@ -42,38 +42,56 @@ class Foodcourt::DiscountsController < BaseFoodcourtController
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;
# sale.save
if discount_items.length > 0
#save sale item for discount
discount_items.each do |di|
origin_sale_item = SaleItem.find(di["id"])
discount = di['discount'].to_d
discount_type = di['discount_type']
sale_item = SaleItem.new
sale_item = SaleItem.find(di["id"])
discount_item = SaleItem.find_or_initialize_by(parent_id: di['id'])
sale_item.menu_category_code = origin_sale_item.menu_category_code
sale_item.menu_category_name = origin_sale_item.menu_category_name
discount_item.discount = discount
if discount_type == 'nett'
discount_item.discount_type = 'nett'
discount_item.product_name = "#{sale_item.product_name} - discount"
unit_price = discount
elsif discount_type == 'percentage'
discount_item.discount_type = 'percentage'
discount_item.product_name = "#{sale_item.product_name} - discount(#{discount}%)"
unit_price = sale_item.unit_price * (discount / 100)
end
sale_item.sale_id = sale_id
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
sale_item.product_name = di["name"]
sale_item.item_instance_code = origin_sale_item.item_instance_code
sale_item.product_alt_name = ""
sale_item.status = "Discount"
price = unit_price * sale_item.qty
sale_item.qty = -1
sale_item.unit_price = di["price"].to_f * -1
sale_item.taxable_price = di["price"]
sale_item.is_taxable = 1
sale_item.account_id = origin_sale_item.account_id
discount_item.menu_category_code = sale_item.menu_category_code
discount_item.menu_category_name = sale_item.menu_category_name
sale_item.price = di["price"]
sale_item.save
discount_item.sale_id = sale_id
discount_item.product_code = sale_item != nil ? sale_item.product_code : sale_id
discount_item.item_instance_code = sale_item.item_instance_code
discount_item.product_alt_name = ""
discount_item.status = "Discount"
discount_item.qty = sale_item.qty
discount_item.unit_price = unit_price
discount_item.taxable_price = -price
discount_item.is_taxable = sale_item.is_taxable
discount_item.account_id = sale_item.account_id
discount_item.price = -price
discount_item.save
action_by = current_user.name
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_name, action_by,remark,"ITEMDISCOUNT" )
sale_audit = SaleAudit.record_audit_discount(discount_item.sale_id, sale.cashier_name, action_by, remark, "ITEMDISCOUNT" )
end
end
@@ -102,7 +120,6 @@ class Foodcourt::DiscountsController < BaseFoodcourtController
end
end
render :json => result.to_json
end
@@ -121,24 +138,31 @@ class Foodcourt::DiscountsController < BaseFoodcourtController
table = nil
end
if discount_items.length > 0
#destroy sale item for discount
discount_items.each do |di|
sale_item = SaleItem.find(di["id"])
sale.total_amount = (sale.total_amount + sale_item.price.abs)
discount_item = sale_item.discount_item
next if discount_item.nil?
sale.total_amount = (sale.total_amount + discount_item.price.abs)
action_by = current_user.name
if table.nil?
remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- No Table "
remark = "Remove Item Discount Item Name ->#{discount_item.product_name}-Product Code ->#{discount_item.product_code} | Price [#{discount_item.price}] | Receipt No #{sale.receipt_no} | Table- No Table "
else
remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} "
remark = "Remove Item Discount Item Name ->#{discount_item.product_name}-Product Code ->#{discount_item.product_code} | Price [#{discount_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} "
end
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEITEMDISCOUNT" )
sale_item.destroy
discount_item.destroy
end
end
# sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
# sale.save
# Re-calc All Amount in Sale
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
if table.nil?