add to current selling list ok

This commit is contained in:
Kayn Ty 2018-04-05 16:40:40 +02:00
parent e1bea2f9c8
commit 6543115387
6 changed files with 197 additions and 89 deletions

View File

@ -10,79 +10,98 @@
<div class="well">
{{productsFromDB.length}}
</div>
{% endverbatim %}
<div class="listing-products col-xs-9">
{% for c in categories %}
<h2>
{{ c.name }}
</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">
{{p.name}} x1 {{p.price}}
</li>
</ul>
<h3>Total: {{CurrentSellingTotal}}€</h3>
{% endverbatim %}
<input type="number" id="paid_amount">
<h3>Rendu: xxxx€</h3>
<div class="listing-products col-xs-7">
<div class="category-listing" ng-repeat="c in categories">
<h2>
{{ c.name }}
</h2>
<button ng-repeat="p in c.products track by p.id"
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">
<button class="btn btn-primary" id="pause_selling">
<i class="fa fa-clock"></i>
Pause
</button>
<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">
<button class="btn btn-primary" id="validate_selling">
<i class="fa fa-check"></i>
Valider
</button>
<div class="col-xs-6 text-right">
<strong>
<input type="number" ng-model="p.price"> €
</strong>
</div>
</div>
</form>
<hr>
</div>
<div class="selling-on-hold">
<h4>
Ventes en pause
</h4>
<ul>
<li>h:m:s xxxx€</li>
</ul>
<hr>
</div>
<div class="selling-history">
<h4>
Ventes récentes
</h4>
{% if recentSells %}
<ul>
{% for s in recentSells %}
<li>{{ s.date|date('Y/m/d H:i:s') }} {{ s.amount }}€</li>
{% endfor %}
</li>
</ul>
{% else %}
aucune
{% endif %}
<h3>Total: {{CurrentSellingTotal}}€</h3>
<input type="number" id="paid_amount" ng-model="paidAmount">
<h3>Rendu: {{ abs(CurrentSellingTotal - paidAmount) }}€</h3>
{% endverbatim %}
<div class="row">
<div class="col">
<button class="btn btn-default" id="pause_selling">
<i class="fa fa-clock"></i>
Pause
</button>
</div>
<div class="col">
<button class="btn btn-primary btn-block" id="validate_selling">
<i class="fa fa-check"></i>
Valider
</button>
</div>
</div>
</form>
<hr>
</div>
<div class="selling-on-hold">
<h4>
Ventes en pause
</h4>
<ul>
<li>h:m:s xxxx€</li>
</ul>
<hr>
</div>
<div class="selling-history">
<h4>
Ventes récentes
</h4>
{% if recentSells %}
<ul>
{% for s in recentSells %}
<li>{{ s.date|date('Y/m/d H:i:s') }} {{ s.amount }}€</li>
{% endfor %}
</ul>
{% else %}
aucune
{% endif %}
</div>
</div>
</div>

View File

@ -9,8 +9,15 @@ angular
{id: 3, name: "truc 3", price: 4, category: 2},
{id: 4, name: "truc 4", price: 1, category: 2},
];
$scope.categories = [];
$scope.recentSellings = [];
$scope.pausedSelling = [];
$scope.activeSelling = [];
$scope.activeFestival = {
name : "le festival",
dateCreation: new Date(),
commentaire : ""
};
$scope.CurrentSellingTotal = $scope.activeSelling.reduce(function (a, b) {
return a + b.price;
}, 0);
@ -22,18 +29,16 @@ angular
$scope.pauseSelling = function (selling) {
$scope.pausedSelling.push(selling);
};
$scope.addProduct = function (id) {
let found = $scope.productsFromDB.find({id: id});
if (found) {
$scope.productsToRecord.push(found);
}
$scope.addProduct = function (product) {
$scope.activeSelling.push(product);
};
$scope.fetchProductsFromDB = function () {
console.log('fetch products...');
$http.get('get-my-products').then((data) => {
$http.get('get-my-products').then((rep) => {
console.log('ok');
$scope.productsFromDB = data;
console.log('ok', rep);
$scope.categories = rep.data.categories;
$scope.recentSellings = rep.data.history;
}, (err) => {
console.log(err);
});
@ -45,7 +50,10 @@ angular
console.log('log test ok');
};
$scope.sendForm = function () {
let lesParams = {};
let lesParams = {
activeSelling : $scope.activeSelling,
activeFestival: $scope.activeFestival
};
$http({
method: 'POST',
url : '/add-selling',

View File

@ -56,22 +56,53 @@ class DefaultController extends Controller {
] );
}
/**
* get user products
* @return JsonResponse
*/
public function getMyProductsAction() {
$m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser();
if ( ! $currentUser ) {
return new JsonResponse( [
'categories' => [ [ 'name' => 'demo category', 'products' => [] ] ],
'recentSells' => [['']],
'recentSells' => [ [ '' ] ],
] );
}
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categories = $currentUser->getCategories();
if ( ! $categories ) {
$defaultCategories = $categRepo->find( [ 1, 2 ] );
if ( ! count( $categories ) ) {
$categories = $defaultCategories = $categRepo->findById( [ 1, 2 ] );
$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 );
return new JsonResponse( [

View File

@ -10,8 +10,12 @@ use Doctrine\ORM\Mapping as ORM;
class ProductSold extends Product {
/**
* @ORM\OneToMany(targetEntity="SellRecord", mappedBy="products")
* @ORM\ManyToOne(targetEntity="SellRecord", inversedBy="productsSold")
*/
private $sellRecords;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold")
*/
private $user;
}

View File

@ -9,10 +9,12 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity(repositoryClass="AppBundle\Repository\SellRecordRepository")
*/
class SellRecord {
use Commentable;
/**
* @ORM\ManyToOne(targetEntity="Product", inversedBy="sellRecords")
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="sellRecords")
*/
private $products;
private $productsSold;
/**
* @ORM\Id
@ -36,9 +38,40 @@ class SellRecord {
*/
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
*/
@ -54,11 +87,6 @@ class SellRecord {
}
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="products")
*/
private $user;
/**
* @return mixed
*/

View File

@ -29,13 +29,36 @@ class User extends BaseUser {
private $googleAccessToken;
/**
* templates products
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
*/
private $products;
/**
* variabilised products sold
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="user")
*/
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")
*/
@ -83,11 +106,6 @@ class User extends BaseUser {
$this->products = $products;
}
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", mappedBy="user")
*/
private $categories;
/**
* @return mixed
*/