Commit 9f149383 by Yvon Kerdoncuff

7928 WIP

parent 4c2b3755
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\Adherent;
use App\Entity\GlobalParameter;
use App\Utils\CustomEntityManager;
use App\Utils\TAVCotisationUtils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Twig\Environment;
use Symfony\Component\Console\Input\InputArgument;
/**
* This command is used to import data to complete external adherents data
*/
class ImportExternalAdherentData extends Command
{
protected static $defaultName = 'kohinos:ssa:external-adherent-data-import';
protected $em;
protected $io;
protected $param;
protected $tavCotisationUtils;
public function __construct(
CustomEntityManager $em,
TAVCotisationUtils $tavCotisationUtils
) {
$this->em = $em;
$this->tavCotisationUtils = $tavCotisationUtils;
parent::__construct();
}
protected function configure()
{
$this
->setDescription('SSA : importer via CSV des informations externes non datées concernant les adhérents.')
->addArgument('filepath', InputArgument::OPTIONAL, 'Chemin du fichier csv contenant les données non datées.')
;
}
private function readCsv() {
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io = new SymfonyStyle($input, $output);
$this->io->title('START - importing external adherent data');
$csvFilePath = $input->getArgument('filepath');
if (($handle = fopen($csvFilePath, "r")) !== FALSE) {
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row[0] === 'email') {
// headers row
continue;
}
try {
$adherent = $this->em->getRepository(Adherent::class)->findOneByEmail($row[0], false);
} catch (\Exception $e) {
$this->io->warning('Adherent not found: ' . $row[0]);
continue;
}
$updated = false;
if (is_null($adherent->getHouseholdCount())) {
$adherent->setHouseholdCount(intval($row[1]));
$updated = true;
}
if (is_null($adherent->getCotisationAmount())) {
$adherent->setCotisationAmount(intval($row[2]));
$updated = true;
}
if ($updated) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHouseholdSimplified($adherent);
$this->em->persist($adherent);
$this->io->success('Succesfully updated: ' . $row[0]);
} else {
$this->io->warning('Profil already complete for Adherent: ' . $row[0] . ' (update ignored)');
}
}
$this->em->flush();
fclose($handle);
}
$this->io->success('End');
$memoryUsage = memory_get_usage(true) / 1024 / 1024;
$this->io->text("Batch finished with memory: ${memoryUsage}M");
return 0;
}
}
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\Adherent;
use App\Entity\GlobalParameter;
use App\Utils\CustomEntityManager;
use App\Utils\TAVCotisationUtils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Twig\Environment;
use Symfony\Component\Console\Input\InputArgument;
/**
* This command is used to import data to complete external adherents data
*/
class ImportExternalAdherentDatedData extends Command
{
protected static $defaultName = 'kohinos:ssa:external-adherent-dated-data-import';
protected $em;
protected $io;
protected $param;
protected $tavCotisationUtils;
public function __construct(
CustomEntityManager $em,
TAVCotisationUtils $tavCotisationUtils
) {
$this->em = $em;
$this->tavCotisationUtils = $tavCotisationUtils;
parent::__construct();
}
protected function configure()
{
$this
->setDescription('SSA : importer via CSV des informations externes datées concernant les adhérents,.')
->addArgument('filepath', InputArgument::OPTIONAL, 'Chemin du fichier csv contenant les données datées.')
;
}
private function readCsv() {
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io = new SymfonyStyle($input, $output);
$this->io->title('START - importing external dated adherent data');
$csvFilePath = $input->getArgument('filepath');
if (($handle = fopen($csvFilePath, "r")) !== FALSE) {
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row[0] === 'email') {
// headers row
continue;
}
try {
$adherent = $this->em->getRepository(Adherent::class)->findOneByEmail($row[0], false);
} catch (\Exception $e) {
$this->io->warning('Adherent not found: ' . $row[0]);
continue;
}
$updated = false;
if (is_null($adherent->getHouseholdCount())) {
$adherent->setHouseholdCount(intval($row[1]));
$updated = true;
}
if (is_null($adherent->getCotisationAmount())) {
$adherent->setCotisationAmount(intval($row[2]));
$updated = true;
}
if ($updated) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHouseholdSimplified($adherent);
$this->em->persist($adherent);
$this->io->success('Succesfully updated: ' . $row[0]);
} else {
$this->io->warning('Profil already complete for Adherent: ' . $row[0] . ' (update ignored)');
}
}
$this->em->flush();
fclose($handle);
}
$this->io->success('End');
$memoryUsage = memory_get_usage(true) / 1024 / 1024;
$this->io->text("Batch finished with memory: ${memoryUsage}M");
return 0;
}
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Doctrine\UuidGenerator;
/**
* @ORM\Entity
* @ORM\Table(name="external_adherent_data")
*/
class ExternalAdherentData
{
/**
* @var \Ramsey\Uuid\UuidInterface
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="Adherent")
* @ORM\JoinColumn(name="adherent_id", referencedColumnName="id", nullable=false, unique=true)
*/
private $adherent;
/**
* @ORM\ManyToOne(targetEntity="ExternalDataAgeGroup")
* @ORM\JoinColumn(name="external_data_age_group_id", referencedColumnName="id", nullable=true)
*/
private $externalDataAgeGroup;
/** @ORM\Column(type="integer", nullable=true) */
private $birthYear;
/** @ORM\Column(type="integer", nullable=true) */
private $ageIncomeRatioGroup;
/** @ORM\Column(type="integer", nullable=true) */
private $householdIncomeRadioGroup;
/** @ORM\Column(type="string", length=255) */
private $externalId;
/** @ORM\Column(type="string", length=255) */
private $cohort;
/**
* @ORM\ManyToOne(targetEntity="ExternalDataCCMemberStatus")
* @ORM\JoinColumn(name="external_data_cc_member_status_id", referencedColumnName="id", nullable=true)
*/
private $externalDataCCMemberStatus;
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Doctrine\UuidGenerator;
/**
* @ORM\Entity
* @ORM\Table(name="external_adherent_dated_data")
*/
class ExternalAdherentDatedData
{
/**
* @var \Ramsey\Uuid\UuidInterface
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="Adherent")
* @ORM\JoinColumn(name="adherent_id", referencedColumnName="id", nullable=false, unique=true)
*/
private $adherent;
/** @ORM\Column(type="integer") */
private $year;
/** @ORM\Column(type="float") */
private $householdUnitShares;
/** @ORM\Column(type="integer") */
private $annualIncome;
/** @ORM\Column(type="integer") */
private $monthlyIncome;
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="external_data_age_group")
*/
class ExternalDataAgeGroup {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/** @ORM\Column(type="string", length=50) */
private $ageGroup;
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="external_data_cc_member_status")
*/
class ExternalDataCCMemberStatus {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/** @ORM\Column(type="string", length=50) */
private $memberStatus;
}
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