From fa5fdfa18017fc847b4d758db7951e372a1e2afd Mon Sep 17 00:00:00 2001 From: ty kayn Date: Fri, 5 Jul 2019 16:41:33 +0200 Subject: [PATCH] :zap: export user data in json --- app/Resources/views/logged/history.html.twig | 4 +- assets/css/pages/demo.scss | 2 +- composer.json | 1 + .../Controller/DefaultController.php | 1054 +++++++++-------- src/AppBundle/Entity/ExpenseKind.php | 0 src/AppBundle/Entity/ExpenseKind.php~ | 200 ++++ src/AppBundle/Entity/Festival.php | 0 src/AppBundle/Entity/Festival.php~ | 40 +- src/AppBundle/Entity/Product.php | 0 src/AppBundle/Entity/Product.php~ | 2 +- src/AppBundle/Entity/ProductCategory.php | 0 src/AppBundle/Entity/ProductCategory.php~ | 4 +- src/AppBundle/Entity/ProductSold.php | 0 src/AppBundle/Entity/SellRecord.php | 0 src/AppBundle/Entity/SellRecord.php~ | 2 +- src/AppBundle/Entity/SerieFestival.php | 33 + src/AppBundle/Entity/SerieFestival.php~ | 130 ++ src/AppBundle/Entity/User.php | 83 +- src/AppBundle/Entity/User.php~ | 100 +- 19 files changed, 1127 insertions(+), 528 deletions(-) mode change 100755 => 100644 src/AppBundle/Entity/ExpenseKind.php create mode 100644 src/AppBundle/Entity/ExpenseKind.php~ mode change 100755 => 100644 src/AppBundle/Entity/Festival.php mode change 100755 => 100644 src/AppBundle/Entity/Product.php mode change 100755 => 100644 src/AppBundle/Entity/ProductCategory.php mode change 100755 => 100644 src/AppBundle/Entity/ProductSold.php mode change 100755 => 100644 src/AppBundle/Entity/SellRecord.php mode change 100755 => 100644 src/AppBundle/Entity/SerieFestival.php create mode 100644 src/AppBundle/Entity/SerieFestival.php~ mode change 100755 => 100644 src/AppBundle/Entity/User.php diff --git a/app/Resources/views/logged/history.html.twig b/app/Resources/views/logged/history.html.twig index ea75df99..c4c67cbe 100755 --- a/app/Resources/views/logged/history.html.twig +++ b/app/Resources/views/logged/history.html.twig @@ -7,7 +7,7 @@

Historique

-
+
@@ -51,7 +51,7 @@
-
+

Exporter toutes vos données

diff --git a/assets/css/pages/demo.scss b/assets/css/pages/demo.scss index 3b6ee865..30346a15 100755 --- a/assets/css/pages/demo.scss +++ b/assets/css/pages/demo.scss @@ -80,7 +80,7 @@ code { @media (min-width: 768px) { #wrapper { - width: 80%; + //width: 80%; margin: 2em auto; } diff --git a/composer.json b/composer.json index 3d7b8ed4..f76f48bd 100755 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "sonata-project/admin-bundle": "^3.38", "symfony/monolog-bundle": "^3.1.0", "symfony/polyfill-apcu": "^1.0", + "symfony/serializer": "^4.3", "symfony/swiftmailer-bundle": "^2.6.4", "symfony/symfony": "~3.4", "symfony/templating": "^4.0", diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index 40890e04..924e788b 100755 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -14,603 +14,635 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; +use Symfony\Component\Serializer\Encoder\JsonEncoder; +use Symfony\Component\Serializer\Encoder\XmlEncoder; +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; +use Symfony\Component\Serializer\Serializer; -class DefaultController extends Controller -{ +class DefaultController extends Controller { - private $ownerService; - private $tokenManager; + private $ownerService; + private $tokenManager; - public function __construct(CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService) - { - $this->tokenManager = $tokenManager; - $this->ownerService = $ownerService; - } + public function __construct( CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService ) { + $this->tokenManager = $tokenManager; + $this->ownerService = $ownerService; + } - /** - * @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->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 = $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 ); - 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' => [[]], - 'recentSells' => [['']], - ]); - } + $currentUser = $this->getUser(); + if ( ! $currentUser ) { + return new JsonResponse( [ + 'categories' => [ [] ], + 'recentSells' => [ [ '' ] ], + ] ); + } - $ownerService = $this->ownerService; - $ownerService->setupNewFestival($currentUser); - $activeFestival = $currentUser->getActiveFestival(); + $ownerService = $this->ownerService; + $ownerService->setupNewFestival( $currentUser ); + $activeFestival = $currentUser->getActiveFestival(); - $categRepo = $m->getRepository('AppBundle:ProductCategory'); - $sellingRepo = $m->getRepository('AppBundle:SellRecord'); + $categRepo = $m->getRepository( 'AppBundle:ProductCategory' ); + $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); - $categories = $ownerService->serializeCategoriesOfUser($currentUser); + $categories = $ownerService->serializeCategoriesOfUser( $currentUser ); - $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' => $activeFestival->makeArray(), - ]); - } + return new JsonResponse( [ + 'categories' => $categories, + 'recentSells' => count( $recentSells ), + 'lastFestival' => $activeFestival->makeArray(), + ] ); + } - /** - * get user expenses - * @return JsonResponse - */ - public function getMyExpensesAction() - { - $m = $this->getDoctrine()->getManager(); + /** + * get user expenses + * @return JsonResponse + */ + public function getMyExpensesAction() { + $m = $this->getDoctrine()->getManager(); - $currentUser = $this->getUser(); - if (!$currentUser) { - return new JsonResponse([ - 'expenses' => [[]], - ]); - } + $currentUser = $this->getUser(); + if ( ! $currentUser ) { + return new JsonResponse( [ + 'expenses' => [ [] ], + ] ); + } - $ownerService = $this->ownerService; - $ownerService->setupNewFestival($currentUser); - $expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser); + $ownerService = $this->ownerService; + $ownerService->setupNewFestival( $currentUser ); + $expensesOfUser = $ownerService->serializeExpensesOfUser( $currentUser ); - return new JsonResponse([ - 'expenses' => $expensesOfUser, - 'disponibility' => $currentUser->getDisponibility(), - 'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(), - ]); - } + return new JsonResponse( [ + 'expenses' => $expensesOfUser, + 'disponibility' => $currentUser->getDisponibility(), + 'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(), + ] ); + } - /** - * recieve the json containing the expanse config of a user - * @param Request $request - * @return JsonResponse the list of expanses - */ - public function saveMyExpensesAction(Request $request) - { + /** + * recieve the json containing the expanse config of a user + * + * @param Request $request + * + * @return JsonResponse the list of expanses + */ + public function saveMyExpensesAction( Request $request ) { - $json = json_decode($request->getContent(), true); - $currentUser = $this->getUser(); - $m = $this->getDoctrine()->getManager(); - $myExpenses = $currentUser->getExpenses(); - $categoriesByID = []; + $json = json_decode( $request->getContent(), true ); + $currentUser = $this->getUser(); + $m = $this->getDoctrine()->getManager(); + $myExpenses = $currentUser->getExpenses(); + $categoriesByID = []; - foreach ($myExpenses as $expense) { - $categoriesByID[$expense->getId()] = $expense; - } - // loop on the json config for expanse - // save the user configuration - foreach ($json['expenses'] as $expens) { + foreach ( $myExpenses as $expense ) { + $categoriesByID[ $expense->getId() ] = $expense; + } + // loop on the json config for expanse + // save the user configuration + foreach ( $json[ 'expenses' ] as $expens ) { - if(isset($expens['id'])){ - $foundExpense = $categoriesByID[$expens['id']]; - if($foundExpense){ - // update existing expenses of logged in user - $foundExpense->setName($expens['name']); - $foundExpense->setAmount($expens['amount']); - $foundExpense->setDelay($expens['delay']); - $foundExpense->setRepeatitions($expens['repeat']); - $foundExpense->setEnabled($expens['enabled']); - $m->persist($foundExpense); - } - }else{ - // create new expense for user - $newExpense = new ExpenseKind(); - $newExpense->setUser($currentUser); - $newExpense->setName($expens['name']); - $newExpense->setDelay($expens['delay']); - $newExpense->setAmount($expens['amount']); - $newExpense->setRepeatitions($expens['repeat']); - $newExpense->setEnabled($expens['enabled']); - $m->persist($newExpense); + if ( isset( $expens[ 'id' ] ) ) { + $foundExpense = $categoriesByID[ $expens[ 'id' ] ]; + if ( $foundExpense ) { + // update existing expenses of logged in user + $foundExpense->setName( $expens[ 'name' ] ); + $foundExpense->setAmount( $expens[ 'amount' ] ); + $foundExpense->setDelay( $expens[ 'delay' ] ); + $foundExpense->setRepeatitions( $expens[ 'repeat' ] ); + $foundExpense->setEnabled( $expens[ 'enabled' ] ); + $m->persist( $foundExpense ); + } + } else { + // create new expense for user + $newExpense = new ExpenseKind(); + $newExpense->setUser( $currentUser ); + $newExpense->setName( $expens[ 'name' ] ); + $newExpense->setDelay( $expens[ 'delay' ] ); + $newExpense->setAmount( $expens[ 'amount' ] ); + $newExpense->setRepeatitions( $expens[ 'repeat' ] ); + $newExpense->setEnabled( $expens[ 'enabled' ] ); + $m->persist( $newExpense ); - } - } + } + } - $currentUser->setDisponibility($json['config']['disponibility']); - $currentUser->setAverageMonthlyEarnings($json['config']['averageMonthlyEarnings']); + $currentUser->setDisponibility( $json[ 'config' ][ 'disponibility' ] ); + $currentUser->setAverageMonthlyEarnings( $json[ 'config' ][ 'averageMonthlyEarnings' ] ); - $m->persist($currentUser); - $m->flush(); + $m->persist( $currentUser ); + $m->flush(); - $ownerService = $this->ownerService; - $expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser); + $ownerService = $this->ownerService; + $expensesOfUser = $ownerService->serializeExpensesOfUser( $currentUser ); - return new JsonResponse([ - 'expenses' => $expensesOfUser, - 'disponibility' => $currentUser->getDisponibility(), - 'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(), - ]); - } + return new JsonResponse( [ + 'expenses' => $expensesOfUser, + 'disponibility' => $currentUser->getDisponibility(), + 'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(), + ] ); + } - /** - * @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 = $currentUser->getCategories(); - $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 = $currentUser->getCategories(); + $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", - "activeFestival" => $festivalFound->makeArray(), - "newChiffreAffaire" => $festivalFound->getChiffreAffaire(), - "clientsCount" => count($festivalFound->getSellRecords()), - "recent_sellings" => json_encode($lastSellings), - "dump" => $json, - ], 200); - } + return new JsonResponse( [ + "message" => "ok", + "activeFestival" => $festivalFound->makeArray(), + "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'); - $allSellingList = $sellingRepo->findBy(['user'=>$currentUser->getId()],['id'=>'desc']); - $mySellings = array_splice($allSellingList, 0, 15); - $chiffreAffaires = 0; + /** + * 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' ); + $allSellingList = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ] ); + $mySellings = array_splice( $allSellingList, 0, 15 ); + $chiffreAffaires = 0; - $myFestivals = $currentUser->getFestivals(); + $myFestivals = $currentUser->getFestivals(); - $statisticsFestivals = [ - ]; + $statisticsFestivals = [ + ]; - foreach ($myFestivals as $festival) { - $statisticsFestivals[] = [ - 'date' => $festival->getDateCreation(), - 'name' => $festival->getName(), - 'clients_count' => count($festival->getSellRecords()), - 'chiffreAffaire' => $festival->getChiffreAffaire(), - ]; - } - $statisticsSoldProducts = [ + foreach ( $myFestivals as $festival ) { + $statisticsFestivals[] = [ + 'date' => $festival->getDateCreation(), + 'name' => $festival->getName(), + 'clients_count' => count( $festival->getSellRecords() ), + 'chiffreAffaire' => $festival->getChiffreAffaire(), + ]; + } + $statisticsSoldProducts = [ // ['name' => 'bidule', 'count' => 0, 'value' => 0], - ]; + ]; - $statsForFestivalMock = [ - ['name' => 'festoche bidule', 'clients_count' => 125, 'chiffreAffaire' => 236, 'date' => new \DateTime()], - ]; - foreach ($allSellingList as $client) { - foreach ($client->getProductsSold() as $product) { - $chiffreAffaires += $product->getPrice(); - } - } - foreach ($mySellings as $client) { - foreach ($client->getProductsSold() as $product) { - $chiffreAffaires += $product->getPrice(); + $statsForFestivalMock = [ + [ 'name' => 'festoche bidule', 'clients_count' => 125, 'chiffreAffaire' => 236, 'date' => new \DateTime() ], + ]; + foreach ( $allSellingList as $client ) { + foreach ( $client->getProductsSold() as $product ) { + $chiffreAffaires += $product->getPrice(); + } + } + foreach ( $mySellings as $client ) { + foreach ( $client->getProductsSold() as $product ) { + $chiffreAffaires += $product->getPrice(); - if (!isset($statisticsSoldProducts[$product->getName()])) { - $statisticsSoldProducts[$product->getName()] = - [ - 'name' => $product->getName(), - 'count' => 0, - 'value' => 0 - ]; - } + if ( ! isset( $statisticsSoldProducts[ $product->getName() ] ) ) { + $statisticsSoldProducts[ $product->getName() ] = + [ + 'name' => $product->getName(), + 'count' => 0, + 'value' => 0, + ]; + } - $statisticsSoldProducts[$product->getName()]['count']++; - $statisticsSoldProducts[$product->getName()]['value'] = $statisticsSoldProducts[$product->getName()]['value'] + intval($product->getPrice()); + $statisticsSoldProducts[ $product->getName() ][ 'count' ] ++; + $statisticsSoldProducts[ $product->getName() ][ 'value' ] = $statisticsSoldProducts[ $product->getName() ][ 'value' ] + intval( $product->getPrice() ); - } - } + } + } - return $this->render('logged/history.html.twig', - [ + return $this->render( 'logged/history.html.twig', + [ // 'statisticsFestivals' => $statsForFestivalMock, // mock of festival stats - 'statisticsFestivals' => $statisticsFestivals, - 'statisticsSoldProducts' => $statisticsSoldProducts, - 'chiffreAffaires' => $chiffreAffaires, - 'recentSells' => $mySellings, - 'allSellings' => count($mySellings), - 'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR, - ]); - } + 'statisticsFestivals' => $statisticsFestivals, + 'statisticsSoldProducts' => $statisticsSoldProducts, + 'chiffreAffaires' => $chiffreAffaires, + 'recentSells' => $mySellings, + 'allSellings' => count( $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()); + /** + * export user data in JSON + * @return JsonResponse + * @Route("/logged/export-all-json", name="export_all_json") + */ + public function exportJsonAction() { + $currentUser = $this->getUser(); + $m = $this->getDoctrine()->getManager(); + $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); + $encoders = [ new XmlEncoder(), new JsonEncoder() ]; + $normalizers = [ new ObjectNormalizer() ]; - $fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date('Y-m-d_H-i-s'); + $serializer = new Serializer( $normalizers, $encoders ); - $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', - ]; + $mySellings = $sellingRepo->findByUser( $currentUser->getId() ); + $export = [ + 'export_version' => '1.0', + 'user' => $serializer->normalize( $currentUser, + null, + [ 'attributes' => [ 'id', 'username', 'email', 'salt', 'password' ] ] ), + 'products' => $serializer->normalize( $currentUser->getProducts(), + null, + [ 'attributes' => [ 'id', 'name', 'price' ] ] ), + 'categories' => $serializer->normalize( $currentUser->getCategories(), + null, + [ 'attributes' => [ 'id', 'name' ] ] ), + 'series_festivals' => $serializer->normalize( $currentUser->getSeriesFestivals(), +null, ['attributes'=> [ + 'id', 'name', + ]]), + 'festivals' => $serializer->normalize( $currentUser->getFestivals(), + null, + [ 'attributes' => [ 'id', 'name', 'chiffreAffaire','fraisInscription','fraisHebergement','fraisTransport','fraisRepas' ] ] ), + 'sellings' => $serializer->normalize( $mySellings, + null, + [ 'attributes' => [ 'id', 'amount', 'paidByClient', 'comment', 'gender' ] ] ), + ]; + + return new JsonResponse( $export ); + } + + /** + * 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('festival_index'); - } + // replace this example code with whatever you need + return $this->redirectToRoute( 'festival_index' ); + } - /** - * @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("/previsionnel", name="previsionnel") - */ - public function previsionnelAction() - { + /** + * @Route("/previsionnel", name="previsionnel") + */ + public function previsionnelAction() { // $currentUser = $this->getUser(); // $m = $this->getDoctrine()->getManager(); // $sellingRepo = $m->getRepository('AppBundle:SellRecord'); - return $this->render('logged/previsionnel.html.twig', - [ - 'base_dir' => '', - ]); - } + return $this->render( 'logged/previsionnel.html.twig', + [ + 'base_dir' => '', + ] ); + } - /** - * import lots of products at once - * @Route("/mass-create", name="mass_create") - */ - public function massCreateAction(Request $request) - { - $currentUser = $this->getUser(); - $m = $this->getDoctrine()->getManager(); + /** + * import lots of products at once + * @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]; - 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 { + if ( strpos( $line, ':' ) ) { + // manage catgegories + $boom = explode( ':', trim( $line ) ); + $firstPart = $boom[ 0 ]; + $value = $boom[ 1 ]; + 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 - $boom = explode(';', $line); - $productName = $boom[0]; - $price = 0; - if ($boom[1]) { - $price = intval(str_replace('€', '', $boom[1]));// removing euro symbol - } - // or create new product - if ($productName && !isset($myProductsByName[$productName])) { - $newProduct = new Product(); - $newProduct->setCategory($currentCategory) - ->setName($productName) - ->setStockCount(500) - ->setUser($currentUser) - ->setPrice($price); - $currentUser->addProduct($newProduct); - $m->persist($newProduct); - }// look for existing products - else { - $myProductsByName[$productName]->setPrice($price); - } - } + } + } + } else { + // manage product + $boom = explode( ';', $line ); + $productName = $boom[ 0 ]; + $price = 0; + if ( $boom[ 1 ] ) { + $price = intval( str_replace( '€', '', $boom[ 1 ] ) );// removing euro symbol + } + // or create new product + if ( $productName && ! isset( $myProductsByName[ $productName ] ) ) { + $newProduct = new Product(); + $newProduct->setCategory( $currentCategory ) + ->setName( $productName ) + ->setStockCount( 500 ) + ->setUser( $currentUser ) + ->setPrice( $price ); + $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/src/AppBundle/Entity/ExpenseKind.php b/src/AppBundle/Entity/ExpenseKind.php old mode 100755 new mode 100644 diff --git a/src/AppBundle/Entity/ExpenseKind.php~ b/src/AppBundle/Entity/ExpenseKind.php~ new file mode 100644 index 00000000..c5f31c05 --- /dev/null +++ b/src/AppBundle/Entity/ExpenseKind.php~ @@ -0,0 +1,200 @@ +enabled; + } + + /** + * @param int|null $enabled + */ + public function setEnabled($enabled) + { + $this->enabled = $enabled; + } + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return mixed + */ + public function getUser() + { + return $this->user; + } + + /** + * @param mixed $user + */ + public function setUser($user) + { + $this->user = $user; + } + /** + * Set name. + * + * @param string $name + * + * @return ExpenseKind + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set delay. + * + * @param int|null $delay + * + * @return ExpenseKind + */ + public function setDelay($delay = null) + { + $this->delay = $delay; + + return $this; + } + + /** + * Get delay. + * + * @return int|null + */ + public function getDelay() + { + return $this->delay; + } + + /** + * Set repeatitions. + * + * @param int|null $repeatitions + * + * @return ExpenseKind + */ + public function setRepeatitions($repeatitions = null) + { + $this->repeatitions = $repeatitions; + + return $this; + } + + /** + * Get repeatitions. + * + * @return int|null + */ + public function getRepeatitions() + { + return $this->repeatitions; + } + + /** + * Set amount. + * + * @param float $amount + * + * @return ExpenseKind + */ + public function setAmount($amount) + { + $this->amount = $amount; + + return $this; + } + + /** + * Get amount. + * + * @return float + */ + public function getAmount() + { + return $this->amount; + } +} diff --git a/src/AppBundle/Entity/Festival.php b/src/AppBundle/Entity/Festival.php old mode 100755 new mode 100644 diff --git a/src/AppBundle/Entity/Festival.php~ b/src/AppBundle/Entity/Festival.php~ index e694c66d..e5e2e077 100755 --- a/src/AppBundle/Entity/Festival.php~ +++ b/src/AppBundle/Entity/Festival.php~ @@ -40,7 +40,7 @@ class Festival { /** * @var \stdClass * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord",mappedBy="festival") + * @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord",mappedBy="festival", cascade={"remove"}) */ private $sellRecords; @@ -48,6 +48,10 @@ class Festival { * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="festivals") */ private $user; + /** + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\SerieFestival", inversedBy="festivals") + */ + private $serieFestival; /** * @var @@ -83,11 +87,42 @@ class Festival { private $fraisRepas; + public function __toString() { + return $this->getName(); + } + + /** + * @return mixed + */ + public function getSerieFestival() + { + return $this->serieFestival; + } + + /** + * @param mixed $serieFestival + */ + public function setSerieFestival($serieFestival) + { + $this->serieFestival = $serieFestival; + } + /** * array usable by js * @return array */ public function makeArray(){ + $sellRecords = $this->getSellRecords(); + $soldItems = []; + foreach ( $sellRecords as $sell_record ) { + foreach ( $sell_record->getProductsSold() as $sold ) { + if(!isset($soldItems[$sold->getProduct()->getId()])){ + $soldItems[$sold->getProduct()->getId()] = 0; + } + $soldItems[$sold->getProduct()->getId()]++; + } + + } return [ 'id' => $this->getId(), 'name' => $this->getName(), @@ -97,8 +132,9 @@ class Festival { 'clientsCount' => count($this->getSellRecords()), 'fondDeCaisseAvant' => $this->getFondDeCaisseAvant(), 'fondDeCaisseApres' => $this->getFondDeCaisseApres(), + 'sold' => $soldItems, ]; - + } public function recalculateChiffreAffaire() { $sellings = $this->getSellRecords(); diff --git a/src/AppBundle/Entity/Product.php b/src/AppBundle/Entity/Product.php old mode 100755 new mode 100644 diff --git a/src/AppBundle/Entity/Product.php~ b/src/AppBundle/Entity/Product.php~ index bdfba8c0..5d888919 100755 --- a/src/AppBundle/Entity/Product.php~ +++ b/src/AppBundle/Entity/Product.php~ @@ -43,7 +43,7 @@ class Product { */ private $user; /** - * @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="product") + * @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="product", cascade={"remove"}) */ private $productsSold; diff --git a/src/AppBundle/Entity/ProductCategory.php b/src/AppBundle/Entity/ProductCategory.php old mode 100755 new mode 100644 diff --git a/src/AppBundle/Entity/ProductCategory.php~ b/src/AppBundle/Entity/ProductCategory.php~ index 3602a35b..21aa484e 100755 --- a/src/AppBundle/Entity/ProductCategory.php~ +++ b/src/AppBundle/Entity/ProductCategory.php~ @@ -21,11 +21,11 @@ class ProductCategory { private $name; /** - * @ORM\OneToMany(targetEntity="Product", mappedBy="category") + * @ORM\OneToMany(targetEntity="Product", mappedBy="category", cascade={"remove"}) */ private $products; /** - * @ORM\OneToMany(targetEntity="ProductSold", mappedBy="product") + * @ORM\OneToMany(targetEntity="ProductSold", mappedBy="product", cascade={"remove"}) */ private $productsSold; diff --git a/src/AppBundle/Entity/ProductSold.php b/src/AppBundle/Entity/ProductSold.php old mode 100755 new mode 100644 diff --git a/src/AppBundle/Entity/SellRecord.php b/src/AppBundle/Entity/SellRecord.php old mode 100755 new mode 100644 diff --git a/src/AppBundle/Entity/SellRecord.php~ b/src/AppBundle/Entity/SellRecord.php~ index 6ebfa0d6..1532c81d 100755 --- a/src/AppBundle/Entity/SellRecord.php~ +++ b/src/AppBundle/Entity/SellRecord.php~ @@ -24,7 +24,7 @@ class SellRecord { private $gender; /** * liste des produits de la vente - * @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="sellRecords") + * @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="sellRecords", cascade={"remove", "persist","detach"}) */ private $productsSold; diff --git a/src/AppBundle/Entity/SerieFestival.php b/src/AppBundle/Entity/SerieFestival.php old mode 100755 new mode 100644 index 08a069bb..36fad850 --- a/src/AppBundle/Entity/SerieFestival.php +++ b/src/AppBundle/Entity/SerieFestival.php @@ -127,4 +127,37 @@ class SerieFestival { { $this->dateCreation = $dateCreation; } + /** + * Constructor + */ + public function __construct() + { + $this->festivals = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Add festival. + * + * @param \AppBundle\Entity\Festival $festival + * + * @return SerieFestival + */ + public function addFestival(\AppBundle\Entity\Festival $festival) + { + $this->festivals[] = $festival; + + return $this; + } + + /** + * Remove festival. + * + * @param \AppBundle\Entity\Festival $festival + * + * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. + */ + public function removeFestival(\AppBundle\Entity\Festival $festival) + { + return $this->festivals->removeElement($festival); + } } diff --git a/src/AppBundle/Entity/SerieFestival.php~ b/src/AppBundle/Entity/SerieFestival.php~ new file mode 100644 index 00000000..08a069bb --- /dev/null +++ b/src/AppBundle/Entity/SerieFestival.php~ @@ -0,0 +1,130 @@ +user; + } + + /** + * @param mixed $user + */ + public function setUser($user) + { + $this->user = $user; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return mixed + */ + public function getFestivals() + { + return $this->festivals; + } + + /** + * @param mixed $festivals + */ + public function setFestivals($festivals) + { + $this->festivals = $festivals; + } + + /** + * @return \DateTime + */ + public function getDateCreation() + { + return $this->dateCreation; + } + + /** + * @param \DateTime $dateCreation + */ + public function setDateCreation($dateCreation) + { + $this->dateCreation = $dateCreation; + } +} diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php old mode 100755 new mode 100644 index b239147d..cf0fc078 --- a/src/AppBundle/Entity/User.php +++ b/src/AppBundle/Entity/User.php @@ -35,6 +35,10 @@ class User extends BaseUser { * @ORM\Column(name="google_id", type="string", length=255, nullable=true) */ private $googleId; + /** + * @ORM\Column(name="mastodon_id", type="string", length=255, nullable=true) + */ + private $mastodonId; private $googleAccessToken; /** @@ -76,11 +80,12 @@ class User extends BaseUser { private $averageMonthlyEarnings; /** + * available money, for previsionnel calculation * @ORM\Column(name="disponibility", type="float", nullable=true) */ private $disponibility; /** - * variabilised products sold + * expenses by kind, for previsionnel * @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user") */ private $expenses; @@ -468,4 +473,80 @@ class User extends BaseUser { public function getDisqusId() { return $this->disqusId; } + + /** + * Set mastodonId. + * + * @param string|null $mastodonId + * + * @return User + */ + public function setMastodonId($mastodonId = null) + { + $this->mastodonId = $mastodonId; + + return $this; + } + + /** + * Get mastodonId. + * + * @return string|null + */ + public function getMastodonId() + { + return $this->mastodonId; + } + + /** + * Add seriesFestival. + * + * @param \AppBundle\Entity\SerieFestival $seriesFestival + * + * @return User + */ + public function addSeriesFestival(\AppBundle\Entity\SerieFestival $seriesFestival) + { + $this->seriesFestivals[] = $seriesFestival; + + return $this; + } + + /** + * Remove seriesFestival. + * + * @param \AppBundle\Entity\SerieFestival $seriesFestival + * + * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. + */ + public function removeSeriesFestival(\AppBundle\Entity\SerieFestival $seriesFestival) + { + return $this->seriesFestivals->removeElement($seriesFestival); + } + + /** + * Add expense. + * + * @param \AppBundle\Entity\ExpenseKind $expense + * + * @return User + */ + public function addExpense(\AppBundle\Entity\ExpenseKind $expense) + { + $this->expenses[] = $expense; + + return $this; + } + + /** + * Remove expense. + * + * @param \AppBundle\Entity\ExpenseKind $expense + * + * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. + */ + public function removeExpense(\AppBundle\Entity\ExpenseKind $expense) + { + return $this->expenses->removeElement($expense); + } } diff --git a/src/AppBundle/Entity/User.php~ b/src/AppBundle/Entity/User.php~ index ac9ae139..49a32c6e 100755 --- a/src/AppBundle/Entity/User.php~ +++ b/src/AppBundle/Entity/User.php~ @@ -35,9 +35,16 @@ class User extends BaseUser { * @ORM\Column(name="google_id", type="string", length=255, nullable=true) */ private $googleId; + /** + * @ORM\Column(name="mastodon_id", type="string", length=255, nullable=true) + */ + private $mastodonId; private $googleAccessToken; - + /** + * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users") + */ + private $categories; /** * templates products * @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user") @@ -54,17 +61,96 @@ class User extends BaseUser { * @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user") */ private $festivals; - /** - * current festival we are recording sellings for - * @ORM\OneToOne(targetEntity="AppBundle\Entity\Festival") + * series of festivals + * @ORM\OneToMany(targetEntity="AppBundle\Entity\SerieFestival", mappedBy="user") */ - private $activeFestival; + private $seriesFestivals; + /** + * current festival we are recording sellings for + * @ORM\OneToOne(targetEntity="AppBundle\Entity\Festival") + */ + private $activeFestival; + + //expenses previsionnel configs + /** + * @ORM\Column(name="averageMonthlyEarnings", type="float", nullable=true) + */ + private $averageMonthlyEarnings; + + /** + * available money, for previsionnel calculation + * @ORM\Column(name="disponibility", type="float", nullable=true) + */ + private $disponibility; /** - * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users") + * expenses by kind, for previsionnel + * @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user") */ - private $categories; + private $expenses; + + /** + * @return mixed + */ + public function getAverageMonthlyEarnings() + { + return $this->averageMonthlyEarnings; + } + + /** + * @param mixed $averageMonthlyEarnings + */ + public function setAverageMonthlyEarnings($averageMonthlyEarnings) + { + $this->averageMonthlyEarnings = $averageMonthlyEarnings; + } + /** + * @return mixed + */ + public function getDisponibility() + { + return $this->disponibility; + } + + /** + * @param mixed $disponibility + */ + public function setDisponibility($disponibility) + { + $this->disponibility = $disponibility; + } + + /** + * @return mixed + */ + public function getSeriesFestivals() + { + return $this->seriesFestivals; + } + + /** + * @param mixed $seriesFestivals + */ + public function setSeriesFestivals($seriesFestivals) + { + $this->seriesFestivals = $seriesFestivals; + } + /** + * @return mixed + */ + public function getExpenses() + { + return $this->expenses; + } + + /** + * @param mixed $expenses + */ + public function setExpenses($expenses) + { + $this->expenses = $expenses; + } /** * @return mixed