Commit 9ccbc5eb by Damien Moulard

add relevant tav data in admin adherents export

parent 2a3af91b
......@@ -585,10 +585,11 @@ class AdherentAdmin extends AbstractAdmin
}
}
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$cotisationUtils = $this->getConfigurationPool()->getContainer()->get('app.utils.cotisations');
$container = $this->getConfigurationPool()->getContainer();
$em = $container->get('doctrine')->getManager();
$cotisationUtils = $container->get('app.utils.cotisations');
$iterator = new CustomDoctrineORMQuerySourceIterator($cotisationUtils, $em, $query, $fields);
$iterator = new CustomDoctrineORMQuerySourceIterator($cotisationUtils, $em, $container, $query, $fields);
$iterator->setDateTimeFormat('d/m/Y H:i:s'); //change this to suit your needs
return $iterator;
......
......@@ -875,10 +875,11 @@ class PrestataireAdmin extends AbstractAdmin
}
}
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$cotisationUtils = $this->getConfigurationPool()->getContainer()->get('app.utils.cotisations');
$container = $this->getConfigurationPool()->getContainer();
$em = $container->get('doctrine')->getManager();
$cotisationUtils = $container->get('app.utils.cotisations');
$iterator = new CustomDoctrineORMQuerySourceIterator($cotisationUtils, $em, $query, $fields);
$iterator = new CustomDoctrineORMQuerySourceIterator($cotisationUtils, $em, $container, $query, $fields);
$iterator->setDateTimeFormat('d/m/Y H:i:s'); //change this to suit your needs
return $iterator;
......
......@@ -15,11 +15,14 @@ namespace App\Exporter;
use App\Entity\Adherent;
use App\Entity\Prestataire;
use App\Entity\Flux;
use App\Entity\GlobalParameter;
use App\Utils\CotisationUtils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use Sonata\Exporter\Source\AbstractPropertySourceIterator;
use Sonata\Exporter\Source\SourceIteratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @final since sonata-project/exporter 2.4.
......@@ -32,14 +35,22 @@ class CustomDoctrineORMQuerySourceIterator extends AbstractPropertySourceIterato
protected $query;
protected $em;
protected $cotisationUtils;
protected $container;
/**
* @param array<string> $fields Fields to export
*/
public function __construct(CotisationUtils $cotisationUtils, EntityManagerInterface $em, Query $query, array $fields, string $dateTimeFormat = 'r')
{
public function __construct(
CotisationUtils $cotisationUtils,
EntityManagerInterface $em,
ContainerInterface $container,
Query $query,
array $fields,
string $dateTimeFormat = 'r'
) {
$this->em = $em;
$this->cotisationUtils = $cotisationUtils;
$this->container = $container;
$this->query = clone $query;
$this->query->setParameters($query->getParameters());
foreach ($query->getHints() as $name => $value) {
......@@ -74,12 +85,37 @@ class CustomDoctrineORMQuerySourceIterator extends AbstractPropertySourceIterato
} elseif (!empty($data['Id']) && !empty($data['Email'])) {
//adherent
$adherent = $this->em->getRepository(Adherent::class)->findOneById($data['Id']);
if ($this->container->getParameter('tav_env')) {
// Last TAV cotisation
$cotisations = $this->em->getRepository(Flux::class)->getLastTavCotisation($adherent);
if (count($cotisations) > 0) {
$cotisDate = date("d/m/Y H:i:s", strtotime($cotisations[0]["created_at"]));
$data['Dernière Cotisation'] = $cotisDate;
} else {
$data['Dernière Cotisation'] = "Aucune";
}
// Current emlc balance
$balance = $adherent->getEmlcAccount()->getBalance();
$mlc = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_SYMBOL);
$data['Solde'] = $balance . " " . $mlc;
// Profil de cotisation
$cotisationProfile = $adherent->getProfilDeCotisation();
if (!is_null($cotisationProfile) ) {
$data['Profil de cotisation'] = $cotisationProfile;
} else {
$data['Profil de cotisation'] = "Aucun profil assigné";
}
} else {
$cotisEnd = $this->cotisationUtils->isCotisationValidForAdherent($adherent);
$cotisEnd = is_string($cotisEnd) ? new \DateTime( $cotisEnd ) : $cotisEnd;
$data['Cotisation à jour'] = false == $cotisEnd ? '' : ($cotisEnd->format('d/m/Y'));
$firstCotis = $this->cotisationUtils->getFirstCotisationForAdherent($adherent);
$firstCotis = is_string($firstCotis) ? new \DateTime( $firstCotis ) : $firstCotis;
$data['Première Cotisation'] = false == $firstCotis ? '' : ($firstCotis->format('d/m/Y'));
}
$adminRoles = '';
if (!empty($adherent->getUser())) {
foreach ($adherent->getUser()->getPossiblegroups() as $group) {
......
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