make csv ongoing

This commit is contained in:
Kayn Ty 2018-04-18 15:19:00 +02:00
parent fe8b0aa111
commit a895986183
13 changed files with 268 additions and 9 deletions

View File

@ -17,6 +17,9 @@
{% block navigation %}
{% endblock %}
<div id="bodyland">
<div class="container">
{% include 'default/header.html.twig' %}
</div>
{% block body %}
{% endblock %}
</div>

View File

@ -38,6 +38,13 @@
Festivals
</a>
</li>
<li>
<a class="btn btn-default" href="{{ path('history') }}"
data-toggle="tab">
<i class="fa fa-clock"></i>
Historique
</a>
</li>
</ul>
</div>
</div>

View File

@ -1,6 +1,47 @@
<div class="well">
<a href="">
Exporter vos données
<i class="fa fa-file-o fa-3x"></i>
</a>
</div>
{% extends 'base.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block body %}
<div id="wrapper">
<div id="container" class="container">
<div class="row">
<h1>Historique</h1>
</div>
<div class="row">
<div class="col-xs-6">
<div class="sells">
<h2>
<div class="badge">
{{ recentSells |length }}
</div>
Clients
</h2>
<h2>
Chiffre d'affaires
<div class="badge">
{{ chiffreAffaires }}
</div>
</h2>
<h2>
panier moyen
<div class="badge">
{{ chiffreAffaires / (recentSells |length) }}
</div>
</h2>
<div>
</div>
</div>
</div>
<div class="col-xs-6 text-right">
<a class="btn btn-success" href="{{ path('export_all') }}">
<i class="fa fa-file-o fa-3x"></i>
Exporter toutes vos données en format csv
</a>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -9,6 +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\Security\Csrf\CsrfTokenManagerInterface;
class DefaultController extends Controller {
@ -52,7 +53,6 @@ class DefaultController extends Controller {
$categories = $categRepo->findAll();
$recentSells = $sellingRepo->findBy( [], [ 'id' => 'desc' ], 0, 5 );
// replace this example code with whatever you need
return $this->render( 'logged/dashboard.html.twig',
[
'lastFestival' => $lastFestival,
@ -199,7 +199,6 @@ class DefaultController extends Controller {
$newSellRecord->setDate( new \DateTime() );
$newSellRecord->setUser( $currentUser );
$newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
// $newSellRecord->setUser( $currentUser );
$newSellRecord->setComment( $json[ 'sellingComment' ] );
$currentUser->addSellRecords( $newSellRecord );
@ -214,11 +213,121 @@ class DefaultController extends Controller {
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$lastSellings = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 3 );
// return var_dump( $request->getContent() );
return new JsonResponse( [
"message" => "ok",
"recent_sellings" => json_encode( $lastSellings ),
"dump" => $json,
], 200 );
}
/**
* get the history of user's sellings
* @Route("/history", name="history")
*/
public function historyAction() {
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
$chiffreAffaires = 0;
foreach ( $mySellings as $client ) {
foreach ( $client->getProductsSold() as $product ) {
$chiffreAffaires += $product->getPrice();
}
}
return $this->render( 'logged/history.html.twig',
[
'chiffreAffaires' => $chiffreAffaires,
'recentSells' => $mySellings,
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
] );
}
/**
* export all clients
* @Route("/export-all", name="export_all")
*/
public function exportAllAction() {
// TODO
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
$file = fopen( $fileName . '.csv', 'w' );
// 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',
] );
$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,
[
$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( $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;
}
}

View File

@ -0,0 +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"
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

@ -0,0 +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"
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

@ -0,0 +1,7 @@
"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

@ -0,0 +1,22 @@
"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

@ -0,0 +1,22 @@
"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

@ -0,0 +1,22 @@
"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

@ -0,0 +1,22 @@
"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

@ -0,0 +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"
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

@ -0,0 +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"
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