From 22e2c2e133d839b11893e02b80ba2711dca0cbd3 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 30 Apr 2020 11:25:22 +0200 Subject: [PATCH] render csv bidf bilans --- app/controllers/instructeurs/dossiers_controller.rb | 4 ++++ app/models/etablissement.rb | 9 +++++++++ app/views/shared/dossiers/_identite_entreprise.html.haml | 7 +++++++ config/routes.rb | 1 + 4 files changed, 21 insertions(+) diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index c88e4108d..3b3bb6efd 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -31,6 +31,10 @@ module Instructeurs render 'admin/attestation_templates/show', formats: [:pdf] end + def bilans_bdf + render csv: dossier.etablissement.entreprise_bilans_bdf_to_csv + end + def show @demande_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.demande_seen_at diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 724988afa..04274d820 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -138,6 +138,15 @@ class Etablissement < ApplicationRecord upload_attestation(url, entreprise_attestation_fiscale) end + def entreprise_bilans_bdf_to_csv + headers = ["bilans"].concat(entreprise_bilans_bdf[0].keys) + data = entreprise_bilans_bdf.each_with_index.map do |bilan, i| + month = I18n.l(Date.current - (i + 1).year, format: "%m/%Y") + [month].concat(bilan.values) + end + SpreadsheetArchitect.to_csv(headers: headers, data: data) + end + private def dossier_id_for_export diff --git a/app/views/shared/dossiers/_identite_entreprise.html.haml b/app/views/shared/dossiers/_identite_entreprise.html.haml index f9a3e8ed2..51e5625e1 100644 --- a/app/views/shared/dossiers/_identite_entreprise.html.haml +++ b/app/views/shared/dossiers/_identite_entreprise.html.haml @@ -78,6 +78,13 @@ %th.libelle Attestation fiscale %td= link_to "Consulter l'attestation", url_for(etablissement.entreprise_attestation_fiscale) + - if etablissement.entreprise_bilans_bdf_to_csv.present? + %tr + %th.libelle + Bilans Banque de France + = "en #{etablissement.entreprise_bilans_bdf_monnaie}" + %td= link_to "Consulter les bilans", bilans_bdf_instructeur_dossier_path + - if etablissement.association? %tr %th.libelle Numéro RNA : diff --git a/config/routes.rb b/config/routes.rb index ba024c094..c84893b20 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -318,6 +318,7 @@ Rails.application.routes.draw do get 'attestation' get 'geo_data' get 'apercu_attestation' + get 'bilans_bdf' get 'messagerie' get 'annotations-privees' => 'dossiers#annotations_privees' get 'avis'