Skip to content

Commit de72c64

Browse files
Tweaks to monthly dividend report CSV (#473)
Changes to #431 Sample CSV: ![Screenshot 2025-07-09 at 1 25 10 PM](https://github.com/user-attachments/assets/cbf52088-4111-4846-a2aa-97e868ae151f) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent c1e36ff commit de72c64

File tree

7 files changed

+401
-62
lines changed

7 files changed

+401
-62
lines changed
Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# frozen_string_literal: true
22

3-
require "csv"
4-
53
class DividendReportCsv
6-
HEADERS = ["Date initiated", "Date paid", "Dividend round ID", "Client name", "Total dividends",
7-
"Flexile fees", "Transfer fees", "Total ACH pull", "Number of investors",
8-
"Dividend round status", "Payment processor", "Transfer reference"]
4+
HEADERS = ["Date initiated", "Date paid", "Client name", "Total dividends ($)", "Flexile fees ($)",
5+
"Transfer fees ($)", "Total ACH pull ($)", "Number of investors", "Dividend round status"]
96

107
def initialize(dividend_rounds)
118
@dividend_rounds = dividend_rounds
@@ -23,48 +20,31 @@ def generate
2320

2421
private
2522
def dividend_round_data
26-
@dividend_rounds.each_with_object([]) do |round, rows|
27-
successful_dividends = round.dividends.joins(:dividend_payments)
28-
.merge(DividendPayment.successful)
29-
.includes(:dividend_payments, company_investor: :user)
30-
31-
next if successful_dividends.empty?
32-
33-
total_dividends = successful_dividends.sum(:total_amount_in_cents) / 100.0
34-
total_transfer_fees = successful_dividends.joins(:dividend_payments)
35-
.sum("dividend_payments.transfer_fee_in_cents") / 100.0
36-
37-
flexile_fees = successful_dividends.map do |dividend|
23+
@dividend_rounds.each_with_object([]) do |dividend_round, rows|
24+
dividends = dividend_round.dividends
25+
total_dividends = dividends.sum(:total_amount_in_cents) / 100.0
26+
total_transfer_fees = dividends.joins(:dividend_payments)
27+
.where(dividend_payments: { status: Payments::Status::SUCCEEDED })
28+
.sum("dividend_payments.transfer_fee_in_cents") / 100.0
29+
30+
flexile_fees = dividends.map do |dividend|
3831
calculated_fee = ((dividend.total_amount_in_cents.to_d * 2.9.to_d / 100.to_d) + 30.to_d).round.to_i
3932
[30_00, calculated_fee].min
4033
end.sum / 100.0
4134

42-
total_ach_pull = total_dividends + flexile_fees + total_transfer_fees
35+
total_ach_pull = total_dividends + flexile_fees
4336

44-
payment = successful_dividends.first.dividend_payments.successful.first
4537
rows << [
46-
round.issued_at.to_fs(:us_date),
47-
successful_dividends.first.paid_at&.to_fs(:us_date),
48-
round.id,
49-
round.company.name,
38+
dividend_round.issued_at.to_fs(:us_date),
39+
dividends.paid.first&.paid_at&.to_fs(:us_date),
40+
dividend_round.company.name,
5041
total_dividends,
5142
flexile_fees,
5243
total_transfer_fees,
5344
total_ach_pull,
54-
successful_dividends.count,
55-
round.status,
56-
payment&.processor_name,
57-
payment&.transfer_id
45+
dividends.count,
46+
dividend_round.status,
5847
]
5948
end
6049
end
6150
end
62-
63-
### Usage:
64-
=begin
65-
dividend_rounds = DividendRound.includes(:dividends, :company, dividends: [:dividend_payments, company_investor: :user])
66-
.where("issued_at >= ? AND issued_at <= ?", Time.current.last_month.beginning_of_month, Time.current.last_month.end_of_month)
67-
.order(issued_at: :asc)
68-
attached = { "DividendReport.csv" => DividendReportCsv.new(dividend_rounds).generate }
69-
AdminMailer.custom(to: ["solson@earlygrowth.com"], subject: "Flexile Dividend Report CSV", body: "Attached", attached:).deliver_now
70-
=end

backend/app/sidekiq/dividend_report_csv_email_job.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def perform(recipients)
99

1010
dividend_rounds = DividendRound.includes(:dividends, :company, dividends: [:dividend_payments, company_investor: :user])
1111
.joins(:dividends)
12-
.merge(Dividend.paid)
1312
.where("dividend_rounds.issued_at >= ? AND dividend_rounds.issued_at <= ?",
1413
Time.current.last_month.beginning_of_month,
1514
Time.current.last_month.end_of_month)

backend/spec/fixtures/vcr_cassettes/DividendReportCsvEmailJob/_perform/includes_only_last_month_s_dividend_rounds_in_the_CSV.yml

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/spec/fixtures/vcr_cassettes/DividendReportCsvEmailJob/_perform/orders_dividend_rounds_by_issued_at_ascending.yml

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)