kbzpay
This commit is contained in:
@@ -29,6 +29,37 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
if !sale_payment.nil?
|
||||
if sale_payment.payment_status == 'pending'
|
||||
amount = KbzPay.query(sale_payment.id, current_user)
|
||||
elsif sale_payment.payment_status == 'paid'
|
||||
amount = sale_payment.payment_amount
|
||||
end
|
||||
end
|
||||
|
||||
return amount
|
||||
end
|
||||
|
||||
def process_kbz_payment(sale_id, grand_total, pay_amount, status)
|
||||
if status == 'pending'
|
||||
SalePayment.where("sale_id=? and payment_method=? and payment_status=?", sale_id, KbzPay::KBZ_PAY, 'pending').update_all(:payment_status => 'dead')
|
||||
end
|
||||
|
||||
self.sale_id = sale_id
|
||||
self.payment_method = KbzPay::KBZ_PAY
|
||||
self.payment_amount = self.payment_amount.to_i + pay_amount.to_i
|
||||
if grand_total > 0
|
||||
self.outstanding_amount = grand_total.to_i - pay_amount.to_i
|
||||
else
|
||||
self.outstanding_amount = self.outstanding_amount.to_i - pay_amount.to_i
|
||||
end
|
||||
self.payment_status = status
|
||||
return self.save
|
||||
end
|
||||
|
||||
def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil,payment_for=false)
|
||||
self.sale = invoice
|
||||
self.received_amount = cash_amount
|
||||
@@ -90,8 +121,8 @@ class SalePayment < ApplicationRecord
|
||||
payment_status,membership_data = dinga_payment
|
||||
when "GiftVoucher"
|
||||
payment_status = giftvoucher_payment
|
||||
when "KbzPay"
|
||||
payment_status = giftvoucher_payment
|
||||
when KbzPay::KBZ_PAY
|
||||
payment_status = kbz_payment
|
||||
else
|
||||
puts "it was something else"
|
||||
end
|
||||
@@ -346,6 +377,7 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
payment_status = false
|
||||
|
||||
self.payment_method = "cash"
|
||||
self.payment_amount = self.received_amount
|
||||
if !payment_for
|
||||
@@ -354,8 +386,10 @@ class SalePayment < ApplicationRecord
|
||||
credit_sale_payment = SalePayment.get_credit_total_left(self.sale_id)[0] ? SalePayment.get_credit_total_left(self.sale_id)[0].payment_amount.to_f : 0 ###need to calculate creditnote total in here
|
||||
self.outstanding_amount = credit_sale_payment - self.received_amount.to_f
|
||||
end
|
||||
|
||||
self.payment_status = "paid"
|
||||
payment_status = self.save!
|
||||
|
||||
if !payment_for
|
||||
sale_update_payment_status(self.received_amount,status)
|
||||
end
|
||||
@@ -586,11 +620,13 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
def kbz_payment
|
||||
payment_status = false
|
||||
status, response = KbzPay.pay(amount, receipt_no)
|
||||
if status
|
||||
payment_status = true
|
||||
return
|
||||
end
|
||||
self.payment_amount = self.received_amount
|
||||
self.payment_reference = self.payment_reference
|
||||
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||
self.payment_status = "paid"
|
||||
payment_status = self.save!
|
||||
sale_update_payment_status(self.received_amount)
|
||||
return payment_status
|
||||
end
|
||||
|
||||
def sale_update_payment_status(paid_amount,check_foc = false)
|
||||
@@ -602,6 +638,7 @@ class SalePayment < ApplicationRecord
|
||||
sObj = Sale.find(self.sale_id)
|
||||
is_credit = 0
|
||||
is_foc = 0
|
||||
is_kbz_pay = 0
|
||||
method_status = false
|
||||
sObj.sale_payments.each do |spay|
|
||||
all_received_amount += spay.payment_amount.to_f
|
||||
@@ -611,7 +648,10 @@ class SalePayment < ApplicationRecord
|
||||
if spay.payment_method == "foc"
|
||||
is_foc = 1
|
||||
end
|
||||
if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote"
|
||||
if spay.payment_method == KbzPay::KBZ_PAY
|
||||
is_kbz_pay = 1
|
||||
end
|
||||
if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" || spay.payment_method == 'kbzpay'
|
||||
method_status = true
|
||||
end
|
||||
end
|
||||
@@ -629,6 +669,10 @@ class SalePayment < ApplicationRecord
|
||||
self.sale.payment_status = "foc"
|
||||
end
|
||||
|
||||
if is_kbz_pay > 0
|
||||
self.sale.payment_status = 'paid'
|
||||
end
|
||||
|
||||
self.sale.sale_status = "completed"
|
||||
|
||||
if MembershipSetting.find_by_rebate(1) && is_foc == 0 && is_credit == 0
|
||||
|
||||
Reference in New Issue
Block a user