fix rounding adjustment
This commit is contained in:
@@ -2313,8 +2313,8 @@ private
|
|||||||
self.total_amount = self.total_amount.round(precision)
|
self.total_amount = self.total_amount.round(precision)
|
||||||
self.total_discount = self.total_discount.round(precision)
|
self.total_discount = self.total_discount.round(precision)
|
||||||
self.total_tax = self.total_tax.round(precision)
|
self.total_tax = self.total_tax.round(precision)
|
||||||
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
|
||||||
end
|
end
|
||||||
|
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||||
adjust_rounding
|
adjust_rounding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,28 @@ namespace :shift_sales do
|
|||||||
sales = shift_sale.sales.order(:created_at)
|
sales = shift_sale.sales.order(:created_at)
|
||||||
sales.each do |sale|
|
sales.each do |sale|
|
||||||
|
|
||||||
new_grand_total = sale.total_amount - sale.total_discount + sale.total_tax + sale.rounding_adjustment
|
sale.grand_total = sale.total_amount - sale.total_discount + sale.total_tax
|
||||||
old_grand_total = sale.total_amount - sale.total_discount + sale.total_tax
|
sale.old_grand_total = grand_total
|
||||||
amount_changed = sale.amount_received - new_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
|
cash_amount = 0
|
||||||
credit_amount = 0
|
credit_amount = 0
|
||||||
@@ -56,13 +75,18 @@ namespace :shift_sales do
|
|||||||
else
|
else
|
||||||
other_amount += sale_payment.payment_amount
|
other_amount += sale_payment.payment_amount
|
||||||
end
|
end
|
||||||
outstanding_amount = new_grand_total - sale_payment.payment_amount
|
sale_payment.outstanding_amount = sale.grand_total - sale_payment.payment_amount
|
||||||
sale_payment.update_columns(outstanding_amount: outstanding_amount)
|
sale_payment.update_columns(outstanding_amount: sale_payment.outstanding_amount)
|
||||||
end
|
end
|
||||||
end
|
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'
|
if sale.sale_status != 'void'
|
||||||
total_revenue += sale.total_amount
|
total_revenue += sale.total_amount
|
||||||
@@ -98,22 +122,20 @@ namespace :shift_sales do
|
|||||||
end
|
end
|
||||||
|
|
||||||
shift_sale.update_columns(
|
shift_sale.update_columns(
|
||||||
{
|
total_revenue: total_revenue,
|
||||||
total_revenue: total_revenue,
|
total_discounts: total_discounts,
|
||||||
total_discounts: total_discounts,
|
total_taxes: total_taxes,
|
||||||
total_taxes: total_taxes,
|
grand_total: grand_total,
|
||||||
grand_total: grand_total,
|
cash_sales: cash_sales,
|
||||||
cash_sales: cash_sales,
|
credit_sales: credit_sales,
|
||||||
credit_sales: credit_sales,
|
other_sales: other_sales.to_f,
|
||||||
other_sales: other_sales,
|
nett_sales: nett_sales,
|
||||||
nett_sales: nett_sales,
|
commercial_taxes: commercial_taxes,
|
||||||
commercial_taxes: commercial_taxes,
|
total_rounding: total_rounding,
|
||||||
total_rounding: total_rounding,
|
total_receipt: total_receipt,
|
||||||
total_receipt: total_receipt,
|
total_void: total_void,
|
||||||
total_void: total_void,
|
dining_count: dining_count,
|
||||||
dining_count: dining_count,
|
takeaway_count: takeaway_count
|
||||||
takeaway_count: takeaway_count,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user