Créez facilement vos catégories de produits et vos produits juste en écrivant un nom par ligne dans
diff --git a/app/Resources/views/logged/history.html.twig b/app/Resources/views/logged/history.html.twig
index 49be47b8..e1c82936 100755
--- a/app/Resources/views/logged/history.html.twig
+++ b/app/Resources/views/logged/history.html.twig
@@ -7,6 +7,10 @@
+
+
+
+
{% endblock %}
diff --git a/assets/js/parts/main.js b/assets/js/parts/main.js
index 227099c2..fe3500fc 100755
--- a/assets/js/parts/main.js
+++ b/assets/js/parts/main.js
@@ -1,8 +1,10 @@
+// require('../../../node_modules/canvasjs/dist/canvasjs.3');
+
+
var $ = require('jquery');
// JS is equivalent to the normal "bootstrap" package
// no need to set this to a variable, just require it
require('bootstrap-sass');
-
// or you can include specific pieces
// require('bootstrap-sass/javascripts/bootstrap/tooltip');
// require('bootstrap-sass/javascripts/bootstrap/popover');
diff --git a/package.json b/package.json
index 3fac54c3..cad9071e 100755
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"dependencies": {
"angular": "1.5",
"bootstrap": "^4.0.0",
+ "canvasjs": "^1.8.1",
"font-awesome": "^4.7.0",
"jquery": "1.12.2"
}
diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php
index 40b16c18..3e33123c 100755
--- a/src/AppBundle/Controller/DefaultController.php
+++ b/src/AppBundle/Controller/DefaultController.php
@@ -14,497 +14,539 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
-class DefaultController extends Controller {
+class DefaultController extends Controller
+{
- private $tokenManager;
+ private $tokenManager;
- public function __construct( CsrfTokenManagerInterface $tokenManager = null ) {
- $this->tokenManager = $tokenManager;
- }
+ public function __construct(CsrfTokenManagerInterface $tokenManager = null)
+ {
+ $this->tokenManager = $tokenManager;
+ }
- /**
- * @Route("/", name="homepage")
- */
- public function indexAction( Request $request ) {
- $m = $this->getDoctrine()->getManager();
- $userRepo = $m->getRepository( 'AppBundle:User' );
- $allUsers = $userRepo->findAll();
+ /**
+ * @Route("/", name="homepage")
+ */
+ public function indexAction(Request $request)
+ {
+ $m = $this->getDoctrine()->getManager();
+ $userRepo = $m->getRepository('AppBundle:User');
+ $allUsers = $userRepo->findAll();
- // replace this example code with whatever you need
- return $this->render( 'default/index.html.twig',
- [
- 'usersCount' => count( $allUsers ),
- 'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
- ] );
- }
+ // replace this example code with whatever you need
+ return $this->render('default/index.html.twig',
+ [
+ 'usersCount' => count($allUsers),
+ 'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR,
+ ]);
+ }
- /**
- * @Route("/dashboard", name="dashboard")
- */
- public function dashboardAction( Request $request ) {
- $m = $this->getDoctrine()->getManager();
- $currentUser = $this->getUser();
+ /**
+ * @Route("/dashboard", name="dashboard")
+ */
+ public function dashboardAction(Request $request)
+ {
+ $m = $this->getDoctrine()->getManager();
+ $currentUser = $this->getUser();
// TODO on first login set default values
- $lastFestival = $currentUser->getActiveFestival();
- if ( ! $lastFestival ) {
- $lastFestival = $m->getRepository( 'AppBundle:Festival' )
- ->findOneBy( [ 'user' => $this->getUser()->getId() ],
- [ 'id' => 'desc' ],
- 0,
- 1 );
- }
- if ( $lastFestival ) {
+ $lastFestival = $currentUser->getActiveFestival();
+ if (!$lastFestival) {
+ $lastFestival = $m->getRepository('AppBundle:Festival')
+ ->findOneBy(['user' => $this->getUser()->getId()],
+ ['id' => 'desc'],
+ 0,
+ 1);
+ }
+ if ($lastFestival) {
- $lastFestival->recalculateChiffreAffaire();
- }
- $categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
- $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
- $categories = $categRepo->findAll();
- $recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
+ $lastFestival->recalculateChiffreAffaire();
+ }
+ $categRepo = $m->getRepository('AppBundle:ProductCategory');
+ $sellingRepo = $m->getRepository('AppBundle:SellRecord');
+ $categories = $categRepo->findAll();
+ $recentSells = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 5);
- return $this->render( 'logged/dashboard.html.twig',
- [
- 'lastFestival' => $lastFestival,
- 'categories' => $categories,
- 'currentUser' => $currentUser,
- 'recentSells' => $recentSells,
- 'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
- ] );
- }
+ return $this->render('logged/dashboard.html.twig',
+ [
+ 'lastFestival' => $lastFestival,
+ 'categories' => $categories,
+ 'currentUser' => $currentUser,
+ 'recentSells' => $recentSells,
+ 'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR,
+ ]);
+ }
- /**
- * envoyer un email
- */
- public function emailAction() {
- $name = "noble barbare";
- $message = \Swift_Message::newInstance()
- ->setSubject( 'Hello Email' )
- ->setFrom( 'test-symfony-tykayn@caisse.ciperbliss.com' )
- ->setTo( 'tykayn@gmail.com' )
- ->setBody( $this->renderView( 'default/test-email.html.twig' ),
- 'text/html' );
- $this->get( 'mailer' )->send( $message );
+ /**
+ * envoyer un email
+ */
+ public function emailAction()
+ {
+ $name = "noble barbare";
+ $message = \Swift_Message::newInstance()
+ ->setSubject('Hello Email')
+ ->setFrom('test-symfony-tykayn@caisse.ciperbliss.com')
+ ->setTo('tykayn@gmail.com')
+ ->setBody($this->renderView('default/test-email.html.twig'),
+ 'text/html');
+ $this->get('mailer')->send($message);
//return 'yay test de mail';
- return $this->render(
- 'default/test-email.html.twig',
- [
- ]
- );
- }
+ return $this->render(
+ 'default/test-email.html.twig',
+ [
+ ]
+ );
+ }
- /**
- * get user products
- * @return JsonResponse
- */
- public function getMyProductsAction() {
- $m = $this->getDoctrine()->getManager();
+ /**
+ * get user products
+ * @return JsonResponse
+ */
+ public function getMyProductsAction()
+ {
+ $m = $this->getDoctrine()->getManager();
- $currentUser = $this->getUser();
- if ( ! $currentUser ) {
- return new JsonResponse( [
- 'categories' => [ [ 'name' => 'demo category', 'products' => [] ] ],
- 'recentSells' => [ [ '' ] ],
- ] );
- }
+ $currentUser = $this->getUser();
+ if (!$currentUser) {
+ return new JsonResponse([
+ 'categories' => [['name' => 'demo category', 'products' => []]],
+ 'recentSells' => [['']],
+ ]);
+ }
- $activeFestival = $currentUser->getActiveFestival();
- if ( ! $activeFestival ) {
- $activeFestival = $m->getRepository( 'AppBundle:Festival' )
- ->findOneBy( [ 'user' => $this->getUser()->getId() ],
- [ 'id' => 'desc' ],
- 0,
- 1 );
- if ( ! $activeFestival ) {
- $activeFestival = new Festival();
- $activeFestival->setDateCreation( new \DateTime() )
- ->setName( 'default festival' )
- ->setChiffreAffaire( 0 )
- ->setFondDeCaisseAvant( 0 )
- ->setFondDeCaisseApres( 0 )
- ->setUser( $currentUser );
- }
- $currentUser->setActiveFestival( $activeFestival );
- $m->persist( $activeFestival );
- $m->persist( $currentUser );
- $m->flush();
- }
+ $activeFestival = $currentUser->getActiveFestival();
+ if (!$activeFestival) {
+ $activeFestival = $m->getRepository('AppBundle:Festival')
+ ->findOneBy(['user' => $this->getUser()->getId()],
+ ['id' => 'desc'],
+ 0,
+ 1);
+ if (!$activeFestival) {
+ $activeFestival = new Festival();
+ $activeFestival->setDateCreation(new \DateTime())
+ ->setName('default festival')
+ ->setChiffreAffaire(0)
+ ->setFondDeCaisseAvant(0)
+ ->setFondDeCaisseApres(0)
+ ->setUser($currentUser);
+ }
+ $currentUser->setActiveFestival($activeFestival);
+ $m->persist($activeFestival);
+ $m->persist($currentUser);
+ $m->flush();
+ }
- $categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
- $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
- $categories = $currentUser->getCategories();
- if ( ! count( $categories ) ) {
- $categories = $defaultCategories = $categRepo->findById( [ 1, 2 ] );
- $currentUser->setCategories( $defaultCategories );
- $m->persist( $currentUser );
- }
- $serializedCategories = [];
+ $categRepo = $m->getRepository('AppBundle:ProductCategory');
+ $sellingRepo = $m->getRepository('AppBundle:SellRecord');
+ $categories = $currentUser->getCategories();
+ if (!count($categories)) {
+ $categories = $defaultCategories = $categRepo->findById([1, 2]);
+ $currentUser->setCategories($defaultCategories);
+ $m->persist($currentUser);
+ }
+ $serializedCategories = [];
- foreach ( $categories as $category ) {
- $products = $category->getProducts();
- if ( $products ) {
- $listOfProductsInArray = [];
- foreach ( $products as $product ) {
- $listOfProductsInArray[] = [
- 'id' => $product->getId(),
- 'name' => $product->getName(),
- 'category' => $category->getId(),
- 'price' => 1 * $product->getPrice(),
- 'stockCount' => $product->getStockCount(),
- ];
- }
- $products = $listOfProductsInArray;
- }
- $serializedCategories[] =
- [
- 'id' => $category->getId(),
- 'name' => $category->getName(),
- 'products' => $products ? $products : null,
- ];
+ foreach ($categories as $category) {
+ $products = $category->getProducts();
+ if ($products) {
+ $listOfProductsInArray = [];
+ foreach ($products as $product) {
+ $listOfProductsInArray[] = [
+ 'id' => $product->getId(),
+ 'name' => $product->getName(),
+ 'category' => $category->getId(),
+ 'price' => 1 * $product->getPrice(),
+ 'stockCount' => $product->getStockCount(),
+ ];
+ }
+ $products = $listOfProductsInArray;
+ }
+ $serializedCategories[] =
+ [
+ 'id' => $category->getId(),
+ 'name' => $category->getName(),
+ 'products' => $products ? $products : null,
+ ];
- }
- $categories = $serializedCategories;
+ }
+ $categories = $serializedCategories;
- $recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
+ $recentSells = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 5);
- return new JsonResponse( [
- 'categories' => $categories,
- 'recentSells' => count( $recentSells ),
- 'lastFestival' => [
- 'id' => $activeFestival->getId(),
- 'name' => $activeFestival->getName(),
- 'commentaire' => $activeFestival->getComment(),
- 'dateCreation' => $activeFestival->getDateCreation(),
- 'chiffreAffaire' => $activeFestival->getChiffreAffaire(),
- 'clientsCount' => count( $activeFestival->getSellRecords() ),
- 'fondDeCaisseAvant' => $activeFestival->getFondDeCaisseAvant(),
- 'fondDeCaisseApres' => $activeFestival->getFondDeCaisseApres(),
- ],
- ] );
- }
+ return new JsonResponse([
+ 'categories' => $categories,
+ 'recentSells' => count($recentSells),
+ 'lastFestival' => [
+ 'id' => $activeFestival->getId(),
+ 'name' => $activeFestival->getName(),
+ 'commentaire' => $activeFestival->getComment(),
+ 'dateCreation' => $activeFestival->getDateCreation(),
+ 'chiffreAffaire' => $activeFestival->getChiffreAffaire(),
+ 'clientsCount' => count($activeFestival->getSellRecords()),
+ 'fondDeCaisseAvant' => $activeFestival->getFondDeCaisseAvant(),
+ 'fondDeCaisseApres' => $activeFestival->getFondDeCaisseApres(),
+ ],
+ ]);
+ }
- /**
- * @param Request $request
- * add a selling record corresponding to one client
- *
- * @return JsonResponse
- */
- public function addSellingAction( Request $request ) {
+ /**
+ * @param Request $request
+ * add a selling record corresponding to one client
+ *
+ * @return JsonResponse
+ */
+ public function addSellingAction(Request $request)
+ {
- $json = json_decode( $request->getContent(), true );
- $currentUser = $this->getUser();
- $m = $this->getDoctrine()->getManager();
- $newSellRecord = new SellRecord();
- // sort user categories
- $myCategories = $m->getRepository( 'AppBundle:ProductCategory' )->findAll();
- $categoriesByID = [];
- foreach ( $myCategories as $my_category ) {
- $categoriesByID[ $my_category->getId() ] = $my_category;
- }
+ $json = json_decode($request->getContent(), true);
+ $currentUser = $this->getUser();
+ $m = $this->getDoctrine()->getManager();
+ $newSellRecord = new SellRecord();
+ // sort user categories
+ $myCategories = $m->getRepository('AppBundle:ProductCategory')->findAll();
+ $categoriesByID = [];
+ foreach ($myCategories as $my_category) {
+ $categoriesByID[$my_category->getId()] = $my_category;
+ }
- $productsModels = $m->getRepository( 'AppBundle:Product' )->findAll();
- $productsModelsByID = [];
- foreach ( $productsModels as $product ) {
- $productsModelsByID[ $product->getId() ] = $product;
- }
+ $productsModels = $m->getRepository('AppBundle:Product')->findAll();
+ $productsModelsByID = [];
+ foreach ($productsModels as $product) {
+ $productsModelsByID[$product->getId()] = $product;
+ }
- $sumAmount = 0;
- foreach ( $json[ 'activeSelling' ] as $record ) {
- $productModel = $productsModelsByID[ $record[ 'id' ] ];
- $newProductSold = new ProductSold();
- $newProductSold->setName( $record[ 'name' ] );
- $newProductSold->setImage( "image mock" );
- $newProductSold->setUser( $currentUser );
- $newProductSold->setPrice( $record[ 'price' ] );
- $newProductSold->setComment( $json[ 'sellingComment' ] );
- $newProductSold->setProduct( $productModel );
- $newProductSold->setSellRecords( $newSellRecord );
- // link selling record with user, festival
- $currentUser->addProductsSold( $newProductSold );
- // persist all
- $productModel->setStockCount( $productModel->getStockCount() - 1 );
- $m->persist( $productModel );
- $m->persist( $newProductSold );
- $m->persist( $newProductSold );
- $sumAmount += $record[ 'price' ];
- }
+ $sumAmount = 0;
+ foreach ($json['activeSelling'] as $record) {
+ $productModel = $productsModelsByID[$record['id']];
+ $newProductSold = new ProductSold();
+ $newProductSold->setName($record['name']);
+ $newProductSold->setImage("image mock");
+ $newProductSold->setUser($currentUser);
+ $newProductSold->setPrice($record['price']);
+ $newProductSold->setComment($json['sellingComment']);
+ $newProductSold->setProduct($productModel);
+ $newProductSold->setSellRecords($newSellRecord);
+ // link selling record with user, festival
+ $currentUser->addProductsSold($newProductSold);
+ // persist all
+ $productModel->setStockCount($productModel->getStockCount() - 1);
+ $m->persist($productModel);
+ $m->persist($newProductSold);
+ $m->persist($newProductSold);
+ $sumAmount += $record['price'];
+ }
- $festivalFound = $m->getRepository( 'AppBundle:Festival' )->find( $json[ 'activeFestival' ][ 'id' ] );
- $newSellRecord->setFestival( $festivalFound );
- $newSellRecord->setAmount( $sumAmount );
- $newSellRecord->setDate( new \DateTime() );
- $newSellRecord->setUser( $currentUser );
- $newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
- $newSellRecord->setComment( $json[ 'sellingComment' ] );
+ $festivalFound = $m->getRepository('AppBundle:Festival')->find($json['activeFestival']['id']);
+ $newSellRecord->setFestival($festivalFound);
+ $newSellRecord->setAmount($sumAmount);
+ $newSellRecord->setDate(new \DateTime());
+ $newSellRecord->setUser($currentUser);
+ $newSellRecord->setPaidByClient($json['paidByClient']);
+ $newSellRecord->setComment($json['sellingComment']);
- $festivalFound->addSellRecord( $newSellRecord );
- $currentUser->addSellRecords( $newSellRecord );
+ $festivalFound->addSellRecord($newSellRecord);
+ $currentUser->addSellRecords($newSellRecord);
- $m->persist( $newSellRecord );
- $m->persist( $currentUser );
- $m->persist( $festivalFound );
- $m->flush();
+ $m->persist($newSellRecord);
+ $m->persist($currentUser);
+ $m->persist($festivalFound);
+ $m->flush();
- $festivalFound->recalculateChiffreAffaire();
- $m->persist( $festivalFound );
- $m->flush();
+ $festivalFound->recalculateChiffreAffaire();
+ $m->persist($festivalFound);
+ $m->flush();
- // setup dates
+ // setup dates
- // fetch back history of selling
- $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
- $lastSellings = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 3 );
+ // fetch back history of selling
+ $sellingRepo = $m->getRepository('AppBundle:SellRecord');
+ $lastSellings = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 3);
- return new JsonResponse( [
- "message" => "ok",
- "newChiffreAffaire" => $festivalFound->getChiffreAffaire(),
- "clientsCount" => count( $festivalFound->getSellRecords() ),
- "recent_sellings" => json_encode( $lastSellings ),
- "dump" => $json,
- ], 200 );
- }
+ return new JsonResponse([
+ "message" => "ok",
+ "newChiffreAffaire" => $festivalFound->getChiffreAffaire(),
+ "clientsCount" => count($festivalFound->getSellRecords()),
+ "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();
- }
- }
+ /**
+ * 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;
- 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() );
+ $productsSoldOfUser = $currentUser->getProductsSold();
+ $statisticsSoldProducts = [
+// ['name' => 'bidule', 'count' => 0, 'value' => 0],
+ ];
- $fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
+ $statsForFestival = [
+ ['name' => 'festoche bidule', 'clients_count' => 125, 'chiffre_affaire' => 236],
+ ];
+ foreach ($mySellings as $client) {
+ foreach ($client->getProductsSold() as $product) {
+ $chiffreAffaires += $product->getPrice();
- $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',
- ];
+ if (!isset($statisticsSoldProducts[$product->getName()])) {
+ $statisticsSoldProducts[$product->getName()] =
+ [
+ 'name' => $product->getName(),
+ 'count' => 0,
+ 'value' => 0
+ ];
+ }
+
+// echo '
';
+// var_dump(intval($product->getPrice()));
+// echo '
';
+ $statisticsSoldProducts[$product->getName()]['count']++;
+ $statisticsSoldProducts[$product->getName()]['value'] = $statisticsSoldProducts[$product->getName()]['value'] + intval($product->getPrice());
+
+ }
+ }
+// echo '
';
+// var_dump($statisticsSoldProducts);
+// echo '
';
+
+ return $this->render('logged/history.html.twig',
+ [
+ 'statisticsSoldProducts' => $statisticsSoldProducts,
+ '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');
+
+ $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( $handle,
- $firstLine );
+ fputcsv($handle,
+ $firstLine);
- $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,
- [
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- $sellRecord->getFestival()->getId(),
- $sellRecord->getFestival()->getName(),
- $sellRecord->getFestival()->getDateCreation()->format( 'c' ),
- $sellRecord->getFestival()->getFondDeCaisseAvant(),
- $sellRecord->getFestival()->getFondDeCaisseApres(),
- $sellRecord->getFestival()->getChiffreAffaire(),
- $sellRecord->getFestival()->getComment(),
- ] );
- }
+ $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,
+ [
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ $sellRecord->getFestival()->getId(),
+ $sellRecord->getFestival()->getName(),
+ $sellRecord->getFestival()->getDateCreation()->format('c'),
+ $sellRecord->getFestival()->getFondDeCaisseAvant(),
+ $sellRecord->getFestival()->getFondDeCaisseApres(),
+ $sellRecord->getFestival()->getChiffreAffaire(),
+ $sellRecord->getFestival()->getComment(),
+ ]);
+ }
- }
- }
- rewind( $handle );
- $content = stream_get_contents( $handle );
- fclose( $handle );
+ }
+ }
+ 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"',
- ]
- );
- }
+ return new Response(
+ $content, 200, [
+ 'Content-Type' => 'application/force-download',
+ 'Content-Disposition' => 'attachment; filename="' . $fileName . '.csv"',
+ ]
+ );
+ }
- /**
- * @Route("/set-active-festival/{id}", name="set_active_festival")
- */
- public function setActiveFestivalAction( $id ) {
- $currentUser = $this->getUser();
- $m = $this->getDoctrine()->getManager();
- $repo = $m->getRepository( 'AppBundle:Festival' );
+ /**
+ * @Route("/set-active-festival/{id}", name="set_active_festival")
+ */
+ public function setActiveFestivalAction($id)
+ {
+ $currentUser = $this->getUser();
+ $m = $this->getDoctrine()->getManager();
+ $repo = $m->getRepository('AppBundle:Festival');
- $currentUser->setActiveFestival( $repo->find( $id ) );
- $m->persist( $currentUser );
- $m->flush();
+ $currentUser->setActiveFestival($repo->find($id));
+ $m->persist($currentUser);
+ $m->flush();
- // replace this example code with whatever you need
- return $this->redirectToRoute( 'dashboard' );
- }
+ // replace this example code with whatever you need
+ return $this->redirectToRoute('dashboard');
+ }
- /**
- * @Route("/import", name="import")
- */
- public function importAction() {
- $currentUser = $this->getUser();
- $m = $this->getDoctrine()->getManager();
- $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
+ /**
+ * @Route("/import", name="import")
+ */
+ public function importAction()
+ {
+ $currentUser = $this->getUser();
+ $m = $this->getDoctrine()->getManager();
+ $sellingRepo = $m->getRepository('AppBundle:SellRecord');
- return $this->render( 'logged/import.html.twig',
- [
- 'base_dir' => '',
- ] );
- }
+ return $this->render('logged/import.html.twig',
+ [
+ 'base_dir' => '',
+ ]);
+ }
- /**
- * @Route("/mass-create", name="mass_create")
- */
- public function massCreateAction( Request $request ) {
- $currentUser = $this->getUser();
- $m = $this->getDoctrine()->getManager();
+ /**
+ * @Route("/mass-create", name="mass_create")
+ */
+ public function massCreateAction(Request $request)
+ {
+ $currentUser = $this->getUser();
+ $m = $this->getDoctrine()->getManager();
- $myCategories = $currentUser->getCategories();
- $myCategoriesByName = [];
- $myProductsByName = [];
- $currentCategory = new ProductCategory();
- $currentCategory
- ->addUser( $currentUser )
- ->setName( 'default category' );
+ $myCategories = $currentUser->getCategories();
+ $myCategoriesByName = [];
+ $myProductsByName = [];
+ $currentCategory = new ProductCategory();
+ $currentCategory
+ ->addUser($currentUser)
+ ->setName('default category');
- foreach ( $myCategories as $my_category ) {
- $myCategoriesByName [ $my_category->getName() ] = $my_category;
- foreach ( $my_category->getProducts() as $product ) {
- $myProductsByName[ $product->getName() ] = $product;
- }
- $currentCategory = $my_category;
- }
- $massLines = $request->request->get( 'produits' );
- if ( $request->getMethod() == 'POST' ) {
- $lines = preg_split( '/$\R?^/m', trim( $massLines ) );
- foreach ( $lines as $line ) {
+ foreach ($myCategories as $my_category) {
+ $myCategoriesByName [$my_category->getName()] = $my_category;
+ foreach ($my_category->getProducts() as $product) {
+ $myProductsByName[$product->getName()] = $product;
+ }
+ $currentCategory = $my_category;
+ }
+ $massLines = $request->request->get('produits');
+ if ($request->getMethod() == 'POST') {
+ $lines = preg_split('/$\R?^/m', trim($massLines));
+ foreach ($lines as $line) {
- if ( strpos( $line, ':' ) ) {
- // manage catgegories
- $boom = explode( ':', trim( $line ) );
- $firstPart = $boom[ 0 ];
- $value = $boom[ 1 ];
- echo "gérer une catégorie nommée: $value";
- if ( $firstPart === 'catégorie' && $value ) {
- // look for category by name
- if ( ! isset( $myCategoriesByName[ $value ] ) ) {
- $newCateg = new ProductCategory();
- $newCateg
- ->addUser( $currentUser )
- ->setName( $value );
- $currentUser->addCategory( $newCateg );
- $m->persist( $newCateg );
- $currentCategory = $newCateg; // associate further categories with the newly created one
- } else {
- echo " la catégorie existe déjà";
- }
- }
- } else {
- // manage product
- echo "
$line";
- $boom = explode( ';', $line );
- $productName = $boom[ 0 ];
- $price = 0;
- if ( $boom[ 1 ] ) {
- $price = intval( str_replace( '€', '', $boom[ 1 ] ) );
- }
- // or create new product
- if ( $productName && ! isset( $myProductsByName[ $productName ] ) ) {
- $newProduct = new Product();
- $newProduct->setCategory( $currentCategory )
- ->setName( $productName )
- ->setUser( $currentUser )
- ->setPrice( $price ) // removing euro symbol
- ;
- $currentUser->addProduct( $newProduct );
- $m->persist( $newProduct );
- }// look for existing products
- else {
- $myProductsByName[ $productName ]->setPrice( $price );
- }
- }
+ if (strpos($line, ':')) {
+ // manage catgegories
+ $boom = explode(':', trim($line));
+ $firstPart = $boom[0];
+ $value = $boom[1];
+ echo "gérer une catégorie nommée: $value";
+ if ($firstPart === 'catégorie' && $value) {
+ // look for category by name
+ if (!isset($myCategoriesByName[$value])) {
+ $newCateg = new ProductCategory();
+ $newCateg
+ ->addUser($currentUser)
+ ->setName($value);
+ $currentUser->addCategory($newCateg);
+ $m->persist($newCateg);
+ $currentCategory = $newCateg; // associate further categories with the newly created one
+ } else {
+ echo " la catégorie existe déjà";
+ }
+ }
+ } else {
+ // manage product
+ echo "
$line";
+ $boom = explode(';', $line);
+ $productName = $boom[0];
+ $price = 0;
+ if ($boom[1]) {
+ $price = intval(str_replace('€', '', $boom[1]));
+ }
+ // or create new product
+ if ($productName && !isset($myProductsByName[$productName])) {
+ $newProduct = new Product();
+ $newProduct->setCategory($currentCategory)
+ ->setName($productName)
+ ->setUser($currentUser)
+ ->setPrice($price) // removing euro symbol
+ ;
+ $currentUser->addProduct($newProduct);
+ $m->persist($newProduct);
+ }// look for existing products
+ else {
+ $myProductsByName[$productName]->setPrice($price);
+ }
+ }
- $m->persist( $currentUser );
- }
- // check with existing categories and products, sort them by name.
- // save all
- $m->flush();
- }
+ $m->persist($currentUser);
+ }
+ // check with existing categories and products, sort them by name.
+ // save all
+ $m->flush();
+ }
- return $this->render( 'logged/import.html.twig',
- [] );
- }
+ return $this->render('logged/import.html.twig',
+ []);
+ }
}
diff --git a/yarn.lock b/yarn.lock
index 7ed205ce..25bf0459 100755
--- a/yarn.lock
+++ b/yarn.lock
@@ -1078,6 +1078,10 @@ caniuse-lite@^1.0.30000792:
version "1.0.30000819"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000819.tgz#aabee5fd15a080febab6ae5d30c9ea15f4c6d4e2"
+canvasjs@^1.8.1:
+ version "1.8.1"
+ resolved "https://registry.yarnpkg.com/canvasjs/-/canvasjs-1.8.1.tgz#698a4e002e336ce83ef2f9101a6bd276ba7657a3"
+
caseless@~0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.11.0.tgz#715b96ea9841593cc33067923f5ec60ebda4f7d7"