before sync

This commit is contained in:
Zoey
2019-06-21 10:04:35 +06:30
parent 60a3655dc3
commit f21d144111
17 changed files with 229 additions and 161 deletions

View File

@@ -11,19 +11,21 @@ class SalePayment < ApplicationRecord
def self.sync_sale_payment_records(sale_payments)
if !sale_payments.nil?
sale_payments.each do |sp|
unless SalePayment.exists?(sp['sale_payment_id'])
payment = SalePayment.find_by_sale_payment_id(sp['sale_payment_id'])
# unless SalePayment.exists?(sp['sale_payment_id'])
if payment.nil?
payment = SalePayment.new
payment.sale_payment_id = sp['sale_payment_id']
payment.sale_id = sp['sale_id']
payment.payment_method = sp['payment_method']
payment.payment_amount = sp['payment_amount']
payment.outstanding_amount = sp['outstanding_amount']
payment.payment_reference = sp['payment_reference']
payment.payment_status = sp['payment_status']
payment.save
puts '....... Sale Payment has been created ......'
end
payment.sale_payment_id = sp['sale_payment_id']
payment.sale_id = sp['sale_id']
payment.payment_method = sp['payment_method']
payment.payment_amount = sp['payment_amount']
payment.outstanding_amount = sp['outstanding_amount']
payment.payment_reference = sp['payment_reference']
payment.payment_status = sp['payment_status']
payment.save
end
puts '....... Sale Payment sync completed ......'
end
end