This commit is contained in:
Zoey
2019-06-26 12:05:37 +06:30
parent 8cfb88ca73
commit b948f10209
3 changed files with 10 additions and 6 deletions

View File

@@ -31,7 +31,7 @@ class SalePayment < ApplicationRecord
def self.get_kbz_pay_amount(sale_id, current_user)
amount = 0
sale_payment = SalePayment.where('sale_id=? and payment_status!=?', sale_id, 'dead').last
sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last
if !sale_payment.nil?
if sale_payment.payment_status == 'pending'
amount = KbzPay.query(sale_payment.id, current_user)
@@ -631,6 +631,7 @@ class SalePayment < ApplicationRecord
def sale_update_payment_status(paid_amount,check_foc = false)
#update amount_outstanding
Rails.logger.info '####### SALE UPDATE PAYMENT STATUS #######'
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
self.sale.save!
self.sale.amount_changed = self.sale.amount_received.to_f - self.sale.grand_total.to_f
@@ -656,6 +657,10 @@ class SalePayment < ApplicationRecord
end
end
Rails.logger.info self.sale.grand_total
Rails.logger.info all_received_amount
Rails.logger.info '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
if (self.sale.grand_total <= all_received_amount) && method_status
if is_credit == 0
self.sale.payment_status = "paid"
@@ -669,7 +674,7 @@ class SalePayment < ApplicationRecord
self.sale.payment_status = "foc"
end
if is_kbz_pay > 0
if is_kbz_pay == 1
self.sale.payment_status = 'paid'
end