2018-04-03 17:53:14 +02:00
|
|
|
|
class Champs::SiretController < ApplicationController
|
|
|
|
|
def index
|
|
|
|
|
siret, champ_id = params.required([:siret, :champ_id])
|
|
|
|
|
@champ = Champs::SiretChamp.find(champ_id)
|
|
|
|
|
@etablissement = @champ.etablissement
|
|
|
|
|
if siret == 'blank'
|
|
|
|
|
if @etablissement
|
|
|
|
|
@etablissement.mark_for_destruction
|
|
|
|
|
end
|
|
|
|
|
@blank = true
|
|
|
|
|
elsif siret == 'invalid'
|
|
|
|
|
if @etablissement
|
|
|
|
|
@etablissement.mark_for_destruction
|
|
|
|
|
end
|
2018-07-30 14:33:01 +02:00
|
|
|
|
@error = "Le numéro de SIRET doit comporter exactement 14 chiffres."
|
2018-04-03 17:53:14 +02:00
|
|
|
|
else
|
2018-04-10 12:26:06 +02:00
|
|
|
|
etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, @champ.dossier.procedure_id)
|
2018-04-03 17:53:14 +02:00
|
|
|
|
if etablissement_attributes.present?
|
|
|
|
|
@etablissement = @champ.build_etablissement(etablissement_attributes)
|
|
|
|
|
@etablissement.champ = @champ
|
|
|
|
|
else
|
2018-07-30 14:33:01 +02:00
|
|
|
|
message = ['Nous n’avons pas trouvé d’établissement correspondant à ce numéro de SIRET.']
|
|
|
|
|
message << helpers.link_to('Plus d’informations', "https://faq.demarches-simplifiees.fr/article/4-erreur-siret", target: '_blank')
|
|
|
|
|
@error = helpers.safe_join(message, ' ')
|
2018-04-03 17:53:14 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|