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
aa3fd025
Commit
aa3fd025
authored
Jan 29, 2025
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add script to import existing adherents data for simplified household process
parent
7e886ec1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
10 deletions
+132
-10
ImportSimplifiedHouseholdAdherentsData.php
src/Command/ImportSimplifiedHouseholdAdherentsData.php
+112
-0
AdherentRepository.php
src/Repository/AdherentRepository.php
+20
-10
No files found.
src/Command/ImportSimplifiedHouseholdAdherentsData.php
0 → 100644
View file @
aa3fd025
<?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 adherents profile,
* in order to insure a transition towards simplified household based allowance process.
*/
class
ImportSimplifiedHouseholdAdherentsData
extends
Command
{
protected
static
$defaultName
=
'kohinos:ssa:simplified-household-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 les informations des adhérents existants pour l\'allocation par foyer simplifiée'
)
->
addArgument
(
'filepath'
,
InputArgument
::
REQUIRED
,
'Path to the csv file'
)
;
}
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 simplified household 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
;
}
}
src/Repository/AdherentRepository.php
View file @
aa3fd025
...
...
@@ -19,19 +19,29 @@ class AdherentRepository extends ServiceEntityRepository
parent
::
__construct
(
$registry
,
Adherent
::
class
);
}
public
function
findOneByEmail
(
$email
)
public
function
findOneByEmail
(
$email
,
$enabledOnly
=
true
)
{
$qb
=
$this
->
createQueryBuilder
(
'p'
);
return
$qb
->
leftjoin
(
'p.user'
,
'u'
)
->
where
(
'p.enabled = :enabled'
)
->
andWhere
(
'u.email = :email'
)
->
setParameter
(
'enabled'
,
true
)
->
setParameter
(
'email'
,
$email
)
->
getQuery
()
->
getSingleResult
()
;
if
(
$enabledOnly
)
{
return
$qb
->
leftjoin
(
'p.user'
,
'u'
)
->
where
(
'p.enabled = :enabled'
)
->
andWhere
(
'u.email = :email'
)
->
setParameter
(
'enabled'
,
true
)
->
setParameter
(
'email'
,
$email
)
->
getQuery
()
->
getSingleResult
()
;
}
else
{
return
$qb
->
leftjoin
(
'p.user'
,
'u'
)
->
where
(
'u.email = :email'
)
->
setParameter
(
'email'
,
$email
)
->
getQuery
()
->
getSingleResult
()
;
}
}
/**
...
...
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