From 429325823ce2a32c00f438e8a721d883ef7db4af Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Sun, 2 Jun 2019 18:48:14 +0200 Subject: [PATCH] suite --- Gemfile.lock | 3 - app/assets/javascripts/public.js.coffee | 2 +- .../public_nested_fields copy.coffee | 11 + app/assets/stylesheets/public/top.css.scss | 7 +- app/controllers/admin/sheets_controller.rb | 2 +- app/controllers/public/joins_controller.rb | 308 ++++++++++++++++++ app/controllers/public/renews_controller.rb | 273 ++++++++++++++++ app/helpers/document_line_helper.rb | 9 + app/models/person.rb | 8 + app/models/renew.rb | 55 ++++ app/models/sheet.rb | 39 +++ app/models/sheet_year.rb | 2 +- .../admin/sheets/_sheets_search.html.haml | 6 +- app/views/public/joins/paid.html.haml | 40 +++ app/views/public/joins/paid_by_paypal.haml | 5 + app/views/public/joins/save_sheet.html.haml | 1 + app/views/public/joins/select_sheet.html.haml | 66 ++++ app/views/public/joins/thanks.html.haml | 1 + app/views/public/people/_form.html.haml | 19 ++ app/views/public/people/_person.html.haml | 32 ++ app/views/public/renews/paid_by_paypal.haml | 5 + .../public/renews/select_sheet.html.haml | 19 ++ app/views/public/renews/thanks.html.haml | 1 + app/views/public/shared/_top.html.haml | 3 + config/routes.rb | 26 ++ .../20190314212540_add_web_to_sheets.rb | 7 + db/migrate/20190314212933_create_renews.rb | 45 +++ .../20190315002155_add_paypal_to_sheets.rb | 35 ++ db/schema.rb | 62 +++- test/fixtures/renews.yml | 15 + test/models/renew_test.rb | 7 + 31 files changed, 1103 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/public_nested_fields copy.coffee create mode 100644 app/controllers/public/joins_controller.rb create mode 100644 app/controllers/public/renews_controller.rb create mode 100644 app/models/renew.rb create mode 100644 app/views/public/joins/paid.html.haml create mode 100644 app/views/public/joins/paid_by_paypal.haml create mode 100644 app/views/public/joins/save_sheet.html.haml create mode 100644 app/views/public/joins/select_sheet.html.haml create mode 100644 app/views/public/joins/thanks.html.haml create mode 100644 app/views/public/people/_form.html.haml create mode 100644 app/views/public/people/_person.html.haml create mode 100644 app/views/public/renews/paid_by_paypal.haml create mode 100644 app/views/public/renews/select_sheet.html.haml create mode 100644 app/views/public/renews/thanks.html.haml create mode 100644 db/migrate/20190314212540_add_web_to_sheets.rb create mode 100644 db/migrate/20190314212933_create_renews.rb create mode 100644 db/migrate/20190315002155_add_paypal_to_sheets.rb create mode 100644 test/fixtures/renews.yml create mode 100644 test/models/renew_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index a955f68..805b5d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -244,6 +244,3 @@ DEPENDENCIES uglifier (>= 1.3.0) unicorn (= 4.6.3) wicked_pdf - -BUNDLED WITH - 1.16.1 diff --git a/app/assets/javascripts/public.js.coffee b/app/assets/javascripts/public.js.coffee index c76a630..692cfb7 100644 --- a/app/assets/javascripts/public.js.coffee +++ b/app/assets/javascripts/public.js.coffee @@ -4,7 +4,7 @@ #= require jquery.bxslider #= require jquery.easing.1.3 - +#= require nested_fields @scrollToAnchor = (aid) -> diff --git a/app/assets/javascripts/public_nested_fields copy.coffee b/app/assets/javascripts/public_nested_fields copy.coffee new file mode 100644 index 0000000..5e1756f --- /dev/null +++ b/app/assets/javascripts/public_nested_fields copy.coffee @@ -0,0 +1,11 @@ + +@remove_fields = (link) -> + $(link).prev("input[type=hidden]").val "1" + $(link).closest(".field").hide() + false +@add_fields = (link, association, content) -> + new_id = new Date().getTime() + regexp = new RegExp("new_" + association, "g") + $(link).closest("p").next("." + association + "_form").prepend content.replace(regexp, new_id).replace(association + "_class", "new_field") + $(".new_field").removeClass "new_field" + false \ No newline at end of file diff --git a/app/assets/stylesheets/public/top.css.scss b/app/assets/stylesheets/public/top.css.scss index c21b008..474a07e 100644 --- a/app/assets/stylesheets/public/top.css.scss +++ b/app/assets/stylesheets/public/top.css.scss @@ -62,6 +62,9 @@ } #personnal_menu{ + position:absolute; + top:15px; + right:35px; a{ margin:0; @@ -83,9 +86,7 @@ opacity:1; color:rgba(116,180,55,1); } - position:absolute; - top:15px; - right:35px; + } } diff --git a/app/controllers/admin/sheets_controller.rb b/app/controllers/admin/sheets_controller.rb index 4378581..295a290 100644 --- a/app/controllers/admin/sheets_controller.rb +++ b/app/controllers/admin/sheets_controller.rb @@ -110,7 +110,7 @@ class Admin::SheetsController < ApplicationController @sheet = Sheet.find(params[:id]) else - + render :action => "edit" end end diff --git a/app/controllers/public/joins_controller.rb b/app/controllers/public/joins_controller.rb new file mode 100644 index 0000000..f2a91ca --- /dev/null +++ b/app/controllers/public/joins_controller.rb @@ -0,0 +1,308 @@ +# -*- encoding : utf-8 -*- + +class Public::JoinsController < ApplicationController + + layout "public" + skip_before_filter :verify_authenticity_token, :only => [:ipn] + + + def select_sheet + + if !session[:sheet_id] or !(@sheet = Sheet.where(:id => session[:sheet_id]).first) + @sheet = Sheet.new(:sheet_type => 1, :web => true) + @sheet.people.build(:web => true) + @sheet.sheet_years.build(:year => Renew::YEAR, :payment_type => 3) + else + + end + + + + end + + def save_sheet + + + if !session[:sheet_id] or !(@sheet = Sheet.where(:id => session[:sheet_id]).first) + @sheet = Sheet.new(params.require(:sheet).permit!) + + + if @sheet.save + session[:sheet_id] = @sheet.id + + if @sheet.sheet_years.first.payment_type == 3 + redirect_to paid_by_paypal_public_joins_path + else + redirect_to paid_public_joins_path + end + + else + render action: "select_sheet" + + end + else + if @sheet.update_attributes(params.require(:sheet).permit!) + session[:sheet_id] = @sheet.id + + if @sheet.sheet_years.first.payment_type == 3 + redirect_to paid_by_paypal_public_joins_path + else + redirect_to paid_public_joins_path + end + + else + render action: "select_sheet" + + end + + + end + + end + + + + + def paid + @sheet = Sheet.where(:id => session[:sheet_id]).first + if !@sheet or @sheet.ok + redirect_to select_sheet_public_joins_path + else + + respond_to do |format| + format.html { } + + end + + + end + end + + def paid_by_paypal + @sheet = Sheet.where(:id => session[:sheet_id]).first + + if @sheet and !@sheet.ok + + + + + require 'paypal-sdk-merchant' + @api = PayPal::SDK::Merchant::API.new + + + @set_express_checkout = @api.build_set_express_checkout({ + :SetExpressCheckoutRequestDetails => { + :custom => @sheet.id, + :ReturnURL => do_paypal_payment_public_joins_url, + :CancelURL => select_sheet_public_joins_url(), + :NoShipping => 1, + :PaymentDetails => [{ + :OrderTotal => { + :currencyID => "EUR", + :value =>@sheet.sheet_years.first.amount }, + + :NotifyURL => "http://lepicvert.org"+ipn_public_joins_path, + + :PaymentDetailsItem => [{:Name => "Nouvelle adhésion",:Quantity => 1,:Amount => {:currencyID => "EUR",:value => @sheet.sheet_years.first.amount } }], + :PaymentAction => "Sale" }] } }) + + # Make API call & get response + @set_express_checkout_response = @api.set_express_checkout(@set_express_checkout) + + # Access Response + if @set_express_checkout_response.success? + + @get_express_checkout_details = @api.build_get_express_checkout_details({ + :Token => @sheet.id }) + + @get_express_checkout_details_response = @api.get_express_checkout_details(@get_express_checkout_details) + + + + + @payment_detail = @get_express_checkout_details_response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0] + + + redirect_to @api.express_checkout_url(@set_express_checkout_response.Token) + else + @set_express_checkout_response.Errors + end + + else + redirect_to select_sheet_public_joins_path() + end + + end + + + + def do_paypal_payment + + + require 'paypal-sdk-merchant' + @api = PayPal::SDK::Merchant::API.new + + + @get_express_checkout_details = @api.build_get_express_checkout_details({:Token => params[:token] }) + + @get_express_checkout_details_response = @api.get_express_checkout_details(@get_express_checkout_details) + + + + + # Access Response + if @get_express_checkout_details_response.success? + + @sheet = Sheet.find(@get_express_checkout_details_response.GetExpressCheckoutDetailsResponseDetails.Custom.to_s) + puts "AAA" + puts @get_express_checkout_details_response.GetExpressCheckoutDetailsResponseDetails.Custom.to_s + + else + + + @get_express_checkout_details_response.Errors + end + + # Build request object + @do_express_checkout_payment = @api.build_do_express_checkout_payment({ + :DoExpressCheckoutPaymentRequestDetails => { + :PaymentAction => "Sale", + :Token => params[:token], + :PayerID => params[:PayerID], + :PaymentDetails => [{ + :OrderTotal => { + :currencyID => "EUR", + :value => @sheet.sheet_years.first.amount }, + :NotifyURL => "http://lepicvert.org"+ipn_public_joins_path }] } }) + + # Make API call & get response + @do_express_checkout_payment_response = @api.do_express_checkout_payment(@do_express_checkout_payment) + + # Access Response + if @do_express_checkout_payment_response.success? + @payment_info = @do_express_checkout_payment_response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0] + + @do_express_checkout_payment_response.DoExpressCheckoutPaymentResponseDetails + @do_express_checkout_payment_response.FMFDetails + + + + + + + + + if @payment_info.PaymentStatus.to_s == "Completed" + + @sheet.ok = true + @sheet.save + @sheet.done_return + session[:sheet_id] = nil + + redirect_to thanks_public_joins_url + + else + render :file => 'public/500.html', :status => 500, :layout => false + + end + + + + + + + + else + render :file => 'public/500.html', :status => 500, :layout => false + end + + + + + end + + def ipn + + + @api = PayPal::SDK::Merchant.new + if @api.ipn_valid?(request.raw_post) # return true or false + @sheet = Order.find_by_token(params[:custom].to_s) + if params[:payment_status] == "Completed" + + + + @sheet.paypal_test_ipn= params[:test_ipn] + + @sheet.paypal_txn_type = params[:txn_type] + @sheet.paypal_txn_id = params[:txn_id] + @sheet.paypal_payment_date = params[:payment_date] + + @sheet.paypal_payment_status = params[:payment_status] + @sheet.paypal_reason_code = params[:reason_code] + @sheet.paypal_payment_type = params[:payment_type] + + @sheet.paypal_mc_currency = params[:mc_currency] + @sheet.paypal_mc_fee = params[:mc_fee] + @sheet.paypal_mc_gross = params[:mc_gross] + + @sheet.paypal_residence_country = params[:residence_country] + @sheet.paypal_last_name = params[:last_name] + @sheet.paypal_first_name = params[:first_name] + @sheet.paypal_payer_email = params[:payer_email] + @sheet.paypal_payer_id = params[:payer_id] + @sheet.paypal_payer_status = params[:payer_status] + + @sheet.paypal_receiver_id = params[:receiver_id] + @sheet.paypal_receiver_email = params[:receiver_email] + + @sheet.paypal_protection_eligibility = params[:protection_eligibility] + @sheet.paypal_ipn_track_id = params[:ipn_track_id] + + @sheet.save + puts "le paiement de la commande #{@sheet.id} par paypal est validé" + + else + @sheet.paypal_test_ipn= params[:test_ipn] + + @sheet.paypal_txn_type = params[:txn_type] + @sheet.paypal_txn_id = params[:txn_id] + @sheet.paypal_payment_date = params[:payment_date] + + @sheet.paypal_payment_status = params[:payment_status] + @sheet.paypal_reason_code = params[:reason_code] + @sheet.paypal_payment_type = params[:payment_type] + + @sheet.paypal_mc_currency = params[:mc_currency] + @sheet.paypal_mc_fee = params[:mc_fee] + @sheet.paypal_mc_gross = params[:mc_gross] + + @sheet.paypal_residence_country = params[:residence_country] + @sheet.paypal_last_name = params[:last_name] + @sheet.paypal_first_name = params[:first_name] + @sheet.paypal_payer_email = params[:payer_email] + @sheet.paypal_payer_id = params[:payer_id] + @sheet.paypal_payer_status = params[:payer_status] + + @sheet.paypal_receiver_id = params[:receiver_id] + @sheet.paypal_receiver_email = params[:receiver_email] + + @sheet.paypal_protection_eligibility = params[:protection_eligibility] + @sheet.paypal_ipn_track_id = params[:ipn_track_id] + @sheet.ok = false + + @sheet.save + + @sheet.done_return + + end + + else + + end + render :inline => "test" + end + + + + +end diff --git a/app/controllers/public/renews_controller.rb b/app/controllers/public/renews_controller.rb new file mode 100644 index 0000000..575e329 --- /dev/null +++ b/app/controllers/public/renews_controller.rb @@ -0,0 +1,273 @@ +# -*- encoding : utf-8 -*- + +class Public::RenewsController < ApplicationController + + layout "public" + skip_before_filter :verify_authenticity_token, :only => [:ipn] + + + def select_sheet + @renew = Renew.new(:sheet_number => params[:s]) + end + + def save_sheet + @renew = Renew.new(params.require(:renew).permit!) + + + if @renew.save + session[:renew_id] = @renew.id + redirect_to paid_by_paypal_public_renews_index_path + + else + render action: "select_sheet" + + end + end + + + + + def paid + @renew = Order.find_by_token(params[:id]) + if @renew.paid + redirect_to public_order_path(@renew.token) + else + + respond_to do |format| + format.html { redirect_to paid_by_paypal_public_order_path(@renew.token)} + + end + + + end + end + + def paid_by_paypal + @renew = Renew.where(:id => session[:renew_id]).first + + if @renew and !@renew.ok + + + + + require 'paypal-sdk-merchant' + @api = PayPal::SDK::Merchant::API.new + + + @set_express_checkout = @api.build_set_express_checkout({ + :SetExpressCheckoutRequestDetails => { + :custom => @renew.id, + :ReturnURL => do_paypal_payment_public_renews_index_url, + :CancelURL => select_sheet_public_renews_index_url(), + :NoShipping => 1, + :PaymentDetails => [{ + :OrderTotal => { + :currencyID => "EUR", + :value =>@renew.price }, + + :NotifyURL => "http://lepicvert.org"+ipn_public_renews_index_path, + + :PaymentDetailsItem => [{:Name => "Renouvellement adhésion",:Quantity => 1,:Amount => {:currencyID => "EUR",:value => @renew.price } }], + :PaymentAction => "Sale" }] } }) + + # Make API call & get response + @set_express_checkout_response = @api.set_express_checkout(@set_express_checkout) + + # Access Response + if @set_express_checkout_response.success? + + @get_express_checkout_details = @api.build_get_express_checkout_details({ + :Token => @renew.id }) + + @get_express_checkout_details_response = @api.get_express_checkout_details(@get_express_checkout_details) + + + + + @payment_detail = @get_express_checkout_details_response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0] + + + redirect_to @api.express_checkout_url(@set_express_checkout_response.Token) + else + @set_express_checkout_response.Errors + end + + else + redirect_to select_sheet_public_renews_path() + end + + end + + + + def do_paypal_payment + + + require 'paypal-sdk-merchant' + @api = PayPal::SDK::Merchant::API.new + + + @get_express_checkout_details = @api.build_get_express_checkout_details({:Token => params[:token] }) + + @get_express_checkout_details_response = @api.get_express_checkout_details(@get_express_checkout_details) + + + + + # Access Response + if @get_express_checkout_details_response.success? + + @renew = Renew.find(@get_express_checkout_details_response.GetExpressCheckoutDetailsResponseDetails.Custom.to_s) + puts "AAA" + puts @get_express_checkout_details_response.GetExpressCheckoutDetailsResponseDetails.Custom.to_s + + else + + + @get_express_checkout_details_response.Errors + end + + # Build request object + @do_express_checkout_payment = @api.build_do_express_checkout_payment({ + :DoExpressCheckoutPaymentRequestDetails => { + :PaymentAction => "Sale", + :Token => params[:token], + :PayerID => params[:PayerID], + :PaymentDetails => [{ + :OrderTotal => { + :currencyID => "EUR", + :value => @renew.price }, + :NotifyURL => "http://lepicvert.org"+ipn_public_renews_index_path }] } }) + + # Make API call & get response + @do_express_checkout_payment_response = @api.do_express_checkout_payment(@do_express_checkout_payment) + + # Access Response + if @do_express_checkout_payment_response.success? + @payment_info = @do_express_checkout_payment_response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0] + + @do_express_checkout_payment_response.DoExpressCheckoutPaymentResponseDetails + @do_express_checkout_payment_response.FMFDetails + + + + + + + + + if @payment_info.PaymentStatus.to_s == "Completed" + @renew.payment_type_id = 3 + @renew.ok = true + @renew.save + @renew.done_return + + redirect_to thanks_public_renews_index_url + + else + render :file => 'public/500.html', :status => 500, :layout => false + + end + + + + + + + + else + render :file => 'public/500.html', :status => 500, :layout => false + end + + + + + end + + def ipn + + + @api = PayPal::SDK::Merchant.new + if @api.ipn_valid?(request.raw_post) # return true or false + @renew = Order.find_by_token(params[:custom].to_s) + if params[:payment_status] == "Completed" + + + @renew.payment_type_id = 3 + @renew.ok = true + + @renew.paypal_test_ipn= params[:test_ipn] + + @renew.paypal_txn_type = params[:txn_type] + @renew.paypal_txn_id = params[:txn_id] + @renew.paypal_payment_date = params[:payment_date] + + @renew.paypal_payment_status = params[:payment_status] + @renew.paypal_reason_code = params[:reason_code] + @renew.paypal_payment_type = params[:payment_type] + + @renew.paypal_mc_currency = params[:mc_currency] + @renew.paypal_mc_fee = params[:mc_fee] + @renew.paypal_mc_gross = params[:mc_gross] + + @renew.paypal_residence_country = params[:residence_country] + @renew.paypal_last_name = params[:last_name] + @renew.paypal_first_name = params[:first_name] + @renew.paypal_payer_email = params[:payer_email] + @renew.paypal_payer_id = params[:payer_id] + @renew.paypal_payer_status = params[:payer_status] + + @renew.paypal_receiver_id = params[:receiver_id] + @renew.paypal_receiver_email = params[:receiver_email] + + @renew.paypal_protection_eligibility = params[:protection_eligibility] + @renew.paypal_ipn_track_id = params[:ipn_track_id] + + @renew.save + puts "le paiement de la commande #{@renew.id} par paypal est validé" + + else + @renew.paypal_test_ipn= params[:test_ipn] + + @renew.paypal_txn_type = params[:txn_type] + @renew.paypal_txn_id = params[:txn_id] + @renew.paypal_payment_date = params[:payment_date] + + @renew.paypal_payment_status = params[:payment_status] + @renew.paypal_reason_code = params[:reason_code] + @renew.paypal_payment_type = params[:payment_type] + + @renew.paypal_mc_currency = params[:mc_currency] + @renew.paypal_mc_fee = params[:mc_fee] + @renew.paypal_mc_gross = params[:mc_gross] + + @renew.paypal_residence_country = params[:residence_country] + @renew.paypal_last_name = params[:last_name] + @renew.paypal_first_name = params[:first_name] + @renew.paypal_payer_email = params[:payer_email] + @renew.paypal_payer_id = params[:payer_id] + @renew.paypal_payer_status = params[:payer_status] + + @renew.paypal_receiver_id = params[:receiver_id] + @renew.paypal_receiver_email = params[:receiver_email] + + @renew.paypal_protection_eligibility = params[:protection_eligibility] + @renew.paypal_ipn_track_id = params[:ipn_track_id] + @renew.ok = false + + @renew.save + + @renew.done_return + + end + + else + + end + render :inline => "test" + end + + + + +end diff --git a/app/helpers/document_line_helper.rb b/app/helpers/document_line_helper.rb index fa7c2d5..288994a 100644 --- a/app/helpers/document_line_helper.rb +++ b/app/helpers/document_line_helper.rb @@ -13,5 +13,14 @@ module DocumentLineHelper end link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\");") end + + + def public_link_to_add_fields(name, f, association) + new_object = f.object.class.reflect_on_association(association).klass.new() + fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| + render("public/"+association.to_s + "/form", :form => builder) + end + link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\");") + end end diff --git a/app/models/person.rb b/app/models/person.rb index e20240b..7e5dca1 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -9,7 +9,15 @@ class Person < ActiveRecord::Base validates :surname, :presence => true validates :firstname, :presence => true + + + validates :email, :presence => true, :if => :web? + # validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } + attr_accessor :web + def web? + true if self.web + end def name self.firstname.to_s+" "+self.surname.to_s end diff --git a/app/models/renew.rb b/app/models/renew.rb new file mode 100644 index 0000000..6b6d5b1 --- /dev/null +++ b/app/models/renew.rb @@ -0,0 +1,55 @@ +class Renew < ActiveRecord::Base + belongs_to :sheet + + validates :sheet_number, :presence => true + + validates :email, :presence => true + validates :payment_type_id, :presence => true + + validates :join_type, :presence => true + + before_validation do + self.payment_type_id = 3 + + if self.join_type == 1 + self.price = 10.0 + elsif self.join_type == 2 + self.price = 15.0 + else + self.price = nil + end + + + if self.sheet_number + self.sheet = Sheet.where(:sheet_number => self.sheet_number).first + if !self.sheet + errors.add(:sheet_number, "Numéro d'adhérent invalide") + + end + end + end + + YEAR = 2019 + + def done_return + if self.ok and !self.return_done + + + + 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, ) + + if sheet_year.save + self.return_done = true + self.save + else + false + + end + + end + end +end + + + + diff --git a/app/models/sheet.rb b/app/models/sheet.rb index 39ae7ce..260ef50 100644 --- a/app/models/sheet.rb +++ b/app/models/sheet.rb @@ -13,6 +13,10 @@ class Sheet < ActiveRecord::Base validates :sheet_type, :presence => true + validates :address, :presence => true, :if => :web? + validates :pc, :presence => true, :if => :web? + validates :city, :presence => true, :if => :web? + validates :country, :presence => true, :if => :web? #attr_accessible :donates_attributes, :sheet_type, :people_attributes, :sheet_years_attributes, :corporate, :address, :address2, :address3, :pc, :city, :country, :skills, :other_mail, :other_phone @@ -23,6 +27,40 @@ class Sheet < ActiveRecord::Base SHEET_TYPE = {1 => "adherent",2 => "sympathisant"} + attr_accessor :error_join + + before_validation do + if self.sheet_years[0] + if self.sheet_years[0].join_type == 1 + self.sheet_years[0].amount = 10 + elsif self.sheet_years[0].join_type == 2 + self.sheet_years[0].amount = 15 + end + end + + if self.web + if self.people.size > 1 + if self.sheet_years[0] + if self.sheet_years[0].join_type == 1 + #dsffsd = dssfd + self.errors.add(:error_join, "Vous devez sélectionner l'adhésion familiale si vous voulez spécifier plusieurs personnes") + end + end + end + end + end + + def done_return + self.sheet_years.first.payment_type = 3 + self.sheet_years.first.paid_at = Date.today + + self.sheet_years.first.save + + self.return_done = true + self.save + end + + after_create do self.generate_sheet_number self.generate_token @@ -65,6 +103,7 @@ class Sheet < ActiveRecord::Base requette += "(sheet_type IN(?))" if input[:sheet_type] requette += " AND " if (input[:sheet_year] or input[:sheet_type]) and input[:sheet_city] requette += "(city IN(?))" if input[:sheet_city] + requette += " AND web = 1" if input[:web] conditions = [] conditions << requette conditions << input[:sheet_year] if input[:sheet_year] diff --git a/app/models/sheet_year.rb b/app/models/sheet_year.rb index 982f63a..4aa0ece 100644 --- a/app/models/sheet_year.rb +++ b/app/models/sheet_year.rb @@ -7,7 +7,7 @@ class SheetYear < ActiveRecord::Base #attr_accessible :year, :join_type, :benefactor, :gift_year, :paid_at, :amount, :payment_type, :bank, :check_number, :sheet_id, :plume JOIN_TYPE = {1 => "Individuel", 2 => "Familial", 3 =>"Association"} - PAYMENT_TYPE = {1 => "Chèque", 2 => "Liquide"} + PAYMENT_TYPE = {1 => "Chèque", 2 => "Liquide", 3 => "Paypal (ou carte bancaire)"} after_save do diff --git a/app/views/admin/sheets/_sheets_search.html.haml b/app/views/admin/sheets/_sheets_search.html.haml index 90852b6..f1183cc 100644 --- a/app/views/admin/sheets/_sheets_search.html.haml +++ b/app/views/admin/sheets/_sheets_search.html.haml @@ -43,7 +43,11 @@ %br %br - %br + %h4 Provenance : + =check_box_tag "sheet_filter[web][]", 1, (true if params[:sheet_filter] and params[:sheet_filter][:web] and params[:sheet_filter][:web].include?("1")) + Web + + %br %br %br diff --git a/app/views/public/joins/paid.html.haml b/app/views/public/joins/paid.html.haml new file mode 100644 index 0000000..2013891 --- /dev/null +++ b/app/views/public/joins/paid.html.haml @@ -0,0 +1,40 @@ +%h1 Adhérer + +%p + + +=semantic_form_for @sheet, :url => save_sheet_public_joins_path(), :html => {:method => :get} do |form| + + =form.inputs do + + + %h3 + Votre adhésion + =Renew::YEAR + =":" + + %p + Merci de nous envoyer votre chèque de réglement par courrier ou de passer régler votre adhésion en espèce au local de l'association : 24 place de la Mairie, 38140 Réaumont + + .sheet_years_form + =form.semantic_fields_for :sheet_years do |f| + .field + =f.hidden_field :year + %br + =form.input :error_join, :label => false, :input_html => {:style => "display:none;"} + + %p + Montant de l'adhésion : + =number_to_currency f.object.amount + =# f.input :join_type, :collection => {"Individuel (10€)" => 1, "Familial (15€)" => 2}, :as => :select, :label => "Type d'adhésion :", :include_blank => false + + + + = f.input :payment_type, :collection => SheetYear::PAYMENT_TYPE.map {|u| [u[1], u[0]] }, :as => :select, :label => "Type de paiement : ", :include_blank => false + + + + + + = form.submit 'Changer mon mode de paiement', :class => "btn btn-success" + \ No newline at end of file diff --git a/app/views/public/joins/paid_by_paypal.haml b/app/views/public/joins/paid_by_paypal.haml new file mode 100644 index 0000000..5330180 --- /dev/null +++ b/app/views/public/joins/paid_by_paypal.haml @@ -0,0 +1,5 @@ +%br + +%br +%br +=debug @set_express_checkout_response.Errors \ No newline at end of file diff --git a/app/views/public/joins/save_sheet.html.haml b/app/views/public/joins/save_sheet.html.haml new file mode 100644 index 0000000..f426843 --- /dev/null +++ b/app/views/public/joins/save_sheet.html.haml @@ -0,0 +1 @@ +=debug @sheet.sheet_years \ No newline at end of file diff --git a/app/views/public/joins/select_sheet.html.haml b/app/views/public/joins/select_sheet.html.haml new file mode 100644 index 0000000..4988b70 --- /dev/null +++ b/app/views/public/joins/select_sheet.html.haml @@ -0,0 +1,66 @@ +%h1 Adhérer + +%p + + +=semantic_form_for @sheet, :url => save_sheet_public_joins_path(), :html => {:method => :get} do |form| + + =form.inputs do + + =form.hidden_field :sheet_type + =form.hidden_field :web + + %h3 Foyer + %p= public_link_to_add_fields "Ajouter une personne (attention, si vous indiquez plusieurs personnes vous devez prendre une adhésion familiale)", form, :people + + .people_form + =form.semantic_fields_for :people do |form| + =render :partial => "public/people/form", :locals => {:form => form} + + %h3 Généralités + + =form.hidden_field :corporate + + =form.input :address, :label => "Adresse" + =form.input :address2, :label => "Adresse (suite)" + =form.input :address3, :label => "Adresse (suite)" + =form.input :pc, :label => "Code postal" + =form.input :city, :label => "Ville" + =form.input :country, :label => "Pays", :as => :string + =#form.input :skills, :label => "Compétences" + =#form.input :other_mail, :label => "Autre mail :" + =#form.input :other_phone, :label => "Autre téléphone : " + + %h3 + Votre adhésion + =Renew::YEAR + =":" + + .sheet_years_form + =form.semantic_fields_for :sheet_years do |f| + .field + =f.hidden_field :year + %br + =form.input :error_join, :label => false, :input_html => {:style => "display:none;"} + + = f.input :join_type, :collection => {"Individuel (10€)" => 1, "Familial (15€)" => 2}, :as => :select, :label => "Type d'adhésion :", :include_blank => false + -if false + = f.label :benefactor, "Bienfaiteur : " + = f.check_box :benefactor + + %br + = f.label :gift_year, "Année d'adhésion offerte : " + = f.check_box :gift_year, :onchange => "payment_form($(this));" + + %br + + + + = f.input :payment_type, :collection => SheetYear::PAYMENT_TYPE.map {|u| [u[1], u[0]] }, :as => :select, :label => "Type de paiement : ", :include_blank => false + + + + + + = form.submit 'Adhérer', :class => "btn btn-success" + \ No newline at end of file diff --git a/app/views/public/joins/thanks.html.haml b/app/views/public/joins/thanks.html.haml new file mode 100644 index 0000000..2b4fadc --- /dev/null +++ b/app/views/public/joins/thanks.html.haml @@ -0,0 +1 @@ +%p Merci ! Votre adhésion a bien été enregistrée. \ No newline at end of file diff --git a/app/views/public/people/_form.html.haml b/app/views/public/people/_form.html.haml new file mode 100644 index 0000000..a9c7468 --- /dev/null +++ b/app/views/public/people/_form.html.haml @@ -0,0 +1,19 @@ +.field + .person_form + + .person + + =form.hidden_field :newsletter + =form.hidden_field :web + %table + %tr + + %td=form.input :surname, :label => "Nom" + %td=form.input :firstname, :label => "Prénom" + %td=form.input :email, :label => "Email" + %td{:style => "vertical-align:top;"}=form.input :phone, :label => "Tél" + %td +     + = link_to_remove_fields i(:"trash-o"), form + + \ No newline at end of file diff --git a/app/views/public/people/_person.html.haml b/app/views/public/people/_person.html.haml new file mode 100644 index 0000000..084aad6 --- /dev/null +++ b/app/views/public/people/_person.html.haml @@ -0,0 +1,32 @@ +#sheet_person.line_sheet_block{:id => person.id} + %table{:style => "width:100%;"} + %tr + %td{:style => "width:16%;"}= "Oui" if person.newsletter + + %td{:style => "width:16%;"}= person.surname + + %td{:style => "width:16%;"}= person.firstname + + %td{:style => "width:16%;"}= person.email + + %td{:style => "width:16%;"}= person.phone + + %td{:style => "width:16%;"}= person.job + %tr + %td{:colspan => 5} + -person.newsgroups.each do |ng| + ="| "+ng.name+" |" + + + + %td{:style => "width:16%;text-align:right;"} + -if has_permission?('adherent.edit') + + -if person == person.sheet.person + -img = image_tag("/images/style/quartz-admin/principal_active.png") + -else + -img = image_tag("/images/style/quartz-admin/principal.png") + = link_to img, :url => principal_admin_person_path(person), :method => :get, :remote => true + + -else + =image_tag("/images/style/quartz-admin/principal_active.png") if person == person.sheet.person \ No newline at end of file diff --git a/app/views/public/renews/paid_by_paypal.haml b/app/views/public/renews/paid_by_paypal.haml new file mode 100644 index 0000000..5330180 --- /dev/null +++ b/app/views/public/renews/paid_by_paypal.haml @@ -0,0 +1,5 @@ +%br + +%br +%br +=debug @set_express_checkout_response.Errors \ No newline at end of file diff --git a/app/views/public/renews/select_sheet.html.haml b/app/views/public/renews/select_sheet.html.haml new file mode 100644 index 0000000..55b1b31 --- /dev/null +++ b/app/views/public/renews/select_sheet.html.haml @@ -0,0 +1,19 @@ +%h1 Renouveller mon adhésion + +%p Pour renouveller votre adhésion vous pouvez indiquer votre numéro d'adhérent ci-dessous : + +=semantic_form_for @renew, :url => save_sheet_public_renews_index_path(), :html => {:method => :get} do |f| + + -f.inputs do + + =f.input :sheet_number, :label => "Numéro d'adhérent :" + + =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.submit "Renouveller mon adhésion par CB" + diff --git a/app/views/public/renews/thanks.html.haml b/app/views/public/renews/thanks.html.haml new file mode 100644 index 0000000..4f1d09a --- /dev/null +++ b/app/views/public/renews/thanks.html.haml @@ -0,0 +1 @@ +%p Merci ! Votre renouvellement a bien été enregistré. \ No newline at end of file diff --git a/app/views/public/shared/_top.html.haml b/app/views/public/shared/_top.html.haml index 8e6f456..9e680e7 100644 --- a/app/views/public/shared/_top.html.haml +++ b/app/views/public/shared/_top.html.haml @@ -2,6 +2,9 @@ =link_to image_tag("/logo_pic_vert_w.png", :id => "logo"), "/" #personnal_menu + + =link_to "Rennouveler mon adhésion »", select_sheet_public_renews_index_path + =link_to "Adhérer »", select_sheet_public_joins_path =link_to "Accès au forum »", "/forum" #menu diff --git a/config/routes.rb b/config/routes.rb index ed93bc8..6affec8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,6 +36,32 @@ Survey::Application.routes.draw do namespace :public do + + resources :renews do + collection do + get :select_sheet + get :save_sheet + get :paid_by_paypal + get :do_paypal_payment + post :ipn + get :thanks + end + end + + resources :joins do + collection do + get :select_sheet + get :save_sheet + get :paid_by_paypal + get :paid + get :do_paypal_payment + post :ipn + get :thanks + end + end + + + resources :faqs resources :plumes do diff --git a/db/migrate/20190314212540_add_web_to_sheets.rb b/db/migrate/20190314212540_add_web_to_sheets.rb new file mode 100644 index 0000000..b0003b3 --- /dev/null +++ b/db/migrate/20190314212540_add_web_to_sheets.rb @@ -0,0 +1,7 @@ +class AddWebToSheets < ActiveRecord::Migration + def change + add_column :sheets, :web, :boolean, :default => false + add_column :sheets, :return_done,:boolean, :default => false + add_column :sheets, :ok, :boolean, :default => false + end +end diff --git a/db/migrate/20190314212933_create_renews.rb b/db/migrate/20190314212933_create_renews.rb new file mode 100644 index 0000000..fe755b7 --- /dev/null +++ b/db/migrate/20190314212933_create_renews.rb @@ -0,0 +1,45 @@ +class CreateRenews < ActiveRecord::Migration + def change + create_table :renews do |t| + t.integer :year + t.references :sheet, index: true + t.string :sheet_number + t.integer :join_type + t.boolean :ok, :default => false + t.integer :payment_type_id + + t.string :paypal_test_ipn + + t.string :paypal_txn_type + t.string :paypal_txn_id + t.datetime :paypal_payment_date + + t.string :paypal_payment_status + t.string :paypal_reason_code + t.string :paypal_payment_type + + t.string :paypal_mc_currency + t.string :paypal_mc_fee + t.string :paypal_mc_gross + + t.string :paypal_residence_country + t.string :paypal_last_name + t.string :paypal_first_name + t.string :paypal_payer_email + t.string :paypal_payer_id + t.string :paypal_payer_status + + t.string :paypal_receiver_id + t.string :paypal_receiver_email + + t.string :paypal_protection_eligibility + t.string :paypal_ipn_track_id + + t.string :email + + t.decimal :price, :precision => 10, :scale => 2 + t.boolean :return_done, :default => false + t.timestamps + end + end +end diff --git a/db/migrate/20190315002155_add_paypal_to_sheets.rb b/db/migrate/20190315002155_add_paypal_to_sheets.rb new file mode 100644 index 0000000..0667188 --- /dev/null +++ b/db/migrate/20190315002155_add_paypal_to_sheets.rb @@ -0,0 +1,35 @@ +class AddPaypalToSheets < ActiveRecord::Migration + def change + add_column :sheets, :paypal, :string + + + + add_column :sheets, :paypal_test_ipn, :string + + add_column :sheets, :paypal_txn_type, :string + add_column :sheets, :paypal_txn_id, :string + add_column :sheets, :paypal_payment_date, :datetime + + add_column :sheets, :paypal_payment_status, :string + add_column :sheets, :paypal_reason_code, :string + add_column :sheets, :paypal_payment_type, :string + + add_column :sheets, :paypal_mc_currency, :string + add_column :sheets, :paypal_mc_fee, :string + add_column :sheets, :paypal_mc_gross, :string + + add_column :sheets, :paypal_residence_country, :string + add_column :sheets, :paypal_last_name, :string + add_column :sheets, :paypal_first_name, :string + add_column :sheets, :paypal_payer_email, :string + add_column :sheets, :paypal_payer_id, :string + add_column :sheets, :paypal_payer_status, :string + + add_column :sheets, :paypal_receiver_id, :string + add_column :sheets, :paypal_receiver_email, :string + + add_column :sheets, :paypal_protection_eligibility, :string + add_column :sheets, :paypal_ipn_track_id, :string + + end +end diff --git a/db/schema.rb b/db/schema.rb index 7a056d9..c6a5e41 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: 20180528150643) do +ActiveRecord::Schema.define(version: 20190315002155) do create_table "admins", force: true do |t| t.string "email", default: "", null: false @@ -751,6 +751,42 @@ ActiveRecord::Schema.define(version: 20180528150643) do add_index "question_sets", ["survey_item_id"], name: "index_question_sets_on_survey_item_id", using: :btree add_index "question_sets", ["survey_set_id"], name: "index_question_sets_on_survey_set_id", using: :btree + create_table "renews", force: true do |t| + t.integer "year" + t.integer "sheet_id" + t.string "sheet_number" + t.integer "join_type" + t.boolean "ok", default: false + t.integer "payment_type_id" + t.string "paypal_test_ipn" + t.string "paypal_txn_type" + t.string "paypal_txn_id" + t.datetime "paypal_payment_date" + t.string "paypal_payment_status" + t.string "paypal_reason_code" + t.string "paypal_payment_type" + t.string "paypal_mc_currency" + t.string "paypal_mc_fee" + t.string "paypal_mc_gross" + t.string "paypal_residence_country" + t.string "paypal_last_name" + t.string "paypal_first_name" + t.string "paypal_payer_email" + t.string "paypal_payer_id" + t.string "paypal_payer_status" + t.string "paypal_receiver_id" + t.string "paypal_receiver_email" + t.string "paypal_protection_eligibility" + t.string "paypal_ipn_track_id" + t.string "email" + t.decimal "price", precision: 10, scale: 2 + t.boolean "return_done", default: false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "renews", ["sheet_id"], name: "index_renews_on_sheet_id", using: :btree + create_table "sheet_years", force: true do |t| t.integer "year" t.integer "join_type" @@ -787,6 +823,30 @@ ActiveRecord::Schema.define(version: 20180528150643) do t.boolean "plume" t.string "token" t.string "sheet_number" + t.boolean "web", default: false + t.boolean "return_done", default: false + t.boolean "ok", default: false + t.string "paypal" + t.string "paypal_test_ipn" + t.string "paypal_txn_type" + t.string "paypal_txn_id" + t.datetime "paypal_payment_date" + t.string "paypal_payment_status" + t.string "paypal_reason_code" + t.string "paypal_payment_type" + t.string "paypal_mc_currency" + t.string "paypal_mc_fee" + t.string "paypal_mc_gross" + t.string "paypal_residence_country" + t.string "paypal_last_name" + t.string "paypal_first_name" + t.string "paypal_payer_email" + t.string "paypal_payer_id" + t.string "paypal_payer_status" + t.string "paypal_receiver_id" + t.string "paypal_receiver_email" + t.string "paypal_protection_eligibility" + t.string "paypal_ipn_track_id" end create_table "survey_item_answers", force: true do |t| diff --git a/test/fixtures/renews.yml b/test/fixtures/renews.yml new file mode 100644 index 0000000..b681b4c --- /dev/null +++ b/test/fixtures/renews.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + year: 1 + sheet_id: + sheet_number: MyString + join_type: 1 + ok: false + +two: + year: 1 + sheet_id: + sheet_number: MyString + join_type: 1 + ok: false diff --git a/test/models/renew_test.rb b/test/models/renew_test.rb new file mode 100644 index 0000000..85395c4 --- /dev/null +++ b/test/models/renew_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RenewTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end