|
- require 'lib/models'
- require 'csv'
-
- count = 0
-
- CSV::Reader.parse(File.open('data/2009Q4.csv', 'rb')) do |row|
-
-
-
-
-
-
-
-
-
-
- count += 1
-
- if (count > 4)
-
- p row
-
- directorate = Directorate.first_or_create(:name => row[0].strip)
- service = Service.first_or_create(:name => row[3].strip)
- supplier = Supplier.first_or_create(:name => row[5].strip)
-
- payment = Payment.first_or_create(
- 'trans_no' => row[2],
- 'directorate' => directorate,
- 'service' => service,
- 'supplier' => supplier,
- 'cost_centre' => row[4].strip,
- 'amount' => row[6].strip.gsub(/,/, ''),
- 'd' => row[1],
- 'tyype' => row[7].strip
- )
-
- unless payment.save
- puts "ERROR: Failed to save payment"
- payment.errors.each do |e|
- puts e
- end
- end
- end
- end
|