From ca5f297077054e68b04c9c37255125c3438b5b3c Mon Sep 17 00:00:00 2001 From: ty kayn Date: Wed, 12 Jun 2019 14:13:36 +0200 Subject: [PATCH] responsive on edit forms --- app/Resources/views/base.html.twig | 15 +- .../views/default/login-choices.html.twig | 9 +- .../views/logged/angular/current.html.twig | 168 ++-- .../logged/angular/pause-selling.html.twig | 8 + .../views/logged/angular/totals.html.twig | 30 + .../logged/angular/validate-button.html.twig | 2 + .../views/logged/caisse-main.html.twig | 17 +- .../views/logged/dashboard.html.twig | 137 ++- app/Resources/views/logged/import.html.twig | 4 +- .../views/productcategory/new.html.twig | 2 +- assets/css/pages/_dashboard.scss | 25 +- assets/css/pages/demo.scss | 4 +- assets/css/pages/global.scss | 121 ++- assets/css/pages/responsive.scss | 124 ++- assets/js/parts/main.js | 841 +++++++++--------- assets/js/parts/previsionnel.js | 163 ++++ 16 files changed, 985 insertions(+), 685 deletions(-) create mode 100644 app/Resources/views/logged/angular/pause-selling.html.twig create mode 100644 app/Resources/views/logged/angular/totals.html.twig create mode 100644 assets/js/parts/previsionnel.js diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 791250c1..ee0b2e0a 100755 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -16,13 +16,14 @@
{% block bigMain %} - {% include 'default/header.html.twig' %} -
- - {% block body %} - {% endblock %} -
- {% include 'default/footer.html.twig' %} + {% include 'default/header.html.twig' %} +
+
+ {% block body %} + {% endblock %} +
+
+ {% include 'default/footer.html.twig' %} {% endblock %}
{% block javascripts %} diff --git a/app/Resources/views/default/login-choices.html.twig b/app/Resources/views/default/login-choices.html.twig index 2b8276a4..2d9a8e8c 100755 --- a/app/Resources/views/default/login-choices.html.twig +++ b/app/Resources/views/default/login-choices.html.twig @@ -5,7 +5,7 @@ {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
-
+
-
+
+ + {% trans %}user.greet{% endtrans %} diff --git a/app/Resources/views/logged/angular/current.html.twig b/app/Resources/views/logged/angular/current.html.twig index 495bd65d..481775dc 100755 --- a/app/Resources/views/logged/angular/current.html.twig +++ b/app/Resources/views/logged/angular/current.html.twig @@ -1,47 +1,50 @@ -{% verbatim %} -
+
-
+ -

+
+
+

+ + {% verbatim %} + + Festival + : + + + {{ activeFestival.fondDeCaisseAvant + activeFestival.chiffreAffaire}} € + + + CA {{ activeFestival.chiffreAffaire }} € + + + + + {{ activeFestival.clientsCount }} +

+
+
- Festival: - - - {{ activeFestival.fondDeCaisseAvant + activeFestival.chiffreAffaire}} € - - CA {{ activeFestival.chiffreAffaire }} € - - - - - {{ activeFestival.clientsCount }} -

- + +
+
+ +
-
-
- -
-
- - - -
+ + +
-

new display without duplicates:

-
-
-
@@ -49,104 +52,39 @@
-
+
-
- +
+ {{group.unitPrice}} - € - - {{group.count}} - + € + + {{group.count}} +
-
- - - {{group.totalPrice}} - € - - - +
+ + {{group.totalPrice}} + € + + +

-
-
-
-

Total:

-
-
-

- - {{ CurrentSellingTotal() }} - € -

-
-
-
-
- Le client paie: -
-
- -
-
-
-

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

-
-
-

il manque: {{ CurrentSellingTotal() - paidAmount }} €

-
-
-
-
{% endverbatim %} - {% include 'logged/angular/validate-button.html.twig' %} -{% verbatim %} -
- - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - -
+ {% include 'logged/angular/totals.html.twig' %} + {% include 'logged/angular/validate-button.html.twig' %} + {% include 'logged/angular/pause-selling.html.twig' %} + {% verbatim %} -
- - {% endverbatim %} - diff --git a/app/Resources/views/logged/angular/pause-selling.html.twig b/app/Resources/views/logged/angular/pause-selling.html.twig new file mode 100644 index 00000000..8ca4fa03 --- /dev/null +++ b/app/Resources/views/logged/angular/pause-selling.html.twig @@ -0,0 +1,8 @@ +{% verbatim %} + + + + + + +{% endverbatim %} diff --git a/app/Resources/views/logged/angular/totals.html.twig b/app/Resources/views/logged/angular/totals.html.twig new file mode 100644 index 00000000..9a672a92 --- /dev/null +++ b/app/Resources/views/logged/angular/totals.html.twig @@ -0,0 +1,30 @@ +{% verbatim %} +
+
+
+

Total:

+
+
+

+ + {{ CurrentSellingTotal() }} + € +

+
+
+
+
+ Le client paie: +
+
+ +
+
+
+

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

+
+
+

il manque: {{ CurrentSellingTotal() - paidAmount }} €

+
+
+{% endverbatim %} diff --git a/app/Resources/views/logged/angular/validate-button.html.twig b/app/Resources/views/logged/angular/validate-button.html.twig index eea485e5..655e667c 100755 --- a/app/Resources/views/logged/angular/validate-button.html.twig +++ b/app/Resources/views/logged/angular/validate-button.html.twig @@ -1,3 +1,4 @@ +{% verbatim %} +{% endverbatim %} diff --git a/app/Resources/views/logged/caisse-main.html.twig b/app/Resources/views/logged/caisse-main.html.twig index 7509048f..a56fc51f 100755 --- a/app/Resources/views/logged/caisse-main.html.twig +++ b/app/Resources/views/logged/caisse-main.html.twig @@ -6,11 +6,13 @@
{% endverbatim %} {% include 'logged/angular/loaded-caisse.html.twig' %} - + {% verbatim %}

- Visibilité des catégories + Visibilité des + {{categories.length - categoriesVisibleCount() }} / + {{ categories.length }} catégories

- {% verbatim %} {{ c.name }} -{% endverbatim %} + {{ c.name }} + (caché)
-
\ No newline at end of file +
+
+ +Aucune catégorie enregistrée +
+{% endverbatim %} diff --git a/app/Resources/views/logged/dashboard.html.twig b/app/Resources/views/logged/dashboard.html.twig index 9bdbe80d..2628967f 100755 --- a/app/Resources/views/logged/dashboard.html.twig +++ b/app/Resources/views/logged/dashboard.html.twig @@ -1,96 +1,87 @@ {% extends 'base.html.twig' %} {% block body %} -
-
-
-
-
- - + - + -
-
+ +
+
+
- - Client actuel: - {% verbatim %} - {{ activeSelling.length }} produits -
- +
+ + Client actuel: +
{% verbatim %} +
+
- -
+
- - {% endverbatim %} - {##} - {##} + {{ activeSelling.length }} produits +
{% endverbatim %}
+
-
- - {% include 'logged/caisse-main.html.twig' %} -
+
+ {% include 'logged/caisse-main.html.twig' %} +
- - -
-
-
-

Catégories

-
-
-

Produits

-
-
-

Historique

-
-
+
+
+

Catégories

+
+
+

Produits

+
+
+

Historique

+
+
{##} {##} - {% endblock %} +{% endblock %} diff --git a/app/Resources/views/logged/import.html.twig b/app/Resources/views/logged/import.html.twig index f7df3341..06a04d10 100755 --- a/app/Resources/views/logged/import.html.twig +++ b/app/Resources/views/logged/import.html.twig @@ -4,10 +4,10 @@
-
+
{% include 'logged/mass-register.html.twig' %}
-
+

Importer votre historique de ventes diff --git a/app/Resources/views/productcategory/new.html.twig b/app/Resources/views/productcategory/new.html.twig index f9dd9f71..770834c5 100755 --- a/app/Resources/views/productcategory/new.html.twig +++ b/app/Resources/views/productcategory/new.html.twig @@ -1,7 +1,7 @@ {% extends 'base.html.twig' %} {% block body %} -

Productcategory creation

+

Création de catégorie de produit

{{ form_start(form) }} {{ form_widget(form) }} diff --git a/assets/css/pages/_dashboard.scss b/assets/css/pages/_dashboard.scss index 6f9deb89..c277cdcc 100755 --- a/assets/css/pages/_dashboard.scss +++ b/assets/css/pages/_dashboard.scss @@ -6,10 +6,12 @@ width: 100%; float: left; } + .product-button { width: 80%; text-overflow-ellipsis: "..."; } + .listing-products { .btn, button { @@ -22,21 +24,28 @@ border-color: $all-text-color; box-shadow: 5px 3px 10px 2px #ddd; border-width: 0; + &.btn-primary { background-color: $deepblue; } + &:hover { background: $lightblue; } } + .badge-default { background: $lightblue; } + .badge-success { background: mix(green, $lightblue); } } + .input-comment { + width: calc(100% - 40px); + } } // container of categories @@ -44,7 +53,7 @@ overflow-x: auto; overflow-y: hidden; //width: 100%; - height: 80vh; + height: 75vh; background: #ccc; padding: 0.5rem; } @@ -54,23 +63,31 @@ background: #dedede; width: 350px; margin: 0 4px; - height: calc(80vh - 1rem); + height: calc(74vh - 1rem); box-sizing: border-box; display: inline-block; //vertical-align: top; white-space: nowrap; //float: left; } -.category-listing{ + +.category-listing { border: solid 1px $grey; padding: 1rem; margin: 0.5rem; border-radius: 0.25rem; } + .validate_selling { margin: 0.25rem; } -.product-listing{ + +.product-listing { height: 70vh; overflow: auto; } +.sellings{ + .remove-item{ + margin-left: 1em; + } +} diff --git a/assets/css/pages/demo.scss b/assets/css/pages/demo.scss index d11bc49e..3b6ee865 100755 --- a/assets/css/pages/demo.scss +++ b/assets/css/pages/demo.scss @@ -40,7 +40,7 @@ code { #wrapper { background: #FFF; margin: 1em auto; - max-width: 800px; + //max-width: 800px; width: 95%; } @@ -133,4 +133,4 @@ code { background: $darkblue; height: 52px; font-size: 1em; -} \ No newline at end of file +} diff --git a/assets/css/pages/global.scss b/assets/css/pages/global.scss index 8d7dbb94..12e3fc1a 100755 --- a/assets/css/pages/global.scss +++ b/assets/css/pages/global.scss @@ -46,9 +46,11 @@ body { .bg-color { background: $deepblue; color: $light; + a { color: $lightblue; } + padding: 1rem; } @@ -84,6 +86,7 @@ label { .padded { padding: 1rem; + &-v { padding: 0; padding-top: 1rem; @@ -93,6 +96,7 @@ label { .marged { margin: 1rem; + &-v { margin: 0; margin-top: 1rem; @@ -117,23 +121,25 @@ label { } .previsionnel { - .config { - font-size: 1.5rem; - } - thead { - font-size: 1.5rem; - } + font-size: 1rem; + //.config { + // font-size: 1.5rem; + //} + //thead { + // font-size: 1.5rem; + //} label { min-width: 220px; } - .exepanse-table { - font-size: 1.5rem; - } - .examples-depenses { - font-size: 1.5rem; - } + + //.exepanse-table { + // font-size: 1.5rem; + //} + //.examples-depenses { + // font-size: 1.5rem; + //} .big-number { - font-size: 2.5rem; + font-size: 1.85rem; color: #2B2d42; } } @@ -147,91 +153,116 @@ input { width: auto; min-width: 2em; } -#menu-dashboard{ - background:$dark; + +#menu-dashboard { + background: $dark; display: flex; position: fixed; left: 0; top: 0; height: 100vh; width: 13vw; + min-width: 300px; overflow-x: auto; - .nav{ - width: 13vw; + z-index: 10; + + .nav { + width: 100%; min-width: 300px; display: block; - border-right: solid 2px mix($dark,$grey); - .btn{ + border-right: solid 2px mix($dark, $grey); + + .btn { color: $light; } - .btn-default{ + + .btn-default { color: $light; - &:hover{ + + &:hover { background: mix($deepblue, $light); - color: $dark ; + color: $dark; font-weight: 600; } } } - i.fa{ - float:left; + + i.fa { + float: left; margin-right: 1em; color: $light; } } -.nav > li > a:hover, .nav > li > a{ - &:focus{ + +.nav > li > a:hover, .nav > li > a { + &:focus { background: transparent; border: none; color: $lightblue; } - &:focus{ + + &:focus { background: transparent; border: none; color: $lightblue; } } -.btn{ - border :0; + +.btn { + border: 0; } -.btn-default{ + +.btn-default { background: transparent; } -.btn-success{ + +.btn-success { background-color: $deepblue; font-weight: 800; } + .table > thead > tr > td, -table td{ - padding: 0.5em; - } -.login-fosub{ - .padded{ +table td { + padding: 0.5em; +} + +.login-fosub { + .padded { padding: 3em; } - input[type=submit]{ + + input[type=submit] { background: $primary; - color:$light; + color: $light; display: block; margin-top: 1em; padding: 1em; border: 0; width: 100%; - &:hover{ + + &:hover { background: $lightblue; } } } -#fos_user_profile_form{ - div{ +#fos_user_profile_form { + div { margin: 0.5em auto; } } -#bodyland{ - .container{ - min-height: 1000px; +#bodyland { + .container { + min-height: 100vh; } -} \ No newline at end of file +} + +#menu_button{ + z-index: 10; + position: absolute; + right: 1em; + top: -2px; + font-size: 1rem; +} diff --git a/assets/css/pages/responsive.scss b/assets/css/pages/responsive.scss index df53e712..f26bbe6d 100755 --- a/assets/css/pages/responsive.scss +++ b/assets/css/pages/responsive.scss @@ -1,25 +1,25 @@ - @media all and(max-width: 1200px) { - nav{ + nav { min-width: auto; } - html,body{ + html, body { font-size: 1.2rem; } .bg-shader { - height: 100%; - min-height: 100vh; - } + height: 100%; + min-height: 100vh; + } .product-values-block { padding: 1em; } - #homepage{ - .main-section{ + #homepage { + .main-section { padding: 2rem; } - .btn{ - display:block; + + .btn { + display: block; width: 100%; font-size: 1.25em; } @@ -28,9 +28,11 @@ .product-box { width: 100%; } + .product-button { min-width: calc(100% - 56px) } + .listing-products { .btn, button { @@ -42,12 +44,104 @@ } } -@media all and(max-width: 600px) { - html,body{ - font-size: 1.5rem; +@media all and(max-width: 1200px) { + + #bodyland { + .container { + min-height: 100vh; + width: 80vw; + } } - .category-listing{ - width: calc(100% - 2rem); + #menu-dashboard { + font-size: 1rem; + width: 19vw; + min-width: 200px; + + .nav { + min-width: 200px; + } + } + + form { + margin-top: 3em; + + select { + width: 100%; + margin: 1em 0; + } + + + ul { + margin-top: 1em; + list-style-type: none; + + a { + display: block; + + .fa { + margin-right: 1em; + } + } + } + } +} + +@media all and(max-width: 600px) { + + html, body { + font-size: 1rem; + } + #menu-dashboard .nav .logo-home.btn-default { + height: auto; + font-size: 2em; + } + #menu-dashboard { + width: 100vw; + visibility: hidden; + + &.shown { + visibility: visible; + } + + .nav { + + min-width: 200px; + height: 100vh; + overflow: auto; + + a { + font-size: 2rem; + } + } + } + + .category-listing { + width: calc(100vw - 9rem); + height: 25vh; + min-height: auto; + float: left; + clear: both; + overflow: auto; + } + .sellings, .client-now { + + input { + width: 100%; + font-size: 1.5rem; + padding: 0.5rem; + } + } + .big-footer { + font-size: 1rem; + } + #caisse-now .product-box { + margin-bottom: 0.25rem; + } + #caisse-now .listing-products button { + padding: 0.5rem 1rem; + + .express-button { + padding: 0.5rem 1rem; + } } } diff --git a/assets/js/parts/main.js b/assets/js/parts/main.js index 576ad307..e579a526 100755 --- a/assets/js/parts/main.js +++ b/assets/js/parts/main.js @@ -10,448 +10,461 @@ require('bootstrap-sass'); $(document).ready(function () { $('[data-toggle="popover"]').popover(); + $('#menu_button').on('click', function(){ + $('#menu-dashboard').toggleClass('shown'); + }) }); +require('./caisseCtrl'); +require('./dashboard'); +var PrevisionnelCtrl = require('./previsionnel'); + console.log('hello console for main.js'); var stuff = ['initialstuff']; - // TODO split controllers in other files angular - .module('caisse', []) - .controller('CaisseCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { - $scope.productsFromDB = []; // loaded products - $scope.categories = []; // product categories - $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 = {}; - $scope.countProductsSoldForActiveFestival = {}; - $scope.paidAmount = 0; - $scope.expressSelling = true; - $scope.pausedSelling = []; - $scope.show_config = { - stock_count: false, - sold: true, - }; - $scope.activeItemsSold = []; // list of products ID to sell - $scope.activeSelling = []; // list of products to sell - $scope.activeSellingFiltered = []; // list of products to sell - $scope.activeFestival = { // an event where selling take place - id: null, - name: "le festival", - dateCreation: new Date(), - chiffreAffaire: 0, - clientsCount: 0, - commentaire: "" - }; + .module('caisse', []) + .controller('CaisseCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { + $scope.productsFromDB = []; // loaded products + $scope.categories = []; // product categories + $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 = {}; + $scope.countProductsSoldForActiveFestival = {}; + $scope.paidAmount = 0; + $scope.expressSelling = true; + $scope.pausedSelling = []; + $scope.show_config = { + stock_count: false, + sold : true, + }; + $scope.activeItemsSold = []; // list of products ID to sell + $scope.activeSelling = []; // list of products to sell + $scope.activeSellingFiltered = []; // list of products to sell + $scope.activeFestival = { // an event where selling take place + id : null, + name : "le festival", + dateCreation : new Date(), + chiffreAffaire: 0, + clientsCount : 0, + commentaire : "" + }; + /** + * set the right paid amount + */ + $scope.setRightAmountPaid = function () { + // debugger; + $scope.paidAmount += $scope.sumOfList($scope.activeSelling); + } + /** + * deduplicate the active selling items in the view, + * show a count for each of them when there are more than one + */ + $scope.refreshDeduplicateSellings = () => { + let soldObjectsIdsCount = {} + $scope.activeSellingFiltered = {}; - /** - * set the right paid amount - */ - $scope.setRightAmountPaid = function () { - // debugger; - $scope.paidAmount += $scope.sumOfList($scope.activeSelling); - } - /** - * deduplicate the active selling items in the view, - * show a count for each of them when there are more than one - */ - $scope.refreshDeduplicateSellings = () => { - let soldObjectsIdsCount = {} - $scope.activeSellingFiltered = {}; + $scope.activeSelling.forEach(elem => { + let groupId = elem.id; + let group = soldObjectsIdsCount[groupId]; + if (group) { // sort elements by the product id corresponding + group.count++; + group.totalPrice += (elem.price * 1); + group.sellings.push(elem); + } else { - $scope.activeSelling.forEach(elem => { - let groupId = elem.id; - let group = soldObjectsIdsCount[groupId]; - if (group) { // sort elements by the product id corresponding - group.count++; - group.totalPrice += (elem.price * 1); - group.sellings.push(elem); - } else { + soldObjectsIdsCount[groupId] = { + groupId : groupId, + count : 1, + name : elem.name, + unitPrice : elem.price * 1, + totalPrice: elem.price * 1, + sellings : [elem], + } + } + }); + $scope.activeSellingFiltered = soldObjectsIdsCount; - soldObjectsIdsCount[groupId] = { - groupId: groupId, - count: 1, - name: elem.name, - unitPrice: elem.price * 1, - totalPrice: elem.price * 1, - sellings: [elem], - } - } - }); - $scope.activeSellingFiltered = soldObjectsIdsCount; + } - } + /** + * 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 * 1; + } + return counter; + }; + /** + * sum of current selling list prices + * @returns {number} + * @constructor + */ + $scope.CurrentSellingTotal = function () { + return $scope.sumOfList($scope.activeSelling); + }; - /** - * 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.categoriesVisibleCount = function () { + let count = 0; + $scope.categories.forEach(function (elem) { + elem.hidden ? count++ : ""; + }); + return count; + } - $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.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) { - $scope.activeSelling = selling; - }; - $scope.pauseSelling = function (selling) { - $scope.pausedSelling.push(selling); - }; - /** - * add to current sell list - * @param product - */ - $scope.addProduct = function (product) { - product.stockCount--; - $scope.activeSelling.push(product); - $scope.activeItemsSold.push(product.id); - $scope.regenActiveSellingIds(); - $scope.refreshDeduplicateSellings(); - $scope.setRightAmountPaid(); - }; - /** - * remove from current sell list - * @param product - */ - $scope.removeProduct = function (product, index) { - product.stockCount++; - $scope.activeSelling.splice($index, 1); - $scope.regenActiveSellingIds(); - $scope.refreshDeduplicateSellings(); - }; - /** - * remove all products of a certain group id in the active Selling - * @param productId - * @returns {*} - */ - $scope.removeGroupeProducts = function (productId) { - console.log("##### removeGroupeProducts", productId); - console.log("$scope.activeSelling", $scope.activeSelling); - $scope.activeSelling = $scope.activeSelling.filter(elem => elem.id != productId) - console.log("$scope.activeSelling", $scope.activeSelling); - $scope.regenActiveSellingIds(); - $scope.refreshDeduplicateSellings(); - } - $scope.removeAll = function () { + }; + $scope.stuff = stuff; + $scope.setActiveSelling = function (selling) { + $scope.activeSelling = selling; + }; + $scope.pauseSelling = function (selling) { + $scope.pausedSelling.push(selling); + }; + /** + * add to current sell list + * @param product + */ + $scope.addProduct = function (product) { + product.stockCount--; + $scope.activeSelling.push(product); + $scope.activeItemsSold.push(product.id); + $scope.regenActiveSellingIds(); + $scope.refreshDeduplicateSellings(); + $scope.setRightAmountPaid(); + }; + /** + * remove from current sell list + * @param product + */ + $scope.removeProduct = function (product, index) { + product.stockCount++; + $scope.activeSelling.splice($index, 1); + $scope.regenActiveSellingIds(); + $scope.refreshDeduplicateSellings(); + }; + /** + * remove all products of a certain group id in the active Selling + * @param productId + * @returns {*} + */ + $scope.removeGroupeProducts = function (productId) { + console.log("##### removeGroupeProducts", productId); + console.log("$scope.activeSelling", $scope.activeSelling); + $scope.activeSelling = $scope.activeSelling.filter(elem => elem.id != productId) + console.log("$scope.activeSelling", $scope.activeSelling); + $scope.regenActiveSellingIds(); + $scope.refreshDeduplicateSellings(); + } + $scope.removeAll = function () { - $scope.activeSelling = []; - $scope.regenActiveSellingIds(); - $scope.refreshDeduplicateSellings(); - }; - $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.activeSelling = []; + $scope.regenActiveSellingIds(); + $scope.refreshDeduplicateSellings(); + }; + $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.clearSellingComment = function () { - $scope.sellingComment = ''; - document.querySelector('.client-now input').focus(); - }; - $scope.clearCurrentSelling = function () { - $scope.paidAmount = 0; - $scope.clearSellingComment(); - $scope.activeSelling = []; - $scope.removeAll(); - }; + $scope.clearSellingComment = function () { + $scope.sellingComment = ''; + document.querySelector('.client-now input').focus(); + }; + $scope.clearCurrentSelling = function () { + $scope.paidAmount = 0; + $scope.clearSellingComment(); + $scope.activeSelling = []; + $scope.removeAll(); + }; - // http related calls - $scope.fetchProductsFromDB = function () { - console.log('fetch products...'); - $http.get('get-my-products').then((rep) => { + // http related calls + $scope.fetchProductsFromDB = function () { + console.log('fetch products...'); + $http.get('get-my-products').then((rep) => { - console.log('ok', rep); - customCategories = []; - for (let c of rep.data.categories) { - c.hidden = false; - customCategories.push(c); - } - console.log('customCategories', customCategories); - $scope.categories = customCategories; - $scope.productsFromDB = customCategories; - // $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; - $scope.activeFestival.chiffreAffaire = rep.data.lastFestival.chiffreAffaire; - $scope.activeFestival.fondDeCaisseAvant = rep.data.lastFestival.fondDeCaisseAvant; - $scope.activeFestival.fondDeCaisseApres = rep.data.lastFestival.fondDeCaisseApres; - $scope.activeFestival.clientsCount = rep.data.lastFestival.clientsCount; - // stat count for items - $scope.countProductsSoldForActiveFestival = rep.data.lastFestival.sold; - console.log(' $scope.countProductsSoldForActiveFestival', $scope.countProductsSoldForActiveFestival); - //done - $scope.initLoadDone = true; - }, (err) => { - console.log(err); - $scope.initLoadDone = true; - }); - }; + console.log('ok', rep); + customCategories = []; + for (let c of rep.data.categories) { + c.hidden = false; + customCategories.push(c); + } + console.log('customCategories', customCategories); + $scope.categories = customCategories; + $scope.productsFromDB = customCategories; + // $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; + $scope.activeFestival.chiffreAffaire = rep.data.lastFestival.chiffreAffaire; + $scope.activeFestival.fondDeCaisseAvant = rep.data.lastFestival.fondDeCaisseAvant; + $scope.activeFestival.fondDeCaisseApres = rep.data.lastFestival.fondDeCaisseApres; + $scope.activeFestival.clientsCount = rep.data.lastFestival.clientsCount; + // stat count for items + $scope.countProductsSoldForActiveFestival = rep.data.lastFestival.sold; + console.log(' $scope.countProductsSoldForActiveFestival', $scope.countProductsSoldForActiveFestival); + //done + $scope.initLoadDone = true; + }, (err) => { + console.log(err); + $scope.initLoadDone = true; + }); + }; - /** - * sell one product, assuming the client has the right amount of money - * @param product - */ - $scope.expressSell = function (product) { - $scope.addProduct(product); - $scope.sendForm(); - }; - $scope.recentId = 0; - $scope.logger = function (stuff) { - console.log('logger', stuff); - }; - $scope.sendForm = function () { - console.log('$scope.sellingComment', $scope.sellingComment); - console.log("$scope.activeSelling", $scope.activeSelling); - let lesParams = { - paidByClient: $scope.paidAmount, - sellingComment: $scope.sellingComment, - activeSelling: $scope.activeSelling, - activeFestival: $scope.activeFestival - }; - $scope.recentSellings.push({ - id: $scope.recentId++, - amount: $scope.CurrentSellingTotal(), - paidAmount: $scope.paidAmount, - products: - angular - .copy($scope.activeSelling) - }); - console.log('$scope.recentSellings', $scope.recentSellings); - $scope.lesParams = lesParams; - $http({ - method: 'POST', - url: 'add-selling', - headers: { - 'Content-Type': 'application/json' - }, - data: lesParams // pass in data as strings - }).then(function (rep) { + /** + * sell one product, assuming the client has the right amount of money + * @param product + */ + $scope.expressSell = function (product) { + $scope.addProduct(product); + $scope.sendForm(); + }; + $scope.recentId = 0; + $scope.logger = function (stuff) { + console.log('logger', stuff); + }; + $scope.sendForm = function () { + console.log('$scope.sellingComment', $scope.sellingComment); + console.log("$scope.activeSelling", $scope.activeSelling); + let lesParams = { + paidByClient : $scope.paidAmount, + sellingComment: $scope.sellingComment, + activeSelling : $scope.activeSelling, + activeFestival: $scope.activeFestival + }; + $scope.recentSellings.push({ + id : $scope.recentId++, + amount : $scope.CurrentSellingTotal(), + paidAmount: $scope.paidAmount, + products : + angular + .copy($scope.activeSelling) + }); + console.log('$scope.recentSellings', $scope.recentSellings); + $scope.lesParams = lesParams; + $http({ + method : 'POST', + url : 'add-selling', + headers: { + 'Content-Type': 'application/json' + }, + data : lesParams // pass in data as strings + }).then(function (rep) { - $scope.clearCurrentSelling(); - // if successful, bind success message to message - $scope.successMessage = rep.data.message; - $scope.activeFestival.chiffreAffaire = rep.data.newChiffreAffaire; - $scope.activeFestival.clientsCount = rep.data.clientsCount; - $scope.countProductsSoldForActiveFestival = rep.data.activeFestival.sold; - $scope.showTemporaryMessage(); - console.log(rep); - if (!rep.success) { - // if not successful, bind errors to error variables - $scope.errors = rep.errors; - } - }, function (rep) { - console.log('nope! ', rep.data); - }) - ; - }; + $scope.clearCurrentSelling(); + // if successful, bind success message to message + $scope.successMessage = rep.data.message; + $scope.activeFestival.chiffreAffaire = rep.data.newChiffreAffaire; + $scope.activeFestival.clientsCount = rep.data.clientsCount; + $scope.countProductsSoldForActiveFestival = rep.data.activeFestival.sold; + $scope.showTemporaryMessage(); + console.log(rep); + if (!rep.success) { + // if not successful, bind errors to error variables + $scope.errors = rep.errors; + } + }, function (rep) { + console.log('nope! ', rep.data); + }) + ; + }; - $scope.sellingOk = false; - $scope.tempMessage = {}; - $scope.showTemporaryMessage = function () { - if ($scope.sellingOk) { - return; - } - $scope.sellingOk = true; - $timeout.cancel($scope.tempMessage); - $scope.tempMessage = $timeout(function () { - $scope.sellingOk = false; - }, 2000) - }; - $scope.init = (function () { - $scope.fetchProductsFromDB(); - })(); - }]) - .controller('previsionnelCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { + $scope.sellingOk = false; + $scope.tempMessage = {}; + $scope.showTemporaryMessage = function () { + if ($scope.sellingOk) { + return; + } + $scope.sellingOk = true; + $timeout.cancel($scope.tempMessage); + $scope.tempMessage = $timeout(function () { + $scope.sellingOk = false; + }, 2000) + }; + $scope.init = (function () { + $scope.fetchProductsFromDB(); + })(); + }]) + .controller('previsionnelCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { - $scope.config = { - initialLoadingDone: false, - loading: false, - lines: 24, - debounceTime: 300, // miliseconds to wait before updating model and saving changes - /** - * expenses kind of the user - */ - disponibility: 5000, - averageMonthlyEarnings: 600, - warningThershold: 2000, - showDelays: false, - showRepeats: false, - monthsBeforeNoMoney: null, - }; + $scope.config = { + initialLoadingDone : false, + loading : false, + lines : 24, + debounceTime : 300, // miliseconds to wait before updating model and saving changes + /** + * expenses kind of the user + */ + disponibility : 5000, + averageMonthlyEarnings: 600, + warningThershold : 2000, + showDelays : false, + showRepeats : false, + monthsBeforeNoMoney : null, + }; - let exampleExpenses = [ - {name: "appart", amount: 800, delay: 0, repeat: $scope.config.lines, enabled: true}, - {name: "assurance voiture", amount: 50, delay: 0, repeat: $scope.config.lines, enabled: true}, - {name: "internet", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true}, - {name: "elec", amount: 100, delay: 0, repeat: $scope.config.lines, enabled: true}, - {name: "chat", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true}, - {name: "transports", amount: 70, delay: 0, repeat: $scope.config.lines, enabled: false}, - ]; + let exampleExpenses = [ + {name: "appart", amount: 800, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "assurance voiture", amount: 50, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "internet", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "elec", amount: 100, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "chat", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "transports", amount: 70, delay: 0, repeat: $scope.config.lines, enabled: false}, + ]; - // $scope.expenses=[]; - $scope.expenses = exampleExpenses; + // $scope.expenses=[]; + $scope.expenses = exampleExpenses; - /** - * sum of all monthly expenses, ignoring delay - * @returns {number} - */ - $scope.sumMonthlyExpenses = () => { - let sum = 0; - $scope.expenses.forEach((elem) => { - if (elem.enabled) { - sum += elem.amount; - } - }) - return sum; - }; - $scope.previsionTable = []; - $scope.calculatePrevisionTable = () => { - let turns = $scope.config.lines; - let monthly = $scope.sumMonthlyExpenses(); - let available = $scope.config.disponibility; - let previsionTable = []; - let changedNoMoneyConfig = false; - $scope.config.monthsBeforeNoMoney = null; - for (let i = 0; i <= turns; i++) { - // TODO take in account delays in expenses - available = available - monthly + $scope.config.averageMonthlyEarnings; - let newLine = { - expense: monthly, - available: available, - }; + /** + * sum of all monthly expenses, ignoring delay + * @returns {number} + */ + $scope.sumMonthlyExpenses = () => { + let sum = 0; + $scope.expenses.forEach((elem) => { + if (elem.enabled) { + sum += elem.amount; + } + }) + return sum; + }; + $scope.previsionTable = []; + $scope.calculatePrevisionTable = () => { + let turns = $scope.config.lines; + let monthly = $scope.sumMonthlyExpenses(); + let available = $scope.config.disponibility; + let previsionTable = []; + let changedNoMoneyConfig = false; + $scope.config.monthsBeforeNoMoney = null; + for (let i = 0; i <= turns; i++) { + // TODO take in account delays in expenses + available = available - monthly + $scope.config.averageMonthlyEarnings; + let newLine = { + expense : monthly, + available: available, + }; - if (available <= 0 && !changedNoMoneyConfig) { - $scope.config.monthsBeforeNoMoney = i; - changedNoMoneyConfig = true; - } - previsionTable.push(newLine); - } - $scope.previsionTable = previsionTable; - $scope.makeGraphPointsOfPrevisionTable(previsionTable); - return previsionTable; - }; - $scope.graphPointsPrevision = []; - $scope.makeGraphPointsOfPrevisionTable = (previsionTable) => { - console.log("previsionTable", previsionTable); - $scope.graphPointsPrevision = []; - for (let i = 0; i < previsionTable.length; i++) { - $scope.graphPointsPrevision.push({ - label: previsionTable[i].available + " euros restants dans " + i + " mois", - y: previsionTable[i].available, - x: i, - }) - } + if (available <= 0 && !changedNoMoneyConfig) { + $scope.config.monthsBeforeNoMoney = i; + changedNoMoneyConfig = true; + } + previsionTable.push(newLine); + } + $scope.previsionTable = previsionTable; + $scope.makeGraphPointsOfPrevisionTable(previsionTable); + return previsionTable; + }; + $scope.graphPointsPrevision = []; + $scope.makeGraphPointsOfPrevisionTable = (previsionTable) => { + console.log("previsionTable", previsionTable); + $scope.graphPointsPrevision = []; + for (let i = 0; i < previsionTable.length; i++) { + $scope.graphPointsPrevision.push({ + label: previsionTable[i].available + " euros restants dans " + i + " mois", + y : previsionTable[i].available, + x : i, + }) + } - } + } - $scope.updateconf = (rep) => { - // update view calculs - $scope.calculatePrevisionTable(); - $scope.updateCanevas() - // flags - $scope.config.loading = false; - $scope.config.initialLoadingDone = true; - $scope.config.disponibility = rep.data.disponibility; - $scope.config.averageMonthlyEarnings = rep.data.averageMonthlyEarnings; - // default data when user has nothing saved - console.log('rep.data.expenses.length', rep.data.expenses.length) - if (!rep.data.expenses.length) { - $scope.expenses = exampleExpenses; - } else { - $scope.expenses = rep.data.expenses; - } - }; - // http related calls - $scope.fetchExpenses = () => { - console.log('fetch expenses...'); - $scope.config.loading = true; + $scope.updateconf = (rep) => { + // update view calculs + $scope.calculatePrevisionTable(); + $scope.updateCanevas() + // flags + $scope.config.loading = false; + $scope.config.initialLoadingDone = true; + $scope.config.disponibility = rep.data.disponibility; + $scope.config.averageMonthlyEarnings = rep.data.averageMonthlyEarnings; + // default data when user has nothing saved + console.log('rep.data.expenses.length', rep.data.expenses.length) + if (!rep.data.expenses.length) { + $scope.expenses = exampleExpenses; + } else { + $scope.expenses = rep.data.expenses; + } + }; + // http related calls + $scope.fetchExpenses = () => { + console.log('fetch expenses...'); + $scope.config.loading = true; - $http.get('get-my-expenses').then((rep) => { - console.log('get-my-expenses', rep.data.expenses); - $scope.updateconf(rep) - }, - $scope.manageError) - }; - $scope.save = function () { - if ($scope.config.loading) { - console.log('already saving'); - return; - } - console.log('update expenses...'); - $scope.config.loading = true; - $http.post('save-my-expenses', { - expenses: $scope.expenses, - config: $scope.config - }) - .then((rep) => { - console.log('save-my-expenses', rep); - $scope.updateconf(rep) - }, - $scope.manageError) - }; - $scope.addExpense = function () { - $scope.expenses.push({ - name: "", - repeat: 0, - delay: 0, - amount: 0, - }) - }; - $scope.init = function () { - $scope.fetchExpenses(); - }; - $scope.manageError = (error) => { - console.error(error); - $scope.config.loading = false; + $http.get('get-my-expenses').then((rep) => { + console.log('get-my-expenses', rep.data.expenses); + $scope.updateconf(rep) + }, + $scope.manageError) + }; + $scope.save = function () { + if ($scope.config.loading) { + console.log('already saving'); + return; + } + console.log('update expenses...'); + $scope.config.loading = true; + $http.post('save-my-expenses', { + expenses: $scope.expenses, + config : $scope.config + }) + .then((rep) => { + console.log('save-my-expenses', rep); + $scope.updateconf(rep) + }, + $scope.manageError) + }; + $scope.addExpense = function () { + $scope.expenses.push({ + name : "", + repeat: 0, + delay : 0, + amount: 0, + }) + }; + $scope.init = function () { + $scope.fetchExpenses(); + }; + $scope.manageError = (error) => { + console.error(error); + $scope.config.loading = false; - } - $scope.updateCanevas = function () { - var dataPoints = $scope.graphPointsPrevision; - var chartContainer = new CanvasJS.Chart("simulationPrevision", { - title: { - text: "Euros disponibles dans le temps" - }, - // animationEnabled: true, - data: [ - { - // Change type to "doughnut", "line", "splineArea", etc. - type: "splineArea", - dataPoints: dataPoints - } - ] - }); - chartContainer.render(); - } - $scope.init(); - }]); + }; + $scope.updateCanevas = function () { + var dataPoints = $scope.graphPointsPrevision; + var chartContainer = new CanvasJS.Chart("simulationPrevision", { + title: { + text: "Euros disponibles dans le temps" + }, + // animationEnabled: true, + data : [ + { + // Change type to "doughnut", "line", "splineArea", etc. + type : "splineArea", + dataPoints: dataPoints + } + ] + }); + chartContainer.render(); + }; + $scope.init(); + }]); diff --git a/assets/js/parts/previsionnel.js b/assets/js/parts/previsionnel.js new file mode 100644 index 00000000..5f39a44a --- /dev/null +++ b/assets/js/parts/previsionnel.js @@ -0,0 +1,163 @@ +export var PrevisionnelCtrl = function ($scope, $http, $timeout) { + + $scope.config = { + initialLoadingDone : false, + loading : false, + lines : 24, + debounceTime : 300, // miliseconds to wait before updating model and saving changes + /** + * expenses kind of the user + */ + disponibility : 5000, + averageMonthlyEarnings: 600, + warningThershold : 2000, + showDelays : false, + showRepeats : false, + monthsBeforeNoMoney : null, + }; + + let exampleExpenses = [ + {name: "appart", amount: 800, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "assurance voiture", amount: 50, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "internet", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "elec", amount: 100, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "chat", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true}, + {name: "transports", amount: 70, delay: 0, repeat: $scope.config.lines, enabled: false}, + ]; + + // $scope.expenses=[]; + $scope.expenses = exampleExpenses; + + /** + * sum of all monthly expenses, ignoring delay + * @returns {number} + */ + $scope.sumMonthlyExpenses = () => { + let sum = 0; + $scope.expenses.forEach((elem) => { + if (elem.enabled) { + sum += elem.amount; + } + }) + return sum; + }; + $scope.previsionTable = []; + $scope.calculatePrevisionTable = () => { + let turns = $scope.config.lines; + let monthly = $scope.sumMonthlyExpenses(); + let available = $scope.config.disponibility; + let previsionTable = []; + let changedNoMoneyConfig = false; + $scope.config.monthsBeforeNoMoney = null; + for (let i = 0; i <= turns; i++) { + // TODO take in account delays in expenses + available = available - monthly + $scope.config.averageMonthlyEarnings; + let newLine = { + expense : monthly, + available: available, + }; + + if (available <= 0 && !changedNoMoneyConfig) { + $scope.config.monthsBeforeNoMoney = i; + changedNoMoneyConfig = true; + } + previsionTable.push(newLine); + } + $scope.previsionTable = previsionTable; + $scope.makeGraphPointsOfPrevisionTable(previsionTable); + return previsionTable; + }; + $scope.graphPointsPrevision = []; + $scope.makeGraphPointsOfPrevisionTable = (previsionTable) => { + console.log("previsionTable", previsionTable); + $scope.graphPointsPrevision = []; + for (let i = 0; i < previsionTable.length; i++) { + $scope.graphPointsPrevision.push({ + label: previsionTable[i].available + " euros restants dans " + i + " mois", + y : previsionTable[i].available, + x : i, + }) + } + + } + + $scope.updateconf = (rep) => { + // update view calculs + $scope.calculatePrevisionTable(); + $scope.updateCanevas() + // flags + $scope.config.loading = false; + $scope.config.initialLoadingDone = true; + $scope.config.disponibility = rep.data.disponibility; + $scope.config.averageMonthlyEarnings = rep.data.averageMonthlyEarnings; + // default data when user has nothing saved + console.log('rep.data.expenses.length', rep.data.expenses.length) + if (!rep.data.expenses.length) { + $scope.expenses = exampleExpenses; + } else { + $scope.expenses = rep.data.expenses; + } + }; + // http related calls + $scope.fetchExpenses = () => { + console.log('fetch expenses...'); + $scope.config.loading = true; + + $http.get('get-my-expenses').then((rep) => { + console.log('get-my-expenses', rep.data.expenses); + $scope.updateconf(rep) + }, + $scope.manageError) + }; + $scope.save = function () { + if ($scope.config.loading) { + console.log('already saving'); + return; + } + console.log('update expenses...'); + $scope.config.loading = true; + $http.post('save-my-expenses', { + expenses: $scope.expenses, + config : $scope.config + }) + .then((rep) => { + console.log('save-my-expenses', rep); + $scope.updateconf(rep) + }, + $scope.manageError) + }; + $scope.addExpense = function () { + $scope.expenses.push({ + name : "", + repeat: 0, + delay : 0, + amount: 0, + }) + }; + $scope.init = function () { + $scope.fetchExpenses(); + }; + $scope.manageError = (error) => { + console.error(error); + $scope.config.loading = false; + + } + $scope.updateCanevas = function () { + var dataPoints = $scope.graphPointsPrevision; + var chartContainer = new CanvasJS.Chart("simulationPrevision", { + title: { + text: "Euros disponibles dans le temps" + }, + // animationEnabled: true, + data : [ + { + // Change type to "doughnut", "line", "splineArea", etc. + type : "splineArea", + dataPoints: dataPoints + } + ] + }); + chartContainer.render(); + } + $scope.init(); +};