diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index 4447d733..cca86721 100755 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -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"', + ] + ); } } diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-14-39.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-14-39.csv deleted file mode 100644 index 48be6026..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-14-39.csv +++ /dev/null @@ -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" diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-15-16.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-15-16.csv deleted file mode 100644 index 48be6026..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-15-16.csv +++ /dev/null @@ -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" diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-15-59.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-15-59.csv deleted file mode 100644 index 032acdab..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-15-59.csv +++ /dev/null @@ -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 diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-16-22.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-16-22.csv deleted file mode 100644 index 1b10e523..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-16-22.csv +++ /dev/null @@ -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, diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-17.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-17.csv deleted file mode 100644 index 1b10e523..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-17.csv +++ /dev/null @@ -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, diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-38.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-38.csv deleted file mode 100644 index 1b10e523..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-38.csv +++ /dev/null @@ -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, diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-40.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-40.csv deleted file mode 100644 index 1b10e523..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-17-40.csv +++ /dev/null @@ -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, diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-18-43.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-18-43.csv deleted file mode 100644 index 48be6026..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-18-43.csv +++ /dev/null @@ -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" diff --git a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-18-44.csv b/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-18-44.csv deleted file mode 100644 index 48be6026..00000000 --- a/web/export_caisse-cipherbliss_tykayn_2018-04-18_15-18-44.csv +++ /dev/null @@ -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"