export bilans in ods and xlsx
This commit is contained in:
parent
e803276464
commit
cf9d6ccf34
4 changed files with 20 additions and 9 deletions
|
@ -32,7 +32,8 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def bilans_bdf
|
||||
render csv: dossier.etablissement.entreprise_bilans_bdf_to_csv
|
||||
extension = params[:format]
|
||||
render extension.to_sym => dossier.etablissement.entreprise_bilans_bdf_to_sheet(extension)
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -159,12 +159,8 @@ class Etablissement < ApplicationRecord
|
|||
entreprise_last_bilan_info_cle("besoin_en_fonds_de_roulement")
|
||||
end
|
||||
|
||||
def entreprise_bilans_bdf_to_csv
|
||||
headers = bilans_headers.concat(bilans_new_keys)
|
||||
data = entreprise_bilans_bdf.map do |bilan|
|
||||
headers.map { |h| bilan[h] }
|
||||
end
|
||||
SpreadsheetArchitect.to_csv(headers: headers, data: data)
|
||||
def entreprise_bilans_bdf_to_sheet(format)
|
||||
SpreadsheetArchitect.send("to_#{format}".to_sym, bilans_bdf_data)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -178,6 +174,14 @@ class Etablissement < ApplicationRecord
|
|||
entreprise_bilans_bdf.first[key]
|
||||
end
|
||||
|
||||
def bilans_bdf_data
|
||||
headers = bilans_headers.concat(bilans_new_keys)
|
||||
data = entreprise_bilans_bdf.map do |bilan|
|
||||
headers.map { |h| bilan[h] }
|
||||
end
|
||||
{ headers: headers, data: data }
|
||||
end
|
||||
|
||||
def dossier_id_for_export
|
||||
if dossier_id
|
||||
dossier_id.to_s
|
||||
|
|
|
@ -92,7 +92,13 @@
|
|||
- if controller.is_a?(Instructeurs::AvisController)
|
||||
%td= link_to "Consulter les bilans", bilans_bdf_instructeur_avis_path(@avis.id)
|
||||
- else
|
||||
%td= link_to "Consulter les bilans", bilans_bdf_instructeur_dossier_path(procedure_id: @dossier.procedure.id, dossier_id: @dossier.id)
|
||||
%td
|
||||
Consulter les bilans
|
||||
= link_to "au format csv", bilans_bdf_instructeur_dossier_path(procedure_id: @dossier.procedure.id, dossier_id: @dossier.id, format: 'csv')
|
||||
,
|
||||
= link_to "au format xlsx", bilans_bdf_instructeur_dossier_path(procedure_id: @dossier.procedure.id, dossier_id: @dossier.id, format: 'xlsx')
|
||||
ou
|
||||
= link_to "au format ods", bilans_bdf_instructeur_dossier_path(procedure_id: @dossier.procedure.id, dossier_id: @dossier.id, format: 'ods')
|
||||
%tr
|
||||
%th.libelle
|
||||
Résultat exercice
|
||||
|
|
|
@ -75,7 +75,7 @@ describe Etablissement do
|
|||
]
|
||||
end
|
||||
|
||||
subject { etablissement.entreprise_bilans_bdf_to_csv.split("\n") }
|
||||
subject { etablissement.entreprise_bilans_bdf_to_sheet('csv').split("\n") }
|
||||
|
||||
it "build a csv with keys in right order" do
|
||||
headers = subject[0].split(',')
|
||||
|
|
Loading…
Reference in a new issue