update sale audit

This commit is contained in:
Aung Myo
2017-10-31 12:08:27 +06:30
parent a687b45193
commit 56940d7f00
21 changed files with 348 additions and 215 deletions

View File

@@ -21,7 +21,7 @@ class Origami::DiscountsController < BaseOrigamiController
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
table = DiningFacility.find(table_id)
# 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;
@@ -46,14 +46,24 @@ class Origami::DiscountsController < BaseOrigamiController
sale_item.price = di["price"]
sale_item.save
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
end
# 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} "
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)
result = {:status=> "Success", :table_id => table_id, :table_type => table_type }
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
else
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type }
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type }
end
@@ -67,13 +77,18 @@ class Origami::DiscountsController < BaseOrigamiController
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
table = DiningFacility.find(table_id)
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)
action_by = current_user.id
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} "
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEITEMDISCOUNT" )
sale_item.destroy
end
end
@@ -82,9 +97,9 @@ class Origami::DiscountsController < BaseOrigamiController
# sale.save
# Re-calc All Amount in Sale
sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount)
result = {:status=> "Success", :table_id => table_id, :table_type => table_type }
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
else
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type }
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type }
end
render :json => result.to_json
@@ -115,6 +130,10 @@ class Origami::DiscountsController < BaseOrigamiController
#destroy in sale.sale_items
sale.sale_items.destroy(discount_items)
action_by = current_user.id
remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- #{table.name} "
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEALLDISCOUNT" )
# Re-calc All Amount in Sale
sale.compute_by_sale_items(sale_id, sale.sale_items, 0)
result = {:status=> "Success", :table_id => table_id, :table_type => table_type }