Commit b145bf02 by Damien Moulard

WIP third party financers: import retroactive data script

parent 5b393d66
<?php
declare(strict_types=1);
namespace App\Command;
// use App\Entity\Adherent;
// use App\Entity\Flux;
use App\Entity\Allocation;
use App\Utils\CustomEntityManager;
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 Symfony\Component\Console\Input\InputOption;
/**
* This command is used to create ThirdPartyAllocationFunding instances for existing allocation Flux.
* Fetch flux after and before mandatory parameter dates.
*/
class CreateThirdPartyAllocationFundingsFromExistingFlux extends Command
{
protected static $defaultName = 'kohinos:ssa:create-third-party-fundings-from-existing-flux';
protected $em;
protected $io;
protected $param;
public function __construct(CustomEntityManager $em) {
$this->em = $em;
parent::__construct();
}
protected function configure()
{
$this
->setDescription('SSA : créer les instances de ThirdPartyFundings à partir des flux de cotisation existantes entre les dates indiquées')
->addOption(
'batchamount',
null,
InputOption::VALUE_REQUIRED,
"Nombre de cotisations à traiter lors de cette opération"
)
->addArgument('startDatetime', InputArgument::REQUIRED, 'Date et heure de début de prise en compte des flux (format 2026-01-01 00:00:00')
->addArgument('endDatetime', InputArgument::REQUIRED, 'Date et heure de début de prise en compte des flux (format 2026-02-01 00:00:00');
;
// TODO: mandatory before date, after date
}
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 - creating third party fundings');
// get batch amount param
$batchAmount = $input->hasOption('batchamount') ? $input->getOption('batchamount') : null;
$allocation = $this->em->getRepository(Allocation::class)->findAllForSsaExport();
// TODOs
// Create allocations pour test
// Get all Allocation items where cotisation flux is created after and before param date and where adherent's third party financer is not null
// Call TAVCotisationUtils->createThirdPartyAllocationFunding() for each cotis
$this->em->flush();
$this->io->success("END - created {$count} third party fundings");
$memoryUsage = memory_get_usage(true) / 1024 / 1024;
$this->io->text("Batch finished with memory: ${memoryUsage}M");
return 0;
}
}
...@@ -11,9 +11,9 @@ use Doctrine\ORM\Mapping as ORM; ...@@ -11,9 +11,9 @@ use Doctrine\ORM\Mapping as ORM;
/** /**
* Third party entities that participate to fund adherent allocations. * Third party entities that participate to fund adherent allocations.
* Each Adhérent can only be supported by one Third Party Financer. * Each Adhérent can only be supported by one Third Party Financer.
* Each time an adherent gets his allowance : * Each time an adherent gets their allowance :
* - the flux of cosisation and reversement are created as usual * - the flux of cosisation and reversement are created as usual
* - create a ThirdPartyAllocationFunding instance to save the information that the financer supported funded [fundingAmount] among the reversement amount * - create a ThirdPartyAllocationFunding instance to save the information that the financer funded [fundingAmount] among the reversement amount
* *
* @ORM\Entity(repositoryClass=ThirdPartyFinancerRepository::class) * @ORM\Entity(repositoryClass=ThirdPartyFinancerRepository::class)
*/ */
......
...@@ -47,6 +47,24 @@ class AllocationRepository extends ServiceEntityRepository ...@@ -47,6 +47,24 @@ class AllocationRepository extends ServiceEntityRepository
} }
} }
/**
* @return Adherent[] Returns an array of Adherent objects
*/
public function findbyDateAndAdherentHasThirdPartyFinancer($thirdPartId)
{
$qb = $this->createQueryBuilder('al');
// TODO add dates
return $qb
->leftjoin('al.adherent', 'adh')
->leftjoin('al.cotisationFlux', 'cf')
->where('adh.thirdPartyFinancer IS NOT NULL')
->getQuery()
->getResult()
;
}
// /** // /**
// * @return Allocation[] Returns an array of Allocation objects // * @return Allocation[] Returns an array of Allocation objects
// */ // */
......
...@@ -414,7 +414,7 @@ class TAVCotisationUtils ...@@ -414,7 +414,7 @@ class TAVCotisationUtils
/** /**
* Create the ThirdPartyAllocationFunding from adherent and cotisation flux data * Create the ThirdPartyAllocationFunding from adherent and cotisation flux data
*/ */
private function createThirdPartyAllocationFunding( public function createThirdPartyAllocationFunding(
$adherent, $adherent,
$flux, $flux,
&$fluxCotis, &$fluxCotis,
......
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