fix payment amount mismatch
This commit is contained in:
@@ -1438,10 +1438,10 @@ end
|
|||||||
cash = 0.0
|
cash = 0.0
|
||||||
self.sale_payments.each do |pay|
|
self.sale_payments.each do |pay|
|
||||||
if pay.payment_method == 'cash'
|
if pay.payment_method == 'cash'
|
||||||
cash = pay.payment_amount-self.amount_changed
|
cash += pay.payment_amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return cash
|
return cash - self.amount_changed
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_credit_amount
|
def get_credit_amount
|
||||||
|
|||||||
@@ -637,15 +637,14 @@ 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
|
||||||
sale = self.sale
|
sale = self.sale
|
||||||
|
total_payment_amount = sale.sale_payments.reload.sum(&:payment_amount)
|
||||||
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
|
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
|
||||||
sale.amount_changed = sale.amount_received.to_f - sale.grand_total.to_f
|
sale.amount_changed = total_payment_amount - sale.grand_total.to_f
|
||||||
|
|
||||||
all_received_amount = sale.sale_payments.reload.sum(&:payment_amount)
|
|
||||||
|
|
||||||
is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
|
is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
|
||||||
is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
|
is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
|
||||||
|
|
||||||
if sale.grand_total <= all_received_amount && sale.sale_status == "new"
|
if sale.grand_total <= total_payment_amount && sale.sale_status == "new"
|
||||||
sale.payment_status = "paid"
|
sale.payment_status = "paid"
|
||||||
if is_credit
|
if is_credit
|
||||||
sale.payment_status = "outstanding"
|
sale.payment_status = "outstanding"
|
||||||
|
|||||||
Reference in New Issue
Block a user