config of logged routes
This commit is contained in:
parent
8e3ba4ed5f
commit
97717179cf
@ -88,7 +88,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
btn-default
|
btn-default
|
||||||
{% endif %}" href="{{ path('import') }}"
|
{% endif %}" href="{{ path('import') }}"
|
||||||
>
|
>
|
||||||
<i class="fa fa-arrow-circle-o-up"></i>
|
<i class="fa fa-arrow-circle-o-up"></i>
|
||||||
Import
|
Import
|
||||||
</a>
|
</a>
|
||||||
@ -100,7 +100,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
btn-default
|
btn-default
|
||||||
{% endif %}" href="{{ path('previsionnel') }}"
|
{% endif %}" href="{{ path('previsionnel') }}"
|
||||||
>
|
>
|
||||||
<i class="fa fa-arrow-circle-o-up"></i>
|
<i class="fa fa-arrow-circle-o-up"></i>
|
||||||
Prévisionnel
|
Prévisionnel
|
||||||
</a>
|
</a>
|
||||||
|
@ -1,62 +1,61 @@
|
|||||||
|
|
||||||
fos_user_profile:
|
fos_user_profile:
|
||||||
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
|
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
|
||||||
prefix: /profile
|
prefix: /profile
|
||||||
|
|
||||||
fos_user_register:
|
fos_user_register:
|
||||||
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
|
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
|
||||||
prefix: /register
|
prefix: /register
|
||||||
|
|
||||||
fos_user_resetting:
|
fos_user_resetting:
|
||||||
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
|
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
|
||||||
prefix: /resetting
|
prefix: /resetting
|
||||||
|
|
||||||
fos_user_change_password:
|
fos_user_change_password:
|
||||||
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
|
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
|
||||||
prefix: /profile
|
prefix: /profile
|
||||||
app:
|
app:
|
||||||
resource: '@AppBundle/Controller/'
|
resource: '@AppBundle/Controller/'
|
||||||
type: annotation
|
type: annotation
|
||||||
## app specific stuff
|
## app specific stuff
|
||||||
app_festival:
|
app_festival:
|
||||||
resource: "@AppBundle/Controller/FestivalController.php"
|
resource: "@AppBundle/Controller/FestivalController.php"
|
||||||
type: annotation
|
type: annotation
|
||||||
# legal info pages
|
# legal info pages
|
||||||
app_legal:
|
app_legal:
|
||||||
resource: "@AppBundle/Controller/LegalController.php"
|
resource: "@AppBundle/Controller/LegalController.php"
|
||||||
type: annotation
|
type: annotation
|
||||||
|
|
||||||
app_product_category:
|
app_product_category:
|
||||||
resource: "@AppBundle/Controller/ProductCategoryController.php"
|
resource: "@AppBundle/Controller/ProductCategoryController.php"
|
||||||
type: annotation
|
type: annotation
|
||||||
|
|
||||||
app_product:
|
app_product:
|
||||||
resource: "@AppBundle/Controller/ProductController.php"
|
resource: "@AppBundle/Controller/ProductController.php"
|
||||||
type: annotation
|
type: annotation
|
||||||
|
|
||||||
app_sell_record:
|
app_sell_record:
|
||||||
resource: "@AppBundle/Controller/SellRecordController.php"
|
resource: "@AppBundle/Controller/SellRecordController.php"
|
||||||
type: annotation
|
type: annotation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# async calls
|
||||||
get_my_products:
|
get_my_products:
|
||||||
path: /get-my-products
|
path: /logged/get-my-products
|
||||||
defaults: { _controller: AppBundle:Default:getMyProducts }
|
defaults: { _controller: AppBundle:Default:getMyProducts }
|
||||||
get_my_expenses:
|
get_my_expenses:
|
||||||
path: /get-my-expenses
|
path: /logged/get-my-expenses
|
||||||
defaults: { _controller: AppBundle:Default:getMyExpenses }
|
defaults: { _controller: AppBundle:Default:getMyExpenses }
|
||||||
save_my_expenses:
|
save_my_expenses:
|
||||||
path: /save-my-expenses
|
path: /logged/save-my-expenses
|
||||||
defaults: { _controller: AppBundle:Default:saveMyExpenses }
|
defaults: { _controller: AppBundle:Default:saveMyExpenses }
|
||||||
|
|
||||||
add_selling:
|
add_selling:
|
||||||
path: /add-selling
|
path: /logged/add-selling
|
||||||
defaults: { _controller: AppBundle:Default:addSelling }
|
defaults: { _controller: AppBundle:Default:addSelling }
|
||||||
|
|
||||||
fos_user:
|
fos_user:
|
||||||
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
|
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
|
||||||
# emails
|
# emails
|
||||||
tktest_mail:
|
tktest_mail:
|
||||||
path: /admin/test-email
|
path: /admin/test-email
|
||||||
defaults: { _controller: AppBundle:Default:email }
|
defaults: { _controller: AppBundle:Default:email }
|
||||||
|
@ -34,6 +34,7 @@ security:
|
|||||||
access_control:
|
access_control:
|
||||||
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
||||||
- { path: ^/dashboard$, role: IS_AUTHENTICATED_REMEMBERED }
|
- { path: ^/dashboard$, role: IS_AUTHENTICATED_REMEMBERED }
|
||||||
|
- { path: ^/logged$, role: IS_AUTHENTICATED_REMEMBERED }
|
||||||
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
||||||
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
||||||
- { path: ^/admin/, role: ROLE_ADMIN }
|
- { path: ^/admin/, role: ROLE_ADMIN }
|
||||||
|
@ -16,375 +16,375 @@ console.log('hello console for main.js');
|
|||||||
var stuff = ['initialstuff'];
|
var stuff = ['initialstuff'];
|
||||||
|
|
||||||
angular
|
angular
|
||||||
.module('caisse', [])
|
.module('caisse', [])
|
||||||
.controller('CaisseCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
|
.controller('CaisseCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
|
||||||
$scope.productsFromDB = []; // loaded products
|
$scope.productsFromDB = []; // loaded products
|
||||||
$scope.categories = []; // product categories
|
$scope.categories = []; // product categories
|
||||||
$scope.sellingComment = "un gens"; // 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.initLoadDone = false; // becames true after first init of product loading
|
||||||
$scope.recentSellings = [];
|
$scope.recentSellings = [];
|
||||||
$scope.lesParams = {};
|
$scope.lesParams = {};
|
||||||
$scope.countProductsSoldForActiveFestival = {};
|
$scope.countProductsSoldForActiveFestival = {};
|
||||||
$scope.paidAmount = 0;
|
$scope.paidAmount = 0;
|
||||||
$scope.expressSelling = true;
|
$scope.expressSelling = true;
|
||||||
$scope.pausedSelling = [];
|
$scope.pausedSelling = [];
|
||||||
$scope.show_config = {
|
$scope.show_config = {
|
||||||
stock_count: false,
|
stock_count: false,
|
||||||
sold: true,
|
sold : true,
|
||||||
};
|
};
|
||||||
$scope.activeItemsSold = []; // list of products ID to sell
|
$scope.activeItemsSold = []; // list of products ID to sell
|
||||||
$scope.activeSelling = []; // list of products to sell
|
$scope.activeSelling = []; // list of products to sell
|
||||||
$scope.activeFestival = { // an event where selling take place
|
$scope.activeFestival = { // an event where selling take place
|
||||||
id: null,
|
id : null,
|
||||||
name: "le festival",
|
name : "le festival",
|
||||||
dateCreation: new Date(),
|
dateCreation : new Date(),
|
||||||
chiffreAffaire: 0,
|
chiffreAffaire: 0,
|
||||||
clientsCount: 0,
|
clientsCount : 0,
|
||||||
commentaire: ""
|
commentaire : ""
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* get the sum of products prices
|
* get the sum of products prices
|
||||||
* @param list
|
* @param list
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
$scope.sumOfList = function (list) {
|
$scope.sumOfList = function (list) {
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
counter += list[i].price;
|
counter += list[i].price;
|
||||||
}
|
}
|
||||||
return counter;
|
return counter;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* sum of current selling list prices
|
* sum of current selling list prices
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
$scope.CurrentSellingTotal = function () {
|
$scope.CurrentSellingTotal = function () {
|
||||||
return $scope.sumOfList($scope.activeSelling);
|
return $scope.sumOfList($scope.activeSelling);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.regenActiveSellingIds = function () {
|
$scope.regenActiveSellingIds = function () {
|
||||||
$scope.activeItemsSold = [];
|
$scope.activeItemsSold = [];
|
||||||
$scope.paidAmount = 0;
|
$scope.paidAmount = 0;
|
||||||
for (let obj in $scope.activeSelling) {
|
for (let obj in $scope.activeSelling) {
|
||||||
$scope.activeItemsSold.push(obj.id);
|
$scope.activeItemsSold.push(obj.id);
|
||||||
}
|
}
|
||||||
$scope.paidAmount += $scope.sumOfList($scope.activeSelling);
|
$scope.paidAmount += $scope.sumOfList($scope.activeSelling);
|
||||||
};
|
};
|
||||||
$scope.stuff = stuff;
|
$scope.stuff = stuff;
|
||||||
$scope.setActiveSelling = function (selling) {
|
$scope.setActiveSelling = function (selling) {
|
||||||
$scope.activeSelling = selling;
|
$scope.activeSelling = selling;
|
||||||
};
|
};
|
||||||
$scope.pauseSelling = function (selling) {
|
$scope.pauseSelling = function (selling) {
|
||||||
$scope.pausedSelling.push(selling);
|
$scope.pausedSelling.push(selling);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* add to current sell list
|
* add to current sell list
|
||||||
* @param product
|
* @param product
|
||||||
*/
|
*/
|
||||||
$scope.addProduct = function (product) {
|
$scope.addProduct = function (product) {
|
||||||
product.stockCount--;
|
product.stockCount--;
|
||||||
$scope.activeSelling.push(product);
|
$scope.activeSelling.push(product);
|
||||||
$scope.activeItemsSold.push(product.id);
|
$scope.activeItemsSold.push(product.id);
|
||||||
$scope.regenActiveSellingIds();
|
$scope.regenActiveSellingIds();
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* remove from current sell list
|
* remove from current sell list
|
||||||
* @param product
|
* @param product
|
||||||
*/
|
*/
|
||||||
$scope.removeProduct = function (product, index) {
|
$scope.removeProduct = function (product, index) {
|
||||||
product.stockCount++;
|
product.stockCount++;
|
||||||
$scope.activeSelling.splice($index, 1);
|
$scope.activeSelling.splice($index, 1);
|
||||||
$scope.regenActiveSellingIds()
|
$scope.regenActiveSellingIds()
|
||||||
};
|
};
|
||||||
$scope.pauseSelling = function () {
|
$scope.pauseSelling = function () {
|
||||||
$scope.pausedSelling.push(angular.copy($scope.activeSelling));
|
$scope.pausedSelling.push(angular.copy($scope.activeSelling));
|
||||||
$scope.activeSelling = [];
|
$scope.activeSelling = [];
|
||||||
};
|
};
|
||||||
$scope.setBackPausedSelling = function (sellingList, index) {
|
$scope.setBackPausedSelling = function (sellingList, index) {
|
||||||
$scope.activeSelling = angular.copy(sellingList);
|
$scope.activeSelling = angular.copy(sellingList);
|
||||||
$scope.pausedSelling.splice(index, 1);
|
$scope.pausedSelling.splice(index, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.clearSellingComment = function () {
|
$scope.clearSellingComment = function () {
|
||||||
$scope.sellingComment = '';
|
$scope.sellingComment = '';
|
||||||
document.querySelector('#sellingCommentInput').focus();
|
document.querySelector('#sellingCommentInput').focus();
|
||||||
};
|
};
|
||||||
$scope.clearCurrentSelling = function () {
|
$scope.clearCurrentSelling = function () {
|
||||||
$scope.paidAmount = 0;
|
$scope.paidAmount = 0;
|
||||||
// $scope.sellingComment = "";
|
// $scope.sellingComment = "";
|
||||||
$scope.activeSelling = [];
|
$scope.activeSelling = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
// http related calls
|
// http related calls
|
||||||
$scope.fetchProductsFromDB = function () {
|
$scope.fetchProductsFromDB = function () {
|
||||||
console.log('fetch products...');
|
console.log('fetch products...');
|
||||||
$http.get('get-my-products').then((rep) => {
|
$http.get('logged/get-my-products').then((rep) => {
|
||||||
|
|
||||||
console.log('ok', rep);
|
console.log('ok', rep);
|
||||||
customCategories = [];
|
customCategories = [];
|
||||||
for (let c of rep.data.categories) {
|
for (let c of rep.data.categories) {
|
||||||
c.hidden = false;
|
c.hidden = false;
|
||||||
customCategories.push(c);
|
customCategories.push(c);
|
||||||
}
|
}
|
||||||
console.log('customCategories', customCategories);
|
console.log('customCategories', customCategories);
|
||||||
$scope.categories = customCategories;
|
$scope.categories = customCategories;
|
||||||
$scope.productsFromDB = customCategories;
|
$scope.productsFromDB = customCategories;
|
||||||
// $scope.recentSellings = rep.data.history;
|
// $scope.recentSellings = rep.data.history;
|
||||||
// festoche
|
// festoche
|
||||||
$scope.activeFestival.id = rep.data.lastFestival.id;
|
$scope.activeFestival.id = rep.data.lastFestival.id;
|
||||||
$scope.activeFestival.name = rep.data.lastFestival.name;
|
$scope.activeFestival.name = rep.data.lastFestival.name;
|
||||||
$scope.activeFestival.dateCreation = rep.data.lastFestival.dateCreation;
|
$scope.activeFestival.dateCreation = rep.data.lastFestival.dateCreation;
|
||||||
$scope.activeFestival.commentaire = rep.data.lastFestival.commentaire;
|
$scope.activeFestival.commentaire = rep.data.lastFestival.commentaire;
|
||||||
$scope.activeFestival.chiffreAffaire = rep.data.lastFestival.chiffreAffaire;
|
$scope.activeFestival.chiffreAffaire = rep.data.lastFestival.chiffreAffaire;
|
||||||
$scope.activeFestival.fondDeCaisseAvant = rep.data.lastFestival.fondDeCaisseAvant;
|
$scope.activeFestival.fondDeCaisseAvant = rep.data.lastFestival.fondDeCaisseAvant;
|
||||||
$scope.activeFestival.fondDeCaisseApres = rep.data.lastFestival.fondDeCaisseApres;
|
$scope.activeFestival.fondDeCaisseApres = rep.data.lastFestival.fondDeCaisseApres;
|
||||||
$scope.activeFestival.clientsCount = rep.data.lastFestival.clientsCount;
|
$scope.activeFestival.clientsCount = rep.data.lastFestival.clientsCount;
|
||||||
// stat count for items
|
// stat count for items
|
||||||
$scope.countProductsSoldForActiveFestival = rep.data.lastFestival.sold;
|
$scope.countProductsSoldForActiveFestival = rep.data.lastFestival.sold;
|
||||||
console.log(' $scope.countProductsSoldForActiveFestival', $scope.countProductsSoldForActiveFestival);
|
console.log(' $scope.countProductsSoldForActiveFestival', $scope.countProductsSoldForActiveFestival);
|
||||||
//done
|
//done
|
||||||
$scope.initLoadDone = true;
|
$scope.initLoadDone = true;
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
$scope.initLoadDone = true;
|
$scope.initLoadDone = true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sell one product, assuming the client has the right amount of money
|
* sell one product, assuming the client has the right amount of money
|
||||||
* @param product
|
* @param product
|
||||||
*/
|
*/
|
||||||
$scope.expressSell = function (product) {
|
$scope.expressSell = function (product) {
|
||||||
$scope.addProduct(product);
|
$scope.addProduct(product);
|
||||||
$scope.sendForm();
|
$scope.sendForm();
|
||||||
};
|
};
|
||||||
$scope.recentId = 0;
|
$scope.recentId = 0;
|
||||||
$scope.logger = function (stuff) {
|
$scope.logger = function (stuff) {
|
||||||
console.log('logger', stuff);
|
console.log('logger', stuff);
|
||||||
};
|
};
|
||||||
$scope.sendForm = function () {
|
$scope.sendForm = function () {
|
||||||
console.log('$scope.sellingComment', this.sellingComment);
|
console.log('$scope.sellingComment', this.sellingComment);
|
||||||
let lesParams = {
|
let lesParams = {
|
||||||
paidByClient: this.paidAmount,
|
paidByClient : this.paidAmount,
|
||||||
sellingComment: this.sellingComment,
|
sellingComment: this.sellingComment,
|
||||||
activeSelling: this.activeSelling,
|
activeSelling : this.activeSelling,
|
||||||
activeFestival: this.activeFestival
|
activeFestival: this.activeFestival
|
||||||
};
|
};
|
||||||
$scope.recentSellings.push({
|
$scope.recentSellings.push({
|
||||||
id: this.recentId++,
|
id : this.recentId++,
|
||||||
amount: this.CurrentSellingTotal(),
|
amount : this.CurrentSellingTotal(),
|
||||||
paidAmount: this.paidAmount,
|
paidAmount: this.paidAmount,
|
||||||
products:
|
products :
|
||||||
angular
|
angular
|
||||||
.copy(this.activeSelling)
|
.copy(this.activeSelling)
|
||||||
});
|
});
|
||||||
console.log('$scope.recentSellings', this.recentSellings);
|
console.log('$scope.recentSellings', this.recentSellings);
|
||||||
$scope.lesParams = lesParams;
|
$scope.lesParams = lesParams;
|
||||||
$http({
|
$http({
|
||||||
method: 'POST',
|
method : 'POST',
|
||||||
url: 'add-selling',
|
url : 'add-selling',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
data: lesParams // pass in data as strings
|
data : lesParams // pass in data as strings
|
||||||
}).then(function (rep) {
|
}).then(function (rep) {
|
||||||
$scope.clearCurrentSelling();
|
$scope.clearCurrentSelling();
|
||||||
// if successful, bind success message to message
|
// if successful, bind success message to message
|
||||||
$scope.successMessage = rep.data.message;
|
$scope.successMessage = rep.data.message;
|
||||||
$scope.activeFestival.chiffreAffaire = rep.data.newChiffreAffaire;
|
$scope.activeFestival.chiffreAffaire = rep.data.newChiffreAffaire;
|
||||||
$scope.activeFestival.clientsCount = rep.data.clientsCount;
|
$scope.activeFestival.clientsCount = rep.data.clientsCount;
|
||||||
$scope.countProductsSoldForActiveFestival = rep.data.activeFestival.sold;
|
$scope.countProductsSoldForActiveFestival = rep.data.activeFestival.sold;
|
||||||
$scope.showTemporaryMessage();
|
$scope.showTemporaryMessage();
|
||||||
console.log(rep);
|
console.log(rep);
|
||||||
if (!rep.success) {
|
if (!rep.success) {
|
||||||
// if not successful, bind errors to error variables
|
// if not successful, bind errors to error variables
|
||||||
$scope.errors = rep.errors;
|
$scope.errors = rep.errors;
|
||||||
}
|
}
|
||||||
}, function (rep) {
|
}, function (rep) {
|
||||||
console.log('nope! ', rep.data);
|
console.log('nope! ', rep.data);
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.sellingOk = false;
|
$scope.sellingOk = false;
|
||||||
$scope.tempMessage = {};
|
$scope.tempMessage = {};
|
||||||
$scope.showTemporaryMessage = function () {
|
$scope.showTemporaryMessage = function () {
|
||||||
if ($scope.sellingOk) {
|
if ($scope.sellingOk) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.sellingOk = true;
|
$scope.sellingOk = true;
|
||||||
$timeout.cancel($scope.tempMessage);
|
$timeout.cancel($scope.tempMessage);
|
||||||
$scope.tempMessage = $timeout(function () {
|
$scope.tempMessage = $timeout(function () {
|
||||||
$scope.sellingOk = false;
|
$scope.sellingOk = false;
|
||||||
}, 2000)
|
}, 2000)
|
||||||
};
|
};
|
||||||
$scope.init = (function () {
|
$scope.init = (function () {
|
||||||
$scope.fetchProductsFromDB();
|
$scope.fetchProductsFromDB();
|
||||||
})();
|
})();
|
||||||
}])
|
}])
|
||||||
.controller('previsionnelCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
|
.controller('previsionnelCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
|
||||||
|
|
||||||
$scope.config = {
|
$scope.config = {
|
||||||
initialLoadingDone: false,
|
initialLoadingDone : false,
|
||||||
loading: false,
|
loading : false,
|
||||||
lines: 24,
|
lines : 24,
|
||||||
debounceTime: 300, // miliseconds to wait before updating model and saving changes
|
debounceTime : 300, // miliseconds to wait before updating model and saving changes
|
||||||
/**
|
/**
|
||||||
* expenses kind of the user
|
* expenses kind of the user
|
||||||
*/
|
*/
|
||||||
disponibility: 5000,
|
disponibility : 5000,
|
||||||
averageMonthlyEarnings: 600,
|
averageMonthlyEarnings: 600,
|
||||||
warningThershold: 2000,
|
warningThershold : 2000,
|
||||||
showDelays: false,
|
showDelays : false,
|
||||||
showRepeats: false,
|
showRepeats : false,
|
||||||
monthsBeforeNoMoney: null,
|
monthsBeforeNoMoney : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
let exampleExpenses = [
|
let exampleExpenses = [
|
||||||
{name: "appart", amount: 800, delay: 0, repeat: $scope.config.lines, enabled: true},
|
{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: "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: "internet", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true},
|
||||||
{name: "elec", amount: 100, 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: "chat", amount: 20, delay: 0, repeat: $scope.config.lines, enabled: true},
|
||||||
{name: "transports", amount: 70, delay: 0, repeat: $scope.config.lines, enabled: false},
|
{name: "transports", amount: 70, delay: 0, repeat: $scope.config.lines, enabled: false},
|
||||||
];
|
];
|
||||||
|
|
||||||
// $scope.expenses=[];
|
// $scope.expenses=[];
|
||||||
$scope.expenses = exampleExpenses;
|
$scope.expenses = exampleExpenses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sum of all monthly expenses, ignoring delay
|
* sum of all monthly expenses, ignoring delay
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
$scope.sumMonthlyExpenses = () => {
|
$scope.sumMonthlyExpenses = () => {
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
$scope.expenses.forEach((elem) => {
|
$scope.expenses.forEach((elem) => {
|
||||||
if (elem.enabled) {
|
if (elem.enabled) {
|
||||||
sum += elem.amount;
|
sum += elem.amount;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return sum;
|
return sum;
|
||||||
};
|
};
|
||||||
$scope.previsionTable = [];
|
$scope.previsionTable = [];
|
||||||
$scope.calculatePrevisionTable = () => {
|
$scope.calculatePrevisionTable = () => {
|
||||||
let turns = $scope.config.lines;
|
let turns = $scope.config.lines;
|
||||||
let monthly = $scope.sumMonthlyExpenses();
|
let monthly = $scope.sumMonthlyExpenses();
|
||||||
let available = $scope.config.disponibility;
|
let available = $scope.config.disponibility;
|
||||||
let previsionTable = [];
|
let previsionTable = [];
|
||||||
let changedNoMoneyConfig = false;
|
let changedNoMoneyConfig = false;
|
||||||
$scope.config.monthsBeforeNoMoney = null;
|
$scope.config.monthsBeforeNoMoney = null;
|
||||||
for (let i = 0; i <= turns; i++) {
|
for (let i = 0; i <= turns; i++) {
|
||||||
// TODO take in account delays in expenses
|
// TODO take in account delays in expenses
|
||||||
available = available - monthly + $scope.config.averageMonthlyEarnings;
|
available = available - monthly + $scope.config.averageMonthlyEarnings;
|
||||||
let newLine = {
|
let newLine = {
|
||||||
expense: monthly,
|
expense : monthly,
|
||||||
available: available,
|
available: available,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (available <= 0 && !changedNoMoneyConfig) {
|
if (available <= 0 && !changedNoMoneyConfig) {
|
||||||
$scope.config.monthsBeforeNoMoney = i;
|
$scope.config.monthsBeforeNoMoney = i;
|
||||||
changedNoMoneyConfig = true;
|
changedNoMoneyConfig = true;
|
||||||
}
|
}
|
||||||
previsionTable.push(newLine);
|
previsionTable.push(newLine);
|
||||||
}
|
}
|
||||||
$scope.previsionTable = previsionTable;
|
$scope.previsionTable = previsionTable;
|
||||||
$scope.makeGraphPointsOfPrevisionTable(previsionTable);
|
$scope.makeGraphPointsOfPrevisionTable(previsionTable);
|
||||||
return previsionTable;
|
return previsionTable;
|
||||||
};
|
};
|
||||||
$scope.graphPointsPrevision = [];
|
$scope.graphPointsPrevision = [];
|
||||||
$scope.makeGraphPointsOfPrevisionTable = (previsionTable) => {
|
$scope.makeGraphPointsOfPrevisionTable = (previsionTable) => {
|
||||||
console.log("previsionTable", previsionTable);
|
console.log("previsionTable", previsionTable);
|
||||||
$scope.graphPointsPrevision = [];
|
$scope.graphPointsPrevision = [];
|
||||||
for (let i = 0; i < previsionTable.length; i++) {
|
for (let i = 0; i < previsionTable.length; i++) {
|
||||||
$scope.graphPointsPrevision.push({
|
$scope.graphPointsPrevision.push({
|
||||||
label: previsionTable[i].available + " euros restants dans " + i + " mois",
|
label: previsionTable[i].available + " euros restants dans " + i + " mois",
|
||||||
y: previsionTable[i].available,
|
y : previsionTable[i].available,
|
||||||
x: i,
|
x : i,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.updateconf = (rep) => {
|
$scope.updateconf = (rep) => {
|
||||||
// update view calculs
|
// update view calculs
|
||||||
$scope.calculatePrevisionTable();
|
$scope.calculatePrevisionTable();
|
||||||
$scope.updateCanevas()
|
$scope.updateCanevas()
|
||||||
// flags
|
// flags
|
||||||
$scope.config.loading = false;
|
$scope.config.loading = false;
|
||||||
$scope.config.initialLoadingDone = true;
|
$scope.config.initialLoadingDone = true;
|
||||||
$scope.config.disponibility = rep.data.disponibility;
|
$scope.config.disponibility = rep.data.disponibility;
|
||||||
$scope.config.averageMonthlyEarnings = rep.data.averageMonthlyEarnings;
|
$scope.config.averageMonthlyEarnings = rep.data.averageMonthlyEarnings;
|
||||||
// default data when user has nothing saved
|
// default data when user has nothing saved
|
||||||
console.log('rep.data.expenses.length', rep.data.expenses.length)
|
console.log('rep.data.expenses.length', rep.data.expenses.length)
|
||||||
if (!rep.data.expenses.length) {
|
if (!rep.data.expenses.length) {
|
||||||
$scope.expenses = exampleExpenses;
|
$scope.expenses = exampleExpenses;
|
||||||
} else {
|
} else {
|
||||||
$scope.expenses = rep.data.expenses;
|
$scope.expenses = rep.data.expenses;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// http related calls
|
// http related calls
|
||||||
$scope.fetchExpenses = () => {
|
$scope.fetchExpenses = () => {
|
||||||
console.log('fetch expenses...');
|
console.log('fetch expenses...');
|
||||||
$scope.config.loading = true;
|
$scope.config.loading = true;
|
||||||
|
|
||||||
$http.get('get-my-expenses').then((rep) => {
|
$http.get('get-my-expenses').then((rep) => {
|
||||||
console.log('get-my-expenses', rep.data.expenses);
|
console.log('get-my-expenses', rep.data.expenses);
|
||||||
$scope.updateconf(rep)
|
$scope.updateconf(rep)
|
||||||
},
|
},
|
||||||
$scope.manageError)
|
$scope.manageError)
|
||||||
};
|
};
|
||||||
// save TODO
|
// save TODO
|
||||||
|
|
||||||
$scope.save = () => {
|
$scope.save = () => {
|
||||||
if ($scope.config.loading) {
|
if ($scope.config.loading) {
|
||||||
console.log('already saving');
|
console.log('already saving');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('update expenses...');
|
console.log('update expenses...');
|
||||||
$scope.config.loading = true;
|
$scope.config.loading = true;
|
||||||
$http.post('save-my-expenses', {
|
$http.post('save-my-expenses', {
|
||||||
expenses: $scope.expenses,
|
expenses: $scope.expenses,
|
||||||
config: $scope.config
|
config : $scope.config
|
||||||
})
|
})
|
||||||
.then((rep) => {
|
.then((rep) => {
|
||||||
console.log('save-my-expenses', rep);
|
console.log('save-my-expenses', rep);
|
||||||
$scope.updateconf(rep)
|
$scope.updateconf(rep)
|
||||||
},
|
},
|
||||||
$scope.manageError)
|
$scope.manageError)
|
||||||
};
|
};
|
||||||
$scope.addExpense = () => {
|
$scope.addExpense = () => {
|
||||||
$scope.expenses.push({
|
$scope.expenses.push({
|
||||||
name: "",
|
name : "",
|
||||||
repeat: 0,
|
repeat: 0,
|
||||||
delay: 0,
|
delay : 0,
|
||||||
amount: 0,
|
amount: 0,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
$scope.init = () => {
|
$scope.init = () => {
|
||||||
$scope.fetchExpenses();
|
$scope.fetchExpenses();
|
||||||
};
|
};
|
||||||
$scope.manageError = (error) => {
|
$scope.manageError = (error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
$scope.config.loading = false;
|
$scope.config.loading = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
$scope.updateCanevas = () => {
|
$scope.updateCanevas = () => {
|
||||||
var dataPoints = $scope.graphPointsPrevision;
|
var dataPoints = $scope.graphPointsPrevision;
|
||||||
var chartContainer = new CanvasJS.Chart("simulationPrevision", {
|
var chartContainer = new CanvasJS.Chart("simulationPrevision", {
|
||||||
title: {
|
title: {
|
||||||
text: "Euros disponibles dans le temps"
|
text: "Euros disponibles dans le temps"
|
||||||
},
|
},
|
||||||
// animationEnabled: true,
|
// animationEnabled: true,
|
||||||
data: [
|
data : [
|
||||||
{
|
{
|
||||||
// Change type to "doughnut", "line", "splineArea", etc.
|
// Change type to "doughnut", "line", "splineArea", etc.
|
||||||
type: "splineArea",
|
type : "splineArea",
|
||||||
dataPoints: dataPoints
|
dataPoints: dataPoints
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
chartContainer.render();
|
chartContainer.render();
|
||||||
}
|
}
|
||||||
$scope.init();
|
$scope.init();
|
||||||
}]);
|
}]);
|
||||||
|
0
web/config.php
Normal file → Executable file
0
web/config.php
Normal file → Executable file
Loading…
Reference in New Issue
Block a user