Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'fastercsv'
- data = FasterCSV.read(ARGV[0], :headers => true, :header_converters => :symbol)
- rows = []
- headers = ["Transaction Date", "Transaction Amount", "Payee", "Description", "Reference", "Transaction Type", "Cheque No."]
- data.each do |r|
- hash = r.to_hash
- date = hash[:date]
- amount = hash[:credit].to_f + hash[:debit].to_f
- transaction_type = hash[:type]
- payee = nil
- description = hash[:narrative_1]
- reference = nil
- cheque_no = nil
- case transaction_type
- when 'CHG'
- # Charge
- if hash[:narrative_1] =~ /^([0-9]{2}[A-Z]{3})[-\s]A\/C\s*#{hash[:account_number]}/
- # This is bank account fees!
- description = "Account Fees " + $1
- end
- when 'CHQ', 'BGC'
- # Cheque, Lodgement
- cheque_no = hash[:narrative_1]
- description = nil
- else
- raise "unknown transaction type #{transaction_type}"
- end
- values = [date, amount, payee, description, reference, transaction_type, cheque_no]
- rows << FasterCSV::Row.new(headers, values)
- end
- table = FasterCSV::Table.new(rows)
- File.open("xero-upload.csv", "w") do |f|
- f.write table.to_csv
- end
Add Comment
Please, Sign In to add comment