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
->with('Informations de cotisation')
->add('recurrentPaymentReason', HiddenType::class, [
'mapped' => false,
'data' => $reason,
'data' => implode(" ", array_column($reason,'reason')),
'attr' => [
'class' => 'recurrentPaymentReason'
]
......
......@@ -130,7 +130,7 @@ class UserAdherentController extends FluxController
private function paiementCotisTavValidation($flux) {
//Look for existing recurring payment
if($reason = $this->tavCotisationsUtils->checkExistingRecurringPayment($flux->getDestinataire()->getUser()->getEmail())) {
return $reason;
return implode(" ", array_column($reason,'reason'));
}
// Look for existing cotisation
......
......@@ -12,6 +12,9 @@ use Doctrine\ORM\Mapping as ORM;
*/
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\JoinColumn(name="adherent_dest_id", referencedColumnName="id", nullable=true)
......
......@@ -188,9 +188,10 @@ class Payment extends BasePayment
* Returns false otherwise
*
* @param $reason
* @param $monthNumberSinceInitialPaymentDate
* @return bool|null
*/
public function isRecurringPaymentEndedOrExpired(&$reason)
public function isRecurringPaymentEndedOrExpired(&$reason,&$monthNumberSinceInitialPaymentDate)
{
if (
!$this->details
......@@ -225,6 +226,20 @@ class Payment extends BasePayment
)
: 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
$paymentEndDateDueToExpiry = new DateTime();
$paymentEndDateDueToExpiry->setDate($this->details['vads_expiry_year'], $this->details['vads_expiry_month'], $day + 1);
......
......@@ -33,7 +33,7 @@ class AchatMonnaieAdherentFormType extends AchatMonnaieFormType
'em' => $this->em,
])
->add('reference', HiddenType::class, [
'data' => 'Achat monnaie en CB Adhérent',
'data' => AchatMonnaieAdherent::REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB,
])
;
if (null != $don) {
......
......@@ -58,7 +58,7 @@ class AchatMonnaieAdherentRecurrentFormType extends AchatMonnaieAdherentFormType
])
->remove('reference')
->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
'clientEmail' => $userEmail,
]);
$res = "";
$res = [];
foreach($recurringPayments as $p) {
if (
$p->getStatus() !== GetHumanStatus::STATUS_FAILED
......@@ -75,8 +75,9 @@ class TAVCotisationUtils
//This is why we can not rely on $p->getStatus to decide if a recurring
//payment is still active or ended or expired.
$reason = "";
if($p->isRecurringPaymentEndedOrExpired($reason) !== true) {
$res .= ($reason . " ");
$monthNumberSinceInitialPaymentDate = -1;
if($p->isRecurringPaymentEndedOrExpired($reason,$monthNumberSinceInitialPaymentDate) !== true) {
$res[] = ['reason' => $reason, 'monthNumberSinceInitialPaymentDate' => $monthNumberSinceInitialPaymentDate];
}
}
}
......@@ -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
) {
$reason = "";
if($p->isRecurringPaymentEndedOrExpired($reason) !== true) {
$monthNumberSinceInitialPaymentDate = -1;
if($p->isRecurringPaymentEndedOrExpired($reason,$monthNumberSinceInitialPaymentDate) !== true) {
$p->setStatus(GetHumanStatus::STATUS_CANCELED);
$this->em->persist($p);
}
......
......@@ -22,7 +22,7 @@
{% endif %}
{% else %}
{% set existingRecurringPayment = checkExistingRecurringPayment(app.user.email) %}
{% if existingRecurringPayment != "" %}
{% if existingRecurringPayment|length > 0 %}
{% include '@kohinos/tav/block/ongoing_recurring_payment.html.twig' with {'existingPaymentDescription': existingRecurringPayment} %}
{% else %}
{% include '@kohinos/tav/block/adherent_payer_cotisation.html.twig' %}
......
......@@ -8,7 +8,9 @@
{% 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/>
<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' }}
{% elseif flux.type == 'prelevement_cotisation_adherent_depassement_plafond' %}
{{ "Réduction de l'allocation après dépassement du plafond" }}
......@@ -20,8 +22,26 @@
{{ flux.parenttype|capitalize }} : {{ flux.type|replace({'_' : ' => '}) }}
{% endif %}
</h3>
<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>
{% if flux.reference == constant('App\\Entity\\AchatMonnaieAdherent::REFERENCE_ACHAT_MONNAIE_ADHERENT_EN_CB_RECURRENT') %}
<p>Vous avez été prélevé de {{ flux.montant|number_format(2) }} euros</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> #}
{% endblock %}
\ No newline at end of file
{% set existingPaymentDescription = existingPaymentDescription|default('') %}
{% set existingPaymentDescription = existingPaymentDescription|default([]) %}
<div class="card mb-3 blocksolde">
<div class="card-body p-2">
<br/>
<p>{{existingPaymentDescription}}</p>
<p>
{% for oneExistingPaymentInfo in existingPaymentDescription %}
{{ oneExistingPaymentInfo.reason }}
{% endfor %}
</p>
<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.
</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