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

View File

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

View File

@ -2,6 +2,7 @@
namespace AppBundle\Controller;
use AppBundle\Entity\Festival;
use AppBundle\Entity\ProductSold;
use AppBundle\Entity\SellRecord;
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\Request;
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 {
@ -43,6 +41,12 @@ class DefaultController extends Controller {
public function dashboardAction( Request $request ) {
$m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser();
$lastFestival = $m->getRepository( 'AppBundle:Festival' )
->findOneBy( [ 'user' => $this->getUser()->getId() ],
[ 'id' => 'desc' ],
0,
1 );
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categories = $categRepo->findAll();
@ -51,6 +55,7 @@ class DefaultController extends Controller {
// replace this example code with whatever you need
return $this->render( 'logged/dashboard.html.twig',
[
'lastFestival' => $lastFestival,
'categories' => $categories,
'currentUser' => $currentUser,
'recentSells' => $recentSells,
@ -64,6 +69,8 @@ class DefaultController extends Controller {
*/
public function getMyProductsAction() {
$m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser();
if ( ! $currentUser ) {
return new JsonResponse( [
@ -71,6 +78,27 @@ class DefaultController extends Controller {
'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' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categories = $currentUser->getCategories();
@ -105,11 +133,20 @@ class DefaultController extends Controller {
}
$categories = $serializedCategories;
$recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
return new JsonResponse( [
'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' ];
}
$festivalFound = $m->getRepository( 'AppBundle:Festival' )->find( $json[ 'activeFestival' ][ 'id' ] );
$newSellRecord->setFestival( $festivalFound );
$newSellRecord->setAmount( $sumAmount );
$newSellRecord->setDate( new \DateTime() );
$newSellRecord->setUser( $currentUser );

View File

@ -2,6 +2,7 @@
namespace AppBundle\Entity;
use AppBundle\Traits\Commentable;
use Doctrine\ORM\Mapping as ORM;
/**
@ -11,6 +12,8 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository")
*/
class Festival {
use Commentable;
/**
* @var int
*
@ -46,6 +49,23 @@ class Festival {
*/
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
*
@ -171,4 +191,70 @@ class Festival {
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

@ -2,6 +2,7 @@
namespace AppBundle\Entity;
use AppBundle\Traits\Commentable;
use Doctrine\ORM\Mapping as ORM;
/**
@ -11,6 +12,8 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity(repositoryClass="AppBundle\Repository\FestivalRepository")
*/
class Festival {
use Commentable;
/**
* @var int
*
@ -46,6 +49,23 @@ class Festival {
*/
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
*
@ -149,4 +169,92 @@ class Festival {
public function removeSellRecord( \AppBundle\Entity\SellRecord $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

@ -126,8 +126,7 @@ class ProductCategory {
*
* @return ProductCategory
*/
public function addUser(\AppBundle\Entity\User $user)
{
public function addUser( \AppBundle\Entity\User $user ) {
$this->users[] = $user;
return $this;
@ -138,8 +137,7 @@ class ProductCategory {
*
* @param \AppBundle\Entity\User $user
*/
public function removeUser(\AppBundle\Entity\User $user)
{
public function removeUser( \AppBundle\Entity\User $user ) {
$this->users->removeElement( $user );
}
}

View File

@ -45,6 +45,12 @@ class User extends BaseUser {
*/
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")
*/
@ -252,8 +258,7 @@ class User extends BaseUser {
*
* @return User
*/
public function addFestival(\AppBundle\Entity\Festival $festival)
{
public function addFestival( \AppBundle\Entity\Festival $festival ) {
$this->festivals[] = $festival;
return $this;
@ -266,8 +271,7 @@ class User extends BaseUser {
*
* @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 );
}
@ -276,8 +280,29 @@ class User extends BaseUser {
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFestivals()
{
public function getFestivals() {
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;
/**
* current festival we are recording sellings for
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Festival")
*/
private $activeFestival;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
*/
@ -244,4 +250,37 @@ class User extends BaseUser {
public function removeSellRecord( \AppBundle\Entity\SellRecord $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}
*/
public function buildForm( FormBuilderInterface $builder, array $options ) {
$builder->add( 'name' )// ->add('dateCreation')
;
$builder
->add( 'name' )
->add( 'chiffreAffaire' )
->add( 'fondDeCaisseAvant' )
->add( 'fondDeCaisseApres' )
->add( 'dateCreation' );
}
/**