Skip to content

Instantly share code, notes, and snippets.

@gtan66
Last active August 29, 2015 14:17
Show Gist options
  • Save gtan66/7f631126fee7ca9a22b1 to your computer and use it in GitHub Desktop.
Save gtan66/7f631126fee7ca9a22b1 to your computer and use it in GitHub Desktop.
Get Move Out info by month for accounting
p = PrimaryReservation.where(move_out_type: "Move Out").where(ended_on: Time.current.beginning_of_month.to_date...1.month.from_now.beginning_of_month.to_date)
def get_moveOut_info(p)
results = p.select{|r| r.reservable.name != "WW Membership"}.map do |p|
account = p.account
account_admin = p.account.account_admin
ach = account.account_admin.ach_profiles.where(location_id: p.location.id).where(move_out_refund: true).last
office = p.reservable
sd = account.reservations.select{|r| r.parent_id==p.id && r.reservable.name == "Security Deposit"}.last
{
short_code: account.short_code,
account_admin: account_admin.name,
company_name: account.name.delete(","),
routing_number: ach.present? ? ach.routing_number : "",
account_number: ach.present? ? ach.account_number : "",
security_deposit: sd.present? ? sd.price.abs : "",
location: p.location.code,
space: office.name
}
end
results.sort_by{|h| h[:short_code]}
end
sorted = get_moveOut_info(p)
sorted.map{ |r| puts "#{r[:short_code]}, #{r[:account_admin]}, #{r[:company_name]}, #{r[:routing_number]}, #{r[:account_number]}, #{r[:security_deposit]}, #{r[:location]}, #{r[:space]}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment