Commit 9a51843b by Yvon Kerdoncuff

Merge branch '6712-send-informative-mail-foreach-recurring-payment-notification' into 'develop'

6712 send informative mail foreach recurring payment notification

See merge request cooperatic/kohinos-tav!116
parents 7c6aacd7 741a906f
...@@ -422,7 +422,7 @@ class AdherentAdmin extends AbstractAdmin ...@@ -422,7 +422,7 @@ class AdherentAdmin extends AbstractAdmin
->with('Informations de cotisation') ->with('Informations de cotisation')
->add('recurrentPaymentReason', HiddenType::class, [ ->add('recurrentPaymentReason', HiddenType::class, [
'mapped' => false, 'mapped' => false,
'data' => $reason, 'data' => implode(" ", array_column($reason,'reason')),
'attr' => [ 'attr' => [
'class' => 'recurrentPaymentReason' 'class' => 'recurrentPaymentReason'
] ]
......
...@@ -130,7 +130,7 @@ class UserAdherentController extends FluxController ...@@ -130,7 +130,7 @@ class UserAdherentController extends FluxController
private function paiementCotisTavValidation($flux) { private function paiementCotisTavValidation($flux) {
//Look for existing recurring payment //Look for existing recurring payment
if($reason = $this->tavCotisationsUtils->checkExistingRecurringPayment($flux->getDestinataire()->getUser()->getEmail())) { if($reason = $this->tavCotisationsUtils->checkExistingRecurringPayment($flux->getDestinataire()->getUser()->getEmail())) {
return $reason; return implode(" ", array_column($reason,'reason'));
} }
// Look for existing cotisation // Look for existing cotisation
......
...@@ -12,6 +12,9 @@ use Doctrine\ORM\Mapping as ORM; ...@@ -12,6 +12,9 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class AchatMonnaieAdherent extends AchatMonnaie class AchatMonnaieAdherent extends AchatMonnaie
{ {
const REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB = "Achat monnaie en CB Adhérent";
const REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB_RECURRENT = "Achat monnaie en CB (récurrent) Adhérent";
/** /**
* @ORM\ManyToOne(targetEntity="Adherent") * @ORM\ManyToOne(targetEntity="Adherent")
* @ORM\JoinColumn(name="adherent_dest_id", referencedColumnName="id", nullable=true) * @ORM\JoinColumn(name="adherent_dest_id", referencedColumnName="id", nullable=true)
......
...@@ -188,9 +188,10 @@ class Payment extends BasePayment ...@@ -188,9 +188,10 @@ class Payment extends BasePayment
* Returns false otherwise * Returns false otherwise
* *
* @param $reason * @param $reason
* @param $monthNumberSinceInitialPaymentDate
* @return bool|null * @return bool|null
*/ */
public function isRecurringPaymentEndedOrExpired(&$reason) public function isRecurringPaymentEndedOrExpired(&$reason,&$monthNumberSinceInitialPaymentDate)
{ {
if ( if (
!$this->details !$this->details
...@@ -225,6 +226,20 @@ class Payment extends BasePayment ...@@ -225,6 +226,20 @@ class Payment extends BasePayment
) )
: null; //assume no end date if recurrenceMonthsCount not set : null; //assume no end date if recurrenceMonthsCount not set
//Compute most recent occurence number
$effective_creation_date = DateTime::createFromFormat(
'Ymd',
substr($this->details['vads_effective_creation_date'], 0, 8),
);
if (!$effective_creation_date) {
$reason = "Error parsing vads_effective_creation_date : " . $this->details['vads_effective_creation_date'];
return null;
}
$effective_creation_date->setTime(0,0);
$now = new DateTime();
$now->setTime(0,0);
$monthNumberSinceInitialPaymentDate = $effective_creation_date->diff($now)->m + 1;
//Now check expiry date //Now check expiry date
$paymentEndDateDueToExpiry = new DateTime(); $paymentEndDateDueToExpiry = new DateTime();
$paymentEndDateDueToExpiry->setDate($this->details['vads_expiry_year'], $this->details['vads_expiry_month'], $day + 1); $paymentEndDateDueToExpiry->setDate($this->details['vads_expiry_year'], $this->details['vads_expiry_month'], $day + 1);
......
...@@ -33,7 +33,7 @@ class AchatMonnaieAdherentFormType extends AchatMonnaieFormType ...@@ -33,7 +33,7 @@ class AchatMonnaieAdherentFormType extends AchatMonnaieFormType
'em' => $this->em, 'em' => $this->em,
]) ])
->add('reference', HiddenType::class, [ ->add('reference', HiddenType::class, [
'data' => 'Achat monnaie en CB Adhérent', 'data' => AchatMonnaieAdherent::REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB,
]) ])
; ;
if (null != $don) { if (null != $don) {
......
...@@ -58,7 +58,7 @@ class AchatMonnaieAdherentRecurrentFormType extends AchatMonnaieAdherentFormType ...@@ -58,7 +58,7 @@ class AchatMonnaieAdherentRecurrentFormType extends AchatMonnaieAdherentFormType
]) ])
->remove('reference') ->remove('reference')
->add('reference', HiddenType::class, [ ->add('reference', HiddenType::class, [
'data' => 'Achat monnaie en CB (récurrent) Adhérent', 'data' => AchatMonnaieAdherent::REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB_RECURRENT,
]) ])
; ;
......
...@@ -61,7 +61,7 @@ class TAVCotisationUtils ...@@ -61,7 +61,7 @@ class TAVCotisationUtils
'clientEmail' => $userEmail, 'clientEmail' => $userEmail,
]); ]);
$res = ""; $res = [];
foreach($recurringPayments as $p) { foreach($recurringPayments as $p) {
if ( if (
$p->getStatus() !== GetHumanStatus::STATUS_FAILED $p->getStatus() !== GetHumanStatus::STATUS_FAILED
...@@ -75,8 +75,9 @@ class TAVCotisationUtils ...@@ -75,8 +75,9 @@ class TAVCotisationUtils
//This is why we can not rely on $p->getStatus to decide if a recurring //This is why we can not rely on $p->getStatus to decide if a recurring
//payment is still active or ended or expired. //payment is still active or ended or expired.
$reason = ""; $reason = "";
if($p->isRecurringPaymentEndedOrExpired($reason) !== true) { $monthNumberSinceInitialPaymentDate = -1;
$res .= ($reason . " "); if($p->isRecurringPaymentEndedOrExpired($reason,$monthNumberSinceInitialPaymentDate) !== true) {
$res[] = ['reason' => $reason, 'monthNumberSinceInitialPaymentDate' => $monthNumberSinceInitialPaymentDate];
} }
} }
} }
...@@ -334,7 +335,8 @@ class TAVCotisationUtils ...@@ -334,7 +335,8 @@ class TAVCotisationUtils
&& array_key_exists('vads_identifier',$p->getDetails()) //some payment without vads_identifier have status NEW, which are not valid payments && array_key_exists('vads_identifier',$p->getDetails()) //some payment without vads_identifier have status NEW, which are not valid payments
) { ) {
$reason = ""; $reason = "";
if($p->isRecurringPaymentEndedOrExpired($reason) !== true) { $monthNumberSinceInitialPaymentDate = -1;
if($p->isRecurringPaymentEndedOrExpired($reason,$monthNumberSinceInitialPaymentDate) !== true) {
$p->setStatus(GetHumanStatus::STATUS_CANCELED); $p->setStatus(GetHumanStatus::STATUS_CANCELED);
$this->em->persist($p); $this->em->persist($p);
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
{% endif %} {% endif %}
{% else %} {% else %}
{% set existingRecurringPayment = checkExistingRecurringPayment(app.user.email) %} {% set existingRecurringPayment = checkExistingRecurringPayment(app.user.email) %}
{% if existingRecurringPayment != "" %} {% if existingRecurringPayment|length > 0 %}
{% include '@kohinos/tav/block/ongoing_recurring_payment.html.twig' with {'existingPaymentDescription': existingRecurringPayment} %} {% include '@kohinos/tav/block/ongoing_recurring_payment.html.twig' with {'existingPaymentDescription': existingRecurringPayment} %}
{% else %} {% else %}
{% include '@kohinos/tav/block/adherent_payer_cotisation.html.twig' %} {% include '@kohinos/tav/block/adherent_payer_cotisation.html.twig' %}
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
{% block content %} {% block content %}
<h2 style="font-size: 18px; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-weight: bold; line-height: 1.2em; margin: 40px 0 10px;">{{ user.name|title }}</h2><br/> <h2 style="font-size: 18px; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-weight: bold; line-height: 1.2em; margin: 40px 0 10px;">{{ user.name|title }}</h2><br/>
<h3> <h3>
{% if flux.type == 'reconversion' %} {% if flux.reference == constant('App\\Entity\\AchatMonnaieAdherent::REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB_RECURRENT') %}
{{ flux.reference }}
{% elseif flux.type == 'reconversion' %}
{{ 'Demande de reconversion' }} {{ 'Demande de reconversion' }}
{% elseif flux.type == 'prelevement_cotisation_adherent_depassement_plafond' %} {% elseif flux.type == 'prelevement_cotisation_adherent_depassement_plafond' %}
{{ "Réduction de l'allocation après dépassement du plafond" }} {{ "Réduction de l'allocation après dépassement du plafond" }}
...@@ -20,8 +22,26 @@ ...@@ -20,8 +22,26 @@
{{ flux.parenttype|capitalize }} : {{ flux.type|replace({'_' : ' => '}) }} {{ flux.parenttype|capitalize }} : {{ flux.type|replace({'_' : ' => '}) }}
{% endif %} {% endif %}
</h3> </h3>
<p>De {{ flux.expediteur }} à {{ flux.destinataire }}</p> {% if flux.reference == constant('App\\Entity\\AchatMonnaieAdherent::REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB_RECURRENT') %}
<p>Montant de {{ flux.montant|number_format(2) }} (Moyen : {{ flux.moyen }})</p> <p>Vous avez été prélevé de {{ flux.montant|number_format(2) }} euros</p>
<p>Référence : {{ flux.reference }}</p> {% set existingRecurringPayment = checkExistingRecurringPayment(user.email) %}
{% if existingRecurringPayment|length == 1 %}
{% set currentRecurringPayment = existingRecurringPayment[0] %}
{# Counting time since initial payment is the trick I use here to easily compute a realistic prelevement number #}
{# This estimate will be wrong in some cases where what happened on Payzen is different from
what was expected when payment has been created #}
<p>Echéance n°{{ currentRecurringPayment.monthNumberSinceInitialPaymentDate }}.</p>
<p>{{ currentRecurringPayment.reason }}</p>
<p>Pour demander une interruption anticipée, merci de contacter la caisse à l'adresse {{ KOH_MLC_CONTACT_EMAIL }} au minimum dix jours avant la prochaine échéance.</p>
{% elseif existingRecurringPayment|length > 1 %}
<p>Vous avez plusieurs paiements récurrents en cours. Merci de contacter la caisse à l'adresse {{ KOH_MLC_CONTACT_EMAIL }} pour un dépannage.</p>
{% else %}
<p>Vous n'avez plus aucun paiement récurrent en cours.</p>
{% endif %}
{% else %}
<p>De {{ flux.expediteur }} à {{ flux.destinataire }}</p>
<p>Montant de {{ flux.montant|number_format(2) }} (Moyen : {{ flux.moyen }})</p>
<p>Référence : {{ flux.reference }}</p>
{% endif %}
{# <p>Opérateur : {{ flux.operateur.name }}</p> #} {# <p>Opérateur : {{ flux.operateur.name }}</p> #}
{% endblock %} {% endblock %}
\ No newline at end of file
{% set existingPaymentDescription = existingPaymentDescription|default('') %} {% set existingPaymentDescription = existingPaymentDescription|default([]) %}
<div class="card mb-3 blocksolde"> <div class="card mb-3 blocksolde">
<div class="card-body p-2"> <div class="card-body p-2">
<br/> <br/>
<p>{{existingPaymentDescription}}</p> <p>
{% for oneExistingPaymentInfo in existingPaymentDescription %}
{{ oneExistingPaymentInfo.reason }}
{% endfor %}
</p>
<p class="form-text text-muted"> <p class="form-text text-muted">
Pour demander une interruption anticipée, merci de contacter la caisse à l'adresse {{ KOH_MLC_CONTACT_EMAIL }} au minimum dix jours avant la prochaine échéance. Pour demander une interruption anticipée, merci de contacter la caisse à l'adresse {{ KOH_MLC_CONTACT_EMAIL }} au minimum dix jours avant la prochaine échéance.
</p> </p>
......
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