exportation ok

This commit is contained in:
Kayn Ty 2018-04-18 15:27:45 +02:00
parent a895986183
commit ffa183fa38
10 changed files with 78 additions and 165 deletions

View File

@ -9,7 +9,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
class DefaultController extends Controller {
@ -257,77 +257,89 @@ class DefaultController extends Controller {
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
$file = fopen( $fileName . '.csv', 'w' );
$handle = fopen( 'php://memory', 'r+' );
$firstLine = [
'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',
];
// save the column headers
fputcsv( $file,
[
'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',
] );
fputcsv( $handle,
$firstLine );
$response = new StreamedResponse();
$response->setCallback( function () {
$chiffreAffaires = 0;
foreach ( $mySellings as $sellRecord ) {
foreach ( $sellRecord->getProductsSold() as $productSold ) {
$chiffreAffaires += $productSold->getPrice();
// add a line to the csv file
fputcsv( $file,
$chiffreAffaires = 0;
foreach ( $mySellings as $sellRecord ) {
foreach ( $sellRecord->getProductsSold() as $productSold ) {
$chiffreAffaires += $productSold->getPrice();
// add a line to the csv file
fputcsv( $handle,
[
$productSold->getId(),
$sellRecord->getDate()->format( 'c' ),
$sellRecord->getDate()->format( 'H' ),
$sellRecord->getDate()->format( 'i' ),
$sellRecord->getDate()->format( 's' ),
$sellRecord->getComment(),
$sellRecord->getPaidByClient(),
$productSold->getName(),
$productSold->getImage(),
$productSold->getProduct()->getCategory()->getId(),
$productSold->getProduct()->getCategory()->getName(),
$productSold->getPrice(),
] );
if ( $sellRecord->getFestival() ) {
fputcsv( $handle,
[
$productSold->getId(),
$sellRecord->getDate()->format( 'c' ),
$sellRecord->getDate()->format( 'H' ),
$sellRecord->getDate()->format( 'i' ),
$sellRecord->getDate()->format( 's' ),
$sellRecord->getComment(),
$sellRecord->getPaidByClient(),
$productSold->getName(),
$productSold->getImage(),
$productSold->getProduct()->getCategory()->getId(),
$productSold->getProduct()->getCategory()->getName(),
$productSold->getPrice(),
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
$sellRecord->getFestival()->getId(),
$sellRecord->getFestival()->getName(),
$sellRecord->getFestival()->getDateCreation()->format( 'c' ),
$sellRecord->getFestival()->getFondDeCaisseAvant(),
$sellRecord->getFestival()->getFondDeCaisseApres(),
$sellRecord->getFestival()->getChiffreAffaire(),
$sellRecord->getFestival()->getComment(),
] );
if ( $sellRecord->getFestival() ) {
fputcsv( $file,
[
$sellRecord->getFestival()->getId(),
$sellRecord->getFestival()->getName(),
$sellRecord->getFestival()->getDateCreation()->format( 'c' ),
$sellRecord->getFestival()->getFondDeCaisseAvant(),
$sellRecord->getFestival()->getFondDeCaisseApres(),
$sellRecord->getFestival()->getChiffreAffaire(),
$sellRecord->getFestival()->getComment(),
] );
}
}
}
fclose( $file );
} );
$response->setStatusCode( 200 );
$response->headers->set( 'Content-Type', 'text/csv; charset=utf-8' );
$response->headers->set( 'Content-Disposition', 'attachment; filename="' . $fileName . '"' );
return $response;
}
}
rewind( $handle );
$content = stream_get_contents( $handle );
fclose( $handle );
return new Response(
$content, 200, [
'Content-Type' => 'application/force-download',
'Content-Disposition' => 'attachment; filename="' . $fileName . '.csv"',
]
);
}
}

View File

@ -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 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

View File

@ -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 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

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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 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

View File

@ -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 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