This commit is contained in:
Nicolas Bally 2019-06-14 11:53:31 +02:00
parent 011d04ed5c
commit bfd2801043
14 changed files with 586 additions and 161 deletions

15
Gemfile
View File

@ -1,9 +1,8 @@
source 'http://rubygems.org' source 'http://rubygems.org'
gem 'rails', '4.2.6' gem 'rails', '4.2.6'
gem "mysql2" gem "mysql2", '~> 0.3.18'
gem 'sass-rails', '5.0.3' gem 'sass-rails', '5.0.3'
@ -63,7 +62,7 @@ gem 'gravatar_image_tag'
#gem 'country_select' #gem 'country_select'
gem 'roo', '~> 2.1.0' gem 'roo', '~> 2.8.2'
gem 'roo-xls' gem 'roo-xls'
gem 'curb' gem 'curb'
@ -84,11 +83,17 @@ gem "nokogiri"
gem 'elasticsearch-model' gem 'elasticsearch-model'
gem 'elasticsearch-rails' gem 'elasticsearch-rails'
gem 'twitter-text' #gem 'twitter-text'
gem 'pygments.rb' gem 'pygments.rb'
gem 'redcarpet' gem 'redcarpet'
gem 'omniauth-facebook' gem 'omniauth-facebook'
gem 'truncate_html' gem 'truncate_html'
gem 'axlsx', '3.0.0.pre'
gem 'axlsx_rails'
gem 'zip-zip'

View File

@ -37,153 +37,173 @@ GEM
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
acts_as_commentable (4.0.2) acts_as_commentable (4.0.2)
acts_as_tree (2.1.0) acts_as_tree (2.9.0)
activerecord (>= 3.0.0) activerecord (>= 3.0.0)
addressable (2.4.0) arel (6.0.4)
arel (6.0.3) axlsx (3.0.0.pre)
bcrypt (3.1.10) htmlentities (~> 4.3, >= 4.3.4)
binding_of_caller (0.7.2) mimemagic (~> 0.3)
nokogiri (~> 1.8, >= 1.8.2)
rubyzip (~> 1.2, >= 1.2.1)
axlsx_rails (0.5.2)
actionpack (>= 3.1)
axlsx (>= 2.0.1)
bcrypt (3.1.13)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
builder (3.2.2) builder (3.2.3)
byebug (3.5.1) byebug (11.0.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
capistrano (2.15.9) capistrano (2.15.9)
highline highline
net-scp (>= 1.0.0) net-scp (>= 1.0.0)
net-sftp (>= 2.0.0) net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14) net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0) net-ssh-gateway (>= 1.1.0)
carrierwave (0.10.0) carrierwave (1.3.1)
activemodel (>= 3.2.0) activemodel (>= 4.0.0)
activesupport (>= 3.2.0) activesupport (>= 4.0.0)
json (>= 1.7)
mime-types (>= 1.16) mime-types (>= 1.16)
coffee-rails (4.1.0) coffee-rails (4.1.1)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.1.x)
coffee-script (2.3.0) coffee-script (2.4.1)
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.9.1) coffee-script-source (1.12.2)
columnize (0.9.0) commonjs (0.2.7)
concurrent-ruby (1.0.2) concurrent-ruby (1.1.5)
countries (1.2.2) countries (3.0.0)
currencies (~> 0.4.2) i18n_data (~> 0.8.0)
i18n_data (~> 0.7.0) sixarm_ruby_unaccent (~> 1.1)
country_select (2.5.1) unicode_utils (~> 1.4)
countries (~> 1.2.0) country_select (4.0.0)
countries (~> 3.0)
sort_alphabetical (~> 1.0) sort_alphabetical (~> 1.0)
curb (0.8.8) crass (1.0.4)
currencies (0.4.2) curb (0.9.10)
debug_inspector (0.0.2) debug_inspector (0.0.3)
debugger-linecache (1.2.0) elasticsearch (7.1.0)
elasticsearch (1.0.15) elasticsearch-api (= 7.1.0)
elasticsearch-api (= 1.0.15) elasticsearch-transport (= 7.1.0)
elasticsearch-transport (= 1.0.15) elasticsearch-api (7.1.0)
elasticsearch-api (1.0.15)
multi_json multi_json
elasticsearch-model (0.1.8) elasticsearch-model (6.0.0)
activesupport (> 3) activesupport (> 3)
elasticsearch (> 0.4) elasticsearch (> 1)
hashie hashie
elasticsearch-rails (0.1.8) elasticsearch-rails (6.0.0)
elasticsearch-transport (1.0.15) elasticsearch-transport (7.1.0)
faraday faraday
multi_json multi_json
erubis (2.7.0) erubis (2.7.0)
execjs (2.3.0) execjs (2.7.0)
faraday (0.12.1) faraday (0.15.4)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
fastimage (1.8.1) fastimage (2.1.5)
addressable (~> 2.3, >= 2.3.5) ffi (1.11.1)
formtastic (2.3.0) formtastic (2.3.0)
actionpack (>= 3.0) actionpack (>= 3.0)
formtastic-bootstrap (3.0.0) formtastic-bootstrap (3.0.0)
formtastic (>= 2.2) formtastic (>= 2.2)
geocoder (1.2.9) geocoder (1.5.1)
globalid (0.3.6) globalid (0.4.2)
activesupport (>= 4.1.0) activesupport (>= 4.2.0)
gravatar_image_tag (1.2.0) gravatar_image_tag (1.2.0)
haml (4.0.6) haml (5.1.1)
temple (>= 0.8.0)
tilt tilt
haml-rails (0.8.2) haml-rails (1.0.0)
actionpack (>= 4.0.1) actionpack (>= 4.0.1)
activesupport (>= 4.0.1) activesupport (>= 4.0.1)
haml (>= 3.1, < 5.0) haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1) html2haml (>= 1.0.1)
railties (>= 4.0.1) railties (>= 4.0.1)
hashie (3.5.5) hashie (3.6.0)
highline (1.7.8) highline (2.0.2)
html2haml (2.0.0) html2haml (2.2.0)
erubis (~> 2.7.0) erubis (~> 2.7.0)
haml (~> 4.0.0) haml (>= 4.0, < 6)
nokogiri (~> 1.6.0) nokogiri (>= 1.6.0)
ruby_parser (~> 3.5) ruby_parser (~> 3.5)
i18n (0.7.0) htmlentities (4.3.4)
i18n_data (0.7.0) i18n (0.9.5)
concurrent-ruby (~> 1.0)
i18n_data (0.8.0)
iban-tools (1.1.0) iban-tools (1.1.0)
jbuilder (2.2.8) jbuilder (2.9.1)
activesupport (>= 3.0.0, < 5) activesupport (>= 4.2.0)
multi_json (~> 1.2) jquery-rails (4.3.5)
jquery-rails (4.0.3) rails-dom-testing (>= 1, < 3)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.3) json (1.8.6)
jwt (1.5.6) jwt (2.2.1)
kaminari (0.16.3) kaminari (1.1.1)
actionpack (>= 3.0.0) activesupport (>= 4.1.0)
activesupport (>= 3.0.0) kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-bootstrap (3.0.1) kaminari-bootstrap (3.0.1)
kaminari (>= 0.13.0) kaminari (>= 0.13.0)
rails rails
kgio (2.9.3) kaminari-core (1.1.1)
kgio (2.11.2)
less (2.6.0)
commonjs (~> 0.2.7)
less-rails (4.0.0)
actionpack (>= 4)
less (~> 2.6.0)
sprockets (>= 2)
libv8 (3.16.14.19) libv8 (3.16.14.19)
loofah (2.0.3) loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.4) mail (2.7.1)
mime-types (>= 1.16, < 4) mini_mime (>= 0.1.1)
mime-types (3.1) mime-types (3.2.2)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521) mime-types-data (3.2019.0331)
mini_portile2 (2.1.0) mimemagic (0.3.3)
minitest (5.9.0) mini_mime (1.0.1)
multi_json (1.12.1) mini_portile2 (2.4.0)
minitest (5.11.3)
multi_json (1.13.1)
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.0.0) multipart-post (2.1.1)
mysql2 (0.3.18) mysql2 (0.3.21)
net-scp (1.2.1) net-scp (2.0.0)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5, < 6.0.0)
net-sftp (2.1.2) net-sftp (2.1.2)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (2.7.0) net-ssh (2.7.0)
net-ssh-gateway (1.2.0) net-ssh-gateway (1.3.0)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
nokogiri (1.6.8) nokogiri (1.10.3)
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.4.0)
pkg-config (~> 1.1.7) oauth2 (1.4.1)
oauth2 (1.4.0) faraday (>= 0.8, < 0.16.0)
faraday (>= 0.8, < 0.13) jwt (>= 1.0, < 3.0)
jwt (~> 1.0)
multi_json (~> 1.3) multi_json (~> 1.3)
multi_xml (~> 0.5) multi_xml (~> 0.5)
rack (>= 1.2, < 3) rack (>= 1.2, < 3)
omniauth (1.6.1) omniauth (1.9.0)
hashie (>= 3.4.6, < 3.6.0) hashie (>= 3.4.6, < 3.7.0)
rack (>= 1.6.2, < 3) rack (>= 1.6.2, < 3)
omniauth-facebook (4.0.0) omniauth-facebook (5.0.0)
omniauth-oauth2 (~> 1.2) omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.4.0) omniauth-oauth2 (1.6.0)
oauth2 (~> 1.0) oauth2 (~> 1.1)
omniauth (~> 1.2) omniauth (~> 1.9)
pkg-config (1.1.7) posix-spawn (0.3.13)
posix-spawn (0.3.11) pygments.rb (1.2.1)
pygments.rb (0.6.3) multi_json (>= 1.0.0)
posix-spawn (~> 0.3.6) rack (1.6.11)
yajl-ruby (~> 1.2.0)
rack (1.6.8)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (4.2.6) rails (4.2.6)
@ -199,98 +219,101 @@ GEM
sprockets-rails sprockets-rails
rails-deprecated_sanitizer (1.0.3) rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha) activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7) rails-dom-testing (1.0.9)
activesupport (>= 4.2.0.beta, < 5.0) activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6.0) nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1) rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3) rails-html-sanitizer (1.0.4)
loofah (~> 2.0) loofah (~> 2.2, >= 2.2.2)
railties (4.2.6) railties (4.2.6)
actionpack (= 4.2.6) actionpack (= 4.2.6)
activesupport (= 4.2.6) activesupport (= 4.2.6)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
raindrops (0.13.0) raindrops (0.19.0)
rake (11.2.2) rake (12.3.2)
rdoc (4.2.0) rb-fsevent (0.10.3)
json (~> 1.4) rb-inotify (0.10.0)
redcarpet (3.3.4) ffi (~> 1.0)
rdoc (4.3.0)
redcarpet (3.4.0)
ref (2.0.0) ref (2.0.0)
rmagick (2.13.4) rmagick (3.1.0)
roo (2.1.1) roo (2.8.2)
nokogiri (~> 1) nokogiri (~> 1)
rubyzip (~> 1.1, < 2.0.0) rubyzip (>= 1.2.1, < 2.0.0)
roo-xls (1.0.0) roo-xls (1.2.0)
nokogiri nokogiri
roo (>= 2.0.0beta1, < 3) roo (>= 2.0.0, < 3)
spreadsheet (> 0.9.0) spreadsheet (> 0.9.0)
ruby-ole (1.2.11.8) ruby-ole (1.2.12.2)
ruby_parser (3.6.4) ruby_parser (3.13.1)
sexp_processor (~> 4.1) sexp_processor (~> 4.9)
rubyzip (1.1.7) rubyzip (1.2.3)
rvm-capistrano (1.4.1) rvm-capistrano (1.4.1)
capistrano (>= 2.0.0) capistrano (>= 2.0.0)
sass (3.4.22) sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.3) sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
sass (~> 3.1) sass (~> 3.1)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1) tilt (~> 1.1)
sdoc (0.4.1) sdoc (0.4.2)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0) rdoc (~> 4.0)
sexp_processor (4.4.5) sexp_processor (4.12.1)
slop (3.6.0) sixarm_ruby_unaccent (1.2.0)
sort_alphabetical (1.0.2) sort_alphabetical (1.1.0)
unicode_utils (>= 1.2.2) unicode_utils (>= 1.2.2)
spreadsheet (1.0.9) spreadsheet (1.2.4)
ruby-ole (>= 1.0) ruby-ole (>= 1.0)
spring (1.3.2) spring (2.0.2)
sprockets (3.6.2) activesupport (>= 4.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-rails (3.0.4) sprockets-rails (3.2.1)
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
temple (0.8.1)
therubyracer (0.12.3) therubyracer (0.12.3)
libv8 (~> 3.16.14.15) libv8 (~> 3.16.14.15)
ref ref
thor (0.19.1) thor (0.20.3)
thread_safe (0.3.5) thread_safe (0.3.6)
tilt (1.4.1) tilt (1.4.1)
truncate_html (0.9.3) truncate_html (0.9.3)
turbolinks (2.5.3) turbolinks (5.2.0)
coffee-rails turbolinks-source (~> 5.2)
twitter-bootstrap-rails (3.2.0) turbolinks-source (5.2.0)
actionpack (~> 4.1) twitter-bootstrap-rails (3.2.2)
execjs (~> 2.2) actionpack (>= 3.1)
rails (~> 4.1) execjs (>= 2.2.2, >= 2.2)
railties (~> 4.1) less-rails (>= 2.5.0)
twitter-text (1.13.4) railties (>= 3.1)
unf (~> 0.1.0) tzinfo (1.2.5)
tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.7.0) uglifier (4.1.20)
execjs (>= 0.3.0) execjs (>= 0.3.0, < 3)
json (>= 1.8.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
unicode_utils (1.4.0) unicode_utils (1.4.0)
unicorn (4.8.3) unicorn (5.5.1)
kgio (~> 2.6) kgio (~> 2.6)
rack
raindrops (~> 0.7) raindrops (~> 0.7)
web-console (2.0.0) web-console (2.3.0)
activemodel (~> 4.0) activemodel (>= 4.0)
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
railties (~> 4.0) railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
wicked_pdf (0.11.0) wicked_pdf (1.4.0)
rails activesupport
yajl-ruby (1.2.1) zip-zip (0.3)
rubyzip (>= 1.0.0)
PLATFORMS PLATFORMS
ruby ruby
@ -298,6 +321,8 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
acts_as_commentable acts_as_commentable
acts_as_tree acts_as_tree
axlsx (= 3.0.0.pre)
axlsx_rails
bcrypt (~> 3.1.7) bcrypt (~> 3.1.7)
byebug byebug
capistrano (= 2.15.9) capistrano (= 2.15.9)
@ -317,7 +342,7 @@ DEPENDENCIES
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
kaminari-bootstrap kaminari-bootstrap
mysql2 mysql2 (~> 0.3.18)
net-ssh (~> 2.7.0) net-ssh (~> 2.7.0)
nokogiri nokogiri
omniauth-facebook omniauth-facebook
@ -326,7 +351,7 @@ DEPENDENCIES
rails (= 4.2.6) rails (= 4.2.6)
redcarpet redcarpet
rmagick rmagick
roo (~> 2.1.0) roo (~> 2.8.2)
roo-xls roo-xls
rvm-capistrano (= 1.4.1) rvm-capistrano (= 1.4.1)
sass-rails (= 5.0.3) sass-rails (= 5.0.3)
@ -336,11 +361,11 @@ DEPENDENCIES
truncate_html truncate_html
turbolinks turbolinks
twitter-bootstrap-rails twitter-bootstrap-rails
twitter-text
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
unicorn unicorn
web-console (~> 2.0) web-console (~> 2.0)
wicked_pdf wicked_pdf
zip-zip
BUNDLED WITH BUNDLED WITH
1.16.1 1.16.4

View File

@ -0,0 +1,322 @@
# -*- encoding : utf-8 -*-
class Admin::ExportsController < ApplicationController
layout "admin"
before_filter :auth_admin
def prepare_file
@file = params[:csv_file]
require 'roo'
@xlsx = Roo::Spreadsheet.open(@file)
#xlsx = Roo::Excelx.new("./new_prices.xlsx")
# Use the extension option if the extension is ambiguous.
#xlsx = Roo::Spreadsheet.open('./rails_temp_upload', extension: :xlsx)
@xlsx.info
require 'csv'
@sheet = @xlsx.sheet(0)
if @sheet.cell(1,1) == "Factures vente enregistrées"
@filename = "Export-ventes"
@credit = true
headers = @sheet.row(2)
@rows = @sheet.parse()
@rows= @rows.drop(1)
@rows= @rows.drop(1)
@elements = []
@rows.each do |r|
i = 0
t = {}
r.each do |c|
t[headers[i]] = c
i += 1
end
@elements << t
end
end
@table_header = ["compte comptable", "compte client", "client","date", "numero piece","N° projet", "débit", "crédit"]
@table = []
@elements.each do |e|
#TTC
line = []
line << "41100000"
line << e["N° client à facturer"]
line << e["Nom"]
line << e["Date document"]
line << e[""]
line << e["N° projet"]
if @credit
line << ('%.2f' % e["Montant TTC"]).to_s.sub(".",",")
line << ""
else
line << ""
line << ('%.2f' % e["Montant TTC"]).to_s.sub(".",",")
end
@table << line
if e["Centre cout Code"] == "VENTES"
cpt = "70100000"
elsif e["Centre cout Code"] == "LOCATION"
cpt = "70830000"
else
cpt = ""
end
line = []
line << cpt
line << e["N° client à facturer"]
line << e["Nom"]
line << e["Date document"]
line << e[""]
line << e["N° projet"]
if @credit
line << ""
line << ('%.2f' % e["Montant"]).to_s.sub(".",",")
else
line << ('%.2f' % e["Montant"]).to_s.sub(".",",")
line << ""
end
@table << line
#TVA
line = []
line << "44566000"
line << e["N° client à facturer"]
line << e["Nom"]
line << e["Date document"]
line << e[""]
line << e["N° projet"]
if @credit
line << ""
line << ('%.2f' % (e["Montant TTC"] - e["Montant"])).to_s.sub(".",",")
else
line << ('%.2f' % (e["Montant TTC"] - e["Montant"])).to_s.sub(".",",")
line << ""
end
@table << line
end
respond_to do |format|
format.html{
}
format.xlsx {
response.headers['Content-Disposition'] = "attachment; filename=#{@filename}-#{Time.now.to_s.to_slug}.xlsx"
}
end
if false
require 'csv'
csv_text = @file.tempfile.read.force_encoding('ISO-8859-1').encode('utf-8')
@imported_csv = CSV.parse(csv_text, :headers => true, :col_sep => ";")
@headers = [
"Opérateur",
"Forfait",
"Date fin d'engagement",
"Numéro de ligne",
"Site",
"Numéro"
]
j_bill_line_types.each do |j_bill_line_type|
@headers << j_bill_line_type.name
@headers << j_bill_line_type.name
end
@headers << "Total"
@csv = CSV.generate(:headers => true, :col_sep => ";") do |csv|
csv << @headers
date = @start
line = [
"",
"",
"",
"",
""
]
j_bill_line_types.each do |j_bill_line_type|
line << "Prix"
line << "Volume"
end
line << ""
csv << line
j_bills.joins(:j_line).order("j_lines.number ASC").each do |j_bill|
j_line = j_bill.j_line
line = []
line << j_bill.j_forfait.j_operateur.name if j_bill.j_forfait and j_bill.j_forfait.j_operateur
line << j_bill.j_forfait.name if j_bill.j_forfait
if j_bill.j_line and j_bill.j_line.active_forfait
line << j_bill.j_line.active_forfait.end_at
else
line << ""
end
line << number_to_phone(j_bill.j_line.number)
line << j_bill.j_line.hardware
line << j_bill.bill_number
j_bill_line_types.each do |j_bill_line_type|
pr = j_bill.j_bill_lines.where(:j_bill_line_type_id => j_bill_line_type.id).sum(:amount)
v = j_bill.j_bill_lines.where(:j_bill_line_type_id => j_bill_line_type.id).sum("volume").to_f
if pr != 00 or v != 0
if j_bill_line_type.unit == "Secondes"
line << short_format_time(v)
else
line << v
end
else
line << ""
end
if pr != 00
line << ActionController::Base.helpers.number_to_currency(pr)
else
line << ""
end
end
line << ActionController::Base.helpers.number_to_currency(j_bill.amount)
csv << line
end
end
@data_to_send = @csv.encode('iso-8859-1', :undef => :replace, :replace => '')
file_path = Rails.root.join("pdf", "export_mois.csv")
File.open(file_path, "w+") do |f|
f.write(@data_to_send)
end
respond_to do |format|
format.html{
require 'csv'
csv_text = File.read(file_path).encode('utf-8')
@csv = CSV.parse(csv_text, :headers => true, :col_sep => ";")
}
format.csv {
send_file file_path, :filename => "export-csv.csv", :type => 'text/csv; charset=iso-8859-1; header=present'
}
end
end
end
def index
end
end

View File

@ -0,0 +1,2 @@
class ExportHist < ActiveRecord::Base
end

View File

@ -0,0 +1,4 @@
=form_tag prepare_file_admin_exports_path(:format => :xlsx), multipart: true do
=file_field_tag :csv_file
=submit_tag "importer", :class => "btn btn-primary"

View File

@ -0,0 +1,21 @@
%p{:style => "margin:1em;"}
=# link_to ic(:download)+' Télécharger en .xlsx', params.merge(format: :xlsx), :class => "btn btn-primary"
%table.table.table-striped
%tr
-@table_header.each do |th|
%th=th
-@table.each do |tr|
%tr
-tr.each do |td|
%td=td

View File

@ -0,0 +1,7 @@
wb = xlsx_package.workbook
wb.add_worksheet(name: "import") do |sheet|
sheet.add_row @table_header
@table.each do |tr|
sheet.add_row tr
end
end

View File

@ -77,9 +77,11 @@
%li= link_to "Communiqués de presse", admin_press_releases_path %li= link_to "Communiqués de presse", admin_press_releases_path
%li= link_to "Url courte", admin_tiny_urls_path %li= link_to "Url courte", admin_tiny_urls_path
-if current_admin.contact_role -if current_admin.contact_role
%li= link_to "Contacts", admin_contacts_path %li= link_to "Contacts", admin_contacts_path
%li= link_to "Conversion exports 4PS", admin_exports_path

View File

@ -2,3 +2,5 @@
# Add new mime types for use in respond_to blocks: # Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf # Mime::Type.register "text/richtext", :rtf
Mime::Type.register "application/vnd.ms-excel", :xlsx

View File

@ -482,12 +482,18 @@ end
get "admin/exports" => "admin/exports#index"
namespace :admin do namespace :admin do
resources :exports do
collection do
post :prepare_file
end
end
resources :detenus resources :detenus
resources :investigation_cats do resources :investigation_cats do

View File

@ -0,0 +1,9 @@
class CreateExportHists < ActiveRecord::Migration
def change
create_table :export_hists do |t|
t.string :piece
t.timestamps null: false
end
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190424164427) do ActiveRecord::Schema.define(version: 20190613184241) do
create_table "admins", force: :cascade do |t| create_table "admins", force: :cascade do |t|
t.string "name", limit: 255 t.string "name", limit: 255
@ -305,6 +305,12 @@ ActiveRecord::Schema.define(version: 20190424164427) do
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "export_hists", force: :cascade do |t|
t.string "piece", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "external_links", force: :cascade do |t| create_table "external_links", force: :cascade do |t|
t.string "title", limit: 255 t.string "title", limit: 255
t.text "description", limit: 65535 t.text "description", limit: 65535

7
test/fixtures/export_hists.yml vendored Normal file
View File

@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
piece: MyString
two:
piece: MyString

View File

@ -0,0 +1,7 @@
require 'test_helper'
class ExportHistTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end