2018-03-06 13:44:29 +01:00
|
|
|
class Etablissement < ApplicationRecord
|
2015-08-10 11:05:06 +02:00
|
|
|
belongs_to :dossier
|
2015-11-16 11:23:29 +01:00
|
|
|
|
2018-04-03 16:27:59 +02:00
|
|
|
has_one :champ, class_name: 'Champs::SiretChamp'
|
2016-06-20 13:57:57 +02:00
|
|
|
has_many :exercices, dependent: :destroy
|
2016-01-06 15:48:06 +01:00
|
|
|
|
2018-02-22 16:53:29 +01:00
|
|
|
accepts_nested_attributes_for :exercices
|
|
|
|
|
2018-04-03 17:53:14 +02:00
|
|
|
validates :siret, presence: true
|
|
|
|
validates :dossier_id, uniqueness: { allow_nil: true }
|
|
|
|
|
2018-07-25 19:34:06 +02:00
|
|
|
def search_terms
|
|
|
|
[
|
|
|
|
entreprise_siren,
|
|
|
|
entreprise_numero_tva_intracommunautaire,
|
|
|
|
entreprise_forme_juridique,
|
|
|
|
entreprise_forme_juridique_code,
|
|
|
|
entreprise_nom_commercial,
|
|
|
|
entreprise_raison_sociale,
|
|
|
|
entreprise_siret_siege_social,
|
|
|
|
entreprise_nom,
|
|
|
|
entreprise_prenom,
|
|
|
|
association_rna,
|
|
|
|
association_titre,
|
|
|
|
association_objet,
|
|
|
|
siret,
|
|
|
|
naf,
|
|
|
|
libelle_naf,
|
|
|
|
adresse,
|
|
|
|
code_postal,
|
|
|
|
localite,
|
|
|
|
code_insee_localite
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-04-03 14:29:30 +02:00
|
|
|
def spreadsheet_columns
|
|
|
|
[
|
|
|
|
['Dossier ID', :dossier_id_for_export],
|
|
|
|
['Champ', :libelle_for_export],
|
|
|
|
['Établissement SIRET', :siret],
|
|
|
|
['Établissement siège social', :siege_social],
|
|
|
|
['Établissement NAF', :naf],
|
|
|
|
['Établissement libellé NAF', :libelle_naf],
|
|
|
|
['Établissement Adresse', :adresse],
|
|
|
|
['Établissement numero voie', :numero_voie],
|
|
|
|
['Établissement type voie', :type_voie],
|
|
|
|
['Établissement nom voie', :nom_voie],
|
|
|
|
['Établissement complément adresse', :complement_adresse],
|
|
|
|
['Établissement code postal', :code_postal],
|
|
|
|
['Établissement localité', :localite],
|
|
|
|
['Établissement code INSEE localité', :code_insee_localite],
|
|
|
|
['Entreprise SIREN', :entreprise_siren],
|
|
|
|
['Entreprise capital social', :entreprise_capital_social],
|
|
|
|
['Entreprise numero TVA intracommunautaire', :entreprise_numero_tva_intracommunautaire],
|
|
|
|
['Entreprise forme juridique', :entreprise_forme_juridique],
|
|
|
|
['Entreprise forme juridique code', :entreprise_forme_juridique_code],
|
|
|
|
['Entreprise nom commercial', :entreprise_nom_commercial],
|
|
|
|
['Entreprise raison sociale', :entreprise_raison_sociale],
|
|
|
|
['Entreprise SIRET siège social', :entreprise_siret_siege_social],
|
|
|
|
['Entreprise code effectif entreprise', :entreprise_code_effectif_entreprise],
|
|
|
|
['Entreprise date de création', :entreprise_date_creation],
|
|
|
|
['Entreprise nom', :entreprise_nom],
|
|
|
|
['Entreprise prénom', :entreprise_prenom],
|
|
|
|
['Association RNA', :association_rna],
|
|
|
|
['Association titre', :association_titre],
|
|
|
|
['Association objet', :association_objet],
|
|
|
|
['Association date de création', :association_date_creation],
|
|
|
|
['Association date de déclaration', :association_date_declaration],
|
|
|
|
['Association date de publication', :association_date_publication]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2018-04-23 11:57:38 +02:00
|
|
|
def siren
|
|
|
|
entreprise_siren
|
|
|
|
end
|
|
|
|
|
2016-01-06 15:48:06 +01:00
|
|
|
def geo_adresse
|
2016-01-19 17:19:38 +01:00
|
|
|
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')
|
2016-01-06 15:48:06 +01:00
|
|
|
end
|
2017-06-22 14:58:29 +02:00
|
|
|
|
|
|
|
def inline_adresse
|
2018-01-15 19:14:09 +01:00
|
|
|
# squeeze needed because of space in excess in the data
|
2019-02-13 09:57:33 +01:00
|
|
|
[
|
|
|
|
"#{numero_voie} #{type_voie} #{nom_voie}",
|
|
|
|
complement_adresse,
|
|
|
|
"#{code_postal} #{localite}"
|
2019-02-13 19:22:38 +01:00
|
|
|
].reject(&:blank?).join(', ').squeeze(' ')
|
2017-06-22 14:58:29 +02:00
|
|
|
end
|
2018-04-03 17:53:14 +02:00
|
|
|
|
2018-04-23 11:57:38 +02:00
|
|
|
def association?
|
|
|
|
association_rna.present?
|
2018-04-05 18:54:33 +02:00
|
|
|
end
|
|
|
|
|
2018-04-23 11:57:38 +02:00
|
|
|
def entreprise
|
|
|
|
Entreprise.new(
|
|
|
|
siren: entreprise_siren,
|
|
|
|
capital_social: entreprise_capital_social,
|
|
|
|
numero_tva_intracommunautaire: entreprise_numero_tva_intracommunautaire,
|
|
|
|
forme_juridique: entreprise_forme_juridique,
|
|
|
|
forme_juridique_code: entreprise_forme_juridique_code,
|
|
|
|
nom_commercial: entreprise_nom_commercial,
|
|
|
|
raison_sociale: entreprise_raison_sociale,
|
|
|
|
siret_siege_social: entreprise_siret_siege_social,
|
|
|
|
code_effectif_entreprise: entreprise_code_effectif_entreprise,
|
2020-04-21 15:52:08 +02:00
|
|
|
effectif_mensuel: entreprise_effectif_mensuel,
|
|
|
|
effectif_mois: entreprise_effectif_mois,
|
|
|
|
effectif_annee: entreprise_effectif_annee,
|
2018-04-23 11:57:38 +02:00
|
|
|
date_creation: entreprise_date_creation,
|
|
|
|
nom: entreprise_nom,
|
|
|
|
prenom: entreprise_prenom,
|
|
|
|
inline_adresse: inline_adresse
|
|
|
|
)
|
2018-04-05 18:54:33 +02:00
|
|
|
end
|
2019-04-03 14:29:30 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def dossier_id_for_export
|
|
|
|
if dossier_id
|
|
|
|
dossier_id.to_s
|
|
|
|
elsif champ
|
|
|
|
champ.dossier_id.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def libelle_for_export
|
2019-07-30 15:39:42 +02:00
|
|
|
champ&.libelle || 'Dossier'
|
2019-04-03 14:29:30 +02:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|