update discount for qs

This commit is contained in:
Aung Myo
2018-02-15 11:23:40 +06:30
parent 0d515d9c93
commit a2bd8795cc
2 changed files with 27 additions and 5 deletions

View File

@@ -7,7 +7,11 @@ class Origami::DiscountsController < BaseOrigamiController
@cashier_type = params[:type]
if Sale.exists?(sale_id)
@sale_data = Sale.find(sale_id)
@table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id)
if @sale_data.bookings[0].dining_facility_id.to_i > 0
@table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id)
else
@table = nil
end
end
@member_discount = MembershipSetting.find_by_discount(1)
@@ -23,8 +27,15 @@ class Origami::DiscountsController < BaseOrigamiController
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
table_id = sale.bookings[0].dining_facility_id
table = DiningFacility.find(table_id)
if sale.bookings[0].dining_facility_id.to_i > 0
table_id = sale.bookings[0].dining_facility_id
table = DiningFacility.find(table_id)
else
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;
@@ -34,7 +45,6 @@ class Origami::DiscountsController < BaseOrigamiController
#save sale item for discount
discount_items.each do |di|
origin_sale_item = SaleItem.find(di["id"])
puts origin_sale_item.to_json
sale_item = SaleItem.new
sale_item.sale_id = sale_id
@@ -55,6 +65,7 @@ class Origami::DiscountsController < BaseOrigamiController
action_by = current_user.id
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_id, action_by,remark,"ITEMDISCOUNT" )
end
@@ -63,7 +74,12 @@ class Origami::DiscountsController < BaseOrigamiController
# Re-calc All Amount in Sale
if overall_discount.to_f > 0
action_by = current_user.id
remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} "
if table.nil?
remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} "
else
remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} "
end
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" )
end
sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f)