still dev dis
This commit is contained in:
@@ -29,7 +29,6 @@ class Origami::DiscountsController < BaseOrigamiController
|
||||
if discount_items.length > 0
|
||||
#save sale item for discount
|
||||
discount_items.each do |di|
|
||||
puts di
|
||||
origin_sale_item = SaleItem.find(di["id"])
|
||||
sale_item = SaleItem.new
|
||||
|
||||
@@ -53,6 +52,61 @@ class Origami::DiscountsController < BaseOrigamiController
|
||||
render :json => dining.to_json
|
||||
end
|
||||
|
||||
# Remove selected discount Items
|
||||
def remove_discount_items
|
||||
sale_id = params[:sale_id]
|
||||
discount_items = JSON.parse(params[:discount_items])
|
||||
if Sale.exists?(sale_id)
|
||||
sale = Sale.find(sale_id)
|
||||
table_id = sale.bookings[0].dining_facility_id
|
||||
table_type = DiningFacility.find(table_id).type
|
||||
|
||||
if discount_items.length > 0
|
||||
#destroy sale item for discount
|
||||
discount_items.each do |di|
|
||||
sale_item = SaleItem.find(di["id"])
|
||||
price = (sale_item.price - 0)
|
||||
sale.total_amount = (sale.total_amount + price)
|
||||
sale_item.destroy
|
||||
end
|
||||
end
|
||||
|
||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
|
||||
sale.save
|
||||
end
|
||||
|
||||
dining = {:table_id => table_id, :table_type => table_type }
|
||||
|
||||
render :json => dining.to_json
|
||||
end
|
||||
|
||||
# Remove all discount Items
|
||||
def remove_all_discount
|
||||
sale_id = params[:id]
|
||||
|
||||
if Sale.exists?(sale_id)
|
||||
sale = Sale.find(sale_id)
|
||||
table_id = sale.bookings[0].dining_facility_id
|
||||
table_type = DiningFacility.find(table_id).type
|
||||
|
||||
#destroy all discount sale item
|
||||
sale.sale_items.each do |si|
|
||||
if si.remark == "Discount" && si.price < 0
|
||||
price = (si.price - 0)
|
||||
sale.total_amount = (sale.total_amount + price)
|
||||
si.destroy
|
||||
end
|
||||
end
|
||||
|
||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
|
||||
sale.save
|
||||
end
|
||||
|
||||
dining = {:table_id => table_id, :table_type => table_type }
|
||||
|
||||
render :json => dining.to_json
|
||||
end
|
||||
|
||||
#discount for selected order
|
||||
# def create
|
||||
# sale_id = params[:sale_id]
|
||||
|
||||
Reference in New Issue
Block a user