diff --git a/app/models/import_csv.rb b/app/models/import_csv.rb index 9e018a7..1fe5013 100644 --- a/app/models/import_csv.rb +++ b/app/models/import_csv.rb @@ -6,6 +6,8 @@ class ImportCsv < ApplicationRecord has_many :import_csv_elements + has_many :elements, :through => :import_csv_elements + acts_as_tree validates :file, :presence => true @@ -40,11 +42,11 @@ class ImportCsv < ApplicationRecord self.import_csv_headers << ImportCsvHeader.new(:name => header) end - - self.table_name.classify.constantize.import_csv_fields.each do |h| + + self.table_source.classify.constantize.import_csv_fields.each do |h| if self.parent and c = self.parent.import_csv_champs.where(:champ => h.to_s).first - self.import_csv_champs.new(:champ => h.to_s, :header => c.header) - else + self.import_csv_champs.new(:champ => h.to_s, :header => c.header, :value => c.value) + elsif !self.parent self.import_csv_champs.new(:champ => h.to_s) end @@ -55,6 +57,15 @@ class ImportCsv < ApplicationRecord end + + def table_source + if self.table_name == "val_de_vienne" + name = "p_customer" + else + name = self.table_name + end + end + def charge @@ -87,7 +98,7 @@ class ImportCsv < ApplicationRecord end def load - self.table_name.classify.constantize.import_csv(self.charge, self) + self.table_source.classify.constantize.import_csv(self.charge, self) diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 2f430a5..7447a3a 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -73,7 +73,7 @@ class PCustomer < ApplicationRecord validates :cgv, :presence => true, :if => :require_cgv #validates :rgpd, :presence => true, :if => :require_cgv - validates :past_id, :uniqueness => true, :if => :imported + #validates :past_id, :uniqueness => true, :if => :imported acts_as_caching :fields => [:show_name, :particular_name, :particular_firstname] @@ -127,15 +127,15 @@ class PCustomer < ApplicationRecord self.sticker = true end - if circuit = Circuit.where(:past_id => self.imp_circuit_1).first + if self.imp_circuit_1? and circuit = Circuit.where(:past_id => self.imp_circuit_1).first self.circuit_1_id = circuit.id end - if circuit = Circuit.where(:past_id => self.imp_circuit_2).first + if self.imp_circuit_2? and circuit = Circuit.where(:past_id => self.imp_circuit_2).first self.circuit_2_id = circuit.id end - if circuit = Circuit.where(:past_id => self.imp_circuit_3).first + if self.imp_circuit_3? and circuit = Circuit.where(:past_id => self.imp_circuit_3).first self.circuit_3_id = circuit.id end @@ -160,7 +160,12 @@ class PCustomer < ApplicationRecord self.do_import if self.refresh_import == "true" end - acts_as_csv_import :fields =>[:imported, :email, :password, :past_id,:imp_cp,:imp_country,:imp_ref,:imp_email,:imp_firstname,:imp_name,:imp_fonction,:imp_organisme,:imp_address,:imp_cp2,:imp_city,:imp_tel,:imp_portable,:imp_lien,:imp_comment,:imp_iban,:imp_bic,:imp_circuit_1,:imp_circuit_2,:imp_circuit_3,:imp_partenaire,:imp_ecran,:imp_blocage,:imp_valid,:imp_user_valid,:imp_offre,:imp_info,:imp_cgu,:imp_test,:imp_stickers,:imp_npai,:npai,:imp_relance_adresse,:imp_demande_info,:imp_creation,:imp_modification, :refresh_import] + + before_validation do + self.generate_mdp = true if !self.id and self.import_name == "val" + end + + acts_as_csv_import :fields =>[:generate_mdp, :imported,:import_name,:unlimited, :email, :password, :past_id,:imp_cp,:imp_country,:imp_ref,:imp_email,:imp_firstname,:imp_name,:imp_fonction,:imp_organisme,:imp_address,:imp_cp2,:imp_city,:imp_tel,:imp_portable,:imp_lien,:imp_comment,:imp_iban,:imp_bic,:imp_circuit_1,:imp_circuit_2,:imp_circuit_3,:imp_partenaire,:imp_ecran,:imp_blocage,:imp_valid,:imp_user_valid,:imp_offre,:imp_info,:imp_cgu,:imp_test,:imp_stickers,:imp_npai,:npai,:imp_relance_adresse,:imp_demande_info,:imp_creation,:imp_modification, :refresh_import] attr_accessor :actual_password, :valid_last_password, :valid_public, :generate_mdp, :valid_pswd_confirmation, :require_cgv @@ -202,7 +207,13 @@ class PCustomer < ApplicationRecord before_validation do - + if !self.id and self.import_name = "val" + if p = PCustomer.where(:email => self.email).first + p.unlimited = true + p.import_name = "val" + p.save + end + end if self.valid_last_password and !PCustomer.find(self.id).authenticate(self.actual_password) @@ -239,9 +250,12 @@ class PCustomer < ApplicationRecord self.generate_mdp = false if self.save #GeneralMailer.send_qi_mail("fr", "generation_mdp", self.email, {"mdp" => ps}).deliver - - mail_hist = MailHist.generate_mail(:fr, MailType.find_by_slug("generation_mdp"), self.email, {:arguments => {:mdp => ps, :civilite => self.particular.civilite, :nom => self.particular.name, :prenom => self.particular.firstname }, :p_customer => self, :element => self}) - + if self.import_name.to_s == "val" + mail_hist = MailHist.generate_mail(:fr, MailType.find_by_slug("import_val_de_vienne"), self.email, {:arguments => {:mdp => ps, :civilite => self.particular.civilite, :nom => self.particular.name, :prenom => self.particular.firstname }, :p_customer => self, :element => self}) + else + + mail_hist = MailHist.generate_mail(:fr, MailType.find_by_slug("generation_mdp"), self.email, {:arguments => {:mdp => ps, :civilite => self.particular.civilite, :nom => self.particular.name, :prenom => self.particular.firstname }, :p_customer => self, :element => self}) + end else end diff --git a/app/views/admin/import_csv_champs/_form.html.haml b/app/views/admin/import_csv_champs/_form.html.haml index 6c296ec..4112df6 100644 --- a/app/views/admin/import_csv_champs/_form.html.haml +++ b/app/views/admin/import_csv_champs/_form.html.haml @@ -1,5 +1,5 @@ %tr.m_odr_product_remise_form.field - %td{:style => "width:200px;"}= form.input :champ, :label => false, :as => :select, :collection => @import_csv.table_name.classify.constantize.import_csv_fields.map{|a| a.to_s} + %td{:style => "width:200px;"}= form.input :champ, :label => false, :as => :select, :collection => @import_csv.table_source.classify.constantize.import_csv_fields.map{|a| a.to_s} -if !form.object.header? and @import_csv.import_csv_headers.all.map{|a| a.name}.include?(form.object.champ) diff --git a/app/views/admin/import_csvs/_form.html.haml b/app/views/admin/import_csvs/_form.html.haml index 28ab675..2112474 100644 --- a/app/views/admin/import_csvs/_form.html.haml +++ b/app/views/admin/import_csvs/_form.html.haml @@ -6,12 +6,12 @@ = f.input :name, :label => "Nom de l'import :" = f.input :file, :label => "file :" - = f.input :table_name, :label => "Table :" , :as => :select, :collection => ["p_customers", "circuits", "organisateurs", "m_odr_product_sizes", "m_odr_places", "circuit_regions", "m_events", "departement_frances"] + = f.input :table_name, :label => "Table :" , :as => :select, :collection => ["p_customers", "circuits", "organisateurs", "m_odr_product_sizes", "m_odr_places", "circuit_regions", "m_events", "departement_frances", "val_de_vienne"] -if f.object.id %table.import_csv_champs_form -if f.object.import_csv_champs.count == 0 - -@import_csv.table_name.classify.constantize.import_csv_fields.each do |h| + -@import_csv.table_source.classify.constantize.import_csv_fields.each do |h| -f.object.import_csv_champs.new(:champ => h.to_s) =f.semantic_fields_for :import_csv_champs do |form| diff --git a/app/views/admin/import_csvs/show.html.haml b/app/views/admin/import_csvs/show.html.haml index 3969500..02b258d 100644 --- a/app/views/admin/import_csvs/show.html.haml +++ b/app/views/admin/import_csvs/show.html.haml @@ -7,4 +7,8 @@ .qi_row .qi_pannel.qi_plain.padding - =debug @import_csv \ No newline at end of file + =debug @import_csv + + %table + -@import_csv.import_csv_elements.all.each do |el| + =render el.element if el.element \ No newline at end of file diff --git a/app/views/admin/p_customers/_form.html.haml b/app/views/admin/p_customers/_form.html.haml index d8847da..cb87d02 100755 --- a/app/views/admin/p_customers/_form.html.haml +++ b/app/views/admin/p_customers/_form.html.haml @@ -22,7 +22,7 @@ .col-sm-2 - = form.input :parent_id, :label => "Si un ambassadeur vous a parlé de nous, sélectionnez son nom dans la liste :", :include_blank => true, :collection => PCustomer.where(:ambassadeur => true).all, :as => :select, :member_label => :member_label + = form.input :parent_id, :label => "Ambassadeur :", :include_blank => true, :collection => PCustomer.where(:ambassadeur => true).all, :as => :select, :member_label => :member_label .col-sm-2 %br @@ -39,7 +39,18 @@ .col-sm-2 %br = form.input :test_user, :label => "Client test ?", :as => :boolean - + + .row.qi_cancel_margins + .col-sm-4 + %br + = form.input :unlimited, :label => "Nbr de primes déplafonné ?", :as => :boolean + + .col-sm-4 + = form.object.import_name + + .col-sm-4 + =l form.object.import_date if form.object.import_date + =# form.input :tel, :label => "Tel :" diff --git a/app/views/public/p_customers/_new_form.html.haml b/app/views/public/p_customers/_new_form.html.haml index 33389b4..a28ab24 100644 --- a/app/views/public/p_customers/_new_form.html.haml +++ b/app/views/public/p_customers/_new_form.html.haml @@ -6,7 +6,7 @@ =f.hidden_field :valid_public -if PCustomer.where(:ambassadeur => true).count > 0 - =f.input :parent_code, :label => "Code ambassadeur", :collection => PCustomer.where(:ambassadeur => true).map{|a| ["#{a.mlm_token} - #{a.show_name}", a.mlm_token]} + =f.input :parent_code, :label => "Si un ambassadeur vous a parlé de nous, sélectionnez son nom dans la liste :", :collection => PCustomer.where(:ambassadeur => true).map{|a| ["#{a.mlm_token} - #{a.show_name}", a.mlm_token]} =f.input :email, :label => "Email" =f.input :password, :label => "Mot de passe", :as => :password diff --git a/db/migrate/20210318103907_add_unlimited_to_p_customers.rb b/db/migrate/20210318103907_add_unlimited_to_p_customers.rb new file mode 100644 index 0000000..f84cc7d --- /dev/null +++ b/db/migrate/20210318103907_add_unlimited_to_p_customers.rb @@ -0,0 +1,7 @@ +class AddUnlimitedToPCustomers < ActiveRecord::Migration[6.0] + def change + add_column :p_customers, :unlimited, :boolean, :default => false + add_column :p_customers, :import_name, :string + add_column :p_customers, :import_date, :datetime + end +end