Last active
August 29, 2015 14:02
-
-
Save williscool/884f7ef59a5fe9ada932 to your computer and use it in GitHub Desktop.
Get payment history of specific client from harvest
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
require 'harvested' | |
harvest = Harvest.hardy_client(subdomain: 'YOUR_SUBDOMAIN', username: 'YOUR_USERNAME_OR_EMAIL', password: 'YOUR_PASSWORD') | |
specific_client = harvest.clients.all.select{|c| c.name == 'specific_client'}.first | |
all_invoices = harvest.invoices.all | |
invoices = all_invoices.select{|i| i.client_id = specific_client.id} | |
jaged_payments = invoices.collect{|i| harvest.invoice_payments.all(i) } # call takes a second. grab a cup of tea. and/or add some logging. | |
all_payments = jaged_payments.flatten | |
require 'active_support/all' | |
#csv_string = CSV.generate do |csv| | |
CSV.open("harvest_payment_report_all.csv", "wb") do |csv| | |
csv << ["Payment Date", "Invoice Payment Was Applied to", "Payment Amount", "Currency Symbol", "Currency","Notes"] | |
all_payments.each{|p| csv << [p.paid_at.to_date.strftime("%m/%d/%Y"), invoices.select{|i| i.id.to_i == p.invoice_id.to_i }.first.number.to_i, p.amount, "$", "United States Dollars - USD", p.notes.gsub("\n", " ") ]} | |
end |
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
gem install specific_install | |
gem specific_install zmoazeni/harvested | |
gem install rails # may work with just activesupport but life is just so much easier if you can call to_datetime with a string so you need active support | |
ruby generate_payment_report.rb # or use run the commands in the console with pry or irb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment