mise à jour stickers

This commit is contained in:
Nicolas Bally 2021-05-06 13:50:39 +02:00
parent 318bffc203
commit 1a63ef9f44
5 changed files with 68 additions and 2 deletions

View File

@ -110,3 +110,6 @@ gem 'axlsx_rails'
gem 'iban-tools'
gem "mailjet"
gem "roo"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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