This commit is contained in:
Nweni
2017-06-09 13:52:36 +06:30
parent 8b99f4844e
commit 82de95ca22
7 changed files with 27 additions and 31 deletions

View File

@@ -205,12 +205,22 @@ class SalePayment < ApplicationRecord
end
def sale_update_payment_status(paid_amount)
puts "sale update"
#update amount_outstanding
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received.to_f
if (self.sale.grand_total <= self.sale.amount_received.to_f && self.sale.amount_changed.to_f > 0)
all_received_amount = 0.0
sObj = self.sale
sObj.sale_payments.each do |spay|
puts spay
puts spay.payment_amount
all_received_amount += spay.payment_amount.to_f
end
puts all_received_amount
puts self.sale.grand_total
if (self.sale.grand_total <= all_received_amount)
puts " sale update ......"
self.sale.payment_status = "paid"
self.sale.sale_status = "completed"