fix shift sale balance
This commit is contained in:
@@ -1424,7 +1424,7 @@ end
|
|||||||
|
|
||||||
def get_cash_amount
|
def get_cash_amount
|
||||||
self.sale_payments.where(payment_method: 'cash', payment_status: 'paid')
|
self.sale_payments.where(payment_method: 'cash', payment_status: 'paid')
|
||||||
.pluck(:payment_amount).reduce(:+)
|
.pluck(:payment_amount).reduce(0, :+) - self.amount_changed
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_credit_amount
|
def get_credit_amount
|
||||||
@@ -2309,15 +2309,13 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
def round_to_precision
|
def round_to_precision
|
||||||
if (self.total_amount != self.total_amount_was || self.total_discount != self.total_discount_was || self.total_tax != self.total_tax_was)
|
if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0)
|
||||||
if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0)
|
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
|
||||||
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
|
||||||
end
|
|
||||||
adjust_rounding
|
|
||||||
end
|
end
|
||||||
|
adjust_rounding
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_stock_journal
|
def update_stock_journal
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class SalePayment < ApplicationRecord
|
|||||||
amount_due = invoice.sale_payments
|
amount_due = invoice.sale_payments
|
||||||
.map(&:payment_amount).reduce(invoice.grand_total, :-)
|
.map(&:payment_amount).reduce(invoice.grand_total, :-)
|
||||||
end
|
end
|
||||||
|
|
||||||
if amount_due > 0
|
if amount_due > 0
|
||||||
payment_status = false
|
payment_status = false
|
||||||
membership_data = nil
|
membership_data = nil
|
||||||
@@ -374,7 +374,7 @@ class SalePayment < ApplicationRecord
|
|||||||
|
|
||||||
private
|
private
|
||||||
def cash_payment(payment_for=false)
|
def cash_payment(payment_for=false)
|
||||||
|
|
||||||
sale_payments_data = SalePayment.find_by_sale_id(self.sale_id)
|
sale_payments_data = SalePayment.find_by_sale_id(self.sale_id)
|
||||||
payment_status = false
|
payment_status = false
|
||||||
|
|
||||||
@@ -391,7 +391,7 @@ class SalePayment < ApplicationRecord
|
|||||||
payment_status = self.save!
|
payment_status = self.save!
|
||||||
if !payment_for
|
if !payment_for
|
||||||
sale_update_payment_status(self.received_amount)
|
sale_update_payment_status(self.received_amount)
|
||||||
else
|
else
|
||||||
update_shift_for_credit_payment()
|
update_shift_for_credit_payment()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -636,6 +636,9 @@ class SalePayment < ApplicationRecord
|
|||||||
|
|
||||||
def sale_update_payment_status(paid_amount, check_foc = false)
|
def sale_update_payment_status(paid_amount, check_foc = false)
|
||||||
#update amount_outstanding
|
#update amount_outstanding
|
||||||
|
if ['completed'].include? sale.sale_status
|
||||||
|
return
|
||||||
|
end
|
||||||
sale = self.sale
|
sale = self.sale
|
||||||
sale_payments = sale.sale_payments.reload
|
sale_payments = sale.sale_payments.reload
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user