diff --git a/Gemfile b/Gemfile index a6ee408..7aa15bf 100644 --- a/Gemfile +++ b/Gemfile @@ -110,3 +110,6 @@ gem 'axlsx_rails' gem 'iban-tools' gem "mailjet" + + +gem "roo" diff --git a/Gemfile.lock b/Gemfile.lock index bf7b95f..4eae6b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -286,6 +286,9 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) rmagick (4.0.0) + roo (2.8.2) + nokogiri (~> 1) + rubyzip (>= 1.2.1, < 2.0.0) ruby-vips (2.0.17) ffi (~> 1.9) ruby_dep (1.5.0) @@ -409,6 +412,7 @@ DEPENDENCIES rails (= 6.0.3) rails_autolink rmagick + roo sass-rails (~> 5) searchkick selenium-webdriver diff --git a/app/controllers/admin/p_customers_controller.rb b/app/controllers/admin/p_customers_controller.rb index 12ed913..819ce19 100644 --- a/app/controllers/admin/p_customers_controller.rb +++ b/app/controllers/admin/p_customers_controller.rb @@ -670,6 +670,30 @@ class Admin::PCustomersController < ApplicationController + end + + + def update_stickers + + if params[:file] + data = Roo::Spreadsheet.open(params[:file].tempfile.path, extension: :xlsx) # open spreadsheet + headers = data.row(1) # get header row + @data = [] + data.each_with_index do |row, idx| + next if idx == 0 # skip header + # create hash from headers and cells + user_data = Hash[[headers, row].transpose] + @data << user_data + + + + end + end + + + + + end diff --git a/app/views/admin/p_customers/update_stickers.html.haml b/app/views/admin/p_customers/update_stickers.html.haml new file mode 100644 index 0000000..b1ad518 --- /dev/null +++ b/app/views/admin/p_customers/update_stickers.html.haml @@ -0,0 +1,34 @@ +.qi_row + .qi_pannel.qi_plain.padding + + =form_tag "", multipart: true do + =file_field_tag :file + %br + =submit_tag "Mettre à jour les stickers", :class => "btn btn-primary" + + +-if @data + + %table.table + -@data.each do |d| + %tr + %td + =d["Nom"] + %td + =d["Prénom"] + + -if p_customers = PCustomer.where("cc_particular_name = ? and cc_particular_firstname = ?", d["Nom"],d["Prénom"]) and p_customers.count == 1 and p_customer = p_customers.first + %td + =p_customer.cc_particular_name + %td + =p_customer.cc_particular_firstname + -p_customer.sticker = true + -p_customer.save + + -else + %td{:style => "color:red;font-weight:bold;"} + =ic(:warning) + Utilisateur introuvable + + %td + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 325e49b..dbf9cff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -676,7 +676,7 @@ Rails.application.routes.draw do resources :particulars - resources :p_customers + resources :p_customers resources :p_customer_auths do collection do @@ -871,7 +871,8 @@ Rails.application.routes.draw do get :autocomplete get :import get :import_cat - + get :update_stickers + post :update_stickers get :import3 end