exportation ok
This commit is contained in:
parent
a895986183
commit
ffa183fa38
@ -9,7 +9,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
|
|
||||||
class DefaultController extends Controller {
|
class DefaultController extends Controller {
|
||||||
@ -257,11 +257,9 @@ class DefaultController extends Controller {
|
|||||||
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
|
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
|
||||||
|
|
||||||
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
|
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
|
||||||
$file = fopen( $fileName . '.csv', 'w' );
|
|
||||||
|
|
||||||
// save the column headers
|
$handle = fopen( 'php://memory', 'r+' );
|
||||||
fputcsv( $file,
|
$firstLine = [
|
||||||
[
|
|
||||||
'product sold id',
|
'product sold id',
|
||||||
'date',
|
'date',
|
||||||
'hour',
|
'hour',
|
||||||
@ -281,18 +279,17 @@ class DefaultController extends Controller {
|
|||||||
'caisse after',
|
'caisse after',
|
||||||
'festival ca',
|
'festival ca',
|
||||||
'festival comment',
|
'festival comment',
|
||||||
] );
|
];
|
||||||
|
// save the column headers
|
||||||
|
fputcsv( $handle,
|
||||||
$response = new StreamedResponse();
|
$firstLine );
|
||||||
$response->setCallback( function () {
|
|
||||||
|
|
||||||
$chiffreAffaires = 0;
|
$chiffreAffaires = 0;
|
||||||
foreach ( $mySellings as $sellRecord ) {
|
foreach ( $mySellings as $sellRecord ) {
|
||||||
foreach ( $sellRecord->getProductsSold() as $productSold ) {
|
foreach ( $sellRecord->getProductsSold() as $productSold ) {
|
||||||
$chiffreAffaires += $productSold->getPrice();
|
$chiffreAffaires += $productSold->getPrice();
|
||||||
// add a line to the csv file
|
// add a line to the csv file
|
||||||
fputcsv( $file,
|
fputcsv( $handle,
|
||||||
[
|
[
|
||||||
$productSold->getId(),
|
$productSold->getId(),
|
||||||
$sellRecord->getDate()->format( 'c' ),
|
$sellRecord->getDate()->format( 'c' ),
|
||||||
@ -308,8 +305,20 @@ class DefaultController extends Controller {
|
|||||||
$productSold->getPrice(),
|
$productSold->getPrice(),
|
||||||
] );
|
] );
|
||||||
if ( $sellRecord->getFestival() ) {
|
if ( $sellRecord->getFestival() ) {
|
||||||
fputcsv( $file,
|
fputcsv( $handle,
|
||||||
[
|
[
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
$sellRecord->getFestival()->getId(),
|
$sellRecord->getFestival()->getId(),
|
||||||
$sellRecord->getFestival()->getName(),
|
$sellRecord->getFestival()->getName(),
|
||||||
$sellRecord->getFestival()->getDateCreation()->format( 'c' ),
|
$sellRecord->getFestival()->getDateCreation()->format( 'c' ),
|
||||||
@ -322,12 +331,15 @@ class DefaultController extends Controller {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose( $file );
|
rewind( $handle );
|
||||||
} );
|
$content = stream_get_contents( $handle );
|
||||||
$response->setStatusCode( 200 );
|
fclose( $handle );
|
||||||
$response->headers->set( 'Content-Type', 'text/csv; charset=utf-8' );
|
|
||||||
$response->headers->set( 'Content-Disposition', 'attachment; filename="' . $fileName . '"' );
|
|
||||||
|
|
||||||
return $response;
|
return new Response(
|
||||||
|
$content, 200, [
|
||||||
|
'Content-Type' => 'application/force-download',
|
||||||
|
'Content-Disposition' => 'attachment; filename="' . $fileName . '.csv"',
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
|
@ -1 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
|
@ -1,7 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
||||||
5,2018-04-17T14:33:51+02:00,14,33,51,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
6,2018-04-17T14:36:15+02:00,14,36,15,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
7,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
8,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
9,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
10,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -1,22 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
||||||
5,2018-04-17T14:33:51+02:00,14,33,51,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
6,2018-04-17T14:36:15+02:00,14,36,15,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
7,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
8,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
9,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
10,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
11,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
12,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
13,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
14,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
15,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
16,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
17,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -1,22 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
||||||
5,2018-04-17T14:33:51+02:00,14,33,51,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
6,2018-04-17T14:36:15+02:00,14,36,15,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
7,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
8,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
9,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
10,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
11,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
12,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
13,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
14,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
15,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
16,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
17,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -1,22 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
||||||
5,2018-04-17T14:33:51+02:00,14,33,51,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
6,2018-04-17T14:36:15+02:00,14,36,15,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
7,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
8,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
9,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
10,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
11,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
12,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
13,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
14,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
15,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
16,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
17,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -1,22 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
||||||
5,2018-04-17T14:33:51+02:00,14,33,51,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
6,2018-04-17T14:36:15+02:00,14,36,15,sellingComment,20.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
7,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
8,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
9,2018-04-17T15:07:53+02:00,15,07,53,,0.00,aaaaaa,"image mock",1,fanzine,3.00
|
|
||||||
10,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
11,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
12,2018-04-18T15:14:32+02:00,15,14,32,,0.00,"un truc","image mock",1,fanzine,2.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
13,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
14,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
15,2018-04-18T15:14:32+02:00,15,14,32,,0.00,aaaaaa,"image mock",1,fanzine,1.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
16,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
||||||
17,2018-04-18T15:14:32+02:00,15,14,32,,0.00,bbbb,"image mock",2,badges,10.00
|
|
||||||
4,"japan expo",2018-04-17T15:37:15+02:00,0,0,0,
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -1 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
|
@ -1 +0,0 @@
|
|||||||
"product sold id",date,hour,min,sec,"client comment","client paid","product name","product image","product category id","product category name","product price","festival id","festival name","festival creation date","caisse before","caisse after","festival ca","festival comment"
|
|
|
Loading…
Reference in New Issue
Block a user