For Pull
This commit is contained in:
@@ -8,7 +8,7 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
|
||||
|
||||
def process_payment(invoice, action_by, cash_amount,payment_method)
|
||||
def process_payment(invoice, action_by, cash_amount, payment_method)
|
||||
|
||||
self.sale = invoice
|
||||
self.received_amount = cash_amount
|
||||
@@ -75,7 +75,7 @@ class SalePayment < ApplicationRecord
|
||||
}
|
||||
)
|
||||
return response;
|
||||
|
||||
|
||||
end
|
||||
|
||||
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id,campaign_type_id)
|
||||
@@ -93,9 +93,9 @@ class SalePayment < ApplicationRecord
|
||||
else
|
||||
response =false;
|
||||
end
|
||||
|
||||
|
||||
return response;
|
||||
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
@@ -103,7 +103,7 @@ class SalePayment < ApplicationRecord
|
||||
payment_status = false
|
||||
self.payment_method = "cash"
|
||||
self.payment_amount = self.received_amount
|
||||
self.outstanding_amount = self.sale.grand_total - self.received_amount
|
||||
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||
self.payment_status = "paid"
|
||||
payment_method = self.save!
|
||||
|
||||
@@ -195,21 +195,33 @@ class SalePayment < ApplicationRecord
|
||||
if membership_data["status"]==true
|
||||
SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid')
|
||||
sale_update_payment_status(self.received_amount.to_f)
|
||||
|
||||
|
||||
else
|
||||
sale_update_payment_status(0)
|
||||
end
|
||||
|
||||
|
||||
return payment_status
|
||||
|
||||
end
|
||||
|
||||
def sale_update_payment_status(paid_amount)
|
||||
puts "sale update"
|
||||
#update amount_outstanding
|
||||
self.sale.amount_received = self.sale.amount_received + paid_amount
|
||||
self.sale.amount_changed = paid_amount - self.sale.amount_received
|
||||
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
|
||||
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
|
||||
|
||||
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"
|
||||
self.sale.save!
|
||||
|
||||
Reference in New Issue
Block a user