Commit 856eb656 by Yvon Kerdoncuff

Merge branch…

Merge branch '6839-check-existing-recurring-payment-before-performing-payment-at-comptoir' into 'develop'

use method to check both existing cotisation and recurring payment at comptoir

See merge request cooperatic/kohinos-tav!117
parents 9a51843b 554bcfc6
...@@ -128,17 +128,11 @@ class UserAdherentController extends FluxController ...@@ -128,17 +128,11 @@ class UserAdherentController extends FluxController
* Returns error message or null if no error. * Returns error message or null if no error.
*/ */
private function paiementCotisTavValidation($flux) { private function paiementCotisTavValidation($flux) {
//Look for existing recurring payment
if($reason = $this->tavCotisationsUtils->checkExistingRecurringPayment($flux->getDestinataire()->getUser()->getEmail())) {
return implode(" ", array_column($reason,'reason'));
}
// Look for existing cotisation
if ($this->tavCotisationsUtils->checkExistingCotisation($flux)) {
return "Cotisation déjà payée ce mois-ci.";
}
$destinataire = $flux->getDestinataire(); $destinataire = $flux->getDestinataire();
if($reason = $this->tavCotisationsUtils->preventCotisationDuplication($destinataire)) {
return $reason;
}
// Look for cotisation data depending on active process // Look for cotisation data depending on active process
if (true == $this->getParameter('household_based_allowance')) { if (true == $this->getParameter('household_based_allowance')) {
......
...@@ -205,10 +205,10 @@ class UserComptoirController extends FluxController ...@@ -205,10 +205,10 @@ class UserComptoirController extends FluxController
$flux = $form->getData(); $flux = $form->getData();
// Look for existing cotisation // Look for existing cotisation
if ($this->tavCotisationsUtils->checkExistingCotisation($flux)) { if ($reason = $this->tavCotisationsUtils->preventCotisationDuplication($flux->getDestinataire())) {
$this->addFlash( $this->addFlash(
'error', 'error',
$this->translator->trans('L\'adhérent•e a déjà payé sa cotisation ce mois-ci.') $this->translator->trans($reason)
); );
return $this->redirectToRoute('index'); return $this->redirectToRoute('index');
......
...@@ -33,15 +33,32 @@ class TAVCotisationUtils ...@@ -33,15 +33,32 @@ class TAVCotisationUtils
} }
/** /**
* Check if cotisation already exist this month the the recipient of the given Flux. * Check if there is an active recurring paiement or if cotisation already exist this month
* by returning a descriptive reason string if so, else an empty string.
*/ */
public function checkExistingCotisation(Flux $flux) public function preventCotisationDuplication(Adherent $adherent)
{
//Look for existing recurring payment
if($reason = $this->checkExistingRecurringPayment($adherent->getUser()->getEmail())) {
return implode(" ", array_column($reason,'reason'));
}
//Look for existing cotisation
if ($this->checkExistingCotisation($adherent)) {
return "Cotisation déjà payée ce mois-ci.";
}
return "";
}
/**
* Check if cotisation already exist this month.
*/
private function checkExistingCotisation(Adherent $adherent)
{ {
$first_day_this_month = date('Y-m-01'); $first_day_this_month = date('Y-m-01');
$last_day_this_month = date('Y-m-t'); $last_day_this_month = date('Y-m-t');
$existing = $this->em->getRepository(Flux::class)->getTavCotisationsBetweenDates( $existing = $this->em->getRepository(Flux::class)->getTavCotisationsBetweenDates(
$flux->getDestinataire(), $adherent,
$first_day_this_month, $first_day_this_month,
$last_day_this_month $last_day_this_month
); );
...@@ -50,7 +67,8 @@ class TAVCotisationUtils ...@@ -50,7 +67,8 @@ class TAVCotisationUtils
} }
/** /**
* Returns a descriptive string of existing payment, or empty string. * Returns an array containing a descriptive string of existing payment
* as well as other information about the payment, or an empty array.
* *
* @param String $userEmail * @param String $userEmail
*/ */
......
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