This commit is contained in:
Nicolas Bally 2020-07-22 15:50:47 +02:00
parent 3fecbf7e7f
commit dbcab11c01
27 changed files with 436 additions and 25 deletions

View File

@ -100,5 +100,13 @@ class Admin::MOdrPrimesController < ApplicationController
redirect_back(fallback_location:"/")
end
def attente_roulage
@m_odr_prime = MOdrPrime.find(params[:id])
@m_odr_prime.change_state("En attente de roulage")
redirect_back(fallback_location:"/")
end
end

View File

@ -213,6 +213,19 @@ class Admin::PCustomersController < ApplicationController
elsif params[:search][:test_user].to_s == "Non"
@p_customers = @p_customers.where(:test_user => false)
end
if params[:search][:npai].to_s == "Oui"
@p_customers = @p_customers.where(:npai => true)
elsif params[:search][:npai].to_s == "Non"
@p_customers = @p_customers.where(:npai => false)
end
if params[:search][:sticker].to_s == "Oui"
@p_customers = @p_customers.where(:sticker => true)
elsif params[:search][:sticker].to_s == "Non"
@p_customers = @p_customers.where(:sticker => false)
end
if params[:code].to_s != ""
@ -222,6 +235,10 @@ class Admin::PCustomersController < ApplicationController
if params[:name].to_s != ""
@p_customers = @p_customers.joins(:particulars).where("p_customers.code LIKE ? or particulars.organisation LIKE ? or particulars.name LIKE ? or particulars.firstname LIKE ?","%#{params[:name]}%", "%#{params[:name]}%", "%#{params[:name]}%", "%#{params[:name]}%")
end
if params[:email].to_s != ""
@p_customers = @p_customers.where("p_customers.email LIKE ?","%#{params[:email]}%")
end
if params[:city].to_s != ""
@p_customers = @p_customers.joins(:particulars).where("particulars.cp LIKE ? or particulars.city LIKE ?","%#{params[:city]}%", "%#{params[:city]}%")
@ -416,6 +433,33 @@ class Admin::PCustomersController < ApplicationController
@p_customer = PCustomer.find(params[:id])
end
def npai
@p_customer = PCustomer.find(params[:id])
end
def toggle_npai
@p_customer = PCustomer.find(params[:id])
if @p_customer.npai
@p_customer.npai = false
message = "NPAI levé"
else
@p_customer.npai = true
message = "NPAI signalé"
end
@p_customer.save
@p_customer.particular.generate_hist(message) if @p_customer.particular
redirect_back(fallback_location:"/")
end
def create
@p_customer = PCustomer.new(params.require(:p_customer).permit!)

View File

@ -0,0 +1,76 @@
# -*- encoding : utf-8 -*-
class Admin::ParticularHistsController < ApplicationController
layout "admin"
before_action :auth_admin
before_action :admin_space
def admin_space
@admin_space = "default"
end
def index
@particular_hists = ParticularHist.all
@particular_hists = sort_by_sorting(@particular_hists, "id DESC")
respond_to do |format|
format.html{
params[:search][:per_page] = params[:search][:per_page] || 100
per_page = params[:search][:per_page]
page = (params[:page] and params[:page] != "") ? params[:page] : 1
@particular_hists = @particular_hists.page(page).per(per_page)
}
end
end
def show
@particular_hist = ParticularHist.find(params[:id])
end
def new
@particular_hist = ParticularHist.new
end
def edit
@particular_hist = ParticularHist.find(params[:id])
end
def create
@particular_hist = ParticularHist.new(params.require(:particular_hist).permit!)
if @particular_hist.save
else
render action: "new"
end
end
def update
@particular_hist = ParticularHist.find(params[:id])
if @particular_hist.update_attributes(params.require(:particular_hist).permit!)
else
render action: "edit"
end
end
def destroy
@particular_hist = ParticularHist.find(params[:id])
@particular_hist.destroy
end
end

View File

@ -2,6 +2,8 @@ class PCustomer < ApplicationRecord
acts_as_tree
has_many :particular_hists
has_many :price_documents
has_many :particulars, :as => :owner, :dependent => :destroy
@ -257,6 +259,8 @@ class PCustomer < ApplicationRecord
:mlm_token => {:name => "Code ambassadeur", :reorder => true},
:enabled => "Actif ?",
:test_user => "Utilisateur test ?",
:npai => "NPAI ?",
:sticker => "Stickers envoyés ?",
:parent => "Ambassadeur",
@ -280,6 +284,10 @@ class PCustomer < ApplicationRecord
end
def particular_fill?
true if self.particular.firstname? and self.particular.name? and self.particular.address2? and self.particular.cp? and self.particular.city?
end
before_destroy do
if self.p_customer_sheets.count > 0 or self.p_payments.count > 0
false

View File

@ -100,4 +100,28 @@ class Particular < ApplicationRecord
end
after_save do
self.generate_hist
end
def generate_hist(message = "Changement des coordonnées")
if self.owner_type == "PCustomer"
particular_hist = ParticularHist.new(:p_customer_id => self.owner_id, :particular_id => self.id)
[:civilite, :name, :firstname, :address_2, :address_3, :cp, :city, :country, :tel, :email].each do |att|
eval "particular_hist.#{att.to_s} = self.#{att.to_s}"
end
particular_hist.description = message
particular_hist.email = self.owner.email
particular_hist.npai = self.owner.npai
particular_hist.save
end
end
end

View File

@ -0,0 +1,29 @@
class ParticularHist < ApplicationRecord
belongs_to :particular
belongs_to :p_customer
acts_as_sorting :fields => {
:id => {:name => "Id", :reorder => true},
# :p_customer => {:name => "Client", :reorder => true, :sort_name => "p_customers.cc_show_name"},
:created_at => {:name => "Date", :reorder => true},
:npai => {:name => "NPAI ?", :reorder => true, :as => :boolean},
:description => {:name => "Evenement", :reorder => true},
:civilite => {:name => "Civilité", :reorder => true},
:name => {:name => "Nom", :reorder => true},
:firstname => {:name => "Nom", :reorder => true},
#:address_1 => {:name => "Nom", :reorder => true},
:address_2 => {:name => "Adresse", :reorder => true},
:address_3 => {:name => "Adresse suite", :reorder => true},
:cp => {:name => "Code postal", :reorder => true},
:city => {:name => "Ville", :reorder => true},
:country => {:name => "Pays", :reorder => true},
:tel => {:name => "Tel", :reorder => true},
:email => {:name => "Email", :reorder => true},
#:actions => {:name => "Actions", :reorder => true},
}
end

View File

@ -74,14 +74,17 @@
= link_to i(:pencil), edit_admin_m_odr_file_path(m_odr_prime_file.m_odr_file), :remote => false
-if @m_odr_prime.state == "A traiter" or @m_odr_prime.state == "Validé" and @m_odr_prime.m_odr_virements.where(:refused => false).count == 0
-if @m_odr_prime.state == "A traiter" or @m_odr_prime.state == "Validé" or @m_odr_prime.state == "En attente de roulage" and @m_odr_prime.m_odr_virements.where(:refused => false).count == 0
-if @m_odr_prime.m_odr_file_roulage.date? and @m_odr_prime.m_odr_file_roulage.date <= Date.today
=link_to "Générer le virement", generate_virement_admin_m_odr_prime_path(@m_odr_prime), :class => "btn btn-primary"
-else
%span.btn.btn-default
Vous pourrez générer le virement une fois la date de roulage passée.
-if @m_odr_prime.state == "En attente de roulage"
%span.btn.btn-default
Vous pourrez générer le virement une fois la date de roulage passée.
-else
=link_to 'Valider et passer au statut "en attente de roulage"', attente_roulage_admin_m_odr_prime_path(@m_odr_prime), :class => "btn btn-primary"
%hr
Virements

View File

@ -83,8 +83,10 @@
-else
-if current_admin.has_permission?("customers-d")
= link_to i(:"trash-o"), [:admin, p_customer], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer ce client ? ' } , :remote => true if p_customer.can_destroy?
-if current_admin.has_permission?("customers-d")
-if current_admin.has_permission?("customers-u")
= link_to i(:pencil), edit_admin_p_customer_path(p_customer), :remote => false
-if current_admin.has_permission?("customers-npai")
= link_to "NPAI", npai_admin_p_customer_path(p_customer), :remote => false
-if current_admin.has_permission?("customers-s")
= link_to i(:eye), admin_p_customer_path(p_customer)

View File

@ -23,8 +23,13 @@
%td=text_field_tag :code, params[:code],:class => "form-control", :placeholder => "Code client"
%td=text_field_tag :name, params[:name],:class => "form-control", :placeholder => "Nom"
%td=text_field_tag :email, params[:email],:class => "form-control", :placeholder => "Email"
%td=text_field_tag :city, params[:city],:class => "form-control", :placeholder => "Ville"
%td=text_field_tag :tel, params[:tel],:class => "form-control", :placeholder => "Tel"
@ -59,14 +64,14 @@
=select_tag "search[test_user]", options_for_select([[""], "Oui", "Non"], params[:search][:test_user])
%td
Catégorie :
=select_tag "search[p_customer_cat_id]", options_for_select([["",""],["Aucune","null"]]+PCustomerCat.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:p_customer_cat_id])
-if !current_admin.p_commercial
%td
Commercial :
=select_tag "search[p_commercial_id]", options_for_select([["",""],["Aucun","null"]]+PCommercial.order(:name).all.map{|a| [a.member_label, a.id]}, params[:search][:p_commercial_id])
NPAI ?
=select_tag "search[npai]", options_for_select([[""], "Oui", "Non"], params[:search][:npai])
%td
Stickers envoyés ?
=select_tag "search[sticker]", options_for_select([[""], "Oui", "Non"], params[:search][:sticker])

View File

@ -0,0 +1,48 @@
.qi_header
.right{:style => "text-align:right;"}
= link_to i(:pencil), edit_admin_p_customer_path(@p_customer), :remote => false
%h1
Utilisateurs
%span
Historique des changements de coordonnées
%span
=@p_customer.code
=@p_customer.show_name
%br
.qi_tab_header.qi_padding
.right{:style => "text-align:right;"}
-if @p_customer.npai
= link_to "Lever le NPAI", toggle_npai_admin_p_customer_path(@p_customer), :remote => false, :class => "btn btn-success"
-else
= link_to "Signaler le NPAI", toggle_npai_admin_p_customer_path(@p_customer), :remote => false, :class => "btn btn-danger"
.clear
-params[:search][:per_page] = params[:search][:per_page] || 50
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@particular_hists =@p_customer.particular_hists
-@particular_hists = sort_by_sorting(@particular_hists, "created_at DESC")
-@particular_hists = @particular_hists.page(page).per(per_page)
=#debug MailHist.qi_ordered_table_name
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @particular_hists}

View File

@ -0,0 +1,28 @@
=semantic_form_for [:admin, @particular_hist], :remote => true do |f|
.content
=f.inputs do
= f.input :particular, :label => "particular :"
= f.input :p_customer, :label => "p_customer :"
= f.input :description, :label => "description :"
= f.input :name, :label => "name :"
= f.input :firstname, :label => "firstname :"
= f.input :address_1, :label => "address_1 :"
= f.input :address_2, :label => "address_2 :"
= f.input :address_3, :label => "address_3 :"
= f.input :address_4, :label => "address_4 :"
= f.input :address_5, :label => "address_5 :"
= f.input :cp, :label => "cp :"
= f.input :city, :label => "city :"
= f.input :country, :label => "country :"
= f.input :tel, :label => "tel :"
= f.input :email, :label => "email :"
= f.input :civilite, :label => "civilite :"
= f.input :npai, :label => "npai :"
.actions=f.submit "sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,16 @@
%tr#particular_hist_row{:id => particular_hist.id}
-tr = {}
-tr[:actions] = capture do
%td.actions
= link_to i(:"trash-o"), [:admin, particular_hist], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
= link_to i(:pencil), edit_admin_particular_hist_path(particular_hist), :remote => true
= link_to i(:eye), admin_particular_hist_path(particular_hist), :remote => true
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => particular_hist}

View File

@ -0,0 +1,2 @@
$('#particular_hists_rows').prepend("<%= escape_javascript(render(@particular_hist))%>");
close_pane_hover();

View File

@ -0,0 +1 @@
$('#particular_hist_row_<%= @particular_hist.id %>').remove();

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,15 @@
.qi_header
.right= link_to ic(:plus)+' Ajouter', new_admin_particular_hist_path(), :class => "btn btn-primary btn-ap-add", :remote => true
%h1
.qi_search_row
=form_tag "", :method => "get", :onsubmit => "" do
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @particular_hists}
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @particular_hists}

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,10 @@
.qi_header
%h1
%span
.qi_row
.qi_pannel.qi_plain.padding
=debug @particular_hist

View File

@ -0,0 +1,2 @@
$('#particular_hist_row_<%= @particular_hist.id %>').replaceWith("<%= escape_javascript(render(@particular_hist))%>");
close_pane_hover();

View File

@ -31,10 +31,11 @@
.element
=link_to admin_menu_items_path(:menu_id => 1) do
.cat#big_cat_ventes
=ic :"globe"
CMS
-if current_admin.has_permission?("CMS")
=link_to admin_menu_items_path(:menu_id => 1) do
.cat#big_cat_ventes
=ic :"globe"
CMS

View File

@ -131,8 +131,8 @@
-c = current_p_customer.m_odr_primes.where(:state => "Virement envoyé").count
-c = current_p_customer.m_odr_primes.where(:state => ["En attente de roulage", "Virement envoyé"]).count
-ca = current_p_customer.m_odr_primes.where(:state => ["En attente de roulage"]).count
-if c > 0
%br
%br
@ -154,6 +154,15 @@
primes obtenues sur 5 pour 2020
-else
prime obtenue sur 5 pour 2020
-if ca > 1
(dont
=ca
primes versées après la date du roulage sur circuit.)
-elsif ca > 0
(dont
=ca
prime versée après la date du roulage sur circuit.)
-if current_p_customer.m_odr_primes.count > 0
%table.table

View File

@ -21,14 +21,14 @@
-v = object.send(key.to_s)
-if value.instance_of? Hash and value[:format]
-if value[:format] == :date
-if value.instance_of? Hash and (value[:format] or value[:as])
-value[:as] = value[:format] if value[:format] and !value[:as]
-if value[:as] == :date
%td=l v, :format => :short_date
-elsif value[:format] == :boolean
-elsif value[:as] == :boolean
%td="Oui" if v
-elsif value[:format] == :currency
-elsif value[:as] == :currency
%td.numeraire=number_to_currency v
-else

View File

@ -91,6 +91,7 @@ fr:
human: "le %A %d %B %Y à %Hh%M"
human_date: "%A %d %B %Y"
only_month: "%B %Y"
short_date: "%d/%m/%Y"
am: 'am'
pm: 'pm'

View File

@ -1,6 +1,17 @@
Rails.application.routes.draw do
namespace :admin do
resources :particular_hists do
member do
end
collection do
end
end
end
namespace :admin do
resources :circuit_region_cats do
member do
@ -95,6 +106,7 @@ Rails.application.routes.draw do
namespace :admin do
resources :m_odr_primes do
member do
get :attente_roulage
get :generate_virement
get :send_mail
get :refuse
@ -848,6 +860,9 @@ Rails.application.routes.draw do
member do
get :etat
get :archive_import
get :npai
get :toggle_npai
get :ask_particular
end
collection do

View File

@ -0,0 +1,28 @@
class CreateParticularHists < ActiveRecord::Migration[6.0]
def change
create_table :particular_hists do |t|
t.references :particular, foreign_key: true
t.references :p_customer, foreign_key: true
t.text :description
t.string :name
t.string :firstname
t.string :address_1
t.string :address_2
t.string :address_3
t.string :address_4
t.string :address_5
t.string :cp
t.string :city
t.string :country
t.string :tel
t.string :email
t.string :civilite
t.boolean :npai, :default => false
t.timestamps
PCustomer.update_all(:npai => false)
PCustomer.where(:imp_npai => "oui").update_all(:npai => true)
end
end
end

View File

@ -0,0 +1,6 @@
class AddParticularThankableToPCustomers < ActiveRecord::Migration[6.0]
def change
add_column :p_customers, :particular_thankable, :boolean, :default => false
add_column :p_customers, :particular_mail_sended, :boolean, :default => false
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_07_22_084354) do
ActiveRecord::Schema.define(version: 2020_07_22_123358) do
create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name"
@ -1735,6 +1735,8 @@ ActiveRecord::Schema.define(version: 2020_07_22_084354) do
t.boolean "test_user", default: false
t.string "cc_show_name"
t.string "ac_show_name"
t.boolean "particular_thankable", default: false
t.boolean "particular_mail_sended", default: false
t.index ["market_discount_id"], name: "index_p_customers_on_market_discount_id"
t.index ["p_customer_cat_id"], name: "index_p_customers_on_p_customer_cat_id"
t.index ["particular_id"], name: "index_p_customers_on_particular_id"
@ -2262,6 +2264,30 @@ ActiveRecord::Schema.define(version: 2020_07_22_084354) do
t.datetime "updated_at", precision: 6, null: false
end
create_table "particular_hists", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.bigint "particular_id"
t.bigint "p_customer_id"
t.text "description"
t.string "name"
t.string "firstname"
t.string "address_1"
t.string "address_2"
t.string "address_3"
t.string "address_4"
t.string "address_5"
t.string "cp"
t.string "city"
t.string "country"
t.string "tel"
t.string "email"
t.string "civilite"
t.boolean "npai", default: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["p_customer_id"], name: "index_particular_hists_on_p_customer_id"
t.index ["particular_id"], name: "index_particular_hists_on_particular_id"
end
create_table "particulars", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.boolean "pro", default: false
t.string "organisation"
@ -2963,6 +2989,8 @@ ActiveRecord::Schema.define(version: 2020_07_22_084354) do
add_foreign_key "p_product_prices", "p_price_cats"
add_foreign_key "p_product_prices", "p_product_refs"
add_foreign_key "p_product_ref_price_histories", "p_product_refs"
add_foreign_key "particular_hists", "p_customers"
add_foreign_key "particular_hists", "particulars"
add_foreign_key "s_modules", "s_modules_states"
add_foreign_key "timer_watchers", "admins"
add_foreign_key "tva_rates", "accounting_zones"