Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
monnaies-locales
kohinos
Commits
956fb4ad
Commit
956fb4ad
authored
Aug 14, 2020
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix export des operations
parent
27396758
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
76 deletions
+124
-76
FluxController.php
src/Controller/FluxController.php
+94
-1
UserPrestataireController.php
src/Controller/UserPrestataireController.php
+2
-71
transactions.html.twig
templates/block/transactions.html.twig
+4
-4
messages.en.xlf
translations/messages.en.xlf
+12
-0
messages.fr.xlf
translations/messages.fr.xlf
+12
-0
No files found.
src/Controller/FluxController.php
View file @
956fb4ad
...
@@ -11,6 +11,7 @@ use Symfony\Component\Form\AbstractType;
...
@@ -11,6 +11,7 @@ use Symfony\Component\Form\AbstractType;
use
Symfony\Component\Form\Form
;
use
Symfony\Component\Form\Form
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\StreamedResponse
;
use
Symfony\Component\HttpFoundation\Session\SessionInterface
;
use
Symfony\Component\HttpFoundation\Session\SessionInterface
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Security\Core\Security
;
use
Symfony\Component\Security\Core\Security
;
...
@@ -18,6 +19,7 @@ use Symfony\Component\Translation\TranslatorInterface;
...
@@ -18,6 +19,7 @@ use Symfony\Component\Translation\TranslatorInterface;
use
Payum\Core\Payum
;
use
Payum\Core\Payum
;
use
Payum\Core\Request\GetHumanStatus
;
use
Payum\Core\Request\GetHumanStatus
;
use
Payum\Core\Request\Notify
;
use
Payum\Core\Request\Notify
;
use
App\Entity\Flux
;
use
App\Entity\Payment
;
use
App\Entity\Payment
;
use
App\Entity\Siege
;
use
App\Entity\Siege
;
use
App\Entity\User
;
use
App\Entity\User
;
...
@@ -27,7 +29,12 @@ use App\Entity\AchatMonnaieAdherent;
...
@@ -27,7 +29,12 @@ use App\Entity\AchatMonnaieAdherent;
use
App\Entity\AchatMonnaiePrestataire
;
use
App\Entity\AchatMonnaiePrestataire
;
use
App\Entity\CotisationAdherent
;
use
App\Entity\CotisationAdherent
;
use
App\Entity\CotisationPrestataire
;
use
App\Entity\CotisationPrestataire
;
use
Sonata\Exporter\Handler
;
use
Sonata\Exporter\Source\DoctrineORMQuerySourceIterator
;
use
Sonata\Exporter\Writer\CsvWriter
;
use
Sonata\Exporter\Writer\JsonWriter
;
use
Sonata\Exporter\Writer\XmlWriter
;
use
Sonata\Exporter\Writer\XlsWriter
;
use
Symfony\Component\Serializer\Normalizer\AbstractNormalizer
;
use
Symfony\Component\Serializer\Normalizer\AbstractNormalizer
;
/**
/**
...
@@ -101,6 +108,92 @@ class FluxController extends AbstractController
...
@@ -101,6 +108,92 @@ class FluxController extends AbstractController
]);
]);
}
}
/**
* Export all transferts / transactions for a user role
*
* @param Request $request Request
* @param String $format Format of export ('json', 'xml', 'csv', 'xls')
* @Route("/flux/export/{format}/", name="exportUserFlux", defaults={"format": "csv"})
*/
public
function
exportFluxAction
(
Request
$request
,
$format
=
'csv'
)
{
//Prepare query depending on user role
$query
=
null
;
$user
=
$this
->
security
->
getUser
();
if
(
$this
->
session
->
get
(
'_prestagere'
)
!=
null
&&
$this
->
security
->
getUser
()
->
isGranted
(
'ROLE_PRESTATAIRE'
))
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByPrestataire
(
$this
->
session
->
get
(
'_prestagere'
));
}
elseif
(
$user
->
getAdherent
()
!=
null
&&
$this
->
security
->
getUser
()
->
isGranted
(
'ROLE_ADHERENT'
))
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByAdherent
(
$user
->
getAdherent
());
}
elseif
(
$this
->
session
->
get
(
'_comptoirgere'
)
!=
null
&&
$this
->
security
->
getUser
()
->
isGranted
(
'ROLE_COMPTOIR'
))
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByComptoir
(
$this
->
session
->
get
(
'_comptoirgere'
));
}
elseif
(
$this
->
session
->
get
(
'_groupegere'
)
!=
null
&&
$this
->
security
->
getUser
()
->
isGranted
(
'ROLE_GESTION_GROUPE'
))
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByGroupe
(
$this
->
session
->
get
(
'_groupegere'
));
}
if
(
$query
!=
null
)
{
// Prepare the data source
$fields
=
[
'expediteur'
,
'destinataire'
,
'type'
,
'parenttype'
,
'montant'
,
'moyen'
,
'operateur'
];
$source
=
new
DoctrineORMQuerySourceIterator
(
$query
,
$fields
);
$filename
=
sprintf
(
'export_flux_%s.%s'
,
date
(
'Y_m_d_H_i_s'
,
strtotime
(
'now'
)),
$format
);
return
$this
->
getResponse
(
$format
,
$filename
,
$source
);
}
else
{
$this
->
addFlash
(
'error'
,
$this
->
translator
->
trans
(
'Export impossible.'
)
);
return
$this
->
redirectToRoute
(
'index'
);
}
}
private
function
getResponse
(
$format
,
$filename
,
$source
)
{
switch
(
$format
)
{
case
'xls'
:
$writer
=
new
XlsWriter
(
'php://output'
);
$contentType
=
'application/vnd.ms-excel'
;
break
;
case
'xml'
:
$writer
=
new
XmlWriter
(
'php://output'
);
$contentType
=
'text/xml'
;
break
;
case
'json'
:
$writer
=
new
JsonWriter
(
'php://output'
);
$contentType
=
'application/json'
;
break
;
case
'csv'
:
$writer
=
new
CsvWriter
(
'php://output'
,
','
,
'"'
,
'\\'
,
true
,
true
);
$contentType
=
'text/csv'
;
break
;
default
:
throw
new
\RuntimeException
(
'Invalid format'
);
}
$callback
=
static
function
()
use
(
$source
,
$writer
)
{
$handler
=
Handler
::
create
(
$source
,
$writer
);
$handler
->
export
();
};
return
new
StreamedResponse
(
$callback
,
200
,
[
'Content-Type'
=>
$contentType
,
'Content-Disposition'
=>
sprintf
(
'attachment; filename="%s"'
,
$filename
),
]);
}
/*
/*
* Crée une instance de Payment et redirige vers la page de paiement
* Crée une instance de Payment et redirige vers la page de paiement
*/
*/
...
...
src/Controller/UserPrestataireController.php
View file @
956fb4ad
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
namespace
App\Controller
;
namespace
App\Controller
;
use
App\Entity\Flux
;
use
App\Entity\Prestataire
;
use
App\Entity\Prestataire
;
use
App\Entity\Rubrique
;
use
App\Entity\Rubrique
;
use
App\Entity\TransactionPrestataireAdherent
;
use
App\Entity\TransactionPrestataireAdherent
;
...
@@ -17,9 +16,6 @@ use App\Form\Type\TransfertPrestataireSiegeFormType;
...
@@ -17,9 +16,6 @@ use App\Form\Type\TransfertPrestataireSiegeFormType;
use
App\Form\Type\AchatMonnaiePrestataireFormType
;
use
App\Form\Type\AchatMonnaiePrestataireFormType
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted
;
use
Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted
;
use
Sonata\Exporter\Handler
;
use
Sonata\Exporter\Source\DoctrineORMQuerySourceIterator
;
use
Sonata\Exporter\Writer\CsvWriter
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Routing\Annotation\Route
;
...
@@ -101,7 +97,7 @@ class UserPrestataireController extends FluxController
...
@@ -101,7 +97,7 @@ class UserPrestataireController extends FluxController
return
$this
->
manageFluxForm
(
return
$this
->
manageFluxForm
(
$request
,
$request
,
$form
,
$form
,
$this
->
session
->
get
(
'_prestagere'
)
->
get
C
ompte
(),
$this
->
session
->
get
(
'_prestagere'
)
->
get
Ec
ompte
(),
$this
->
translator
->
trans
(
'Transaction bien effectuée !'
),
$this
->
translator
->
trans
(
'Transaction bien effectuée !'
),
$this
->
translator
->
trans
(
'Transaction à un '
)
.
$type
$this
->
translator
->
trans
(
'Transaction à un '
)
.
$type
);
);
...
@@ -121,7 +117,7 @@ class UserPrestataireController extends FluxController
...
@@ -121,7 +117,7 @@ class UserPrestataireController extends FluxController
return
$this
->
manageFluxForm
(
return
$this
->
manageFluxForm
(
$request
,
$request
,
$form
,
$form
,
$this
->
session
->
get
(
'_prestagere'
)
->
get
C
ompte
(),
$this
->
session
->
get
(
'_prestagere'
)
->
get
Ec
ompte
(),
$this
->
translator
->
trans
(
'Reconversion envoyée, elle sera validée lorsque le virement sera effectué !'
),
$this
->
translator
->
trans
(
'Reconversion envoyée, elle sera validée lorsque le virement sera effectué !'
),
$this
->
translator
->
trans
(
'Reconversion de monnaie au siège'
)
$this
->
translator
->
trans
(
'Reconversion de monnaie au siège'
)
);
);
...
@@ -154,69 +150,4 @@ class UserPrestataireController extends FluxController
...
@@ -154,69 +150,4 @@ class UserPrestataireController extends FluxController
]);
]);
}
}
/**
* Export all transferts / transactions for prestataire
*
* @param Request $request Request
* @param String $format Format of export ('json', 'xml', 'csv', 'xls')
* @Route("/prestataire/export/{format}/", name="exportPrestaFlux", defaults={"format": "csv"})
* @IsGranted("ROLE_PRESTATAIRE")
*/
public
function
exportFluxAction
(
Request
$request
,
$format
=
'csv'
)
{
// Prepare the data source
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByPrestataire
(
$this
->
session
->
get
(
'_prestagere'
));
$fields
=
[
'expediteur'
,
'destinataire'
,
'type'
,
'parenttype'
,
'montant'
,
'moyen'
,
'operateur'
];
$source
=
new
DoctrineORMQuerySourceIterator
(
$query
,
$fields
);
$filename
=
sprintf
(
'export_flux_%s.%s'
,
date
(
'Y_m_d_H_i_s'
,
strtotime
(
'now'
)),
$format
);
return
$this
->
getResponse
(
$format
,
$filename
,
$source
);
}
private
function
getResponse
(
$format
,
$filename
,
SourceIteratorInterface
$source
)
{
switch
(
$format
)
{
case
'xls'
:
$writer
=
new
XlsWriter
(
'php://output'
);
$contentType
=
'application/vnd.ms-excel'
;
break
;
case
'xml'
:
$writer
=
new
XmlWriter
(
'php://output'
);
$contentType
=
'text/xml'
;
break
;
case
'json'
:
$writer
=
new
JsonWriter
(
'php://output'
);
$contentType
=
'application/json'
;
break
;
case
'csv'
:
$writer
=
new
CsvWriter
(
'php://output'
,
','
,
'"'
,
'\\'
,
true
,
true
);
$contentType
=
'text/csv'
;
break
;
default
:
throw
new
\RuntimeException
(
'Invalid format'
);
}
$callback
=
static
function
()
use
(
$source
,
$writer
)
{
$handler
=
Handler
::
create
(
$source
,
$writer
);
$handler
->
export
();
};
return
new
StreamedResponse
(
$callback
,
200
,
[
'Content-Type'
=>
$contentType
,
'Content-Disposition'
=>
sprintf
(
'attachment; filename="%s"'
,
$filename
),
]);
}
}
}
templates/block/transactions.html.twig
View file @
956fb4ad
...
@@ -45,19 +45,19 @@
...
@@ -45,19 +45,19 @@
<span
class=
"caret"
></span>
<span
class=
"caret"
></span>
</button>
</button>
<div
class=
"dropdown-menu"
aria-labelledby=
"dropdownMenuLink"
>
<div
class=
"dropdown-menu"
aria-labelledby=
"dropdownMenuLink"
>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
Presta
Flux'
,
{
'format'
:
'json'
}
)
}}
"
>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
User
Flux'
,
{
'format'
:
'json'
}
)
}}
"
>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
JSON
JSON
</a>
</a>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
Presta
Flux'
,
{
'format'
:
'xml'
}
)
}}
"
>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
User
Flux'
,
{
'format'
:
'xml'
}
)
}}
"
>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
XML
XML
</a>
</a>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
Presta
Flux'
,
{
'format'
:
'csv'
}
)
}}
"
>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
User
Flux'
,
{
'format'
:
'csv'
}
)
}}
"
>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
CSV
CSV
</a>
</a>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
Presta
Flux'
,
{
'format'
:
'xls'
}
)
}}
"
>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'export
User
Flux'
,
{
'format'
:
'xls'
}
)
}}
"
>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
<i
class=
"fa fa-arrow-circle-o-down"
aria-hidden=
"true"
></i>
XLS
XLS
</a>
</a>
...
...
translations/messages.en.xlf
View file @
956fb4ad
...
@@ -865,6 +865,18 @@
...
@@ -865,6 +865,18 @@
<source>
Cotiser
</source>
<source>
Cotiser
</source>
<target>
Cotiser
</target>
<target>
Cotiser
</target>
</trans-unit>
</trans-unit>
<trans-unit
id=
"STMXKMO"
resname=
"Achat de monnaie locale bien effectué !"
>
<source>
Achat de monnaie locale bien effectué !
</source>
<target>
Achat de monnaie locale bien effectué !
</target>
</trans-unit>
<trans-unit
id=
"dfPWdav"
resname=
"La transaction a été annulée."
>
<source>
La transaction a été annulée.
</source>
<target>
La transaction a été annulée.
</target>
</trans-unit>
<trans-unit
id=
"NXrqKKn"
resname=
"Export impossible."
>
<source>
Export impossible.
</source>
<target>
Export impossible.
</target>
</trans-unit>
</body>
</body>
</file>
</file>
</xliff>
</xliff>
translations/messages.fr.xlf
View file @
956fb4ad
...
@@ -881,6 +881,18 @@
...
@@ -881,6 +881,18 @@
<source>
Cotiser
</source>
<source>
Cotiser
</source>
<target>
Cotiser
</target>
<target>
Cotiser
</target>
</trans-unit>
</trans-unit>
<trans-unit
id=
"STMXKMO"
resname=
"Achat de monnaie locale bien effectué !"
>
<source>
Achat de monnaie locale bien effectué !
</source>
<target>
Achat de monnaie locale bien effectué !
</target>
</trans-unit>
<trans-unit
id=
"dfPWdav"
resname=
"La transaction a été annulée."
>
<source>
La transaction a été annulée.
</source>
<target>
La transaction a été annulée.
</target>
</trans-unit>
<trans-unit
id=
"NXrqKKn"
resname=
"Export impossible."
>
<source>
Export impossible.
</source>
<target>
Export impossible.
</target>
</trans-unit>
</body>
</body>
</file>
</file>
</xliff>
</xliff>
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