Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos-tav
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
agplv3
kohinos-tav
Commits
9ec4f42b
Commit
9ec4f42b
authored
Mar 21, 2024
by
Yvon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create command to perform reconversions for presta with specified frequency
parent
b5cb1754
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
+115
-0
ReconversionMonaPrestatairesCommand.php
src/Command/ReconversionMonaPrestatairesCommand.php
+115
-0
No files found.
src/Command/ReconversionMonaPrestatairesCommand.php
0 → 100644
View file @
9ec4f42b
<?php
declare
(
strict_types
=
1
);
namespace
App\Command
;
use
App\Entity\GlobalParameter
;
use
App\Entity\Prestataire
;
use
App\Entity\Reconversion
;
use
App\Entity\Siege
;
use
App\Enum\MoyenEnum
;
use
App\Enum\ReconversionFrequencyEnum
;
use
App\Utils\CustomEntityManager
;
use
App\Utils\OperationUtils
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Input\InputArgument
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Output\OutputInterface
;
use
Symfony\Component\Console\Style\SymfonyStyle
;
use
Twig\Environment
;
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
class
ReconversionMonaPrestatairesCommand
extends
Command
{
//Call with following crons :
//15 1 14,28 * * kohinos php /home/kohinos/kohinos/bin/console kohinos:ssa:reconversion-prestataires twice_a_month
//17 1 28 * * kohinos php /home/kohinos/kohinos/bin/console kohinos:ssa:reconversion-prestataires once_a_month
//19 1 28 1,3,5,7,9,11 * kohinos php /home/kohinos/kohinos/bin/console kohinos:ssa:reconversion-prestataires once_every_two_month
protected
static
$defaultName
=
'kohinos:ssa:reconversion-prestataires'
;
protected
$em
;
protected
$mailer
;
protected
$templating
;
protected
$io
;
protected
$param
;
protected
$operationUtils
;
public
function
__construct
(
CustomEntityManager
$em
,
\Swift_Mailer
$mailer
,
Environment
$templating
,
OperationUtils
$operationUtils
)
{
$this
->
em
=
$em
;
$this
->
mailer
=
$mailer
;
$this
->
templating
=
$templating
;
$this
->
operationUtils
=
$operationUtils
;
parent
::
__construct
();
}
protected
function
configure
()
{
$this
->
setDescription
(
'SSA : générer des flux de reconversion conformément à la fréquence configurée par les prestataires'
)
->
addArgument
(
'reconvmode'
,
InputArgument
::
REQUIRED
,
'Restriction aux seuls prestataires ayant opté pour la fréquence choisie.'
);
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
)
:
int
{
$this
->
io
=
new
SymfonyStyle
(
$input
,
$output
);
$reconvmode
=
$input
->
getArgument
(
'reconvmode'
);
if
(
!
in_array
(
$reconvmode
,
ReconversionFrequencyEnum
::
getAvailableTypes
()))
{
$this
->
io
->
error
(
"L'argument "
.
$reconvmode
.
' est invalide. Choix possibles : '
.
implode
(
', '
,
ReconversionFrequencyEnum
::
getAvailableTypes
()));
return
1
;
}
$this
->
io
->
title
(
'START. Reconversion pour les prestataires de compte positif ayant choisi la fréquence : '
.
$reconvmode
);
$prestas
=
$this
->
em
->
getRepository
(
Prestataire
::
class
)
->
findBy
([
'reconversionFrequency'
=>
$reconvmode
]);
foreach
(
$prestas
as
$p
)
{
$balance
=
$p
->
getEmlcAccount
()
->
getBalance
();
if
(
$balance
<=
0
)
{
continue
;
}
/* @var Prestataire $p */
$flux
=
new
Reconversion
();
//do not fill operator as it is automated process $entity->setOperateur();
$flux
->
setExpediteur
(
$p
);
$flux
->
setMontant
(
$balance
);
//montant maximal
$flux
->
setDestinataire
(
$this
->
em
->
getRepository
(
Siege
::
class
)
->
getTheOne
());
$flux
->
setMoyen
(
MoyenEnum
::
MOYEN_AUTRE
);
$flux
->
setTauxreconversion
(
!
empty
(
$p
->
getTauxreconversion
())
?
$p
->
getTauxreconversion
()
:
floatval
(
$this
->
em
->
getRepository
(
GlobalParameter
::
class
)
->
val
(
GlobalParameter
::
RECONVERSION_PRESTATAIRE
)
)
);
$now
=
new
\DateTime
();
$flux
->
setReference
(
'Reconversion automatique du '
.
$now
->
format
(
'd/m/Y'
)
.
" pour le mode de reconversion "
.
$reconvmode
);
$this
->
operationUtils
->
executeOperations
(
$flux
);
}
$this
->
io
->
success
(
'End'
);
$memoryUsage
=
memory_get_usage
(
true
)
/
1024
/
1024
;
$this
->
io
->
text
(
"Batch finished with memory: ${memoryUsage}M"
);
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment