Add on information entreprise :

- SIRET Siège social
	- Code naf
	- Code effectif
	- Numéro TVA intracommunautaire
	- Exercices
This commit is contained in:
Xavier J 2015-11-16 11:23:29 +01:00
parent 803ca14f72
commit dd8bafab49
18 changed files with 233 additions and 21 deletions

View file

@ -19,6 +19,17 @@ class Users::DossiersController < UsersController
procedure = Procedure.find(params['procedure_id'])
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
exercices = SIADE::ExercicesAdapter.new(siret).to_params
unless exercices.nil?
exercices.each_value do |exercice|
exercice = Exercice.new(exercice)
exercice.etablissement = @etablissement
exercice.save
end
end
@dossier = Dossier.create(user: current_user)
@dossier.draft!

View file

@ -1,4 +1,6 @@
class Etablissement < ActiveRecord::Base
belongs_to :dossier
belongs_to :entreprise
has_many :exercices
end

3
app/models/exercice.rb Normal file
View file

@ -0,0 +1,3 @@
class Exercice < ActiveRecord::Base
belongs_to :etablissement
end

View file

@ -5,24 +5,34 @@
.row#infos_entreprise
.col-lg-6.col-md-6
%dl.dl-horizontal
%dt Siret :
%dd.text-success= @etablissement.siret
- if @etablissement.siret != @entreprise.siret_siege_social
%dt SIRET siège social :
%dd= @entreprise.siret_siege_social
%dt Forme juridique :
%dd= @entreprise.forme_juridique
%dt libelle naf :
%dt Libellé naf :
%dd= @etablissement.libelle_naf
%dt Code naf :
%dd= @etablissement.naf
%dt Date de création :
%dd= Time.at(@entreprise.date_creation).strftime "%d-%m-%Y"
%dt Effectife entreprise :
%dt Effectif entreprise :
%dd= @entreprise.effectif
%dt Capital social :
%dd= @entreprise.pretty_capital_social
%dt Code effectif :
%dd= @entreprise.code_effectif_entreprise
%dt Numéro TVA intracommunautaire :
%dd= @entreprise.numero_tva_intracommunautaire
.col-lg-6.col-md-6
%dl.dl-horizontal
@ -33,3 +43,14 @@
= line
%br
%dt Capital social :
%dd= @entreprise.pretty_capital_social
%dt Exercices :
%dd
%address
- @etablissement.exercices.each_with_index do |exercice, index|
%strong
= "#{exercice.dateFinExercice.year} : "
= number_to_currency(exercice.ca)
%br

View file

@ -20,6 +20,14 @@
# available at http://guides.rubyonrails.org/i18n.html.
fr:
number:
currency:
format:
unit: '€'
delimiter: ' '
separator: ','
precision: 2
format: '%n %u'
devise:
confirmations:
confirmed: 'Votre compte a été confirmé avec succès.'

View file

@ -0,0 +1,11 @@
class CreateExerciceTable < ActiveRecord::Migration
def change
create_table :exercices do |t|
t.string :ca
t.datetime :dateFinExercice
t.integer :date_fin_exercice_timestamp
end
add_reference :exercices, :etablissement, references: :etablissements
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151110091451) do
ActiveRecord::Schema.define(version: 20151113171605) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -66,6 +66,7 @@ ActiveRecord::Schema.define(version: 20151110091451) do
t.datetime "updated_at", default: '2015-09-22 09:25:29'
t.string "state"
t.integer "user_id"
t.text "json_latlngs"
end
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
@ -104,6 +105,13 @@ ActiveRecord::Schema.define(version: 20151110091451) do
t.integer "entreprise_id"
end
create_table "exercices", force: :cascade do |t|
t.string "ca"
t.datetime "dateFinExercice"
t.integer "date_fin_exercice_timestamp"
t.integer "etablissement_id"
end
create_table "gestionnaires", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false

View file

@ -16,13 +16,20 @@ class SIADE::API
call(base_url + endpoint)
end
def self.call(url)
def self.exercices(siret)
endpoint = "/api/v1/etablissements/exercices/#{siret}"
call(base_url + endpoint)
end
def self.call(url, params = {})
params.merge!(token: SIADETOKEN)
verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE
RestClient::Resource.new(
url,
verify_ssl: verify_ssl_mode
).get(params: { token: SIADETOKEN })
).get(params: params)
end
def self.base_url

View file

@ -0,0 +1,32 @@
class SIADE::ExercicesAdapter
def initialize(siret)
@siret = siret
end
def data_source
@data_source ||= JSON.parse(SIADE::API.exercices(@siret), symbolize_names: true)
rescue
@data_source = nil
end
def to_params
params = {}
data_source[:exercices].each_with_index do |values, i|
params[i] = {}
values.each do |index, value|
params[i][index] = value if attr_to_fetch.include?(index)
end
end
params
rescue
nil
end
def attr_to_fetch
[:ca,
:dateFinExercice,
:date_fin_exercice_timestamp]
end
end

View file

@ -53,6 +53,9 @@ describe Users::DossiersController, type: :controller do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
end
describe 'professionnel fills form' do
@ -98,6 +101,10 @@ describe Users::DossiersController, type: :controller do
expect(Etablissement.last.entreprise).to eq(Entreprise.last)
end
it 'creates exercices for dossier' do
expect { subject }.to change { Exercice.count }.by(3)
end
it 'links procedure to dossier' do
subject
expect(Dossier.last.procedure).to eq(Procedure.last)

View file

@ -47,7 +47,7 @@ describe EntrepriseDecorator do
describe '#pretty_capital_social' do
it 'pretty display capital_social' do
expect(subject.pretty_capital_social).to eq('123 000.00 €')
expect(subject.pretty_capital_social).to eq('123 000,00 €')
end
end

View file

@ -31,6 +31,9 @@ feature 'user path for dossier creation' do
.to_return(body: File.read('spec/support/files/etablissement.json', status: 200))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
page.find_by_id('siret').set siret
page.click_on 'Commencer'
end

View file

@ -29,6 +29,8 @@ feature 'user arrive on siret page' do
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
page.find_by_id('siret').set siret
page.click_on 'Commencer'
end

View file

@ -54,4 +54,35 @@ describe SIADE::API do
end
end
end
describe '.exercices' do
before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/api\/v1\/etablissements\/exercices\/.*token=/)
.to_return(status: status, body: body)
end
context 'when siret does not exist' do
subject { described_class.exercices(siret) }
let(:siret) { '11111111111111' }
let(:status) { 404 }
let(:body) { '' }
it 'raises RestClient::ResourceNotFound' do
expect { subject }.to raise_error(RestClient::ResourceNotFound)
end
end
context 'when siret exists' do
subject { described_class.exercices(siret) }
let(:siret) { '41816609600051' }
let(:status) { 200 }
let(:body) { File.read('spec/support/files/exercices.json') }
it 'raises RestClient::Unauthorized' do
expect(subject).to eq(body)
end
end
end
end

View file

@ -0,0 +1,33 @@
require 'spec_helper'
describe SIADE::ExercicesAdapter do
let(:siret) { '41816609600051' }
subject { described_class.new(siret).to_params }
before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/api\/v1\/etablissements\/exercices\/.*token=/)
.to_return(body: File.read('spec/support/files/exercices.json', status: 200))
end
it '#to_params class est une Hash ?' do
expect(subject).to be_an_instance_of(Hash)
end
it 'have 3 exercices' do
expect(subject.size).to eq(3)
end
context 'Attributs Exercices' do
it 'L\'exercice contient bien un ca' do
expect(subject[0][:ca]).to eq('21009417')
end
it 'L\'exercice contient bien une date de fin d\'exercice' do
expect(subject[0][:dateFinExercice]).to eq("2013-12-31T00:00:00+01:00")
end
it 'L\'exercice contient bien une date_fin_exercice_timestamp' do
expect(subject[0][:date_fin_exercice_timestamp]).to eq(1388444400)
end
end
end

View file

@ -19,5 +19,6 @@ describe Etablissement do
describe 'associations' do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:entreprise) }
it { is_expected.to have_many(:exercices) }
end
end

View file

@ -0,0 +1,13 @@
require 'spec_helper'
describe Exercice do
describe 'database columns' do
it { is_expected.to have_db_column(:ca) }
it { is_expected.to have_db_column(:dateFinExercice) }
it { is_expected.to have_db_column(:date_fin_exercice_timestamp) }
end
describe 'associations' do
it { is_expected.to belong_to(:etablissement) }
end
end

View file

@ -0,0 +1,19 @@
{
"exercices":[
{
"ca":"21009417",
"dateFinExercice":"2013-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1388444400
},
{
"ca":"18968298",
"dateFinExercice":"2012-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1356908400
},
{
"ca":"17768838",
"dateFinExercice":"2011-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1325286000
}
]
}