fix rounding adjustment
This commit is contained in:
@@ -23,9 +23,28 @@ namespace :shift_sales do
|
||||
sales = shift_sale.sales.order(:created_at)
|
||||
sales.each do |sale|
|
||||
|
||||
new_grand_total = sale.total_amount - sale.total_discount + sale.total_tax + sale.rounding_adjustment
|
||||
old_grand_total = sale.total_amount - sale.total_discount + sale.total_tax
|
||||
amount_changed = sale.amount_received - new_grand_total
|
||||
sale.grand_total = sale.total_amount - sale.total_discount + sale.total_tax
|
||||
sale.old_grand_total = grand_total
|
||||
|
||||
license = License.new(ENV["SX_PROVISION_URL"])
|
||||
shop_name = license.read_license_no_decrypt("shop_name")
|
||||
|
||||
shop = if Rails.env.production? || shop_name.present?
|
||||
Shop.find_by(name: shop_name)
|
||||
else
|
||||
Shop.first
|
||||
end
|
||||
|
||||
if shop.is_rounding_adj
|
||||
new_total = Sale.get_rounding_adjustment(sale.grand_total)
|
||||
sale.rounding_adjustment = new_total - sale.grand_total
|
||||
sale.old_grand_total = sale.grand_total
|
||||
sale.grand_total = new_total
|
||||
else
|
||||
sale.rounding_adjustment = 0.00
|
||||
end
|
||||
|
||||
sale.amount_changed = sale.amount_received - sale.grand_total
|
||||
|
||||
cash_amount = 0
|
||||
credit_amount = 0
|
||||
@@ -56,13 +75,18 @@ namespace :shift_sales do
|
||||
else
|
||||
other_amount += sale_payment.payment_amount
|
||||
end
|
||||
outstanding_amount = new_grand_total - sale_payment.payment_amount
|
||||
sale_payment.update_columns(outstanding_amount: outstanding_amount)
|
||||
sale_payment.outstanding_amount = sale.grand_total - sale_payment.payment_amount
|
||||
sale_payment.update_columns(outstanding_amount: sale_payment.outstanding_amount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sale.update_columns(grand_total: new_grand_total, old_grand_total: old_grand_total, amount_changed: amount_changed)
|
||||
sale.update_columns(
|
||||
grand_total: sale.grand_total,
|
||||
old_grand_total: sale.old_grand_total,
|
||||
rounding_adjustment: sale.rounding_adjustment,
|
||||
amount_changed: sale.amount_changed
|
||||
)
|
||||
|
||||
if sale.sale_status != 'void'
|
||||
total_revenue += sale.total_amount
|
||||
@@ -98,22 +122,20 @@ namespace :shift_sales do
|
||||
end
|
||||
|
||||
shift_sale.update_columns(
|
||||
{
|
||||
total_revenue: total_revenue,
|
||||
total_discounts: total_discounts,
|
||||
total_taxes: total_taxes,
|
||||
grand_total: grand_total,
|
||||
cash_sales: cash_sales,
|
||||
credit_sales: credit_sales,
|
||||
other_sales: other_sales,
|
||||
nett_sales: nett_sales,
|
||||
commercial_taxes: commercial_taxes,
|
||||
total_rounding: total_rounding,
|
||||
total_receipt: total_receipt,
|
||||
total_void: total_void,
|
||||
dining_count: dining_count,
|
||||
takeaway_count: takeaway_count,
|
||||
}
|
||||
total_revenue: total_revenue,
|
||||
total_discounts: total_discounts,
|
||||
total_taxes: total_taxes,
|
||||
grand_total: grand_total,
|
||||
cash_sales: cash_sales,
|
||||
credit_sales: credit_sales,
|
||||
other_sales: other_sales.to_f,
|
||||
nett_sales: nett_sales,
|
||||
commercial_taxes: commercial_taxes,
|
||||
total_rounding: total_rounding,
|
||||
total_receipt: total_receipt,
|
||||
total_void: total_void,
|
||||
dining_count: dining_count,
|
||||
takeaway_count: takeaway_count
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user