Skip to content

Instantly share code, notes, and snippets.

@sedrickcz
Created February 16, 2018 23:51
Show Gist options
  • Save sedrickcz/1994ca51d8f907d9be3e9f707df53f84 to your computer and use it in GitHub Desktop.
Save sedrickcz/1994ca51d8f907d9be3e9f707df53f84 to your computer and use it in GitHub Desktop.
Import invoices to db
invoices = SmarterCSV.process('invoices.csv', { col_sep: ";" })
not_found = 0
not_matching_id = 0
ok = 0
invoices.each do |invoice|
tracking_number = TrackingNumber.where(waybill: invoice[:waybill].to_s).first
if tracking_number
if tracking_number.user_id.to_i == invoice[:user_id].to_i
tracking_number.update_attribute(:invoice, invoice[:invoice_file_name])
ok += 1
else
not_matching_id += 1
end
else
not_found += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment