This commit is contained in:
Kayn Ty 2018-04-17 16:15:24 +02:00
parent 80b334cf85
commit 0f1fdc0443
9 changed files with 376 additions and 73 deletions

View File

@ -12,10 +12,7 @@
<h2> <h2>
<i class="fa fa-user"></i> Client actuel: <i class="fa fa-user"></i> Client actuel:
</h2> </h2>
{{ activeSelling.length }} produit {{ activeSelling.length }} produit<span ng-if="activeSelling.length>1">s</span>
<span ng-if="activeSelling.length>1">
s
</span>
<input class="input input-lg" type="text" ng-model="sellingComment" placeholder="nom ou commentaire"> <input class="input input-lg" type="text" ng-model="sellingComment" placeholder="nom ou commentaire">
<hr> <hr>
<ul> <ul>

View File

@ -14,6 +14,7 @@ angular
$scope.activeItemsSold = []; // list of products ID to sell $scope.activeItemsSold = []; // list of products ID to sell
$scope.activeSelling = []; // list of products to sell $scope.activeSelling = []; // list of products to sell
$scope.activeFestival = { // an event where selling take place $scope.activeFestival = { // an event where selling take place
id : null,
name : "le festival", name : "le festival",
dateCreation: new Date(), dateCreation: new Date(),
commentaire : "" commentaire : ""
@ -79,6 +80,12 @@ angular
$scope.categories = rep.data.categories; $scope.categories = rep.data.categories;
$scope.productsFromDB = rep.data.categories; $scope.productsFromDB = rep.data.categories;
$scope.recentSellings = rep.data.history; $scope.recentSellings = rep.data.history;
// festoche
$scope.activeFestival.id = rep.data.lastFestival.id;
$scope.activeFestival.name = rep.data.lastFestival.name;
$scope.activeFestival.dateCreation = rep.data.lastFestival.dateCreation;
$scope.activeFestival.commentaire = rep.data.lastFestival.commentaire;
//done
$scope.initLoadDone = true; $scope.initLoadDone = true;
}, (err) => { }, (err) => {
console.log(err); console.log(err);

View File

@ -2,6 +2,7 @@
namespace AppBundle\Controller; namespace AppBundle\Controller;
use AppBundle\Entity\Festival;
use AppBundle\Entity\ProductSold; use AppBundle\Entity\ProductSold;
use AppBundle\Entity\SellRecord; use AppBundle\Entity\SellRecord;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@ -9,9 +10,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Component\Serializer\Serializer;
class DefaultController extends Controller { class DefaultController extends Controller {
@ -43,18 +41,25 @@ class DefaultController extends Controller {
public function dashboardAction( Request $request ) { public function dashboardAction( Request $request ) {
$m = $this->getDoctrine()->getManager(); $m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser(); $currentUser = $this->getUser();
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); $lastFestival = $m->getRepository( 'AppBundle:Festival' )
$categories = $categRepo->findAll(); ->findOneBy( [ 'user' => $this->getUser()->getId() ],
$recentSells = $sellingRepo->findBy( [], [ 'id' => 'desc' ], 0, 5 ); [ 'id' => 'desc' ],
0,
1 );
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categories = $categRepo->findAll();
$recentSells = $sellingRepo->findBy( [], [ 'id' => 'desc' ], 0, 5 );
// replace this example code with whatever you need // replace this example code with whatever you need
return $this->render( 'logged/dashboard.html.twig', return $this->render( 'logged/dashboard.html.twig',
[ [
'categories' => $categories, 'lastFestival' => $lastFestival,
'currentUser' => $currentUser, 'categories' => $categories,
'recentSells' => $recentSells, 'currentUser' => $currentUser,
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR, 'recentSells' => $recentSells,
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
] ); ] );
} }
@ -63,7 +68,9 @@ class DefaultController extends Controller {
* @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( [
@ -71,6 +78,27 @@ class DefaultController extends Controller {
'recentSells' => [ [ '' ] ], 'recentSells' => [ [ '' ] ],
] ); ] );
} }
$activeFestival = $currentUser->getActiveFestival();
if ( ! $activeFestival ) {
$activeFestival = $m->getRepository( 'AppBundle:Festival' )
->findOneBy( [ 'user' => $this->getUser()->getId() ],
[ 'id' => 'desc' ],
0,
1 );
if ( ! $activeFestival ) {
$activeFestival = new Festival();
$activeFestival->setDateCreation( new \DateTime() );
$activeFestival->setName( 'default festival' );
$activeFestival->setUser( $currentUser );
}
$currentUser->setActiveFestival( $activeFestival );
$m->persist( $activeFestival );
$m->persist( $currentUser );
$m->flush();
}
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' ); $categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categories = $currentUser->getCategories(); $categories = $currentUser->getCategories();
@ -105,11 +133,20 @@ class DefaultController extends Controller {
} }
$categories = $serializedCategories; $categories = $serializedCategories;
$recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 ); $recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
return new JsonResponse( [ return new JsonResponse( [
'categories' => $categories, 'categories' => $categories,
'recentSells' => $recentSells, 'recentSells' => count( $recentSells ),
'lastFestival' => [
'id' => $activeFestival->getId(),
'name' => $activeFestival->getName(),
'commentaire' => $activeFestival->getComment(),
'dateCreation' => $activeFestival->getDateCreation(),
'fondDeCaisseAvant' => $activeFestival->getFondDeCaisseAvant(),
'fondDeCaisseApres' => $activeFestival->getFondDeCaisseApres(),
],
] ); ] );
} }
@ -156,6 +193,8 @@ class DefaultController extends Controller {
$sumAmount += $record[ 'price' ]; $sumAmount += $record[ 'price' ];
} }
$festivalFound = $m->getRepository( 'AppBundle:Festival' )->find( $json[ 'activeFestival' ][ 'id' ] );
$newSellRecord->setFestival( $festivalFound );
$newSellRecord->setAmount( $sumAmount ); $newSellRecord->setAmount( $sumAmount );
$newSellRecord->setDate( new \DateTime() ); $newSellRecord->setDate( new \DateTime() );
$newSellRecord->setUser( $currentUser ); $newSellRecord->setUser( $currentUser );

View File

@ -2,6 +2,7 @@
namespace AppBundle\Entity; namespace AppBundle\Entity;
use AppBundle\Traits\Commentable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
@ -11,6 +12,8 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository") * @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository")
*/ */
class Festival { class Festival {
use Commentable;
/** /**
* @var int * @var int
* *
@ -46,6 +49,23 @@ class Festival {
*/ */
private $user; private $user;
/**
* @var
* @ORM\Column(name="fond_de_caisse_avant", type="float")
*/
private $fondDeCaisseAvant;
/**
* @var
* @ORM\Column(name="fond_de_caisse_apres", type="float")
*/
private $fondDeCaisseApres;
/**
* @var
* @ORM\Column(name="chiffre_affaire", type="float")
*/
private $chiffreAffaire;
/** /**
* Get id * Get id
* *
@ -171,4 +191,70 @@ class Festival {
public function getUser() { public function getUser() {
return $this->user; return $this->user;
} }
/**
* Set fondDeCaisseAvant.
*
* @param float $fondDeCaisseAvant
*
* @return Festival
*/
public function setFondDeCaisseAvant( $fondDeCaisseAvant ) {
$this->fondDeCaisseAvant = $fondDeCaisseAvant;
return $this;
}
/**
* Get fondDeCaisseAvant.
*
* @return float
*/
public function getFondDeCaisseAvant() {
return $this->fondDeCaisseAvant;
}
/**
* Set fondDeCaisseApres.
*
* @param float $fondDeCaisseApres
*
* @return Festival
*/
public function setFondDeCaisseApres( $fondDeCaisseApres ) {
$this->fondDeCaisseApres = $fondDeCaisseApres;
return $this;
}
/**
* Get fondDeCaisseApres.
*
* @return float
*/
public function getFondDeCaisseApres() {
return $this->fondDeCaisseApres;
}
/**
* Set chiffreAffaire.
*
* @param float $chiffreAffaire
*
* @return Festival
*/
public function setChiffreAffaire( $chiffreAffaire ) {
$this->chiffreAffaire = $chiffreAffaire;
return $this;
}
/**
* Get chiffreAffaire.
*
* @return float
*/
public function getChiffreAffaire() {
return $this->chiffreAffaire;
}
} }

View File

@ -2,6 +2,7 @@
namespace AppBundle\Entity; namespace AppBundle\Entity;
use AppBundle\Traits\Commentable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
@ -11,6 +12,8 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository") * @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository")
*/ */
class Festival { class Festival {
use Commentable;
/** /**
* @var int * @var int
* *
@ -46,6 +49,23 @@ class Festival {
*/ */
private $user; private $user;
/**
* @var
* @ORM\Column(name="fond_de_caisse_avant", type="float")
*/
private $fondDeCaisseAvant;
/**
* @var
* @ORM\Column(name="fond_de_caisse_apres", type="float")
*/
private $fondDeCaisseApres;
/**
* @var
* @ORM\Column(name="chiffre_affaire", type="float")
*/
private $chiffreAffaire;
/** /**
* Get id * Get id
* *
@ -149,4 +169,92 @@ class Festival {
public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) { public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords->removeElement( $sellRecord ); $this->sellRecords->removeElement( $sellRecord );
} }
/**
* Set user.
*
* @param \AppBundle\Entity\User|null $user
*
* @return Festival
*/
public function setUser( \AppBundle\Entity\User $user = null ) {
$this->user = $user;
return $this;
}
/**
* Get user.
*
* @return \AppBundle\Entity\User|null
*/
public function getUser() {
return $this->user;
}
/**
* Set fondDeCaisseAvant.
*
* @param float $fondDeCaisseAvant
*
* @return Festival
*/
public function setFondDeCaisseAvant( $fondDeCaisseAvant ) {
$this->fondDeCaisseAvant = $fondDeCaisseAvant;
return $this;
}
/**
* Get fondDeCaisseAvant.
*
* @return float
*/
public function getFondDeCaisseAvant() {
return $this->fondDeCaisseAvant;
}
/**
* Set fondDeCaisseApres.
*
* @param float $fondDeCaisseApres
*
* @return Festival
*/
public function setFondDeCaisseApres( $fondDeCaisseApres ) {
$this->fondDeCaisseApres = $fondDeCaisseApres;
return $this;
}
/**
* Get fondDeCaisseApres.
*
* @return float
*/
public function getFondDeCaisseApres() {
return $this->fondDeCaisseApres;
}
/**
* Set chiffreAffaire.
*
* @param float $chiffreAffaire
*
* @return Festival
*/
public function setChiffreAffaire( $chiffreAffaire ) {
$this->chiffreAffaire = $chiffreAffaire;
return $this;
}
/**
* Get chiffreAffaire.
*
* @return float
*/
public function getChiffreAffaire() {
return $this->chiffreAffaire;
}
} }

View File

@ -119,27 +119,25 @@ class ProductCategory {
$this->products->removeElement( $product ); $this->products->removeElement( $product );
} }
/** /**
* Add user * Add user
* *
* @param \AppBundle\Entity\User $user * @param \AppBundle\Entity\User $user
* *
* @return ProductCategory * @return ProductCategory
*/ */
public function addUser(\AppBundle\Entity\User $user) public function addUser( \AppBundle\Entity\User $user ) {
{ $this->users[] = $user;
$this->users[] = $user;
return $this; return $this;
} }
/** /**
* Remove user * Remove user
* *
* @param \AppBundle\Entity\User $user * @param \AppBundle\Entity\User $user
*/ */
public function removeUser(\AppBundle\Entity\User $user) public function removeUser( \AppBundle\Entity\User $user ) {
{ $this->users->removeElement( $user );
$this->users->removeElement($user); }
}
} }

View File

@ -45,6 +45,12 @@ class User extends BaseUser {
*/ */
private $festivals; private $festivals;
/**
* current festival we are recording sellings for
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Festival")
*/
private $activeFestival;
/** /**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users") * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
*/ */
@ -245,39 +251,58 @@ class User extends BaseUser {
$this->sellRecords->removeElement( $sellRecord ); $this->sellRecords->removeElement( $sellRecord );
} }
/** /**
* Add festival. * Add festival.
* *
* @param \AppBundle\Entity\Festival $festival * @param \AppBundle\Entity\Festival $festival
* *
* @return User * @return User
*/ */
public function addFestival(\AppBundle\Entity\Festival $festival) public function addFestival( \AppBundle\Entity\Festival $festival ) {
{ $this->festivals[] = $festival;
$this->festivals[] = $festival;
return $this; return $this;
} }
/** /**
* Remove festival. * Remove festival.
* *
* @param \AppBundle\Entity\Festival $festival * @param \AppBundle\Entity\Festival $festival
* *
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise. * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/ */
public function removeFestival(\AppBundle\Entity\Festival $festival) public function removeFestival( \AppBundle\Entity\Festival $festival ) {
{ return $this->festivals->removeElement( $festival );
return $this->festivals->removeElement($festival); }
}
/** /**
* Get festivals. * Get festivals.
* *
* @return \Doctrine\Common\Collections\Collection * @return \Doctrine\Common\Collections\Collection
*/ */
public function getFestivals() public function getFestivals() {
{ return $this->festivals;
return $this->festivals; }
}
/**
* Set activeFestival.
*
* @param \AppBundle\Entity\Festival|null $activeFestival
*
* @return User
*/
public function setActiveFestival( \AppBundle\Entity\Festival $activeFestival = null ) {
$this->activeFestival = $activeFestival;
return $this;
}
/**
* Get activeFestival.
*
* @return \AppBundle\Entity\Festival|null
*/
public function getActiveFestival() {
return $this->activeFestival;
}
} }

View File

@ -45,6 +45,12 @@ class User extends BaseUser {
*/ */
private $festivals; private $festivals;
/**
* current festival we are recording sellings for
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Festival")
*/
private $activeFestival;
/** /**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users") * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
*/ */
@ -244,4 +250,37 @@ class User extends BaseUser {
public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) { public function removeSellRecord( \AppBundle\Entity\SellRecord $sellRecord ) {
$this->sellRecords->removeElement( $sellRecord ); $this->sellRecords->removeElement( $sellRecord );
} }
/**
* Add festival.
*
* @param \AppBundle\Entity\Festival $festival
*
* @return User
*/
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 );
}
/**
* Get festivals.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFestivals() {
return $this->festivals;
}
} }

View File

@ -11,8 +11,12 @@ class FestivalType extends AbstractType {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm( FormBuilderInterface $builder, array $options ) { public function buildForm( FormBuilderInterface $builder, array $options ) {
$builder->add( 'name' )// ->add('dateCreation') $builder
; ->add( 'name' )
->add( 'chiffreAffaire' )
->add( 'fondDeCaisseAvant' )
->add( 'fondDeCaisseApres' )
->add( 'dateCreation' );
} }
/** /**