Last active
August 29, 2015 14:14
-
-
Save gtan66/2726347854ff4e483567 to your computer and use it in GitHub Desktop.
SD manual entries report
This file contains hidden or 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
def self.export_security_deposit_manual_entries_to_csv | |
CSV.open("report.csv", "wb") do |csv| | |
accounts = security_deposit_manual_entries | |
for acct in accounts do | |
for sec_deposit in acct.security_deposits do | |
for journal_entry in sec_deposit.journal_entries.where(entry_item_type: "ManualEntryItem") | |
csv << [journal_entry.entry_item.created_at, acct.short_code, sec_deposit.location.code, | |
journal_entry.entry_item.amount.to_f, journal_entry.entry_item.user.try("email"), journal_entry.entry_item.notes] | |
end | |
end | |
end | |
end | |
end | |
def self.security_deposit_manual_entries | |
Account.includes(security_deposits: { journal_entries: :entry_item }).all. | |
select { |e| | |
e.security_deposits.any? { |s| | |
s.journal_entries.any? {|r| | |
r.entry_item_type == "ManualEntryItem" | |
} | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A SQL version for Aviad to use