diff --git a/Gemfile b/Gemfile
index a1ce351..70f6a94 100644
--- a/Gemfile
+++ b/Gemfile
@@ -108,3 +108,5 @@ gem 'axlsx', '3.0.0.pre'
gem 'axlsx_rails'
gem 'iban-tools'
+
+gem "mailjet"
diff --git a/Gemfile.lock b/Gemfile.lock
index 0f65dee..f6c7066 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -126,6 +126,8 @@ GEM
countries (~> 3.0)
sort_alphabetical (~> 1.0)
crass (1.0.4)
+ domain_name (0.5.20190701)
+ unf (>= 0.0.5, < 1.0.0)
elasticsearch (7.3.0)
elasticsearch-api (= 7.3.0)
elasticsearch-transport (= 7.3.0)
@@ -165,6 +167,9 @@ GEM
nokogiri (>= 1.6.0)
ruby_parser (~> 3.5)
htmlentities (4.3.4)
+ http-accept (1.7.0)
+ http-cookie (1.0.3)
+ domain_name (~> 0.5)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
i18n_data (0.8.0)
@@ -209,9 +214,16 @@ GEM
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
+ mailjet (1.5.4)
+ activesupport (>= 3.1.0)
+ rack (>= 1.4.0)
+ rest-client
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
+ mime-types (3.3.1)
+ mime-types-data (~> 3.2015)
+ mime-types-data (3.2019.1009)
mimemagic (0.3.3)
mini_magick (4.10.1)
mini_mime (1.0.2)
@@ -224,6 +236,7 @@ GEM
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-ssh (5.2.0)
+ netrc (0.11.0)
nio4r (2.5.1)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
@@ -267,6 +280,11 @@ GEM
rb-inotify (0.10.0)
ffi (~> 1.0)
regexp_parser (1.6.0)
+ rest-client (2.1.0)
+ http-accept (>= 1.7.0, < 2.0)
+ http-cookie (>= 1.0.2, < 2.0)
+ mime-types (>= 1.16, < 4.0)
+ netrc (~> 0.8)
rmagick (4.0.0)
ruby-vips (2.0.17)
ffi (~> 1.9)
@@ -327,6 +345,9 @@ GEM
railties (>= 3.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
+ unf (0.1.4)
+ unf_ext
+ unf_ext (0.0.7.6)
unicode_utils (1.4.0)
unicorn (5.5.1)
kgio (~> 2.6)
@@ -380,6 +401,7 @@ DEPENDENCIES
jquery-rails
kaminari-bootstrap
listen (>= 3.0.5, < 3.2)
+ mailjet
mysql2
nokogiri
posix-spawn
diff --git a/app/controllers/admin/m_odr_files_controller.rb b/app/controllers/admin/m_odr_files_controller.rb
index 97eab5e..f5651ab 100644
--- a/app/controllers/admin/m_odr_files_controller.rb
+++ b/app/controllers/admin/m_odr_files_controller.rb
@@ -39,6 +39,18 @@ class Admin::MOdrFilesController < ApplicationController
end
end
+
+ def send_mail
+ @m_odr_file = MOdrFile.find(params[:id])
+ @m_odr_rep = @m_odr_file.m_odr_rep
+
+ @m_odr_rep.send_mail_type(params[:slug].to_s, @m_odr_file)
+
+ redirect_to [:admin, @m_odr_rep]
+
+
+ end
+
def create
@m_odr_file = MOdrFile.new(params.require(:m_odr_file).permit!)
diff --git a/app/controllers/admin/m_odr_remises_controller.rb b/app/controllers/admin/m_odr_remises_controller.rb
index 7633215..dff997f 100644
--- a/app/controllers/admin/m_odr_remises_controller.rb
+++ b/app/controllers/admin/m_odr_remises_controller.rb
@@ -10,6 +10,39 @@ class Admin::MOdrRemisesController < ApplicationController
@admin_space = "payments"
end
+ def export_sepa
+ @m_odr_remise = MOdrRemise.find(params[:id])
+
+ @m_odr = @m_odr_remise.m_odr
+
+ @m_odr_virements = @m_odr_remise.m_odr_virements.where(:refused => false)
+
+
+ @prelevement_date = Time.now
+ @iban = @m_odr.iban.to_s
+ @bic = @m_odr.bic.to_s
+ @name = @m_odr.bank_name.to_s
+
+
+
+
+ params[:inline] = false
+ file_path = Rails.root.join("pdf", "sepa", "remise_#{@m_odr_remise.id}.xml")
+ if true or !File.exist?(file_path)
+ @data_to_send = render_to_string(:layout => "admin/m_odr_remises/sepa.html.erb", :layout => false)
+
+ #@data_to_send = "d"
+
+ File.open(file_path, "w+") do |f|
+ f.write(@data_to_send)
+ end
+ end
+
+ send_file file_path, :filename =>"export-#{@m_odr_remise.id}-#{Date.today.strftime("%Y-%m-%d")}.xml" , :type => 'text/xml',:disposition => (params[:inline] ? 'inline' : "attachment")
+
+ end
+
+
def confirm
@m_odr_remise = MOdrRemise.find(params[:id])
@@ -18,6 +51,8 @@ class Admin::MOdrRemisesController < ApplicationController
m_odr_virement.m_odr_rep.change_state("Virement envoyé")
m_odr_virement.save
+ m_odr_virement.m_odr_rep.send_mail_type("succes", m_odr_virement)
+
end
@m_odr_remise.confirmed = true
@m_odr_remise.save
diff --git a/app/controllers/admin/m_odr_rep_ribs_controller.rb b/app/controllers/admin/m_odr_rep_ribs_controller.rb
index 4b25082..92d0299 100644
--- a/app/controllers/admin/m_odr_rep_ribs_controller.rb
+++ b/app/controllers/admin/m_odr_rep_ribs_controller.rb
@@ -56,6 +56,18 @@ class Admin::MOdrRepRibsController < ApplicationController
end
+
+ def send_mail
+ @m_odr_rep_rib = MOdrRepRib.find(params[:id])
+ @m_odr_rep = @m_odr_rep_rib.m_odr_rep
+
+ @m_odr_rep.send_mail_type("erreur-coordonnees-bancaire", @m_odr_rep_rib)
+
+ redirect_to [:admin, @m_odr_rep]
+
+
+ end
+
def destroy
@m_odr_rep_rib = MOdrRepRib.find(params[:id])
diff --git a/app/controllers/admin/m_odr_reps_controller.rb b/app/controllers/admin/m_odr_reps_controller.rb
index 6e2edf6..7f616e3 100644
--- a/app/controllers/admin/m_odr_reps_controller.rb
+++ b/app/controllers/admin/m_odr_reps_controller.rb
@@ -97,6 +97,23 @@ class Admin::MOdrRepsController < ApplicationController
end
+ def refuse
+ @m_odr_rep = MOdrRep.find(params[:id])
+
+ @m_odr_rep.change_state("Refusée")
+
+
+ redirect_to [:admin, @m_odr_rep]
+ end
+
+ def send_mail
+ @m_odr_rep = MOdrRep.find(params[:id])
+ @m_odr_rep.send_mail_type(params[:slug].to_s)
+
+ redirect_to [:admin, @m_odr_rep]
+
+
+ end
end
diff --git a/app/controllers/admin/m_odr_virements_controller.rb b/app/controllers/admin/m_odr_virements_controller.rb
index 82c346d..e75c936 100644
--- a/app/controllers/admin/m_odr_virements_controller.rb
+++ b/app/controllers/admin/m_odr_virements_controller.rb
@@ -91,6 +91,11 @@ class Admin::MOdrVirementsController < ApplicationController
@m_odr_virement.refused = true
@m_odr_virement.save
@m_odr_virement.m_odr_rep.change_state("Erreur sur virement")
+
+ @m_odr_rep = @m_odr_virement.m_odr_rep
+
+ @m_odr_rep.send_mail_type("erreur-coordonnees-bancaire", @m_odr_virement)
+
@m_odr_remise = @m_odr_virement.m_odr_remise if @m_odr_virement.m_odr_remise
end
diff --git a/app/helpers/translation_helper.rb b/app/helpers/translation_helper.rb
index 9217cb1..666828d 100755
--- a/app/helpers/translation_helper.rb
+++ b/app/helpers/translation_helper.rb
@@ -39,7 +39,7 @@ module TranslationHelper
r = 'Facturée'
elsif value == "annulée"
r = 'Annulée'
- elsif ["Erreur sur virement", "Refusé"].include?(value)
+ elsif ["Erreur sur virement", "Refusé", "Refusée"].include?(value)
r = ''+value+''
elsif ["En cours de traitement"].include?(value)
r = ''+value+''
diff --git a/app/models/m_odr_rep.rb b/app/models/m_odr_rep.rb
index cb130f9..c2cc055 100644
--- a/app/models/m_odr_rep.rb
+++ b/app/models/m_odr_rep.rb
@@ -33,7 +33,7 @@ class MOdrRep < ApplicationRecord
def send_mail_type(slug, element = nil)
if self.m_odr and mail_type = self.m_odr.mail_types.where(:slug => slug).first and self.particulars.first and self.particulars.first.email?
- mail_hist = MailHist.generate_mail(:fr, mail_type, self.particulars.first.email, {:arguments => {:nom_odr => self.m_odr.name}, :m_odr => self.m_odr, :m_odr_rep => self})
+ mail_hist = MailHist.generate_mail(:fr, mail_type, self.particulars.first.email, {:arguments => {:nom_odr => self.m_odr.name}, :m_odr => self.m_odr, :m_odr_rep => self, :element => element})
end
end
diff --git a/app/models/m_odr_rep_rib.rb b/app/models/m_odr_rep_rib.rb
index ccf8a68..6089d46 100644
--- a/app/models/m_odr_rep_rib.rb
+++ b/app/models/m_odr_rep_rib.rb
@@ -10,4 +10,8 @@ class MOdrRepRib < ApplicationRecord
validates :iban, :presence => true
validates_with IbanValidator
+
+ has_many :mail_hists, :as => :element
+
+
end
diff --git a/app/models/m_odr_virement.rb b/app/models/m_odr_virement.rb
index c8eb5a8..bd7f1dd 100644
--- a/app/models/m_odr_virement.rb
+++ b/app/models/m_odr_virement.rb
@@ -7,6 +7,7 @@ class MOdrVirement < ApplicationRecord
+
QI_DYNAMICS = %w(remise iban_to bic_to iban_from bic_from bank_name bank_subject libelle )
eval(QI_DYNAMICS_CORE)
diff --git a/app/models/mail_hist.rb b/app/models/mail_hist.rb
index 65fc9d2..dd91db0 100644
--- a/app/models/mail_hist.rb
+++ b/app/models/mail_hist.rb
@@ -15,12 +15,15 @@ class MailHist < ApplicationRecord
def self.qi_table_order
{
- :m_odr => {:name => "ODR"},
- :m_odr_rep => {:name => "Participation"},
+
:created_at => {:name => "Date", :reorder => true},
:from_email => {:name => "Email exp.", :reorder => true},
:to_email => {:name => "Email dest.", :reorder => true},
:subject => {:name => "Sujet.", :reorder => true},
+ :element => {:name => "Elément"},
+ :mail_type => {:name => "Elément"},
+ :m_odr => {:name => "ODR"},
+ :m_odr_rep => {:name => "Participation"},
:actions => "Actions",
}
end
diff --git a/app/views/admin/m_odr_remises/export_sepa.html.erb b/app/views/admin/m_odr_remises/export_sepa.html.erb
new file mode 100644
index 0000000..0931b1a
--- /dev/null
+++ b/app/views/admin/m_odr_remises/export_sepa.html.erb
@@ -0,0 +1,75 @@
+
+
+
+
+ <%=@prelevement_date.strftime("%d/%m/%Y").to_slug %>-<%= @m_odr_remise.id %>
+ <%= Time.now.to_time.utc.iso8601 %>
+ <%= @m_odr_virements.count %>
+ <%= '%.2f' % @m_odr_virements.sum(:amount) %>
+
+ <%= @name %>
+
+
+
+ <%= @prelevement_date.strftime("%d/%m/%Y") %>
+ TRF
+ false
+ <%= @m_odr_virements.count %>
+ <%= '%.2f' % @m_odr_virements.sum(:amount) %>
+
+
+ SEPA
+
+
+ <%= @prelevement_date.strftime("%Y-%m-%d") %>
+
+ <%= @name %>
+
+
+
+ <%= @iban %>
+
+
+
+
+ <%= @bic %>
+
+
+ SLEV
+
+
+ <% @m_odr_virements.all.each do |m_odr_virement| %>
+
+
+ <%= m_odr_virement.token %>
+
+
+ <%= '%.2f' % m_odr_virement.amount %>
+
+
+
+ <%= m_odr_virement.m_odr_rep.long_name %>
+
+
+
+
+ <%= m_odr_virement.bic_to %>
+
+
+
+
+
+
+ <%= m_odr_virement.iban_to.gsub(" ", "") %>
+
+
+
+ <%= m_odr_virement.token %>
+
+
+
+ <% end %>
+
+
+
+
diff --git a/app/views/admin/m_odr_remises/show.html.haml b/app/views/admin/m_odr_remises/show.html.haml
index ad8c173..2a24678 100644
--- a/app/views/admin/m_odr_remises/show.html.haml
+++ b/app/views/admin/m_odr_remises/show.html.haml
@@ -7,10 +7,16 @@
.qi_row
.qi_pannel.qi_plain.padding
+ =link_to "Export CSV", export_sepa_admin_m_odr_remise_path(@m_odr_remise)
+
+
+ %br
+ %br
=link_to "Confirmer maintenant TOUS les virements", confirm_admin_m_odr_remise_path(@m_odr_remise) if !@m_odr_remise.confirmed
+
%hr
Virements
diff --git a/app/views/admin/m_odr_reps/show.html.haml b/app/views/admin/m_odr_reps/show.html.haml
index da7cc05..de835e0 100644
--- a/app/views/admin/m_odr_reps/show.html.haml
+++ b/app/views/admin/m_odr_reps/show.html.haml
@@ -94,6 +94,10 @@
%br
=file.reject_reason
=simple_format file.reject_reason_description if file.reject_reason_description?
+ -[["achat-hors-delais", "Achat hors délais"],["facture-illisible", "Facture illisible"],["pneus-non-porteurs-de-l-offre", "Pneus invalides"]].each do |key|
+ %br
+ =link_to "Envoyer un mail de notification : #{key[1]}", send_mail_admin_m_odr_file_path(file, :slug => key[0]), :remote => false
+ %br
=link_to "Modérer ce fichier", edit_admin_m_odr_file_path(file), :remote => true
@@ -127,11 +131,24 @@
%br
=m_odr_rep_rib.reject_reason
=simple_format m_odr_rep_rib.reject_reason_description if m_odr_rep_rib.reject_reason_description?
+
+ -if m_odr_rep_rib.mail_hists.count == 0
+ =link_to "Envoyer un mail de notification", send_mail_admin_m_odr_rep_rib_path(m_odr_rep_rib), :remote => false
+
=link_to "Modérer ce RIB", edit_admin_m_odr_rep_rib_path(m_odr_rep_rib), :remote => true
-
+ -if @m_odr_rep.state == "Refusée"
+ .red Offre refusée :
+ -[["achat-hors-delais", "Achat hors délais"],["facture-illisible", "Facture illisible"],["pneus-non-porteurs-de-l-offre", "Pneus invalides"]].each do |key|
+ %br
+ =link_to " Envoyer un mail de notification : #{key[1]}", send_mail_admin_m_odr_rep_path(@m_odr_rep, :slug => key[0]), :remote => false
+
+ -else
+ =link_to "Marquer cette offre comme refusée", refuse_admin_m_odr_rep_path(@m_odr_rep)
+
+
.columns.span_8{:style => "padding-left:20px;"}
-file = @m_odr_rep.m_odr_files.order("id DESC").first
-if file
@@ -162,7 +179,9 @@
-params[:search][:per_page] = params[:search][:per_page] || 50
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
- -@mail_hists = @m_odr_rep.mail_hists.page(page).per(per_page)
+ -@mail_hists = @m_odr_rep.mail_hists
+ -@mail_hists = sort_by_sorting(@mail_hists, "created_at DESC")
+ -@mail_hists = @mail_hists.page(page).per(per_page)
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @mail_hists}
diff --git a/app/views/admin/mail_hists/_mail_hist.html.haml b/app/views/admin/mail_hists/_mail_hist.html.haml
index b47ee1e..57e172f 100644
--- a/app/views/admin/mail_hists/_mail_hist.html.haml
+++ b/app/views/admin/mail_hists/_mail_hist.html.haml
@@ -1,11 +1,15 @@
%tr#mail_hist_row{:id => mail_hist.id}
-tr = {}
+ -tr[:mail_type] = capture do
+ %td
+ =mail_hist.mail_type.slug if mail_hist.mail_type
+
-tr[:actions] = capture do
%td.actions
= link_to i(:"trash-o"), [:admin, mail_hist], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
= link_to i(:pencil), edit_admin_mail_hist_path(mail_hist), :remote => true
- = link_to i(:eye), admin_mail_hist_path(mail_hist), :remote => true
+ = link_to i(:eye), admin_mail_hist_path(mail_hist), :remote => false
diff --git a/app/views/admin/mail_hists/show.html.haml b/app/views/admin/mail_hists/show.html.haml
index 40789e4..ab93101 100644
--- a/app/views/admin/mail_hists/show.html.haml
+++ b/app/views/admin/mail_hists/show.html.haml
@@ -7,4 +7,7 @@
.qi_row
.qi_pannel.qi_plain.padding
- =debug @mail_hist
\ No newline at end of file
+ =@mail_hist.subject
+ %hr
+ .content
+ =simple_format @mail_hist.body
\ No newline at end of file
diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml
index fd3e0ba..beb83d1 100644
--- a/app/views/layouts/admin.html.haml
+++ b/app/views/layouts/admin.html.haml
@@ -266,5 +266,5 @@
.clear
- = timer_watcher()
+ = timer_watcher() if Rails.env.production?
diff --git a/config/environments/development.rb b/config/environments/development.rb
index b9c3ceb..4fa1cd1 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -3,6 +3,8 @@ Rails.application.configure do
HOSTNAME="localhost:3000"
+ HOSTNAME="offres.market-inn.fr"
+
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
@@ -64,6 +66,9 @@ Rails.application.configure do
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+
+ #config.action_mailer.delivery_method = :mailjet
+
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
diff --git a/config/initializers/mailjet.rb b/config/initializers/mailjet.rb
new file mode 100644
index 0000000..a1efbd3
--- /dev/null
+++ b/config/initializers/mailjet.rb
@@ -0,0 +1,5 @@
+Mailjet.configure do |config|
+ config.api_key = 'ed3dc73b653201199717a1a0167eba75'
+ config.secret_key = '8533d4572966755e69f1886f907715a1'
+ #config.default_from = 'nbally@olwen-capital.com'
+end
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 44689a7..8dcab6e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -15,6 +15,7 @@ Rails.application.routes.draw do
resources :m_odr_remises do
member do
get :confirm
+ get :export_sepa
end
collection do
get :generate_all
@@ -116,6 +117,7 @@ Rails.application.routes.draw do
resources :m_odr_files do
member do
get :download
+ get :send_mail
end
collection do
@@ -127,6 +129,9 @@ Rails.application.routes.draw do
resources :m_odr_reps do
member do
get :generate_virement
+ get :send_mail
+ get :refuse
+
end
collection do
@@ -137,7 +142,7 @@ Rails.application.routes.draw do
namespace :admin do
resources :m_odr_rep_ribs do
member do
-
+ get :send_mail
end
collection do