Merge branch 'r-1902001-01' into foodcourt
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
class SalePayment < ApplicationRecord
|
||||
|
||||
CARD = ['mpu', 'visa', 'master', 'jcb', 'unionpay']
|
||||
|
||||
self.primary_key = "sale_payment_id"
|
||||
|
||||
#primary key - need to be unique generated for multiple shops
|
||||
@@ -11,7 +14,7 @@ class SalePayment < ApplicationRecord
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
|
||||
|
||||
scope :credits, -> { where(payment_method: 'creditnote') }
|
||||
scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) }
|
||||
scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay']) }
|
||||
|
||||
def self.sync_sale_payment_records(sale_payments)
|
||||
if !sale_payments.nil?
|
||||
@@ -36,7 +39,8 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
def self.get_kbz_pay_amount(sale_id, current_user)
|
||||
amount = 0
|
||||
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
|
||||
kbz_pay_method = PaymentMethodSetting.where(payment_method: KbzPay::KBZ_PAY, gateway_communication_type: ['api', 'Api'], is_active: true)
|
||||
.where.not(gateway_url: [nil, ''], auth_token: [nil, ''], merchant_account_id: [nil, '']).last
|
||||
sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last
|
||||
if !sale_payment.nil? and !kbz_pay_method.nil?
|
||||
if sale_payment.payment_status == 'pending'
|
||||
@@ -120,10 +124,8 @@ class SalePayment < ApplicationRecord
|
||||
payment_status,membership_data = dinga_payment
|
||||
when "GiftVoucher"
|
||||
payment_status = giftvoucher_payment
|
||||
when KbzPay::KBZ_PAY
|
||||
payment_status = kbz_payment
|
||||
else
|
||||
puts "it was something else"
|
||||
else
|
||||
payment_status = external_terminal_card_payment(payment_method, payment_for)
|
||||
end
|
||||
|
||||
if payment_status
|
||||
@@ -361,10 +363,16 @@ class SalePayment < ApplicationRecord
|
||||
# Check for Card Payment
|
||||
def self.get_sale_payments_by_card(sale_payments)
|
||||
# Check for Card Payment
|
||||
payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
|
||||
sale_payments.each do |sp|
|
||||
if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay"
|
||||
return true;
|
||||
payment_methods.each do |m|
|
||||
if sp.payment_method == m
|
||||
return true;
|
||||
end
|
||||
end
|
||||
# if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay"
|
||||
# return true;
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -616,22 +624,12 @@ class SalePayment < ApplicationRecord
|
||||
return payment_status
|
||||
end
|
||||
|
||||
def kbz_payment
|
||||
payment_status = false
|
||||
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)
|
||||
#update amount_outstanding
|
||||
if ['completed'].include? sale.sale_status
|
||||
if !self.sale || ['completed'].include?(self.sale.sale_status)
|
||||
return
|
||||
end
|
||||
|
||||
sale = self.sale
|
||||
sale_payments = sale.sale_payments.reload
|
||||
|
||||
@@ -639,18 +637,14 @@ class SalePayment < ApplicationRecord
|
||||
is_foc = sale_payments.any? { |x| x.payment_method == "foc" } || check_foc
|
||||
|
||||
if is_foc
|
||||
total_payment_amount = 0.0
|
||||
else
|
||||
total_payment_amount = sale_payments.sum(&:payment_amount)
|
||||
end
|
||||
|
||||
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
|
||||
sale.amount_changed = total_payment_amount - sale.grand_total.to_f
|
||||
|
||||
if is_foc
|
||||
sale.amount_received = 0.0
|
||||
sale.amount_changed = 0.0
|
||||
sale.payment_status = 'foc'
|
||||
sale.sale_status = 'completed'
|
||||
elsif sale.grand_total <= total_payment_amount && sale.sale_status == "new"
|
||||
elsif sale.grand_total <= sale_payments.sum(&:payment_amount) && sale.sale_status == "new"
|
||||
sale.amount_received = sale.amount_received + paid_amount.to_d
|
||||
sale.amount_changed = sale_payments.sum(&:payment_amount) - sale.grand_total
|
||||
|
||||
sale.payment_status = "paid"
|
||||
if is_credit
|
||||
sale.payment_status = "outstanding"
|
||||
@@ -682,19 +676,9 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sale.save!
|
||||
|
||||
if check_foc
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif paid_amount.to_f == 0 && !is_credit
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
end
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
end
|
||||
|
||||
# update for cashier shift
|
||||
|
||||
Reference in New Issue
Block a user