Guest User

Untitled

a guest
Jul 12th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. require 'rubygems'
  2. require 'fastercsv'
  3.  
  4. data = FasterCSV.read(ARGV[0], :headers => true, :header_converters => :symbol)
  5. rows = []
  6. headers = ["Transaction Date", "Transaction Amount", "Payee", "Description", "Reference", "Transaction Type", "Cheque No."]
  7.  
  8. data.each do |r|
  9. hash = r.to_hash
  10.  
  11. date = hash[:date]
  12. amount = hash[:credit].to_f + hash[:debit].to_f
  13. transaction_type = hash[:type]
  14. payee = nil
  15. description = hash[:narrative_1]
  16. reference = nil
  17. cheque_no = nil
  18.  
  19. case transaction_type
  20. when 'CHG'
  21. # Charge
  22.  
  23. if hash[:narrative_1] =~ /^([0-9]{2}[A-Z]{3})[-\s]A\/C\s*#{hash[:account_number]}/
  24. # This is bank account fees!
  25. description = "Account Fees " + $1
  26. end
  27.  
  28. when 'CHQ', 'BGC'
  29. # Cheque, Lodgement
  30. cheque_no = hash[:narrative_1]
  31. description = nil
  32. else
  33. raise "unknown transaction type #{transaction_type}"
  34. end
  35.  
  36. values = [date, amount, payee, description, reference, transaction_type, cheque_no]
  37.  
  38. rows << FasterCSV::Row.new(headers, values)
  39. end
  40.  
  41. table = FasterCSV::Table.new(rows)
  42.  
  43. File.open("xero-upload.csv", "w") do |f|
  44. f.write table.to_csv
  45. end
Add Comment
Please, Sign In to add comment