Commit 91d15434 authored by gwendal's avatar gwendal
Browse files

fix: send email when creating service. (related #180, closed #179) This still...

fix: send email when creating service. (related #180, closed #179) This still need work and it's a hotfix
parent dd78fca0
......@@ -103,7 +103,7 @@ class ServicesController < WebController
def create
post_load
# do not notify_service_payment on create, but on activation.
@service.notify_service_payment = false
@service.notify_service_payment = true
@service.service_macs.each do |service_macs|
service_macs.service = @service
end
......
......@@ -15,17 +15,20 @@ class BoardMailer < ActionMailer::Base
def service_payment(service, new_record)
@member = service.member
@service = service
@amount = service.amount.amount
@amount = service.monthly_recurring_charge
@new_record = new_record
@saf = service.saf.blank? ? service.saf : service.saf.amount
@saf = service.saf_charges.empty? ? nil : service.saf_charge
# @total_amount = service.total_amount duration, saf_included: new_record
@payment_method = service.payment_method
@payment_method = service.monthly_payment_method
# @duration = duration
# @renewal_method_changed = renewal_method_changed
mail(to: to, subject: subject(t(:subject, scope: [:board_mailer, :service_payment]) % {
number: @member.number,
login: @service.login,
}))
mail(
to: to,
subject: subject(t(:subject, scope: [:board_mailer, :service_payment]) % {number: @member.number, login: @service.login })
) do |format|
format.text
format.html
end
end
def service_deactived(service)
......
......@@ -28,10 +28,10 @@ class MemberMailer < ActionMailer::Base
@member = service.member
@service = service
@new_record = new_record
@amount = service.amount.amount
@saf = service.saf.blank? ? service.saf : service.saf.amount
@amount = service.monthly_recurring_charge
@saf = service.saf_charges.empty? ? nil : service.saf_charge
# @total_amount = service.total_amount duration, saf_included: new_record
@payment_method = service.payment_method
@payment_method = service.monthly_payment_method
# @duration = duration
# @renewal_method_changed = renewal_method_changed
mail(to: @member.invoicing_email, subject: subject(
......
......@@ -2,6 +2,25 @@ class TreasurerMailer < ActionMailer::Base
default from: Settings.email_from
layout "email"
def service_payment(service, new_record)
@member = service.member
@service = service
@amount = service.monthly_recurring_charge
@new_record = new_record
@saf = service.saf_charges.empty? ? nil : service.saf_charge
# @total_amount = service.total_amount duration, saf_included: new_record
@payment_method = service.monthly_payment_method
# @duration = duration
# @renewal_method_changed = renewal_method_changed
mail(
to: to,
subject: subject(t(:subject, scope: [:treasureur_mailer, :service_payment]) % {number: @member.number, login: @service.login })
) do |format|
format.text
format.html
end
end
def generated_invoices(invoice_count, invoice_records, error_count, error_records)
@invoice_count = invoice_count
@invoice_records = invoice_records
......@@ -34,5 +53,12 @@ class TreasurerMailer < ActionMailer::Base
mail(to: "#{Settings.mail.treasurer}", subject: "[#{Settings.organization_name}] #{t('.subject')}")
end
def to
return Settings.mail.treasurer
end
def subject(subject_suffix)
return "[#{Settings.organization_name}] #{subject_suffix}"
end
end
......@@ -350,6 +350,18 @@ class Service < ActiveRecord::Base
monthly_charges.reduce(0) {|sum, sale| sum + sale.amount}
end
def monthly_payment_method
service_sale_templates.where(["monthly = ? and chargeable = ?", true, true]).pluck(:payment_method).uniq.first
end
def saf_charges
service_sale_templates.where(["once = ? and chargeable = ?", true, true])
end
def saf_charge
saf_charges.reduce(0) {|sum, sale| sum + sale.amount}
end
def add_deposit(args)
amount = args[:deposit_amount]
payment_method = args[:deposit_payment_method]
......@@ -666,7 +678,7 @@ class Service < ActiveRecord::Base
start_at = self.expired_at_was
end
[MemberMailer, CrewMailer, BoardMailer].each do |mailer|
[MemberMailer, CrewMailer, TreasurerMailer, BoardMailer].each do |mailer|
notification_mails << mailer.service_payment(
self, self.new_record?,
)
......
<% t_scope = [:board_mailer, :service_payment]-%>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>
<%= t(:hi, scope: t_scope) %>
</p>
<p>
<%= t(:member_suscribe, scope: t_scope) % {
number: @member.number,
login: @service.login,
amount: @amount,
total_amount: @total_amount,
payment_method: t(@payment_method, scope: :payment_method).downcase,
} %>
<% if @new_record and @saf %>
<%= t(:saf, scope: t_scope) % {saf: @saf} %>
<% end %>
</p>
<p>
<% if @service.expired_at %>
<%= t(:details_expired_at, scope: t_scope) % {expired_at: l(@service.expired_at, format: :long)} %>
<% else %>
<%= t(:details_no_expiration, scope: t_scope) %>
<% end %>
</p>
<p><%= link_to(
polymorphic_url(@service),
polymorphic_url(@service),
)%></p>
<p><%= t(:signature, scope: t_scope) %></p>
</body>
</html>
<%= t('.body',
number: @member.number,
login: @service.login,
amount: @amount,
payment_method: t(@payment_method, scope: :payment_method).downcase,
saf: (@new_record and @saf) ? t('.saf', saf: @saf) : '',
expiration: if @service.expired_at
t('.details_expired_at', expired_at: l(@service.expired_at, format: :long))
else
t('.details_no_expiration')
end,
url: polymorphic_url(@service)
) %>
<% t_scope = [:board_mailer, :service_payment]-%>
<%= word_wrap(t(:hi, scope: t_scope)) %>
<%= word_wrap(t(:member_suscribe, scope: t_scope) % {
number: @member.number,
login: @service.login,
amount: @amount,
total_amount: @total_amount,
payment_method: t(@payment_method, scope: :payment_method).downcase,
}) %>
<% if @new_record and @saf -%>
<%= word_wrap(t(:saf, scope: t_scope) % {saf: @saf}) %>
<% end -%>
<% if @service.expired_at %>
<%= word_wrap(t(:details_expired_at, scope: t_scope) % { expired_at: l(@service.expired_at, format: :long) }) %>
<% else %>
<%= word_wrap(t(:details_no_expiration, scope: t_scope)) %>
<% end %>
<%= polymorphic_url(@service) %>
<%= t(:signature, scope: t_scope) %>
<%= t('.body',
number: @member.number,
login: @service.login,
amount: @amount,
payment_method: t(@payment_method, scope: :payment_method).downcase,
saf: (@new_record and @saf) ? t('.saf', saf: @saf) : '',
expiration: if @service.expired_at
t('.details_expired_at', expired_at: l(@service.expired_at, format: :long))
else
t('.details_no_expiration')
end,
url: polymorphic_url(@service)
) %>
......@@ -516,15 +516,23 @@ fr:
service_payment:
subject: "Paiement du %{login} (%{number})"
hi: "Bonjour,"
member_suscribe: "Le membre %{number} a souscrit l'abonnement %{login} pour %{total_amount} € qu'il réglera par %{payment_method}, à %{amount} € par mois."
body: |
Bonjour,
Le membre %{number} a souscrit l'abonnement %{login} qu'il réglera par %{payment_method}, à %{amount} € par mois.
%{saf}
%{expiration}
Le détail se trouve à l'adresse suivante : %{url}
Pour Rézine,
Ambre - le système d'information qui ne dort jamais.
saf: "Par ailleurs, des frais d'accès au service de %{saf} € sont appliqués."
details_expired_at: "L'abonnement dure jusqu'au %{expired_at}. Le détail se trouve à l'adresse suivante :"
details_no_expiration: "L'abonnement n'a pas de date d'expiration. Le détail se trouve à l'adresse suivante :"
renewal_method_changed:
tacit: "Il est prolongé mensuellement."
on_demand: "Il n'est plus prolongé mensuellement."
signature: "Pour Rézine, Ambre - le système d'information qui ne dort jamais."
details_expired_at: "L'abonnement dure jusqu'au %{expired_at}."
details_no_expiration: "L'abonnement n'a pas de date d'expiration."
# end service_payment
service_deactived:
......@@ -536,6 +544,61 @@ fr:
# end service_deactived
treasurer_mailer:
subscription_payment:
subject: "Paiement de la cotisation %{number}"
body: |
Bonjour,
Le membre %{number} a souscrit à une nouvelle cotisation pour %{amount} €
qu'il réglera par %{payment_method}."
Celle-ci dure jusqu'au %{expired_at}.
Elle a été enregistrée par %{crew}.
Le détail se trouve à l'adresse suivante : %{url}
Pour Rézine,
Ambre - le système d'information qui ne dort jamais.
# end subscription_payment
service_payment:
subject: "Paiement du %{login} (%{number})"
body: |
Bonjour,
Le membre %{number} a souscrit l'abonnement %{login} qu'il réglera par %{payment_method}, à %{amount} € par mois.
%{saf}
%{expiration}
Le détail se trouve à l'adresse suivante : %{url}
Pour Rézine,
Ambre - le système d'information qui ne dort jamais.
saf: "Par ailleurs, des frais d'accès au service de %{saf} € sont appliqués."
details_expired_at: "L'abonnement dure jusqu'au %{expired_at}."
details_no_expiration: "L'abonnement n'a pas de date d'expiration."
# end service_payment
service_actived:
subject: "Activation du %{login} (%{number})"
body: |
Bonjour,
Le service %{login} appartenant à %{number} a été activé.
Pour plus de détail, se rendre à l'adresse suivante :"
Pour Rézine, Ambre - le système d'information qui ne dort jamais.
# end service_actived
service_deactived:
subject: "Désactivation du %{login} (%{number})"
hi: "Bonjour,"
service_stopped: "Le service %{login} appartenant à %{number} a été arrêté."
details: "Il devait expirer le %{expired_at}. Pour plus de détail, se rendre à l'adresse suivante :"
signature: "Pour Rézine, Ambre - le système d'information qui ne dort jamais."
# end service_deactived
generated_invoices:
subject: "Génération de facture"
body: |
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment