diff --git a/app/Resources/views/default/main-screen.html.twig b/app/Resources/views/default/main-screen.html.twig index bcb7b013..5ef6b55d 100755 --- a/app/Resources/views/default/main-screen.html.twig +++ b/app/Resources/views/default/main-screen.html.twig @@ -8,7 +8,9 @@ Votre caisse mobile dynamique en ligne
- Essayez dès maintenant + Essayez dès + maintenant +
{% include 'default/description-app.html.twig' %} @@ -26,7 +28,6 @@

- Créer un compte diff --git a/app/Resources/views/logged/angular/current.html.twig b/app/Resources/views/logged/angular/current.html.twig index b539e478..166c9d80 100755 --- a/app/Resources/views/logged/angular/current.html.twig +++ b/app/Resources/views/logged/angular/current.html.twig @@ -1,10 +1,13 @@ {% verbatim %}
-
+

- Festival:

+ Festival: + {{ activeFestival.chiffreAffaire }} € + +
@@ -13,7 +16,8 @@ Client actuel: {{ activeSelling.length }} produits - + + {{ sellingComment }}
  • diff --git a/assets/js/parts/main.js b/assets/js/parts/main.js index d503f509..3a4683dd 100755 --- a/assets/js/parts/main.js +++ b/assets/js/parts/main.js @@ -5,7 +5,7 @@ angular .controller('CaisseCtrl', ['$scope', '$http', function ($scope, $http, stuff) { $scope.productsFromDB = []; // loaded products $scope.categories = []; // product categories - $scope.sellingComment = ""; // comment about the client or the current selling + $scope.sellingComment = "un gens"; // comment about the client or the current selling $scope.initLoadDone = false; // becames true after first init of product loading $scope.recentSellings = []; $scope.lesParams = {}; @@ -14,10 +14,11 @@ 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 : "" + id : null, + name : "le festival", + dateCreation : new Date(), + chiffreAffaire: 0, + commentaire : "" }; /** * get the sum of products prices @@ -42,9 +43,11 @@ angular $scope.regenActiveSellingIds = function () { $scope.activeItemsSold = []; + $scope.paidAmount = 0; for (let obj in $scope.activeSelling) { $scope.activeItemsSold.push(obj.id); } + $scope.paidAmount += $scope.sumOfList($scope.activeSelling); }; $scope.stuff = stuff; $scope.setActiveSelling = function (selling) { @@ -56,6 +59,9 @@ angular $scope.addProduct = function (product) { $scope.activeSelling.push(product); $scope.activeItemsSold.push(product.id); + $scope.regenActiveSellingIds(); + document.querySelector('#sellingComment').focus() + }; $scope.pauseSelling = function () { $scope.pausedSelling.push(angular.copy($scope.activeSelling)); @@ -85,6 +91,7 @@ angular $scope.activeFestival.name = rep.data.lastFestival.name; $scope.activeFestival.dateCreation = rep.data.lastFestival.dateCreation; $scope.activeFestival.commentaire = rep.data.lastFestival.commentaire; + $scope.activeFestival.chiffreAffaire = rep.data.lastFestival.chiffreAffaire; //done $scope.initLoadDone = true; }, (err) => { @@ -117,6 +124,7 @@ angular } else { // if successful, bind success message to message $scope.successMessage = rep.data.message; + $scope.activeFestival.chiffreAffaire = rep.data.new_ca_festival; // changer le type de bout de phrase demandé $scope.formData["tykayn_portfoliobundle_cadexqphrasepart[type]"]["$viewValue"] = 'nouveauType'; } diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index f9a294d8..2f9a0475 100755 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -54,6 +54,7 @@ class DefaultController extends Controller { 0, 1 ); } + $lastFestival->recalculateChiffreAffaire(); $categRepo = $m->getRepository( 'AppBundle:ProductCategory' ); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); $categories = $categRepo->findAll(); @@ -153,6 +154,7 @@ class DefaultController extends Controller { 'name' => $activeFestival->getName(), 'commentaire' => $activeFestival->getComment(), 'dateCreation' => $activeFestival->getDateCreation(), + 'chiffreAffaire' => $activeFestival->getChiffreAffaire(), 'fondDeCaisseAvant' => $activeFestival->getFondDeCaisseAvant(), 'fondDeCaisseApres' => $activeFestival->getFondDeCaisseApres(), ], @@ -210,10 +212,13 @@ class DefaultController extends Controller { $newSellRecord->setPaidByClient( $json[ 'paidByClient' ] ); $newSellRecord->setComment( $json[ 'sellingComment' ] ); + $festivalFound->recalculateChiffreAffaire(); + $currentUser->addSellRecords( $newSellRecord ); $m->persist( $newSellRecord ); $m->persist( $currentUser ); + $m->persist( $festivalFound ); $m->flush(); // setup dates @@ -224,6 +229,7 @@ class DefaultController extends Controller { return new JsonResponse( [ "message" => "ok", + "new_ca_festival" => $festivalFound->getChiffreAffaire(), "recent_sellings" => json_encode( $lastSellings ), "dump" => $json, ], 200 ); diff --git a/src/AppBundle/Entity/Festival.php b/src/AppBundle/Entity/Festival.php index 2fe96164..a9c45fbc 100644 --- a/src/AppBundle/Entity/Festival.php +++ b/src/AppBundle/Entity/Festival.php @@ -66,6 +66,19 @@ class Festival { */ private $chiffreAffaire; + + public function recalculateChiffreAffaire() { + $sellings = $this->getSellRecords(); + $newChiffreAffaire = 0; + foreach ( $sellings as $selling ) { + $newChiffreAffaire += $selling->getAmount(); + } + + $this->setChiffreAffaire( $newChiffreAffaire ); + + return $this; + } + /** * Get id *