Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. require 'csv'
  2.  
  3. ############### data is as follows ###############################################################
  4. # 136 ,"PPLSI212 ","2004-02-20-05.06.42.000000","0001-01-01-00.00.00.000000"
  5. # 185 ,"PPLSI55 ","2008-04-16-05.06.42.000000","0001-01-01-00.00.00.000000"
  6. # 188 ,"PPLSI212 ","1993-09-07-05.06.42.000000","0001-01-01-00.00.00.000000"
  7. # 245 ,"PPLSI56 ","1998-06-24-05.06.42.000000","0001-01-01-00.00.00.000000"
  8. # 332 ,"PPLSI242.DOP ","2009-09-21-14.33.26.000000","2016-03-01-10.46.23.000000"
  9. # 332 ,"PPLSI242 ","1993-07-20-05.06.42.000000","2009-09-21-14.33.25.000000"
  10. # 332 ,"PPLTX242.BOP ","2016-03-01-10.46.24.000000","0001-01-01-00.00.00.000000"
  11. # 341 ,"PPLSI56 ","1997-08-28-05.06.42.000000","0001-01-01-00.00.00.000000"
  12. # 488 ,"PPLSI178.0 ","1993-08-30-05.06.42.000000","0001-01-01-00.00.00.000000"
  13.  
  14.  
  15. CSV.foreach("./CNTHST.csv", :headers => false) do |row|
  16. deactivated_at = row[3] == "0001-01-01-00.00.00.000000" ? nil : row[3].gsub(".", ":")
  17. subscription = Subscription.find_by(:billing_vendor_id => row[0].squish)
  18. active_at = row[2].gsub(".", ":")
  19. updated_at = deactivated_at.present? ? deactivated_at : active_at
  20.  
  21. if subscription.present?
  22. ContractHistory.create(
  23. :subscription => subscription,
  24. :document => row[1].squish,
  25. :created_at => active_at,
  26. :updated_at => updated_at,
  27. :deactivated_at => deactivated_at
  28. )
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement