fix payment amount mismatch

This commit is contained in:
Thein Lin Kyaw
2020-01-07 10:46:45 +06:30
parent 8b5478cf27
commit eb65271d35
2 changed files with 7 additions and 8 deletions

View File

@@ -70,7 +70,7 @@ class SalePayment < ApplicationRecord
self.sale = invoice
self.received_amount = cash_amount
self.payment_reference = remark
self.action_by = action_by
#get all payment for this invoices
if payment_for
@@ -637,15 +637,14 @@ class SalePayment < ApplicationRecord
def sale_update_payment_status(paid_amount, check_foc = false)
#update amount_outstanding
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_changed = sale.amount_received.to_f - sale.grand_total.to_f
all_received_amount = sale.sale_payments.reload.sum(&:payment_amount)
sale.amount_changed = total_payment_amount - sale.grand_total.to_f
is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
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"
if is_credit
sale.payment_status = "outstanding"