From 0b4935158867caca0c8dcbbac5cee8655adef20f Mon Sep 17 00:00:00 2001 From: Kayn Ty Date: Thu, 5 Apr 2018 17:01:36 +0200 Subject: [PATCH] sum of products ok --- .../views/logged/caisse-main.html.twig | 46 +++++++++++++------ assets/css/split/formulaires.scss | 5 ++ assets/js/parts/main.js | 39 ++++++++++++---- .../Controller/DefaultController.php | 13 +++++- 4 files changed, 79 insertions(+), 24 deletions(-) diff --git a/app/Resources/views/logged/caisse-main.html.twig b/app/Resources/views/logged/caisse-main.html.twig index ee443744..d8e3efbb 100644 --- a/app/Resources/views/logged/caisse-main.html.twig +++ b/app/Resources/views/logged/caisse-main.html.twig @@ -32,14 +32,21 @@
- + Festival: {{activeFestival.name}} + +
+ {{activeSelling.length}} produits
  • - {{p.name}} -
    - +
    + +
    + +
    + +
    @@ -52,22 +59,25 @@
-

Total: {{CurrentSellingTotal}}€

+
+

Total: {{CurrentSellingTotal()}}€

+ +

Rendu: {{ CurrentSellingTotal() - paidAmount }}€

+
- -

Rendu: {{ abs(CurrentSellingTotal - paidAmount) }}€

{% endverbatim %}
+
-
-
@@ -80,10 +90,16 @@

Ventes en pause

- + {% verbatim %}
    -
  • h:m:s xxxx€
  • +
  • + {{ $index }}) {{ list.products.length }} produits, + + {{ sumOfList(list) }}€ + +
+ {% endverbatim %}
diff --git a/assets/css/split/formulaires.scss b/assets/css/split/formulaires.scss index e69de29b..28d16343 100644 --- a/assets/css/split/formulaires.scss +++ b/assets/css/split/formulaires.scss @@ -0,0 +1,5 @@ +.current-selling { + ul { + list-style-type: none; + } +} diff --git a/assets/js/parts/main.js b/assets/js/parts/main.js index 6bad2032..b73afcd0 100644 --- a/assets/js/parts/main.js +++ b/assets/js/parts/main.js @@ -18,9 +18,26 @@ angular dateCreation: new Date(), commentaire : "" }; - $scope.CurrentSellingTotal = $scope.activeSelling.reduce(function (a, b) { - return a + b.price; - }, 0); + /** + * get the sum of products prices + * @param list + * @returns {number} + */ + $scope.sumOfList = function (list) { + let counter = 0; + for (let i = 0; i < list.length; i++) { + counter += list[i].price; + } + return counter; + }; + /** + * sum of current selling list prices + * @returns {number} + * @constructor + */ + $scope.CurrentSellingTotal = function () { + return $scope.sumOfList($scope.activeSelling); + }; $scope.stuff = stuff; $scope.setActiveSelling = function (selling) { @@ -43,11 +60,13 @@ angular console.log(err); }); }; - $scope.init = (function () { - $scope.fetchProductsFromDB(); - })(); - $scope.logtest = function () { - console.log('log test ok'); + $scope.pauseSelling = function () { + $scope.pausedSelling.push(angular.copy($scope.activeSelling)); + $scope.activeSelling = []; + }; + $scope.setBackPausedSelling = function (sellingList, index) { + $scope.activeSelling = angular.copy(sellingList); + $scope.pausedSelling.splice(index, 1); }; $scope.sendForm = function () { let lesParams = { @@ -74,5 +93,9 @@ angular }) ; }; + + $scope.init = (function () { + $scope.fetchProductsFromDB(); + })(); }]); diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index 7721983f..0b81d66f 100644 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -111,7 +111,18 @@ class DefaultController extends Controller { ] ); } - public function addSellingAction() { + /** + * @param Request $request + * add a selling record corresponding to one client + * + * @return JsonResponse + */ + public function addSellingAction( Request $request ) { + var_dump( $request->request ); + // link selling record with user, festival + // setup dates + // persist all + // fetch back history of selling return new JsonResponse( [ "message" => "ok" ] ); } }