update discount for qs

This commit is contained in:
Aung Myo
2018-02-15 11:49:01 +06:30
parent a2bd8795cc
commit a8fdf2ec30

View File

@@ -75,7 +75,7 @@ class Origami::DiscountsController < BaseOrigamiController
if overall_discount.to_f > 0 if overall_discount.to_f > 0
action_by = current_user.id action_by = current_user.id
if table.nil? if table.nil?
remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- no Table "
else else
remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} "
end end
@@ -83,9 +83,17 @@ class Origami::DiscountsController < BaseOrigamiController
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" ) sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" )
end end
sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f)
result = {:status=> "Success", :table_id => table_id, :table_type => table.type } if !table.nil?
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
else
result = {:status=> "Success" }
end
else else
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } if !table.nil?
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type }
else
result = {:status=> "Please, Check Again!" }
end
end end
@@ -98,8 +106,14 @@ class Origami::DiscountsController < BaseOrigamiController
discount_items = JSON.parse(params[:discount_items]) discount_items = JSON.parse(params[:discount_items])
if Sale.exists?(sale_id) if Sale.exists?(sale_id)
sale = Sale.find(sale_id) sale = Sale.find(sale_id)
table_id = sale.bookings[0].dining_facility_id if sale.bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(table_id) table_id = sale.bookings[0].dining_facility_id
table = DiningFacility.find(table_id)
else
table_id = nil
table = nil
end
if discount_items.length > 0 if discount_items.length > 0
#destroy sale item for discount #destroy sale item for discount
@@ -108,7 +122,11 @@ class Origami::DiscountsController < BaseOrigamiController
sale.total_amount = (sale.total_amount + sale_item.price.abs) sale.total_amount = (sale.total_amount + sale_item.price.abs)
action_by = current_user.id action_by = current_user.id
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 "
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 ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} "
end
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEITEMDISCOUNT" ) sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEITEMDISCOUNT" )
sale_item.destroy sale_item.destroy
@@ -119,9 +137,19 @@ class Origami::DiscountsController < BaseOrigamiController
# sale.save # sale.save
# Re-calc All Amount in Sale # Re-calc All Amount in Sale
sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount)
result = {:status=> "Success", :table_id => table_id, :table_type => table.type } if table.nil?
result = {:status=> "Success"}
else
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
end
else else
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } if table.nil?
result = {:status=> "Please, Check Again!"}
else
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type }
end
end end
render :json => result.to_json render :json => result.to_json