Skip to content

Instantly share code, notes, and snippets.

@neanias
Last active March 26, 2020 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neanias/456c40465958b149787813ecb122d188 to your computer and use it in GitHub Desktop.
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.
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