check js func: and card balance amount for Paymal payment

This commit is contained in:
phyusin
2018-10-04 16:31:19 +06:30
parent 497458371b
commit b4aa1c600f
11 changed files with 181 additions and 88 deletions

View File

@@ -119,8 +119,36 @@ class SaleAudit < ApplicationRecord
end
private
def generate_custom_id
self.sale_audit_id = SeedGenerator.generate_id(self.class.name, "SAI")
def self.getCardBalanceAmount(sale_id)
card_balance_amount = 0
sale_audits = SaleAudit.where("sale_id='#{sale_id}' AND action='PAYMAL'")
if !sale_audits.nil?
sale_audits.each do |sale_audit|
if sale_audit.remark.split('}')[0]
if self.valid_json('['+ sale_audit.remark.split('}')[0] + '}]')
remark = JSON.parse(('['+ sale_audit.remark.split('}')[0] + '}]'))
if remark[0]
if remark[0]["status"]
card_balance_amount = remark[0]["card_balance_amount"]
end
end
end
end
end
end
return card_balance_amount
end
def self.valid_json(json)
JSON.parse(json)
return true
rescue JSON::ParserError => e
return false
end
private
def generate_custom_id
self.sale_audit_id = SeedGenerator.generate_id(self.class.name, "SAI")
end
end