Commit 1d7dc9dc by Damien Moulard

adherent admin export: separate external dated data in columns

parent 2f379ae2
......@@ -1048,12 +1048,6 @@ class AdherentAdmin extends AbstractAdmin
$fields["Solde e-MonA"] = 'emlcAccount.balance';
}
if ($this->getConfigurationPool()->getContainer()->getParameter('use_external_data')) {
$fields["Cohorte"] = 'externalData.cohort';
$fields["ID externe"] = 'externalData.external_id';
$fields["Données datées"] = 'externalDatedDataCollection';
}
return $fields;
}
......
......@@ -7,7 +7,7 @@ use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repository\ExternalAdherentDatedDataRepository")
* @ORM\Table(name="external_adherent_dated_data", uniqueConstraints={@ORM\UniqueConstraint(name="adherentyear", columns={"adherent_id", "year"})})
* @UniqueEntity(
* fields={"adherent", "year"},
......
......@@ -16,6 +16,7 @@ namespace App\Exporter;
use App\Entity\Adherent;
use App\Entity\Prestataire;
use App\Entity\Flux;
use App\Entity\ExternalAdherentDatedData;
use App\Entity\GlobalParameter;
use App\Utils\CotisationUtils;
use Doctrine\ORM\EntityManagerInterface;
......@@ -119,6 +120,34 @@ class CustomDoctrineORMQuerySourceIterator extends AbstractPropertySourceIterato
$data['Numéro d\'anonymisation'] = $adherent->getAnonymousToken();
}
$data["Adresse"] = (string) ($adherent->getGeoloc() ?: '');
if ($this->container->getParameter('use_external_data')) {
// Add external data if exists
$ext_data = $adherent->getExternalData();
$data["Cohorte"] = $ext_data ? $ext_data->getCohort() : "";
$data["ID externe"] = $ext_data ? $ext_data->getExternalId() : "";
// Add external dated data if exists
$ext_dated_data = $adherent->getExternalDatedDataCollection();
/**
* If some line have an attribute and others don't, it won't be displayed.
* So we need to make sure every line in the file as [maxDatedDataCount] columns of dated data
*/
$maxDatedDataCount = $this->em->getRepository(ExternalAdherentDatedData::class)->getMaxDatedDataCount();
for($i = 0 ; $i < $maxDatedDataCount; $i++) {
$yearCount = $i+1;
if ($ext_dated_data[$i]) {
$data["Année $yearCount"] = $ext_dated_data[$i]->getYear();
$data["Revenu mensuel $yearCount"] = $ext_dated_data[$i]->getMonthlyIncome();
$data["Revenu annuel $yearCount"] = $ext_dated_data[$i]->getAnnualIncome();
} else {
$data["Année $yearCount"] = "";
$data["Revenu mensuel $yearCount"] = "";
$data["Revenu annuel $yearCount"] = "";
}
}
}
} else {
$cotisEnd = $this->cotisationUtils->isCotisationValidForAdherent($adherent);
$cotisEnd = is_string($cotisEnd) ? new \DateTime( $cotisEnd ) : $cotisEnd;
......
<?php
namespace App\Repository;
use App\Entity\ExternalAdherentDatedData;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ExternalAdherentDatedData>
*
* @method ExternalAdherentDatedData|null find($id, $lockMode = null, $lockVersion = null)
* @method ExternalAdherentDatedData|null findOneBy(array $criteria, array $orderBy = null)
* @method ExternalAdherentDatedData[] findAll()
* @method ExternalAdherentDatedData[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @method null removeAll()
*/
class ExternalAdherentDatedDataRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ExternalAdherentDatedData::class);
$em = $this->getEntityManager();
$this->connection = $em->getConnection();
}
/**
* @throws ORMException
* @return int|Null Returns the max number of ExternalAdherentDatedData an adherent can have
*/
public function getMaxDatedDataCount()
{
$sqlQuery = "SELECT MAX(dated_data_count.count) AS max_dated_data_count
FROM (
SELECT COUNT(*) AS count
FROM external_adherent_dated_data
GROUP BY adherent_id
) AS dated_data_count;";
$statement = $this->connection->prepare($sqlQuery);
$statement->execute();
$result = $statement->fetchAll()[0]["max_dated_data_count"];
return $result;
}
}
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