Created
February 16, 2018 23:51
-
-
Save sedrickcz/1994ca51d8f907d9be3e9f707df53f84 to your computer and use it in GitHub Desktop.
Import invoices to db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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