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