export user data in json

This commit is contained in:
ty kayn 2019-07-05 16:41:33 +02:00
parent 19c7935f58
commit fa5fdfa180
19 changed files with 1127 additions and 528 deletions

View File

@ -7,7 +7,7 @@
<h1>Historique</h1> <h1>Historique</h1>
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-6"> <div class="col-xs-12">
<div class="sells"> <div class="sells">
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-4"> <div class="col-xs-12 col-sm-4">
@ -51,7 +51,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-xs-6 text-right"> <div class="col-xs-12 ">
<h2>Exporter toutes vos données</h2> <h2>Exporter toutes vos données</h2>
<a class="btn btn-success" href="{{ path('export_all') }}"> <a class="btn btn-success" href="{{ path('export_all') }}">
<i class="fa fa-file-excel-o fa-3x"></i> <i class="fa fa-file-excel-o fa-3x"></i>

View File

@ -80,7 +80,7 @@ code {
@media (min-width: 768px) { @media (min-width: 768px) {
#wrapper { #wrapper {
width: 80%; //width: 80%;
margin: 2em auto; margin: 2em auto;
} }

View File

@ -33,6 +33,7 @@
"sonata-project/admin-bundle": "^3.38", "sonata-project/admin-bundle": "^3.38",
"symfony/monolog-bundle": "^3.1.0", "symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0", "symfony/polyfill-apcu": "^1.0",
"symfony/serializer": "^4.3",
"symfony/swiftmailer-bundle": "^2.6.4", "symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "~3.4", "symfony/symfony": "~3.4",
"symfony/templating": "^4.0", "symfony/templating": "^4.0",

View File

@ -14,15 +14,17 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; 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 $ownerService;
private $tokenManager; private $tokenManager;
public function __construct(CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService) public function __construct( CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService ) {
{
$this->tokenManager = $tokenManager; $this->tokenManager = $tokenManager;
$this->ownerService = $ownerService; $this->ownerService = $ownerService;
} }
@ -30,69 +32,66 @@ class DefaultController extends Controller
/** /**
* @Route("/", name="homepage") * @Route("/", name="homepage")
*/ */
public function indexAction(Request $request) public function indexAction( Request $request ) {
{
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$userRepo = $m->getRepository('AppBundle:User'); $userRepo = $m->getRepository( 'AppBundle:User' );
$allUsers = $userRepo->findAll(); $allUsers = $userRepo->findAll();
// replace this example code with whatever you need // replace this example code with whatever you need
return $this->render('default/index.html.twig', return $this->render( 'default/index.html.twig',
[ [
'usersCount' => count($allUsers), 'usersCount' => count( $allUsers ),
'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR, 'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
]); ] );
} }
/** /**
* @Route("/dashboard", name="dashboard") * @Route("/dashboard", name="dashboard")
*/ */
public function dashboardAction(Request $request) public function dashboardAction( Request $request ) {
{
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser(); $currentUser = $this->getUser();
// TODO on first login set default values // TODO on first login set default values
$lastFestival = $currentUser->getActiveFestival(); $lastFestival = $currentUser->getActiveFestival();
if (!$lastFestival) { if ( ! $lastFestival ) {
$lastFestival = $m->getRepository('AppBundle:Festival') $lastFestival = $m->getRepository( 'AppBundle:Festival' )
->findOneBy(['user' => $this->getUser()->getId()], ->findOneBy( [ 'user' => $this->getUser()->getId() ],
['id' => 'desc'], [ 'id' => 'desc' ],
0, 0,
1); 1 );
} }
if ($lastFestival) { if ( $lastFestival ) {
$lastFestival->recalculateChiffreAffaire(); $lastFestival->recalculateChiffreAffaire();
} }
$categRepo = $m->getRepository('AppBundle:ProductCategory'); $categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository('AppBundle:SellRecord'); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categories = $categRepo->findAll(); $categories = $categRepo->findAll();
$recentSells = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 5); $recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
return $this->render('logged/dashboard.html.twig', return $this->render( 'logged/dashboard.html.twig',
[ [
'lastFestival' => $lastFestival, 'lastFestival' => $lastFestival,
'categories' => $categories, 'categories' => $categories,
'currentUser' => $currentUser, 'currentUser' => $currentUser,
'recentSells' => $recentSells, 'recentSells' => $recentSells,
'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR, 'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
]); ] );
} }
/** /**
* envoyer un email * envoyer un email
*/ */
public function emailAction() public function emailAction() {
{
$name = "noble barbare"; $name = "noble barbare";
$message = \Swift_Message::newInstance() $message = \Swift_Message::newInstance()
->setSubject('Hello Email') ->setSubject( 'Hello Email' )
->setFrom('test-symfony-tykayn@caisse.ciperbliss.com') ->setFrom( 'test-symfony-tykayn@caisse.ciperbliss.com' )
->setTo('tykayn@gmail.com') ->setTo( 'tykayn@gmail.com' )
->setBody($this->renderView('default/test-email.html.twig'), ->setBody( $this->renderView( 'default/test-email.html.twig' ),
'text/html'); 'text/html' );
$this->get('mailer')->send($message); $this->get( 'mailer' )->send( $message );
//return 'yay test de mail'; //return 'yay test de mail';
return $this->render( return $this->render(
@ -106,127 +105,126 @@ class DefaultController extends Controller
* get user products * get user products
* @return JsonResponse * @return JsonResponse
*/ */
public function getMyProductsAction() public function getMyProductsAction() {
{
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser(); $currentUser = $this->getUser();
if (!$currentUser) { if ( ! $currentUser ) {
return new JsonResponse([ return new JsonResponse( [
'categories' => [[]], 'categories' => [ [] ],
'recentSells' => [['']], 'recentSells' => [ [ '' ] ],
]); ] );
} }
$ownerService = $this->ownerService; $ownerService = $this->ownerService;
$ownerService->setupNewFestival($currentUser); $ownerService->setupNewFestival( $currentUser );
$activeFestival = $currentUser->getActiveFestival(); $activeFestival = $currentUser->getActiveFestival();
$categRepo = $m->getRepository('AppBundle:ProductCategory'); $categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository('AppBundle:SellRecord'); $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([ return new JsonResponse( [
'categories' => $categories, 'categories' => $categories,
'recentSells' => count($recentSells), 'recentSells' => count( $recentSells ),
'lastFestival' => $activeFestival->makeArray(), 'lastFestival' => $activeFestival->makeArray(),
]); ] );
} }
/** /**
* get user expenses * get user expenses
* @return JsonResponse * @return JsonResponse
*/ */
public function getMyExpensesAction() public function getMyExpensesAction() {
{
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser(); $currentUser = $this->getUser();
if (!$currentUser) { if ( ! $currentUser ) {
return new JsonResponse([ return new JsonResponse( [
'expenses' => [[]], 'expenses' => [ [] ],
]); ] );
} }
$ownerService = $this->ownerService; $ownerService = $this->ownerService;
$ownerService->setupNewFestival($currentUser); $ownerService->setupNewFestival( $currentUser );
$expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser); $expensesOfUser = $ownerService->serializeExpensesOfUser( $currentUser );
return new JsonResponse([ return new JsonResponse( [
'expenses' => $expensesOfUser, 'expenses' => $expensesOfUser,
'disponibility' => $currentUser->getDisponibility(), 'disponibility' => $currentUser->getDisponibility(),
'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(), 'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(),
]); ] );
} }
/** /**
* recieve the json containing the expanse config of a user * recieve the json containing the expanse config of a user
*
* @param Request $request * @param Request $request
*
* @return JsonResponse the list of expanses * @return JsonResponse the list of expanses
*/ */
public function saveMyExpensesAction(Request $request) public function saveMyExpensesAction( Request $request ) {
{
$json = json_decode($request->getContent(), true); $json = json_decode( $request->getContent(), true );
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$myExpenses = $currentUser->getExpenses(); $myExpenses = $currentUser->getExpenses();
$categoriesByID = []; $categoriesByID = [];
foreach ($myExpenses as $expense) { foreach ( $myExpenses as $expense ) {
$categoriesByID[$expense->getId()] = $expense; $categoriesByID[ $expense->getId() ] = $expense;
} }
// loop on the json config for expanse // loop on the json config for expanse
// save the user configuration // save the user configuration
foreach ($json['expenses'] as $expens) { foreach ( $json[ 'expenses' ] as $expens ) {
if(isset($expens['id'])){ if ( isset( $expens[ 'id' ] ) ) {
$foundExpense = $categoriesByID[$expens['id']]; $foundExpense = $categoriesByID[ $expens[ 'id' ] ];
if($foundExpense){ if ( $foundExpense ) {
// update existing expenses of logged in user // update existing expenses of logged in user
$foundExpense->setName($expens['name']); $foundExpense->setName( $expens[ 'name' ] );
$foundExpense->setAmount($expens['amount']); $foundExpense->setAmount( $expens[ 'amount' ] );
$foundExpense->setDelay($expens['delay']); $foundExpense->setDelay( $expens[ 'delay' ] );
$foundExpense->setRepeatitions($expens['repeat']); $foundExpense->setRepeatitions( $expens[ 'repeat' ] );
$foundExpense->setEnabled($expens['enabled']); $foundExpense->setEnabled( $expens[ 'enabled' ] );
$m->persist($foundExpense); $m->persist( $foundExpense );
} }
}else{ } else {
// create new expense for user // create new expense for user
$newExpense = new ExpenseKind(); $newExpense = new ExpenseKind();
$newExpense->setUser($currentUser); $newExpense->setUser( $currentUser );
$newExpense->setName($expens['name']); $newExpense->setName( $expens[ 'name' ] );
$newExpense->setDelay($expens['delay']); $newExpense->setDelay( $expens[ 'delay' ] );
$newExpense->setAmount($expens['amount']); $newExpense->setAmount( $expens[ 'amount' ] );
$newExpense->setRepeatitions($expens['repeat']); $newExpense->setRepeatitions( $expens[ 'repeat' ] );
$newExpense->setEnabled($expens['enabled']); $newExpense->setEnabled( $expens[ 'enabled' ] );
$m->persist($newExpense); $m->persist( $newExpense );
} }
} }
$currentUser->setDisponibility($json['config']['disponibility']); $currentUser->setDisponibility( $json[ 'config' ][ 'disponibility' ] );
$currentUser->setAverageMonthlyEarnings($json['config']['averageMonthlyEarnings']); $currentUser->setAverageMonthlyEarnings( $json[ 'config' ][ 'averageMonthlyEarnings' ] );
$m->persist($currentUser); $m->persist( $currentUser );
$m->flush(); $m->flush();
$ownerService = $this->ownerService; $ownerService = $this->ownerService;
$expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser); $expensesOfUser = $ownerService->serializeExpensesOfUser( $currentUser );
return new JsonResponse([ return new JsonResponse( [
'expenses' => $expensesOfUser, 'expenses' => $expensesOfUser,
'disponibility' => $currentUser->getDisponibility(), 'disponibility' => $currentUser->getDisponibility(),
'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(), 'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(),
]); ] );
} }
/** /**
@ -235,82 +233,81 @@ class DefaultController extends Controller
* *
* @return JsonResponse * @return JsonResponse
*/ */
public function addSellingAction(Request $request) public function addSellingAction( Request $request ) {
{
$json = json_decode($request->getContent(), true); $json = json_decode( $request->getContent(), true );
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$newSellRecord = new SellRecord(); $newSellRecord = new SellRecord();
// sort user categories // sort user categories
$myCategories = $currentUser->getCategories(); $myCategories = $currentUser->getCategories();
$categoriesByID = []; $categoriesByID = [];
foreach ($myCategories as $my_category) { foreach ( $myCategories as $my_category ) {
$categoriesByID[$my_category->getId()] = $my_category; $categoriesByID[ $my_category->getId() ] = $my_category;
} }
$productsModels = $m->getRepository('AppBundle:Product')->findAll(); $productsModels = $m->getRepository( 'AppBundle:Product' )->findAll();
$productsModelsByID = []; $productsModelsByID = [];
foreach ($productsModels as $product) { foreach ( $productsModels as $product ) {
$productsModelsByID[$product->getId()] = $product; $productsModelsByID[ $product->getId() ] = $product;
} }
$sumAmount = 0; $sumAmount = 0;
foreach ($json['activeSelling'] as $record) { foreach ( $json[ 'activeSelling' ] as $record ) {
$productModel = $productsModelsByID[$record['id']]; $productModel = $productsModelsByID[ $record[ 'id' ] ];
$newProductSold = new ProductSold(); $newProductSold = new ProductSold();
$newProductSold->setName($record['name']); $newProductSold->setName( $record[ 'name' ] );
$newProductSold->setImage("image mock"); $newProductSold->setImage( "image mock" );
$newProductSold->setUser($currentUser); $newProductSold->setUser( $currentUser );
$newProductSold->setPrice($record['price']); $newProductSold->setPrice( $record[ 'price' ] );
$newProductSold->setComment($json['sellingComment']); $newProductSold->setComment( $json[ 'sellingComment' ] );
$newProductSold->setProduct($productModel); $newProductSold->setProduct( $productModel );
$newProductSold->setSellRecords($newSellRecord); $newProductSold->setSellRecords( $newSellRecord );
// link selling record with user, festival // link selling record with user, festival
$currentUser->addProductsSold($newProductSold); $currentUser->addProductsSold( $newProductSold );
// persist all // persist all
$productModel->setStockCount($productModel->getStockCount() - 1); $productModel->setStockCount( $productModel->getStockCount() - 1 );
$m->persist($productModel); $m->persist( $productModel );
$m->persist($newProductSold); $m->persist( $newProductSold );
$m->persist($newProductSold); $m->persist( $newProductSold );
$sumAmount += $record['price']; $sumAmount += $record[ 'price' ];
} }
$festivalFound = $m->getRepository('AppBundle:Festival')->find($json['activeFestival']['id']); $festivalFound = $m->getRepository( 'AppBundle:Festival' )->find( $json[ 'activeFestival' ][ 'id' ] );
$newSellRecord->setFestival($festivalFound); $newSellRecord->setFestival( $festivalFound );
$newSellRecord->setAmount($sumAmount); $newSellRecord->setAmount( $sumAmount );
$newSellRecord->setDate(new \DateTime()); $newSellRecord->setDate( new \DateTime() );
$newSellRecord->setUser($currentUser); $newSellRecord->setUser( $currentUser );
$newSellRecord->setPaidByClient($json['paidByClient']); $newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
$newSellRecord->setComment($json['sellingComment']); $newSellRecord->setComment( $json[ 'sellingComment' ] );
$festivalFound->addSellRecord($newSellRecord); $festivalFound->addSellRecord( $newSellRecord );
$currentUser->addSellRecords($newSellRecord); $currentUser->addSellRecords( $newSellRecord );
$m->persist($newSellRecord); $m->persist( $newSellRecord );
$m->persist($currentUser); $m->persist( $currentUser );
$m->persist($festivalFound); $m->persist( $festivalFound );
$m->flush(); $m->flush();
$festivalFound->recalculateChiffreAffaire(); $festivalFound->recalculateChiffreAffaire();
$m->persist($festivalFound); $m->persist( $festivalFound );
$m->flush(); $m->flush();
// setup dates // setup dates
// fetch back history of selling // fetch back history of selling
$sellingRepo = $m->getRepository('AppBundle:SellRecord'); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$lastSellings = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 3); $lastSellings = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 3 );
return new JsonResponse([ return new JsonResponse( [
"message" => "ok", "message" => "ok",
"activeFestival" => $festivalFound->makeArray(), "activeFestival" => $festivalFound->makeArray(),
"newChiffreAffaire" => $festivalFound->getChiffreAffaire(), "newChiffreAffaire" => $festivalFound->getChiffreAffaire(),
"clientsCount" => count($festivalFound->getSellRecords()), "clientsCount" => count( $festivalFound->getSellRecords() ),
"recent_sellings" => json_encode($lastSellings), "recent_sellings" => json_encode( $lastSellings ),
"dump" => $json, "dump" => $json,
], 200); ], 200 );
} }
@ -318,13 +315,12 @@ class DefaultController extends Controller
* get the history of user's sellings * get the history of user's sellings
* @Route("/history", name="history") * @Route("/history", name="history")
*/ */
public function historyAction() public function historyAction() {
{
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository('AppBundle:SellRecord'); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$allSellingList = $sellingRepo->findBy(['user'=>$currentUser->getId()],['id'=>'desc']); $allSellingList = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ] );
$mySellings = array_splice($allSellingList, 0, 15); $mySellings = array_splice( $allSellingList, 0, 15 );
$chiffreAffaires = 0; $chiffreAffaires = 0;
$myFestivals = $currentUser->getFestivals(); $myFestivals = $currentUser->getFestivals();
@ -332,11 +328,11 @@ class DefaultController extends Controller
$statisticsFestivals = [ $statisticsFestivals = [
]; ];
foreach ($myFestivals as $festival) { foreach ( $myFestivals as $festival ) {
$statisticsFestivals[] = [ $statisticsFestivals[] = [
'date' => $festival->getDateCreation(), 'date' => $festival->getDateCreation(),
'name' => $festival->getName(), 'name' => $festival->getName(),
'clients_count' => count($festival->getSellRecords()), 'clients_count' => count( $festival->getSellRecords() ),
'chiffreAffaire' => $festival->getChiffreAffaire(), 'chiffreAffaire' => $festival->getChiffreAffaire(),
]; ];
} }
@ -345,59 +341,99 @@ class DefaultController extends Controller
]; ];
$statsForFestivalMock = [ $statsForFestivalMock = [
['name' => 'festoche bidule', 'clients_count' => 125, 'chiffreAffaire' => 236, 'date' => new \DateTime()], [ 'name' => 'festoche bidule', 'clients_count' => 125, 'chiffreAffaire' => 236, 'date' => new \DateTime() ],
]; ];
foreach ($allSellingList as $client) { foreach ( $allSellingList as $client ) {
foreach ($client->getProductsSold() as $product) { foreach ( $client->getProductsSold() as $product ) {
$chiffreAffaires += $product->getPrice(); $chiffreAffaires += $product->getPrice();
} }
} }
foreach ($mySellings as $client) { foreach ( $mySellings as $client ) {
foreach ($client->getProductsSold() as $product) { foreach ( $client->getProductsSold() as $product ) {
$chiffreAffaires += $product->getPrice(); $chiffreAffaires += $product->getPrice();
if (!isset($statisticsSoldProducts[$product->getName()])) { if ( ! isset( $statisticsSoldProducts[ $product->getName() ] ) ) {
$statisticsSoldProducts[$product->getName()] = $statisticsSoldProducts[ $product->getName() ] =
[ [
'name' => $product->getName(), 'name' => $product->getName(),
'count' => 0, 'count' => 0,
'value' => 0 'value' => 0,
]; ];
} }
$statisticsSoldProducts[$product->getName()]['count']++; $statisticsSoldProducts[ $product->getName() ][ 'count' ] ++;
$statisticsSoldProducts[$product->getName()]['value'] = $statisticsSoldProducts[$product->getName()]['value'] + intval($product->getPrice()); $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' => $statsForFestivalMock, // mock of festival stats
'statisticsFestivals' => $statisticsFestivals, 'statisticsFestivals' => $statisticsFestivals,
'statisticsSoldProducts' => $statisticsSoldProducts, 'statisticsSoldProducts' => $statisticsSoldProducts,
'chiffreAffaires' => $chiffreAffaires, 'chiffreAffaires' => $chiffreAffaires,
'recentSells' => $mySellings, 'recentSells' => $mySellings,
'allSellings' => count($mySellings), 'allSellings' => count( $mySellings ),
'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR, 'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
]); ] );
}
/**
* 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() ];
$serializer = new Serializer( $normalizers, $encoders );
$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 * export all clients
* @Route("/export-all", name="export_all") * @Route("/export-all", name="export_all")
*/ */
public function exportAllAction() public function exportAllAction() {
{
// TODO // TODO
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository('AppBundle:SellRecord'); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$mySellings = $sellingRepo->findByUser($currentUser->getId()); $mySellings = $sellingRepo->findByUser( $currentUser->getId() );
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date('Y-m-d_H-i-s'); $fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
$handle = fopen('php://memory', 'r+'); $handle = fopen( 'php://memory', 'r+' );
$firstLine = [ $firstLine = [
'product sold id', 'product sold id',
'date', 'date',
@ -420,21 +456,21 @@ class DefaultController extends Controller
'festival comment', 'festival comment',
]; ];
// save the column headers // save the column headers
fputcsv($handle, fputcsv( $handle,
$firstLine); $firstLine );
$chiffreAffaires = 0; $chiffreAffaires = 0;
foreach ($mySellings as $sellRecord) { foreach ( $mySellings as $sellRecord ) {
foreach ($sellRecord->getProductsSold() as $productSold) { foreach ( $sellRecord->getProductsSold() as $productSold ) {
$chiffreAffaires += $productSold->getPrice(); $chiffreAffaires += $productSold->getPrice();
// add a line to the csv file // add a line to the csv file
fputcsv($handle, fputcsv( $handle,
[ [
$productSold->getId(), $productSold->getId(),
$sellRecord->getDate()->format('c'), $sellRecord->getDate()->format( 'c' ),
$sellRecord->getDate()->format('H'), $sellRecord->getDate()->format( 'H' ),
$sellRecord->getDate()->format('i'), $sellRecord->getDate()->format( 'i' ),
$sellRecord->getDate()->format('s'), $sellRecord->getDate()->format( 's' ),
$sellRecord->getComment(), $sellRecord->getComment(),
$sellRecord->getPaidByClient(), $sellRecord->getPaidByClient(),
$productSold->getName(), $productSold->getName(),
@ -442,9 +478,9 @@ class DefaultController extends Controller
$productSold->getProduct()->getCategory()->getId(), $productSold->getProduct()->getCategory()->getId(),
$productSold->getProduct()->getCategory()->getName(), $productSold->getProduct()->getCategory()->getName(),
$productSold->getPrice(), $productSold->getPrice(),
]); ] );
if ($sellRecord->getFestival()) { if ( $sellRecord->getFestival() ) {
fputcsv($handle, fputcsv( $handle,
[ [
'', '',
'', '',
@ -460,19 +496,19 @@ class DefaultController extends Controller
'', '',
$sellRecord->getFestival()->getId(), $sellRecord->getFestival()->getId(),
$sellRecord->getFestival()->getName(), $sellRecord->getFestival()->getName(),
$sellRecord->getFestival()->getDateCreation()->format('c'), $sellRecord->getFestival()->getDateCreation()->format( 'c' ),
$sellRecord->getFestival()->getFondDeCaisseAvant(), $sellRecord->getFestival()->getFondDeCaisseAvant(),
$sellRecord->getFestival()->getFondDeCaisseApres(), $sellRecord->getFestival()->getFondDeCaisseApres(),
$sellRecord->getFestival()->getChiffreAffaire(), $sellRecord->getFestival()->getChiffreAffaire(),
$sellRecord->getFestival()->getComment(), $sellRecord->getFestival()->getComment(),
]); ] );
} }
} }
} }
rewind($handle); rewind( $handle );
$content = stream_get_contents($handle); $content = stream_get_contents( $handle );
fclose($handle); fclose( $handle );
return new Response( return new Response(
$content, 200, [ $content, 200, [
@ -486,56 +522,52 @@ class DefaultController extends Controller
/** /**
* @Route("/set-active-festival/{id}", name="set_active_festival") * @Route("/set-active-festival/{id}", name="set_active_festival")
*/ */
public function setActiveFestivalAction($id) public function setActiveFestivalAction( $id ) {
{
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$repo = $m->getRepository('AppBundle:Festival'); $repo = $m->getRepository( 'AppBundle:Festival' );
$currentUser->setActiveFestival($repo->find($id)); $currentUser->setActiveFestival( $repo->find( $id ) );
$m->persist($currentUser); $m->persist( $currentUser );
$m->flush(); $m->flush();
// replace this example code with whatever you need // replace this example code with whatever you need
return $this->redirectToRoute('festival_index'); return $this->redirectToRoute( 'festival_index' );
} }
/** /**
* @Route("/import", name="import") * @Route("/import", name="import")
*/ */
public function importAction() public function importAction() {
{
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository('AppBundle:SellRecord'); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
return $this->render('logged/import.html.twig', return $this->render( 'logged/import.html.twig',
[ [
'base_dir' => '', 'base_dir' => '',
]); ] );
} }
/** /**
* @Route("/previsionnel", name="previsionnel") * @Route("/previsionnel", name="previsionnel")
*/ */
public function previsionnelAction() public function previsionnelAction() {
{
// $currentUser = $this->getUser(); // $currentUser = $this->getUser();
// $m = $this->getDoctrine()->getManager(); // $m = $this->getDoctrine()->getManager();
// $sellingRepo = $m->getRepository('AppBundle:SellRecord'); // $sellingRepo = $m->getRepository('AppBundle:SellRecord');
return $this->render('logged/previsionnel.html.twig', return $this->render( 'logged/previsionnel.html.twig',
[ [
'base_dir' => '', 'base_dir' => '',
]); ] );
} }
/** /**
* import lots of products at once * import lots of products at once
* @Route("/mass-create", name="mass_create") * @Route("/mass-create", name="mass_create")
*/ */
public function massCreateAction(Request $request) public function massCreateAction( Request $request ) {
{
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
@ -544,35 +576,35 @@ class DefaultController extends Controller
$myProductsByName = []; $myProductsByName = [];
$currentCategory = new ProductCategory(); $currentCategory = new ProductCategory();
$currentCategory $currentCategory
->addUser($currentUser) ->addUser( $currentUser )
->setName('default category'); ->setName( 'default category' );
foreach ($myCategories as $my_category) { foreach ( $myCategories as $my_category ) {
$myCategoriesByName [$my_category->getName()] = $my_category; $myCategoriesByName [ $my_category->getName() ] = $my_category;
foreach ($my_category->getProducts() as $product) { foreach ( $my_category->getProducts() as $product ) {
$myProductsByName[$product->getName()] = $product; $myProductsByName[ $product->getName() ] = $product;
} }
$currentCategory = $my_category; $currentCategory = $my_category;
} }
$massLines = $request->request->get('produits'); $massLines = $request->request->get( 'produits' );
if ($request->getMethod() == 'POST') { if ( $request->getMethod() == 'POST' ) {
$lines = preg_split('/$\R?^/m', trim($massLines)); $lines = preg_split( '/$\R?^/m', trim( $massLines ) );
foreach ($lines as $line) { foreach ( $lines as $line ) {
if (strpos($line, ':')) { if ( strpos( $line, ':' ) ) {
// manage catgegories // manage catgegories
$boom = explode(':', trim($line)); $boom = explode( ':', trim( $line ) );
$firstPart = $boom[0]; $firstPart = $boom[ 0 ];
$value = $boom[1]; $value = $boom[ 1 ];
if ($firstPart === 'catégorie' && $value) { if ( $firstPart === 'catégorie' && $value ) {
// look for category by name // look for category by name
if (!isset($myCategoriesByName[$value])) { if ( ! isset( $myCategoriesByName[ $value ] ) ) {
$newCateg = new ProductCategory(); $newCateg = new ProductCategory();
$newCateg $newCateg
->addUser($currentUser) ->addUser( $currentUser )
->setName($value); ->setName( $value );
$currentUser->addCategory($newCateg); $currentUser->addCategory( $newCateg );
$m->persist($newCateg); $m->persist( $newCateg );
$currentCategory = $newCateg; // associate further categories with the newly created one $currentCategory = $newCateg; // associate further categories with the newly created one
} else { } else {
// echo " la catégorie existe déjà"; // echo " la catégorie existe déjà";
@ -580,37 +612,37 @@ class DefaultController extends Controller
} }
} else { } else {
// manage product // manage product
$boom = explode(';', $line); $boom = explode( ';', $line );
$productName = $boom[0]; $productName = $boom[ 0 ];
$price = 0; $price = 0;
if ($boom[1]) { if ( $boom[ 1 ] ) {
$price = intval(str_replace('€', '', $boom[1]));// removing euro symbol $price = intval( str_replace( '€', '', $boom[ 1 ] ) );// removing euro symbol
} }
// or create new product // or create new product
if ($productName && !isset($myProductsByName[$productName])) { if ( $productName && ! isset( $myProductsByName[ $productName ] ) ) {
$newProduct = new Product(); $newProduct = new Product();
$newProduct->setCategory($currentCategory) $newProduct->setCategory( $currentCategory )
->setName($productName) ->setName( $productName )
->setStockCount(500) ->setStockCount( 500 )
->setUser($currentUser) ->setUser( $currentUser )
->setPrice($price); ->setPrice( $price );
$currentUser->addProduct($newProduct); $currentUser->addProduct( $newProduct );
$m->persist($newProduct); $m->persist( $newProduct );
}// look for existing products }// look for existing products
else { else {
$myProductsByName[$productName]->setPrice($price); $myProductsByName[ $productName ]->setPrice( $price );
} }
} }
$m->persist($currentUser); $m->persist( $currentUser );
} }
// check with existing categories and products, sort them by name. // check with existing categories and products, sort them by name.
// save all // save all
$m->flush(); $m->flush();
} }
return $this->render('logged/import.html.twig', return $this->render( 'logged/import.html.twig',
[]); [] );
} }
} }

0
src/AppBundle/Entity/ExpenseKind.php Executable file → Normal file
View File

View File

@ -0,0 +1,200 @@
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ExpenseKind, for previsional compta
*
* @ORM\Table(name="expense_kind")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ExpenseKindRepository")
*/
class ExpenseKind
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var int|null
*
* @ORM\Column(name="delay", type="integer", nullable=true)
*/
private $delay;
/**
* line enabled to calculate on
*
* @ORM\Column(name="enabled", type="boolean", nullable=true)
*/
private $enabled;
/**
* @var int|null
*
* @ORM\Column(name="repeatitions", type="integer", nullable=true)
*/
private $repeatitions;
/**
* @var float
*
* @ORM\Column(name="amount", type="float")
*/
private $amount;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="expenses")
*/
private $user;
/**
* @return int|null
*/
public function getEnabled()
{
return $this->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;
}
}

0
src/AppBundle/Entity/Festival.php Executable file → Normal file
View File

View File

@ -40,7 +40,7 @@ class Festival {
/** /**
* @var \stdClass * @var \stdClass
* *
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord",mappedBy="festival") * @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord",mappedBy="festival", cascade={"remove"})
*/ */
private $sellRecords; private $sellRecords;
@ -48,6 +48,10 @@ class Festival {
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="festivals") * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="festivals")
*/ */
private $user; private $user;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\SerieFestival", inversedBy="festivals")
*/
private $serieFestival;
/** /**
* @var * @var
@ -83,11 +87,42 @@ class Festival {
private $fraisRepas; 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 * array usable by js
* @return array * @return array
*/ */
public function makeArray(){ 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 [ return [
'id' => $this->getId(), 'id' => $this->getId(),
'name' => $this->getName(), 'name' => $this->getName(),
@ -97,6 +132,7 @@ class Festival {
'clientsCount' => count($this->getSellRecords()), 'clientsCount' => count($this->getSellRecords()),
'fondDeCaisseAvant' => $this->getFondDeCaisseAvant(), 'fondDeCaisseAvant' => $this->getFondDeCaisseAvant(),
'fondDeCaisseApres' => $this->getFondDeCaisseApres(), 'fondDeCaisseApres' => $this->getFondDeCaisseApres(),
'sold' => $soldItems,
]; ];
} }

0
src/AppBundle/Entity/Product.php Executable file → Normal file
View File

View File

@ -43,7 +43,7 @@ class Product {
*/ */
private $user; private $user;
/** /**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="product") * @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="product", cascade={"remove"})
*/ */
private $productsSold; private $productsSold;

0
src/AppBundle/Entity/ProductCategory.php Executable file → Normal file
View File

View File

@ -21,11 +21,11 @@ class ProductCategory {
private $name; private $name;
/** /**
* @ORM\OneToMany(targetEntity="Product", mappedBy="category") * @ORM\OneToMany(targetEntity="Product", mappedBy="category", cascade={"remove"})
*/ */
private $products; private $products;
/** /**
* @ORM\OneToMany(targetEntity="ProductSold", mappedBy="product") * @ORM\OneToMany(targetEntity="ProductSold", mappedBy="product", cascade={"remove"})
*/ */
private $productsSold; private $productsSold;

0
src/AppBundle/Entity/ProductSold.php Executable file → Normal file
View File

0
src/AppBundle/Entity/SellRecord.php Executable file → Normal file
View File

View File

@ -24,7 +24,7 @@ class SellRecord {
private $gender; private $gender;
/** /**
* liste des produits de la vente * 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; private $productsSold;

33
src/AppBundle/Entity/SerieFestival.php Executable file → Normal file
View File

@ -127,4 +127,37 @@ class SerieFestival {
{ {
$this->dateCreation = $dateCreation; $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);
}
} }

View File

@ -0,0 +1,130 @@
<?php
namespace AppBundle\Entity;
use AppBundle\Traits\Commentable;
use Doctrine\ORM\Mapping as ORM;
/**
* Festival
*
* @ORM\Table(name="serieFestival")
* @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository")
*/
class SerieFestival {
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* variabilised products sold
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="serieFestival")
*/
private $festivals;
/**
* @var \DateTime
*
* @ORM\Column(name="dateCreation", type="datetime")
*/
private $dateCreation;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="seriesFestivals")
*/
private $user;
/**
* @return mixed
*/
public function getUser()
{
return $this->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;
}
}

83
src/AppBundle/Entity/User.php Executable file → Normal file
View File

@ -35,6 +35,10 @@ class User extends BaseUser {
* @ORM\Column(name="google_id", type="string", length=255, nullable=true) * @ORM\Column(name="google_id", type="string", length=255, nullable=true)
*/ */
private $googleId; private $googleId;
/**
* @ORM\Column(name="mastodon_id", type="string", length=255, nullable=true)
*/
private $mastodonId;
private $googleAccessToken; private $googleAccessToken;
/** /**
@ -76,11 +80,12 @@ class User extends BaseUser {
private $averageMonthlyEarnings; private $averageMonthlyEarnings;
/** /**
* available money, for previsionnel calculation
* @ORM\Column(name="disponibility", type="float", nullable=true) * @ORM\Column(name="disponibility", type="float", nullable=true)
*/ */
private $disponibility; private $disponibility;
/** /**
* variabilised products sold * expenses by kind, for previsionnel
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user") * @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user")
*/ */
private $expenses; private $expenses;
@ -468,4 +473,80 @@ class User extends BaseUser {
public function getDisqusId() { public function getDisqusId() {
return $this->disqusId; 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);
}
} }

View File

@ -35,9 +35,16 @@ class User extends BaseUser {
* @ORM\Column(name="google_id", type="string", length=255, nullable=true) * @ORM\Column(name="google_id", type="string", length=255, nullable=true)
*/ */
private $googleId; private $googleId;
/**
* @ORM\Column(name="mastodon_id", type="string", length=255, nullable=true)
*/
private $mastodonId;
private $googleAccessToken; private $googleAccessToken;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
*/
private $categories;
/** /**
* templates products * templates products
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user") * @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
@ -54,6 +61,11 @@ class User extends BaseUser {
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user") * @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user")
*/ */
private $festivals; private $festivals;
/**
* series of festivals
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SerieFestival", mappedBy="user")
*/
private $seriesFestivals;
/** /**
* current festival we are recording sellings for * current festival we are recording sellings for
@ -61,10 +73,84 @@ class User extends BaseUser {
*/ */
private $activeFestival; private $activeFestival;
//expenses previsionnel configs
/** /**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users") * @ORM\Column(name="averageMonthlyEarnings", type="float", nullable=true)
*/ */
private $categories; private $averageMonthlyEarnings;
/**
* available money, for previsionnel calculation
* @ORM\Column(name="disponibility", type="float", nullable=true)
*/
private $disponibility;
/**
* expenses by kind, for previsionnel
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user")
*/
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 * @return mixed