From 799d6973bf66f2958daa6fa10405a7f7dfeb922f Mon Sep 17 00:00:00 2001 From: Joshua Greben Date: Wed, 7 Feb 2024 10:22:22 -0800 Subject: [PATCH 1/2] Check for matching day before or after payment in folio --- .../download_payment_batch_detail_report.rb | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cyber_source/download_payment_batch_detail_report.rb b/cyber_source/download_payment_batch_detail_report.rb index 15123de..aef95bd 100644 --- a/cyber_source/download_payment_batch_detail_report.rb +++ b/cyber_source/download_payment_batch_detail_report.rb @@ -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}" }) @@ -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}" @@ -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'], @@ -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 @@ -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['status']['name'] == 'Closed' || account['paymentStatus']['name'] == 'Paid fully') end def created_date(account) From 1cd6023f4d353e89aebded644219891e2305d83d Mon Sep 17 00:00:00 2001 From: Joshua Greben Date: Wed, 7 Feb 2024 10:55:18 -0800 Subject: [PATCH 2/2] Only check for Paid fully matches in paymentStatus folio field --- cyber_source/download_payment_batch_detail_report.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cyber_source/download_payment_batch_detail_report.rb b/cyber_source/download_payment_batch_detail_report.rb index aef95bd..32d0b31 100644 --- a/cyber_source/download_payment_batch_detail_report.rb +++ b/cyber_source/download_payment_batch_detail_report.rb @@ -116,8 +116,8 @@ def is_a_payment?(account, batch_date, 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] - dates.include?(created_date(account)) || dates.include?(updated_date(account)) && - (account['status']['name'] == 'Closed' || 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)