From 23eb1c086d85a8a1693b2a71b98e44fa31e517b8 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Tue, 4 Jun 2019 14:36:49 +0200 Subject: [PATCH] suite --- Gemfile.lock | 4 ++-- app/models/renew.rb | 13 ++++++++++--- app/views/layouts/mail.html.haml | 6 +++++- app/views/public/renews/select_sheet.html.haml | 15 ++++++++++++++- config/environments/development.rb | 7 +++++-- .../20190604091050_add_bienfaiteur_to_renews.rb | 6 ++++++ db/schema.rb | 4 +++- 7 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20190604091050_add_bienfaiteur_to_renews.rb diff --git a/Gemfile.lock b/Gemfile.lock index 805b5d2..c827984 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,8 +114,8 @@ GEM net-ssh (2.7.0) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) - nokogiri (1.6.5) - mini_portile (~> 0.6.0) + nokogiri (1.6.0) + mini_portile (~> 0.5.0) non-stupid-digest-assets (1.0.4) orm_adapter (0.5.0) paypal-sdk-core (0.3.1) diff --git a/app/models/renew.rb b/app/models/renew.rb index 6b6d5b1..9cff839 100644 --- a/app/models/renew.rb +++ b/app/models/renew.rb @@ -7,11 +7,18 @@ class Renew < ActiveRecord::Base validates :payment_type_id, :presence => true validates :join_type, :presence => true + validates :personalized_price, :presence => true, numericality:{greater_than_or_equal_to: 20}, :if => :bienfaiteur? before_validation do - self.payment_type_id = 3 + if !self.bienfaiteur + self.personalized_price = nil + end + - if self.join_type == 1 + self.payment_type_id = 3 + if self.bienfaiteur + self.price = self.personalized_price + elsif self.join_type == 1 self.price = 10.0 elsif self.join_type == 2 self.price = 15.0 @@ -36,7 +43,7 @@ class Renew < ActiveRecord::Base - sheet_year = self.sheet.sheet_years.new(:year => Renew::YEAR, :join_type => self.join_type, :paid_at => Time.now, :amount => self.price, :payment_type => self.payment_type_id, ) + sheet_year = self.sheet.sheet_years.new(:benefactor => self.bienfaiteur, :year => Renew::YEAR, :join_type => self.join_type, :paid_at => Time.now, :amount => self.price, :payment_type => self.payment_type_id, ) if sheet_year.save self.return_done = true diff --git a/app/views/layouts/mail.html.haml b/app/views/layouts/mail.html.haml index 237b5b3..250dec5 100755 --- a/app/views/layouts/mail.html.haml +++ b/app/views/layouts/mail.html.haml @@ -35,8 +35,12 @@ %a{:href => "http://www.lepicvert.asso.fr/131/lassociation/adherer", :style => "color:white;text-decoration:none;"} Attention : votre adhésion n'a pas encore été renouvelée pour = Date.today.year.to_s+"." + %br + + =link_to select_sheet_public_renews_index_path(:s => @options[:sheet].sheet_number.to_s), :style => "color:white;text-decoration:underline;" do + %strong + Nouveau : vous pouvez désormais la renouveler directement en ligne, par carte bancaire en suivant ce lien. - %tr{:style => "background:#f4f3ef"} %td{:style => "width:185px;padding:20px;padding-top:22px;padding-bottom:28px;padding-left:30px;"} diff --git a/app/views/public/renews/select_sheet.html.haml b/app/views/public/renews/select_sheet.html.haml index 55b1b31..b96234b 100644 --- a/app/views/public/renews/select_sheet.html.haml +++ b/app/views/public/renews/select_sheet.html.haml @@ -2,6 +2,14 @@ %p Pour renouveller votre adhésion vous pouvez indiquer votre numéro d'adhérent ci-dessous : +%ul + %li + Adhésion individuelle : 10 € + %li + Adhésion familiale : 15 € + %li + Bienfaiteur individuel ou familial : 20 € ou plus + =semantic_form_for @renew, :url => save_sheet_public_renews_index_path(), :html => {:method => :get} do |f| -f.inputs do @@ -10,10 +18,15 @@ =f.input :email, :label => "Email :" - =f.input :join_type, :collection => {"Individuel (10€)" => 1, "Familial (15€)" => 2}, :include_blank => false, :label => "Type d'adhésion", :as => :radio + =f.input :join_type, :collection => {"Individuel" => 1, "Familial" => 2}, :include_blank => false, :label => "Type d'adhésion :", :as => :radio + =f.input :bienfaiteur, :label => "Adhésion bienfaiteur ? (somme libre au dessus de 20€)", :input_html => {:onchange => "if($(this).is(':checked')){$('.bienfaiteur').show();}else{$('.bienfaiteur').hide();}"} + .bienfaiteur{:style => ("display:none" if !@renew.bienfaiteur)} + =f.input :personalized_price, :label => "Montant de votre adhésion bienfaiteur :" + + =f.submit "Renouveller mon adhésion par CB" diff --git a/config/environments/development.rb b/config/environments/development.rb index 9ec620f..7e5ca98 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -29,8 +29,11 @@ Survey::Application.configure do config.assets.debug = true - config.action_mailer.delivery_method = :file - config.action_mailer.default_url_options = { :host => 'localhost:3000' } + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 } + + config.action_mailer.default_url_options = { :host => HOSTNAME } + Rails.application.routes.default_url_options = config.action_mailer.default_url_options = { :host => HOSTNAME, :protocol => 'http' } end diff --git a/db/migrate/20190604091050_add_bienfaiteur_to_renews.rb b/db/migrate/20190604091050_add_bienfaiteur_to_renews.rb new file mode 100644 index 0000000..f9c2d79 --- /dev/null +++ b/db/migrate/20190604091050_add_bienfaiteur_to_renews.rb @@ -0,0 +1,6 @@ +class AddBienfaiteurToRenews < ActiveRecord::Migration + def change + add_column :renews, :bienfaiteur, :boolean, :default => false + add_column :renews, :personalized_price, :decimal, :precision => 10, :scale => 2 + end +end diff --git a/db/schema.rb b/db/schema.rb index c6a5e41..5c1564e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190315002155) do +ActiveRecord::Schema.define(version: 20190604091050) do create_table "admins", force: true do |t| t.string "email", default: "", null: false @@ -783,6 +783,8 @@ ActiveRecord::Schema.define(version: 20190315002155) do t.boolean "return_done", default: false t.datetime "created_at" t.datetime "updated_at" + t.boolean "bienfaiteur", default: false + t.decimal "personalized_price", precision: 10, scale: 2 end add_index "renews", ["sheet_id"], name: "index_renews_on_sheet_id", using: :btree