diff --git a/app/controllers/public/p_customers_controller.rb b/app/controllers/public/p_customers_controller.rb index b4636f5..cdcf40c 100644 --- a/app/controllers/public/p_customers_controller.rb +++ b/app/controllers/public/p_customers_controller.rb @@ -6,6 +6,12 @@ class Public::PCustomersController < ApplicationController @p_customer = PCustomer.new() + + if params[:a] and parent = PCustomer.where(:mlm_token => params[:a].to_s.upcase).first + @p_customer.parent_code = parent.mlm_token + parent.update_token_count + end + @p_customer.particulars << Particular.new(:pro => false, :skip_validation => true) @p_customer.valid_public = true end diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 2eb5d21..2f430a5 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -250,6 +250,11 @@ class PCustomer < ApplicationRecord end + def update_token_count + self.link_token_count = self.link_token_count.to_i + 1 + self.save + end + def self.qi_table_order { @@ -275,6 +280,7 @@ class PCustomer < ApplicationRecord :email => "Email", :particular_tel => "Téléphone", + :link_token_count => {:name => "Nbr. aff. lien amb.", :reorder => true}, :actions => "Actions" } diff --git a/app/views/public/p_customers/_new_form.html.haml b/app/views/public/p_customers/_new_form.html.haml index c172198..50ea3cc 100644 --- a/app/views/public/p_customers/_new_form.html.haml +++ b/app/views/public/p_customers/_new_form.html.haml @@ -5,7 +5,7 @@ =f.inputs do =f.hidden_field :valid_public - =f.input :parent_code, :label => "Code ambassadeur" + =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 :email, :label => "Email" =f.input :password, :label => "Mot de passe", :as => :password diff --git a/db/migrate/20210209165830_add_link_token_count_to_p_customers.rb b/db/migrate/20210209165830_add_link_token_count_to_p_customers.rb new file mode 100644 index 0000000..385254c --- /dev/null +++ b/db/migrate/20210209165830_add_link_token_count_to_p_customers.rb @@ -0,0 +1,5 @@ +class AddLinkTokenCountToPCustomers < ActiveRecord::Migration[6.0] + def change + add_column :p_customers, :link_token_count, :integer + end +end