Commit d7ccf608 authored by Matheus Horstmann's avatar Matheus Horstmann 🐴

Issue#141: If phone2 is blank then phone turns to be empty not nil

Signed-off-by: Matheus Horstmann's avatarMatheus Horstmann <mch15@inf.ufpr.br>
parent 88a553cf
......@@ -48,7 +48,7 @@ class UploaderController < ApplicationController
if not(@ceps.has_key?(cep))
if valida_cep(cep)
addr = get_address(cep)
city = City.where(:name => addr[:localidade]).first
city = City.where(:name => addr[:localidade]).first
cityHall = CityHall.where(:city_id => city[:id])
if not(cityHall.blank?)
@ceps[cep] = [cep, city, cityHall, addr]
......@@ -71,7 +71,7 @@ class UploaderController < ApplicationController
index << i
@error << ["Não é possível cadastrar cidadão para outro município",@lines[i]+2]
next
end
end
end
end
end
......@@ -147,7 +147,7 @@ class UploaderController < ApplicationController
uniq[cpf] = 1
end
end
end
end
deleteFromTransposed(index)
end
......@@ -172,7 +172,7 @@ class UploaderController < ApplicationController
@transposed[11].each_with_index do |phone,i|
if phone.to_s.length <= 14
if phone.blank?
index << i
index << i
@error << ["Telefone 1 não pode ficar em branco",@lines[i]+2]
else
if not(phone =~ phone_regex)
......@@ -188,8 +188,10 @@ class UploaderController < ApplicationController
deleteFromTransposed(index)
index = Array.new
@transposed[12].each_with_index do |phone,i|
if phone.to_s.length <= 14
if phone.blank?
@transposed[12][i] = ''
next
else
if not(phone =~ phone_regex)
......@@ -244,11 +246,11 @@ class UploaderController < ApplicationController
def upload_csv(file)
begin
csv_comma = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false,
csv_comma = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false,
:convert_values_to_numeric => false})
csv_semicolon = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false, :col_sep => ';',
csv_semicolon = SmarterCSV.process(file.path, options={:remove_empty_values =>false,
:remove_zero_values =>false, :col_sep => ';',
:convert_values_to_numeric => false})
rescue EOFError
return redirect_to :upload_instructions, alert: "Arquivo .csv vazio!"
......@@ -275,7 +277,7 @@ def upload_csv(file)
@error = Array.new
@values = Array.new
@transposed = Array.new
@ceps = Hash.new
@ceps = Hash.new
@columns = [ :name,
:cpf,
:rg,
......@@ -298,7 +300,7 @@ def upload_csv(file)
]
csv.each do |csv|
@values << csv.values
@values << csv.values
end
@transposed = @values.transpose
......@@ -308,7 +310,7 @@ def upload_csv(file)
end
#############################################
#nome = 0
#nome = 0
#cpf = 1
#rg = 2
#sus = 3
......@@ -327,23 +329,22 @@ def upload_csv(file)
#city_id = 16
##############################################
##VALIDAÇÕES##
validateCPF(citiz)
validateCEP(citiz)
validateName(citiz)
validateNumber(citiz)
validatePhone(citiz)
validateRG(citiz)
validateBirth(citiz)
validateBirth(citiz)
validateEmail(citiz)
#Verifica se existe no banco e remove da inserção
index = Array.new
@intersection = Citizen.all.pluck(:cpf) & @transposed[1]
......@@ -353,7 +354,7 @@ def upload_csv(file)
index << @transposed[1].index(inter)
@error << ["Usuário já cadastrado",@transposed[1].index(inter)+2]
end
end
end
end
deleteFromTransposed(index)
......@@ -371,7 +372,7 @@ def upload_csv(file)
end
end
hash_cep.each do |k,v|
hash_cep.each do |k,v|
v.map do |id|
@insert[id].insert(16,@ceps[k][1].id) # city_id
if not(@ceps[k][3][:logradouro].blank?)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment