add to current selling list ok
This commit is contained in:
parent
e1bea2f9c8
commit
6543115387
@ -10,43 +10,62 @@
|
|||||||
<div class="well">
|
<div class="well">
|
||||||
{{productsFromDB.length}}
|
{{productsFromDB.length}}
|
||||||
</div>
|
</div>
|
||||||
{% endverbatim %}
|
|
||||||
<div class="listing-products col-xs-9">
|
<div class="listing-products col-xs-7">
|
||||||
{% for c in categories %}
|
<div class="category-listing" ng-repeat="c in categories">
|
||||||
<h2>
|
<h2>
|
||||||
{{ c.name }}
|
{{ c.name }}
|
||||||
</h2>
|
</h2>
|
||||||
{% for p in c.products %}
|
|
||||||
<button class="btn btn-default"
|
|
||||||
ng-click="addProduct({{ p.id }})">
|
|
||||||
{{ p.name }}
|
|
||||||
</button>
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<div class="sellings col-xs-3">
|
|
||||||
<div class="current-selling">
|
|
||||||
<form action="">
|
|
||||||
<ul >
|
|
||||||
{% verbatim %}
|
|
||||||
|
|
||||||
<li ng-repeat="p in activeSelling">
|
<button ng-repeat="p in c.products track by p.id"
|
||||||
{{p.name}} x1 {{p.price}}€
|
class="btn btn-default"
|
||||||
|
ng-click="addProduct( p )">
|
||||||
|
{{ p.name }}
|
||||||
|
<span class="badge">
|
||||||
|
{{ p.price }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="sellings col-xs-5">
|
||||||
|
<div class="current-selling">
|
||||||
|
<form action="#">
|
||||||
|
<input type="text" ng-model="activeFestival.commentaire">
|
||||||
|
<ul>
|
||||||
|
<li ng-repeat="p in activeSelling track by $index">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-6">
|
||||||
|
{{p.name}}
|
||||||
|
<div class="btn btn-warning" ng-click="activeSelling.splice($index,1)">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-6 text-right">
|
||||||
|
<strong>
|
||||||
|
<input type="number" ng-model="p.price"> €
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<h3>Total: {{CurrentSellingTotal}}€</h3>
|
<h3>Total: {{CurrentSellingTotal}}€</h3>
|
||||||
|
|
||||||
|
<input type="number" id="paid_amount" ng-model="paidAmount">
|
||||||
|
<h3>Rendu: {{ abs(CurrentSellingTotal - paidAmount) }}€</h3>
|
||||||
{% endverbatim %}
|
{% endverbatim %}
|
||||||
<input type="number" id="paid_amount">
|
|
||||||
<h3>Rendu: xxxx€</h3>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button class="btn btn-primary" id="pause_selling">
|
<button class="btn btn-default" id="pause_selling">
|
||||||
<i class="fa fa-clock"></i>
|
<i class="fa fa-clock"></i>
|
||||||
Pause
|
Pause
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button class="btn btn-primary" id="validate_selling">
|
<button class="btn btn-primary btn-block" id="validate_selling">
|
||||||
<i class="fa fa-check"></i>
|
<i class="fa fa-check"></i>
|
||||||
Valider
|
Valider
|
||||||
</button>
|
</button>
|
||||||
|
@ -9,8 +9,15 @@ angular
|
|||||||
{id: 3, name: "truc 3", price: 4, category: 2},
|
{id: 3, name: "truc 3", price: 4, category: 2},
|
||||||
{id: 4, name: "truc 4", price: 1, category: 2},
|
{id: 4, name: "truc 4", price: 1, category: 2},
|
||||||
];
|
];
|
||||||
|
$scope.categories = [];
|
||||||
|
$scope.recentSellings = [];
|
||||||
$scope.pausedSelling = [];
|
$scope.pausedSelling = [];
|
||||||
$scope.activeSelling = [];
|
$scope.activeSelling = [];
|
||||||
|
$scope.activeFestival = {
|
||||||
|
name : "le festival",
|
||||||
|
dateCreation: new Date(),
|
||||||
|
commentaire : ""
|
||||||
|
};
|
||||||
$scope.CurrentSellingTotal = $scope.activeSelling.reduce(function (a, b) {
|
$scope.CurrentSellingTotal = $scope.activeSelling.reduce(function (a, b) {
|
||||||
return a + b.price;
|
return a + b.price;
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -22,18 +29,16 @@ angular
|
|||||||
$scope.pauseSelling = function (selling) {
|
$scope.pauseSelling = function (selling) {
|
||||||
$scope.pausedSelling.push(selling);
|
$scope.pausedSelling.push(selling);
|
||||||
};
|
};
|
||||||
$scope.addProduct = function (id) {
|
$scope.addProduct = function (product) {
|
||||||
let found = $scope.productsFromDB.find({id: id});
|
$scope.activeSelling.push(product);
|
||||||
if (found) {
|
|
||||||
$scope.productsToRecord.push(found);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
$scope.fetchProductsFromDB = function () {
|
$scope.fetchProductsFromDB = function () {
|
||||||
console.log('fetch products...');
|
console.log('fetch products...');
|
||||||
$http.get('get-my-products').then((data) => {
|
$http.get('get-my-products').then((rep) => {
|
||||||
|
|
||||||
console.log('ok');
|
console.log('ok', rep);
|
||||||
$scope.productsFromDB = data;
|
$scope.categories = rep.data.categories;
|
||||||
|
$scope.recentSellings = rep.data.history;
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
@ -45,7 +50,10 @@ angular
|
|||||||
console.log('log test ok');
|
console.log('log test ok');
|
||||||
};
|
};
|
||||||
$scope.sendForm = function () {
|
$scope.sendForm = function () {
|
||||||
let lesParams = {};
|
let lesParams = {
|
||||||
|
activeSelling : $scope.activeSelling,
|
||||||
|
activeFestival: $scope.activeFestival
|
||||||
|
};
|
||||||
$http({
|
$http({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url : '/add-selling',
|
url : '/add-selling',
|
||||||
|
@ -56,6 +56,10 @@ class DefaultController extends Controller {
|
|||||||
] );
|
] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get user products
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
public function getMyProductsAction() {
|
public function getMyProductsAction() {
|
||||||
$m = $this->getDoctrine()->getManager();
|
$m = $this->getDoctrine()->getManager();
|
||||||
$currentUser = $this->getUser();
|
$currentUser = $this->getUser();
|
||||||
@ -68,10 +72,37 @@ class DefaultController extends Controller {
|
|||||||
$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();
|
||||||
if ( ! $categories ) {
|
if ( ! count( $categories ) ) {
|
||||||
$defaultCategories = $categRepo->find( [ 1, 2 ] );
|
$categories = $defaultCategories = $categRepo->findById( [ 1, 2 ] );
|
||||||
$currentUser->setCategories( $defaultCategories );
|
$currentUser->setCategories( $defaultCategories );
|
||||||
|
$m->persist( $currentUser );
|
||||||
}
|
}
|
||||||
|
$serializedCategories = [];
|
||||||
|
|
||||||
|
foreach ( $categories as $category ) {
|
||||||
|
$products = $category->getProducts();
|
||||||
|
if ( $products ) {
|
||||||
|
$listOfProductsInArray = [];
|
||||||
|
foreach ( $products as $product ) {
|
||||||
|
$listOfProductsInArray[] = [
|
||||||
|
'id' => $product->getId(),
|
||||||
|
'name' => $product->getName(),
|
||||||
|
'category' => $category->getId(),
|
||||||
|
'price' => 1 * $product->getPrice(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$products = $listOfProductsInArray;
|
||||||
|
}
|
||||||
|
$serializedCategories[] =
|
||||||
|
[
|
||||||
|
'id' => $category->getId(),
|
||||||
|
'name' => $category->getName(),
|
||||||
|
'products' => $products ? $products : null,
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
$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( [
|
||||||
|
@ -10,8 +10,12 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
class ProductSold extends Product {
|
class ProductSold extends Product {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="SellRecord", mappedBy="products")
|
* @ORM\ManyToOne(targetEntity="SellRecord", inversedBy="productsSold")
|
||||||
*/
|
*/
|
||||||
private $sellRecords;
|
private $sellRecords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold")
|
||||||
|
*/
|
||||||
|
private $user;
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,12 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\SellRecordRepository")
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\SellRecordRepository")
|
||||||
*/
|
*/
|
||||||
class SellRecord {
|
class SellRecord {
|
||||||
|
|
||||||
|
use Commentable;
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Product", inversedBy="sellRecords")
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="sellRecords")
|
||||||
*/
|
*/
|
||||||
private $products;
|
private $productsSold;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
@ -36,9 +38,40 @@ class SellRecord {
|
|||||||
*/
|
*/
|
||||||
private $festival;
|
private $festival;
|
||||||
|
|
||||||
use Commentable;
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="sellRecords")
|
||||||
|
*/
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getComment() {
|
||||||
|
return $this->comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $comment
|
||||||
|
*/
|
||||||
|
public function setComment( $comment ) {
|
||||||
|
$this->comment = $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getProductsSold() {
|
||||||
|
return $this->productsSold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $productsSold
|
||||||
|
*/
|
||||||
|
public function setProductsSold( $productsSold ) {
|
||||||
|
$this->productsSold = $productsSold;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
@ -54,11 +87,6 @@ class SellRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="products")
|
|
||||||
*/
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
@ -29,13 +29,36 @@ class User extends BaseUser {
|
|||||||
private $googleAccessToken;
|
private $googleAccessToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* templates products
|
||||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
|
||||||
*/
|
*/
|
||||||
private $products;
|
private $products;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* variabilised products sold
|
||||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="user")
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="user")
|
||||||
*/
|
*/
|
||||||
private $productsSold;
|
private $productsSold;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
|
||||||
|
*/
|
||||||
|
private $categories;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getProductsSold() {
|
||||||
|
return $this->productsSold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $productsSold
|
||||||
|
*/
|
||||||
|
public function setProductsSold( $productsSold ) {
|
||||||
|
$this->productsSold = $productsSold;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord", mappedBy="user")
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord", mappedBy="user")
|
||||||
*/
|
*/
|
||||||
@ -83,11 +106,6 @@ class User extends BaseUser {
|
|||||||
$this->products = $products;
|
$this->products = $products;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", mappedBy="user")
|
|
||||||
*/
|
|
||||||
private $categories;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user