Skip to content

Instantly share code, notes, and snippets.

@bhfailor
Last active August 29, 2015 13:56
Show Gist options
  • Save bhfailor/9272805 to your computer and use it in GitHub Desktop.
Save bhfailor/9272805 to your computer and use it in GitHub Desktop.
Snippet that identifies unprocessed piggyback registrations and then corrects them
# Check all the possible events for troubled piggybacks
parent_problematic = [] # collect all event registrations independent of the event
[34541, 33921, 24391, 34931, 33821, 34221, 35091, 17891, 34071, 35291, 34611, 34051, 31391, 37821].each do |ev_id|
Event.find(ev_id).event_registrations.where("parent_registration_id IS NOT NULL").map{|r|
r.parent_registration_id}.uniq.each do |parent_registration_id|
parent_registration = nil
begin
parent_registration = EventRegistration.find(parent_registration_id)
rescue
#break
end
if !parent_registration.nil? && (parent_registration.status == 'Complete' || parent_registration.status == 'rm_pending') &&
parent_registration.processed == true
children_registrations = parent_registration.children_registrations.where("processed = false AND status='Expired' AND cost IS NOT NULL")
if children_registrations.size > 0
parent_problematic << parent_registration_id
end
end
end
end
puts "Parent registrations with problematic piggybacks: #{parent_problematic}"
# Compare the parent and piggyback registrations
parent_problematic.each do |p_id|
parent = EventRegistration.find(p_id) # get the parent registration
children = parent.children_registrations.where("processed = false AND status='Expired' AND cost IS NOT NULL")
children.each do |c|
puts "event_id for parent: #{parent.event_id} and piggyback: #{c.event_id}"
puts "id for parent: #{parent.id} and piggyback: #{c.id}"
puts "processed for parent: #{parent.processed} and piggyback: #{c.processed}"
puts "status for parent: #{parent.status} and piggyback: #{c.status}"
puts "cost for parent: #{parent.cost} and piggyback: #{c.cost}"
puts "service_fee for parent: #{parent.service_fee} and piggyback: #{c.service_fee}"
puts "club_team for parent: #{parent.club_team} and piggyback: #{c.club_team}"
puts "team_type for parent: #{parent.team_type} and piggyback: #{c.team_type}"
puts "team_id for parent: #{parent.team_id} and piggyback: #{c.team_id}"
# c.save # if this all looks like right, then save to the database!
end
end
# Correct the database for the appropriate parent and piggyback registrations
# by entering the parent registration id numbers in the array below
[720641].each do |p_id|
parent = EventRegistration.find(p_id) # get the parent registration
children = parent.children_registrations.where("processed = false AND status='Expired' AND cost IS NOT NULL")
children.each do |c|
puts "event_id for parent: #{parent.event_id} and piggyback: #{c.event_id}"
puts "id for parent: #{parent.id} and piggyback: #{c.id}"
c.processed = parent.processed
c.status = parent.status
puts "cost for parent: #{parent.cost} and piggyback: #{c.cost}"
puts "service_fee for parent: #{parent.service_fee} and piggyback: #{c.service_fee}"
puts "club_team for parent: #{parent.club_team} and piggyback: #{c.club_team}"
puts "team_type for parent: #{parent.team_type} and piggyback: #{c.team_type}"
puts "team_id for parent: #{parent.team_id} and piggyback: #{c.team_id}"
c.save # if this all looks like right, then save to the database!
end
end
@bhfailor
Copy link
Author

A second file, Rev A, has been added. The snippet was re-factored to include all the events that might have unprocessed piggybacks and to provide a clearer printout comparing the parent and piggyback registrations. The first two snippets should be run first to confirm that the piggyback is indeed valid before marking it as processed and "Complete" in the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment