Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for matching day before or after payment in folio #113

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions cyber_source/download_payment_batch_detail_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def main
if index > 1
user_id = batch_detail.split(',')[4]
paid = batch_detail.split(',')[8]
paydate = batch_detail.split(',')[12]&.chomp
batch_date = batch_detail.split(',')[2]
transaction_date = batch_detail.split(',')[12]&.chomp

begin
accounts = folio_client.get('/accounts', { query: "userId==#{user_id}" })
Expand All @@ -67,13 +68,13 @@ def main
payments = []

accounts['accounts'].each do |a|
next unless is_a_payment?(a, paydate)
next unless is_a_payment?(a, batch_date, transaction_date)

payments << a['amount'].to_f
end

accounts['accounts'].each do |account|
next unless is_a_payment?(account, paydate)
next unless is_a_payment?(account, batch_date, transaction_date)

puts user_id
puts "TOTAL PAYMENTS: #{payments.sum}"
Expand All @@ -82,7 +83,7 @@ def main
if (payments.sum == paid.to_f)

payload = {
paydate: Date.parse(paydate),
transaction_date: Date.parse(transaction_date),
user_id: user_id,
folio_payment_id: account['id'],
library: account['feeFineOwner'],
Expand All @@ -99,7 +100,7 @@ def main
puts credits
sleep(ENV. fetch('SLEEP', 2)&.to_i)
end
credits.any? && CSV.open('files/credits.csv', 'w+') do |csv|
credits.any? && CSV.open('files/credits.csv', 'a') do |csv|
csv << credits.first.keys
credits.each do |credit|
csv << credit.values
Expand All @@ -110,11 +111,13 @@ def main
puts e.backtrace
end

def is_a_payment?(account, paydate)
payment_date = Date.parse(paydate)
def is_a_payment?(account, batch_date, transaction_date)
tx_date = Date.parse(transaction_date)
bx_date = Date.parse(batch_date)
dates = [tx_date - 1, tx_date, tx_date + 1, bx_date - 1, bx_date, bx_date + 1]

(created_date(account) == payment_date || updated_date(account) == payment_date) &&
(account['paymentStatus']['name'] == 'Paid fully')
(dates.include?(created_date(account)) || dates.include?(updated_date(account))) &&
(account['paymentStatus']['name'] == 'Paid fully')
end

def created_date(account)
Expand Down
Loading