page previsionnel
This commit is contained in:
parent
dae7c006d5
commit
d81aa1cbe0
@ -8,6 +8,18 @@
|
||||
ng-app="caisse"
|
||||
ng-controller="previsionnelCtrl as pCtrl"
|
||||
>
|
||||
<div class="row">
|
||||
<div class="col-6"></div>
|
||||
<div class="col-6">
|
||||
|
||||
<div ng-if="config.initialLoadingDone && config.loading">
|
||||
Chargement ...
|
||||
</div>
|
||||
<div ng-if="config.initialLoadingDone && !config.loading">
|
||||
Modifications sauvegardées
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h1>Prévisionnel</h1>
|
||||
<div class="row">
|
||||
<div class="col-7 col-xs-12 col-sm-7">
|
||||
@ -48,7 +60,8 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="postes">
|
||||
<h2>Postes de dépenses mensuelles
|
||||
<h2>
|
||||
{{expenses.length}} Postes de dépenses mensuelles
|
||||
<button ng-click="addExpense()">+</button>
|
||||
</h2>
|
||||
<p class="desc">
|
||||
|
@ -43,6 +43,12 @@ app_sell_record:
|
||||
get_my_products:
|
||||
path: /get-my-products
|
||||
defaults: { _controller: AppBundle:Default:getMyProducts }
|
||||
get_my_expenses:
|
||||
path: /get-my-expenses
|
||||
defaults: { _controller: AppBundle:Default:getMyExpenses }
|
||||
save_my_expenses:
|
||||
path: /save-my-expenses
|
||||
defaults: { _controller: AppBundle:Default:saveMyExpenses }
|
||||
|
||||
add_selling:
|
||||
path: /add-selling
|
||||
|
@ -226,6 +226,8 @@ angular
|
||||
.controller('previsionnelCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
|
||||
|
||||
$scope.config = {
|
||||
initialLoadingDone: false,
|
||||
loading: false,
|
||||
lines: 24,
|
||||
/**
|
||||
* expenses kind of the user
|
||||
@ -289,17 +291,35 @@ angular
|
||||
// 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);
|
||||
})
|
||||
console.log('get-my-expenses', rep.data.expenses);
|
||||
$scope.config.loading = false;
|
||||
$scope.config.initialLoadingDone = true;
|
||||
// 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;
|
||||
}
|
||||
},
|
||||
$scope.manageError)
|
||||
};
|
||||
// save
|
||||
// save TODO
|
||||
$scope.save = () => {
|
||||
console.log('update expenses...');
|
||||
$http.post('save-my-expenses', $scope.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.config.loading = false;
|
||||
},
|
||||
$scope.manageError)
|
||||
};
|
||||
$scope.addExpense = () => {
|
||||
$scope.expenses.push({
|
||||
@ -308,5 +328,14 @@ angular
|
||||
delay: 0,
|
||||
amount: 0,
|
||||
})
|
||||
};
|
||||
$scope.init = ()=>{
|
||||
$scope.fetchExpenses();
|
||||
};
|
||||
$scope.manageError = (error)=>{
|
||||
console.error(error);
|
||||
$scope.config.loading = false;
|
||||
|
||||
}
|
||||
$scope.init();
|
||||
}]);
|
||||
|
@ -138,6 +138,30 @@ class DefaultController extends Controller
|
||||
'lastFestival' => $activeFestival->makeArray(),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* get user products
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getMyExpensesAction()
|
||||
{
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
|
||||
|
||||
$currentUser = $this->getUser();
|
||||
if (!$currentUser) {
|
||||
return new JsonResponse([
|
||||
'expenses' => [[]],
|
||||
]);
|
||||
}
|
||||
|
||||
$ownerService = $this->ownerService;
|
||||
$ownerService->setupNewFestival($currentUser);
|
||||
$expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser);
|
||||
|
||||
return new JsonResponse([
|
||||
'expenses' => $expensesOfUser,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
|
@ -71,6 +71,22 @@ class User extends BaseUser {
|
||||
*/
|
||||
private $categories;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExpenses()
|
||||
{
|
||||
return $this->expenses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $expenses
|
||||
*/
|
||||
public function setExpenses($expenses)
|
||||
{
|
||||
$this->expenses = $expenses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -119,4 +119,27 @@ class OwnerService {
|
||||
|
||||
return $serializedCategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return array
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
*/
|
||||
public function serializeExpensesOfUser( User $user ) {
|
||||
$expenses = $user->getExpenses();
|
||||
$serialized = [];
|
||||
|
||||
foreach ( $expenses as $exp ) {
|
||||
$serialized[] =
|
||||
[
|
||||
'id' => $exp->getId(),
|
||||
'name' => $exp->getName(),
|
||||
'delay' => $exp->getDelay(),
|
||||
'repeat' => $exp->getRepeat(),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
return $serialized;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user