ajout fonction pour génération bons d'achat à la volée

This commit is contained in:
Nicolas Bally 2020-10-06 14:48:51 +02:00
parent 14b08cf87d
commit d170cb31a3
13 changed files with 195 additions and 10 deletions

View File

@ -7,7 +7,10 @@ class Public::MOdrsController < ApplicationController
def show def show
@m_odr = MOdr.where(:slug => params[:slug]).first @m_odr = MOdr.where(:slug => params[:slug]).first
end
def validation_ba
@m_odr = MOdr.where(:slug => params[:slug]).first
end end

View File

@ -27,7 +27,7 @@ module TranslationHelper
value = value.to_s value = value.to_s
if ["brouillon","Reçue"].include?(value) if ["brouillon","Reçue"].include?(value)
r = '<span class="badge badge-pill badge-warning">'+value+'</span>' r = '<span class="badge badge-pill badge-warning">'+value+'</span>'
elsif ["Virement envoyé", "Validé", "Envoyée"].include?(value) elsif ["Virement envoyé", "Validé", "Envoyée","Non utilisé" ].include?(value)
r = '<span class="badge badge-success">'+value+'</span>' r = '<span class="badge badge-success">'+value+'</span>'
elsif value == "commande" elsif value == "commande"
r = '<span class="badge badge-success">Commande</span>' r = '<span class="badge badge-success">Commande</span>'
@ -39,7 +39,7 @@ module TranslationHelper
r = '<span class="badge badge-primary">Facturée</span>' r = '<span class="badge badge-primary">Facturée</span>'
elsif value == "annulée" elsif value == "annulée"
r = '<span class="badge badge-dark">Annulée</span>' r = '<span class="badge badge-dark">Annulée</span>'
elsif ["Erreur sur virement", "Refusé", "Refusée"].include?(value) elsif ["Erreur sur virement", "Refusé", "Refusée", "Déjà utilisé"].include?(value)
r = '<span class="badge badge-danger">'+value+'</span>' r = '<span class="badge badge-danger">'+value+'</span>'
elsif ["En cours de traitement"].include?(value) elsif ["En cours de traitement"].include?(value)
r = '<span class="badge badge-danger" style="background:#865F7C;">'+value+'</span>' r = '<span class="badge badge-danger" style="background:#865F7C;">'+value+'</span>'

View File

@ -336,6 +336,21 @@ file_admin_ok remise particular_civilite particular_name particular_firstname pa
#, :sort_name => "code" #, :sort_name => "code"
end end
before_save do
self.generate_ba_number if self.m_odr and self.m_odr.ba_number_generator
end
def generate_ba_number
if !self.ba_number?
self.ba_number = loop do
ba_number = SecureRandom.hex(3).upcase
break ba_number unless MOdrRep.exists?(ba_number: ba_number)
end
end
end
def csv_m_odr def csv_m_odr
self.m_odr.name if self.m_odr self.m_odr.name if self.m_odr
end end

View File

@ -194,6 +194,10 @@ RIB :
- @m_odr_rep.generate_ba - @m_odr_rep.generate_ba
=link_to "Voir le bon d'achat", @m_odr_rep.ba_url, :class => "btn btn-primary" =link_to "Voir le bon d'achat", @m_odr_rep.ba_url, :class => "btn btn-primary"
-if @m_odr_rep.m_odr.ba_number_generator
-@m_odr_rep.save
=@m_odr_rep.ba_number
-if false -if false
%p Test mail %p Test mail

View File

@ -9,6 +9,16 @@
.place{:style => "top:#{@m_odr_rep.m_odr.ba_place_y}px;"} .place{:style => "top:#{@m_odr_rep.m_odr.ba_place_y}px;"}
=@m_odr_rep.place_name =@m_odr_rep.place_name
=debug @m_odr_rep.m_odr.ba_number_generator
-if @m_odr_rep.m_odr and @m_odr_rep.m_odr.ba_number_generator
.number{:style => "top:#{@m_odr_rep.m_odr.ba_number_place_y}px;"}
=@m_odr_rep.ba_number
-if @m_odr_rep.m_odr and @m_odr_rep.m_odr.ba_show_remise
.number{:style => "top:#{@m_odr_rep.m_odr.ba_remise_place_y}px;"}
=number_to_currency @m_odr_rep.remise
:scss :scss
#ba{ #ba{
@ -34,5 +44,16 @@
text-transform:uppercase; text-transform:uppercase;
font-weigh:bold; font-weigh:bold;
}
.number{
position:absolute;
left:0;
right:0;
text-align:center;
font-size:30px;
text-transform:uppercase;
font-weigh:bold;
} }
} }

View File

@ -126,6 +126,17 @@
=# f.input :ba_place_x, :label => "Position X du revendeur (px) :" =# f.input :ba_place_x, :label => "Position X du revendeur (px) :"
= f.input :ba_place_y, :label => "Position Y du revendeur (px) :" = f.input :ba_place_y, :label => "Position Y du revendeur (px) :"
= f.input :ba_number_place_y, :label => "Position Y du numéro (px) :"
= f.input :ba_show_remise, :label => "Afficher la remise ?"
= f.input :ba_remise_place_y, :label => "Position Y de la remise (px) :"
= f.input :ba_number_generator, :label => "Générer un numéro de bon d'achat unique à l'inscription"
= f.input :ba_interface, :label => "Générer une interface pour les revendeurs permettant de valider le bon d'achat"

View File

@ -9,6 +9,11 @@
-m_odr.m_odr_trackers.each do |mot| -m_odr.m_odr_trackers.each do |mot|
%br %br
=link_to public_m_odr_path(m_odr.slug, :t => mot.token, :lang => nil), public_m_odr_path(m_odr.slug, :t => mot.token, :lang => nil), :target => "_blank" =link_to public_m_odr_path(m_odr.slug, :t => mot.token, :lang => nil), public_m_odr_path(m_odr.slug, :t => mot.token, :lang => nil), :target => "_blank"
%td
-if m_odr.ba_interface
= link_to validation_ba_public_m_odr_path(m_odr.slug, :lang => nil), validation_ba_public_m_odr_path(m_odr.slug, :lang => nil), :target => "_blank"
%td= m_odr.start_at %td= m_odr.start_at
%td= m_odr.end_at %td= m_odr.end_at
%td= m_odr.public_end %td= m_odr.public_end

View File

@ -14,6 +14,7 @@
%th Client %th Client
%th Nom %th Nom
%th Lien %th Lien
%th Lien validation BA
%th Date de début %th Date de début
%th Date de fin %th Date de fin
%th Fin de réception %th Fin de réception

View File

@ -0,0 +1,89 @@
-if @m_odr.start_at > Date.today and params[:force].to_s == ""
%div{:style => "margin-top:30px;font-weight:bold;font-weight:800;font-size:2em;text-transform:uppercase;font-family: 'Open Sans','Helvetica Neue', Helvetica, sans-serif;text-align:center;"}
-count = ((@m_odr.start_at) - (Date.today))
-if @m_odr.landing_text?
=@m_odr.landing_text
-else
Démarrage
%div{:style => "font-weight:bold;font-weight:800;text-transform:uppercase;font-family: 'Open Sans','Helvetica Neue', Helvetica, sans-serif;text-align:center;line-height:200px;position:relative;top:-40px"}
dans
.clock{:style => "margin:2em;display:inline-block;width:auto;margin:0 auto;position:relative;top:35px"}
-if count > 1
jours !
-else
jour !
<script type="text/javascript">
=raw "var clock_max = #{count};"
</script>
:javascript
var countup;
var clock = $('.clock').FlipClock(0, {
clockFace: 'Counter',
minimumDigits: 1,
callbacks:{
init:function (){
}
}
});
if(clock_max > 0){
countup = setInterval(function() {
clock.increment();
if(clock.getTime().time >= clock_max) {
clock.stop();
clearInterval(countup);
}
}, 0);}
-if false
%p{:style => "font-weight:bold;font-size:2em;text-transform:uppercase;font-family:'Helvetica Neue', Helvetica, sans-serif;"}
jours avant l'ouverture
-else
#odr_form
.form_pannel
=form_tag "", :method => "get", :onsubmit => "" do
%p
=text_field_tag :code, params[:code],:class => "form-control", :placeholder => "Numéro du bon d'achat"
%p{:style => "text-align:center;"}
=submit_tag "Rechercher", :class => "btn btn-primary"
%hr
-if params[:code].to_s != ""
-@m_odr_rep = MOdrRep.where(:ba_number => params[:code].to_s.upcase).first
-if params[:code].to_s != "" and !@m_odr_rep
%p Le bon d'achat portant ce numéro n'a pas été trouvé
-elsif @m_odr_rep
-if params[:to_use].to_s == "true"
-@m_odr_rep.ba_used = true
-@m_odr_rep.save
%p
N° Bon d'achat :
=@m_odr_rep.ba_number
d'une valeur de
=number_to_currency @m_odr_rep.remise
%p
Statut :
-if !@m_odr_rep.ba_used
=state_helper "Non utilisé"
%br
%br
=link_to "Signaler comme utilisé dès maintenant", params.permit!.merge({:to_use => true}), :data => {:confirm => "Attention, une fois indiqué comme utilisé ce bon d'achat sera désactivé."}
-else
=state_helper "Déjà utilisé"

View File

@ -1,5 +1,10 @@
Rails.application.routes.draw do Rails.application.routes.draw do
get ':slug/validation_ba.html', to: 'public/m_odrs#validation_ba', :as => :validation_ba_public_m_odr
get "qi_help" => "admin/qi_helps#update", :as => :admin_qi_helps get "qi_help" => "admin/qi_helps#update", :as => :admin_qi_helps
@ -956,9 +961,9 @@ Rails.application.routes.draw do
get "plan" => "public/home#plan" get "plan" => "public/home#plan"
get ':slug.html', to: 'public/m_odrs#show', :as => :public_m_odr get ':slug.html', to: 'public/m_odrs#show', :as => :public_m_odr
root "admin/admin_auths#index" root "admin/admin_auths#index"

View File

@ -0,0 +1,16 @@
class AddBaNumberGenerationToMOdrs < ActiveRecord::Migration[6.0]
def change
add_column :m_odrs, :ba_number_generator, :boolean, :default => false
add_column :m_odrs, :ba_interface, :boolean, :default => false
add_column :m_odrs, :ba_show_remise, :boolean, :default => false
add_column :m_odrs, :ba_number_place_y, :integer
add_column :m_odrs, :ba_number_place_x, :integer
add_column :m_odrs, :ba_remise_place_y, :integer
add_column :m_odrs, :ba_remise_place_x, :integer
end
end

View File

@ -0,0 +1,6 @@
class AddBaNumberToMOdrReps < ActiveRecord::Migration[6.0]
def change
add_column :m_odr_reps, :ba_number, :string
add_column :m_odr_reps, :ba_used, :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. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_07_30_084942) do ActiveRecord::Schema.define(version: 2020_10_06_115533) do
create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name" t.string "name"
@ -517,7 +517,7 @@ ActiveRecord::Schema.define(version: 2020_07_30_084942) do
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
end end
create_table "import_csv_champs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "import_csv_champs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.string "champ" t.string "champ"
t.string "header" t.string "header"
t.string "value" t.string "value"
@ -527,7 +527,7 @@ ActiveRecord::Schema.define(version: 2020_07_30_084942) do
t.index ["import_csv_id"], name: "index_import_csv_champs_on_import_csv_id" t.index ["import_csv_id"], name: "index_import_csv_champs_on_import_csv_id"
end end
create_table "import_csv_elements", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "import_csv_elements", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.bigint "import_csv_id" t.bigint "import_csv_id"
t.string "element_type" t.string "element_type"
t.integer "element_id" t.integer "element_id"
@ -536,7 +536,7 @@ ActiveRecord::Schema.define(version: 2020_07_30_084942) do
t.index ["import_csv_id"], name: "index_import_csv_elements_on_import_csv_id" t.index ["import_csv_id"], name: "index_import_csv_elements_on_import_csv_id"
end end
create_table "import_csv_headers", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "import_csv_headers", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.bigint "import_csv_id" t.bigint "import_csv_id"
t.string "name" t.string "name"
t.string "champ" t.string "champ"
@ -546,7 +546,7 @@ ActiveRecord::Schema.define(version: 2020_07_30_084942) do
t.index ["import_csv_id"], name: "index_import_csv_headers_on_import_csv_id" t.index ["import_csv_id"], name: "index_import_csv_headers_on_import_csv_id"
end end
create_table "import_csvs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "import_csvs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.bigint "m_odr_id" t.bigint "m_odr_id"
t.string "file" t.string "file"
t.text "notes" t.text "notes"
@ -827,6 +827,8 @@ ActiveRecord::Schema.define(version: 2020_07_30_084942) do
t.string "reduc_code" t.string "reduc_code"
t.date "buy_at" t.date "buy_at"
t.decimal "reduc", precision: 14, scale: 2 t.decimal "reduc", precision: 14, scale: 2
t.string "ba_number"
t.boolean "ba_used", default: false
t.index ["m_odr_id"], name: "index_m_odr_reps_on_m_odr_id" t.index ["m_odr_id"], name: "index_m_odr_reps_on_m_odr_id"
t.index ["m_odr_place_id"], name: "index_m_odr_reps_on_m_odr_place_id" t.index ["m_odr_place_id"], name: "index_m_odr_reps_on_m_odr_place_id"
t.index ["m_odr_product_cat_id"], name: "index_m_odr_reps_on_m_odr_product_cat_id" t.index ["m_odr_product_cat_id"], name: "index_m_odr_reps_on_m_odr_product_cat_id"
@ -958,6 +960,13 @@ ActiveRecord::Schema.define(version: 2020_07_30_084942) do
t.boolean "product_process", default: true t.boolean "product_process", default: true
t.boolean "product_needed", default: true t.boolean "product_needed", default: true
t.string "reduc_label" t.string "reduc_label"
t.boolean "ba_number_generator", default: false
t.boolean "ba_interface", default: false
t.boolean "ba_show_remise", default: false
t.integer "ba_number_place_y"
t.integer "ba_number_place_x"
t.integer "ba_remise_place_y"
t.integer "ba_remise_place_x"
t.index ["p_customer_id"], name: "index_m_odrs_on_p_customer_id" t.index ["p_customer_id"], name: "index_m_odrs_on_p_customer_id"
end end
@ -1029,7 +1038,7 @@ ActiveRecord::Schema.define(version: 2020_07_30_084942) do
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
end end
create_table "mail_type_cats", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "mail_type_cats", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.string "name" t.string "name"
t.bigint "m_odr_id" t.bigint "m_odr_id"
t.string "slug" t.string "slug"