2018-02-22 16:53:29 +01:00
|
|
|
class SIRETService
|
|
|
|
def self.fetch(siret, dossier = nil)
|
2018-03-15 16:56:21 +01:00
|
|
|
etablissement = ApiEntreprise::EtablissementAdapter.new(siret, dossier&.procedure_id)
|
|
|
|
entreprise = ApiEntreprise::EntrepriseAdapter.new(siren(siret), dossier&.procedure_id)
|
2018-02-22 16:53:29 +01:00
|
|
|
|
|
|
|
if etablissement.success? && entreprise.success?
|
2018-03-15 16:56:21 +01:00
|
|
|
association = ApiEntreprise::RNAAdapter.new(siret, dossier&.procedure_id)
|
|
|
|
exercices = ApiEntreprise::ExercicesAdapter.new(siret, dossier&.procedure_id)
|
2018-02-22 16:53:29 +01:00
|
|
|
|
|
|
|
params = etablissement.to_params
|
|
|
|
.merge(entreprise.to_params.map { |k,v| ["entreprise_#{k}", v] }.to_h)
|
|
|
|
.merge(association.to_params&.map { |k,v| ["association_#{k}", v] }.to_h)
|
2018-03-28 10:52:54 +02:00
|
|
|
.merge(exercices_attributes: exercices.to_array)
|
2018-02-22 16:53:29 +01:00
|
|
|
|
|
|
|
# This is to fill legacy models and relationships
|
|
|
|
if dossier.present?
|
|
|
|
return params.merge(
|
|
|
|
entreprise_attributes: entreprise.to_params
|
|
|
|
.merge({
|
|
|
|
dossier: dossier,
|
|
|
|
rna_information_attributes: association.to_params
|
|
|
|
}.compact)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
return params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.siren(siret)
|
|
|
|
siret[0..8]
|
|
|
|
end
|
|
|
|
end
|