Last active
March 26, 2020 15:03
-
-
Save neanias/456c40465958b149787813ecb122d188 to your computer and use it in GitHub Desktop.
Production script for generating a CSV of practice managed Mettle-resold companies. Pending Looker report.
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 | |
require "csv" | |
headers = ["Name", "Email", "Subdomain", "Bank Account ID", "Practice Name"] | |
mettle = Reseller.find_by_name("mettle") | |
csv_string = CSV.generate(headers: headers, write_headers: true) do |csv| | |
Company.where(reseller: mettle).where.not(account_manager: nil).each do |c| | |
csv << [ | |
# The bank name usually includes 'mettle' | |
c.name, c.account_owner.email, c.subdomain, c.bank_accounts.where("bank_name LIKE 'mettle%'").take&.id, | |
c.account_manager.accountancy_practice.name | |
] | |
end | |
end | |
puts csv_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment