Last active
July 22, 2020 13:15
-
-
Save pythonandchips/0e7613fbffc9ced25f459657361e2bbb to your computer and use it in GitHub Desktop.
Get count of overdue invoice per company.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch_to_slave_db | |
companies = Company.joins(:subscription).merge(Subscription.live) | |
companies_count = companies.count | |
progress_bar = ProgressBar.new(companies_count) | |
ProgressBar.new(companies_count) | |
companies.find_each do |company| | |
Rails.logger.info({ | |
event: "COMPANY_OVERDUE_INVOICE_COUNT", | |
company_id: company.id, | |
active: company.is_active?, | |
count: company.invoices.overdue.where.not(cached_net_value: 0).unpaid.count | |
}.to_json) | |
progress_bar.increment! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LGTM