Skip to content

Instantly share code, notes, and snippets.

@kshsieh
Last active January 3, 2017 22:01
Show Gist options
  • Save kshsieh/a74422b082a7cf055bffc4581f15bfbc to your computer and use it in GitHub Desktop.
Save kshsieh/a74422b082a7cf055bffc4581f15bfbc to your computer and use it in GitHub Desktop.
blah
CSV.open('referral_update.csv', 'wb') do |csv|
MembershipAgreement.
joins(:membership_agreement_statuses).
where(membership_agreement_statuses: { status: 'sent', success: true }).
where("membership_agreements.created_at < ?", Date.new(2016, 12, 28)).
uniq.
find_each do |membership_agreement|
membership_agreement.all_primary_change_requests.group_by(&:location).each do |location, change_requests_by_location|
TenantService.switch_tenant_with_location_uuid(location.uuid)
change_requests_by_location.group_by(&:reservation_started_on).each do |start_date, change_requests_by_date|
begin
message_json = MembershipAgreements::ForSalesforceSerializer.new(
membership_agreement: membership_agreement,
location: location,
start_date: start_date,
change_requests: change_requests_by_date
).as_json.to_json
csv << [membership_agreement.id_company_info.primary_member.email, membership_agreement.account_uuid, message_json]
rescue Exception => e
next
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment