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,77 +257,89 @@ 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' );
|
|
||||||
|
|
||||||
|
$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
|
// save the column headers
|
||||||
fputcsv( $file,
|
fputcsv( $handle,
|
||||||
[
|
$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',
|
|
||||||
] );
|
|
||||||
|
|
||||||
|
$chiffreAffaires = 0;
|
||||||
$response = new StreamedResponse();
|
foreach ( $mySellings as $sellRecord ) {
|
||||||
$response->setCallback( function () {
|
foreach ( $sellRecord->getProductsSold() as $productSold ) {
|
||||||
|
$chiffreAffaires += $productSold->getPrice();
|
||||||
$chiffreAffaires = 0;
|
// add a line to the csv file
|
||||||
foreach ( $mySellings as $sellRecord ) {
|
fputcsv( $handle,
|
||||||
foreach ( $sellRecord->getProductsSold() as $productSold ) {
|
[
|
||||||
$chiffreAffaires += $productSold->getPrice();
|
$productSold->getId(),
|
||||||
// add a line to the csv file
|
$sellRecord->getDate()->format( 'c' ),
|
||||||
fputcsv( $file,
|
$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"',
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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