page previsionnel

This commit is contained in:
Baptiste Lemoine 2018-08-22 17:10:01 +02:00
parent 1497570c1b
commit 5acff1b274
4 changed files with 141 additions and 15 deletions

View File

@ -93,6 +93,18 @@
Import
</a>
</li>
<li>
<a class="btn {% if app.request.attributes.get('_route') == 'previsionnel' %}
btn-success
{% else %}
btn-default
{% endif %}" href="{{ path('previsionnel') }}"
>
<i class="fa fa-arrow-circle-o-up"></i>
Prévisionnel
</a>
</li>
</ul>
</div>
</div>

View File

@ -4,7 +4,7 @@
<div id="wrapper">
<div class="previsionnel"
ng-app="caisse"
ng-controller="PrevisionnelCtrl as pCtrl"
ng-controller="previsionnelCtrl as pCtrl"
>
<h1>Prévisionnel</h1>
<div class="row">
@ -14,7 +14,8 @@
Configuration
</h2>
Euros disponibles au départ:
<input type="number" ng-model="start">
<input type="number" ng-model="disponibility">
Dépenses mensuelles: {{ sumMonthlyExpenses }}
</div>
<div class="postes">
<h2>Postes de dépenses</h2>
@ -48,24 +49,46 @@
<tbody>
</tbody>
<tr>
<tr ng-repeat="e in pCtrl.expenses">
<td>
{{ e.name }}
</td>
<td>
{{ e.delay }}débute dans X mois
</td>
<td>
{{ e.repeat }}
</td>
<td>
{{ e.repeat * e.amount }}
</td>
<td>
{{ e.amount }}
</td>
<td>
{{ e.amount * 12 }}
</td>
</tr>
</table>
<div class="well">
Exemple:
<strong>
Exemples:
</strong>
appartement
resto au boulot
courses
mutuelle
transport en commun
assurance voiture
assurance moto
trucs de loisirs divers
gaz
elec
internet
épargne
impots
cottisation URSSAF
resto au boulot
courses
serveur wouaibe
assurance voiture
transport en commun
abonnement protonmail VPN
abonnement service audio, vidéo
carburant véhicule
@ -82,12 +105,36 @@
<h2>Simulation sur 5 ans (60 mois)</h2>
<table>
<thead>
</thead>
<tbody>
<tr>
<td>
Month in the future
</td>
<td>
date
</td>
<td>
Dépenses
</td>
<td>
Disponibilité
</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="line in previsionTable">
<td>
{{ $index }}
</td>
<td>
-
</td>
<td>
{{ line.expense }}
</td>
<td ng-class="{ 'bg-warning' : line.available < 0}">
{{ line.available }}
</td>
</tr>
</tbody>

View File

@ -226,11 +226,63 @@ angular
.controller('previsionnelCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
let exampleExpenses = [
{name: "appart", amount: 600},
{name: "assurance voiture", amount: 50},
{name: "internet", amount: 20},
{name: "elec", amount: 100},
{name: "transports", amount: 70},
{name: "chat", amount: 20},
];
/**
* expenses kind of the user
* @type {Array}
*/
$scope.disponibility=5000;
// $scope.expenses=[];
$scope.expenses=exampleExpenses;
/**
* sum of all monthly expenses, ignoring delay
* @returns {number}
*/
$scope.sumMonthlyExpenses = ()=>{
let sum = 0;
$scope.expenses.forEach((elem)=>{
sum += elem.amount;
})
return sum;
};
$scope.previsionTable = ()=>{
let turns = 60;
let monthly = $scope.sumMonthlyExpenses();
let available = $scope.disponibility;
let previsionTable=[];
for (let i=0;i<=turns;i++){
// TODO take in account delays in expenses
let newLine = {
expense: monthly,
available: available - monthly,
};
previsionTable.push(newLine);
}
return previsionTable;
};
// http related calls
$scope.fetchProductsFromDB = function () {
console.log('fetch products...');
$scope.fetchExpenses = ()=>{
console.log('fetch expenses...');
$http.get('get-my-expenses').then((rep) => {
console.log('get-my-expenses',rep);
})
}
};
// save
$scope.save = ()=>{
console.log('update expenses...');
$http.post('save-my-expenses', $scope.expenses)
.then((rep) => {
console.log('save-my-expenses',rep);
})
};
}]);

View File

@ -424,6 +424,21 @@ class DefaultController extends Controller
]);
}
/**
* @Route("/previsionnel", name="previsionnel")
*/
public function previsionnelAction()
{
// $currentUser = $this->getUser();
// $m = $this->getDoctrine()->getManager();
// $sellingRepo = $m->getRepository('AppBundle:SellRecord');
return $this->render('logged/previsionnel.html.twig',
[
'base_dir' => '',
]);
}
/**
* import lots of products at once
* @Route("/mass-create", name="mass_create")