loop save ok
This commit is contained in:
parent
f40ae1e1f5
commit
3fa2457cbe
@ -30,11 +30,11 @@
|
||||
<p class="padded">
|
||||
|
||||
Euros disponibles au départ:
|
||||
<input type="number" ng-model="config.disponibility">
|
||||
<input type="number" ng-model="config.disponibility" ng-change="save()">
|
||||
<br>
|
||||
|
||||
Gains moyen par mois:
|
||||
<input type="number" ng-model="config.averageMonthlyEarnings">
|
||||
<input type="number" ng-model="config.averageMonthlyEarnings" ng-disabled="config.isSaving">
|
||||
</p>
|
||||
<p>
|
||||
<p>
|
||||
|
@ -294,36 +294,38 @@ angular
|
||||
$scope.config.loading = true;
|
||||
|
||||
$http.get('get-my-expenses').then((rep) => {
|
||||
console.log('get-my-expenses', rep.data.expenses);
|
||||
$scope.config.loading = false;
|
||||
console.log('get-my-expenses', rep.data.expenses);
|
||||
$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;
|
||||
}
|
||||
},
|
||||
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 TODO
|
||||
|
||||
$scope.save = () => {
|
||||
if($scope.config.loading ){
|
||||
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,
|
||||
expenses: $scope.expenses,
|
||||
config: $scope.config
|
||||
})
|
||||
.then((rep) => {
|
||||
console.log('save-my-expenses', rep);
|
||||
$scope.config.loading = false;
|
||||
},
|
||||
console.log('save-my-expenses', rep);
|
||||
$scope.config.loading = false;
|
||||
},
|
||||
$scope.manageError)
|
||||
};
|
||||
$scope.addExpense = () => {
|
||||
@ -334,10 +336,10 @@ angular
|
||||
amount: 0,
|
||||
})
|
||||
};
|
||||
$scope.init = ()=>{
|
||||
$scope.init = () => {
|
||||
$scope.fetchExpenses();
|
||||
};
|
||||
$scope.manageError = (error)=>{
|
||||
$scope.manageError = (error) => {
|
||||
console.error(error);
|
||||
$scope.config.loading = false;
|
||||
|
||||
|
@ -162,6 +162,8 @@ class DefaultController extends Controller
|
||||
|
||||
return new JsonResponse([
|
||||
'expenses' => $expensesOfUser,
|
||||
'disponibility' => $currentUser->getDisponibility(),
|
||||
'averageMonthlyEarnings' => $currentUser->getAverageMonthlyEarnings(),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -170,7 +172,7 @@ class DefaultController extends Controller
|
||||
* @param Request $request
|
||||
* @return JsonResponse the list of expanses
|
||||
*/
|
||||
public function saveExpensesAction(Request $request)
|
||||
public function saveMyExpensesAction(Request $request)
|
||||
{
|
||||
|
||||
$json = json_decode($request->getContent(), true);
|
||||
@ -186,33 +188,34 @@ class DefaultController extends Controller
|
||||
// save the user configuration
|
||||
foreach ($json['expenses'] as $expens) {
|
||||
|
||||
if($expens['id']){
|
||||
if(isset($expens['id'])){
|
||||
$foundExpense = $categoriesByID[$expens['id']];
|
||||
if($foundExpense){
|
||||
// update existing expenses of logged in user
|
||||
$foundExpense->setName($expens['name']);
|
||||
$foundExpense->setAmount($expens['amount']);
|
||||
$foundExpense->setDelay($expens['delay']);
|
||||
$foundExpense->setRepeatitions($expens['repeat']);
|
||||
$foundExpense->setEnabled($expens['enabled']);
|
||||
$m->persist($foundExpense);
|
||||
}else{
|
||||
// create new expense for user
|
||||
$newExpense = new ExpenseKind();
|
||||
$newExpense->setUser($currentUser);
|
||||
$newExpense->setName($expens['name']);
|
||||
$newExpense->setAmount($expens['amount']);
|
||||
$newExpense->setRepeatitions($expens['repeat']);
|
||||
$newExpense->setEnabled($expens['enabled']);
|
||||
$m->persist($newExpense);
|
||||
|
||||
}
|
||||
}else{
|
||||
// create new expense for user
|
||||
$newExpense = new ExpenseKind();
|
||||
$newExpense->setUser($currentUser);
|
||||
$newExpense->setName($expens['name']);
|
||||
$newExpense->setDelay($expens['delay']);
|
||||
$newExpense->setAmount($expens['amount']);
|
||||
$newExpense->setRepeatitions($expens['repeat']);
|
||||
$newExpense->setEnabled($expens['enabled']);
|
||||
$m->persist($newExpense);
|
||||
|
||||
}
|
||||
}
|
||||
foreach ($json['config'] as $conf) {
|
||||
|
||||
}
|
||||
$nexExpense = new ExpenseKind();
|
||||
$currentUser->setDisponibility($json['config']['disponibility']);
|
||||
$currentUser->setAverageMonthlyEarnings($json['config']['averageMonthlyEarnings']);
|
||||
|
||||
$m->persist($nexExpense);
|
||||
|
||||
$m->persist($currentUser);
|
||||
$m->flush();
|
||||
|
@ -71,9 +71,10 @@ class User extends BaseUser {
|
||||
|
||||
//expenses previsionnel configs
|
||||
/**
|
||||
* @ORM\Column(name="averageSpend", type="float", nullable=true)
|
||||
* @ORM\Column(name="averageMonthlyEarnings", type="float", nullable=true)
|
||||
*/
|
||||
private $averageSpend;
|
||||
private $averageMonthlyEarnings;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="disponibility", type="float", nullable=true)
|
||||
*/
|
||||
@ -84,21 +85,20 @@ class User extends BaseUser {
|
||||
*/
|
||||
private $expenses;
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAverageSpend()
|
||||
public function getAverageMonthlyEarnings()
|
||||
{
|
||||
return $this->averageSpend;
|
||||
return $this->averageMonthlyEarnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $averageSpend
|
||||
* @param mixed $averageMonthlyEarnings
|
||||
*/
|
||||
public function setAverageSpend($averageSpend)
|
||||
public function setAverageMonthlyEarnings($averageMonthlyEarnings)
|
||||
{
|
||||
$this->averageSpend = $averageSpend;
|
||||
$this->averageMonthlyEarnings = $averageMonthlyEarnings;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
|
@ -132,10 +132,12 @@ class OwnerService {
|
||||
foreach ( $expenses as $exp ) {
|
||||
$serialized[] =
|
||||
[
|
||||
'amount' => $exp->getAmount(),
|
||||
'id' => $exp->getId(),
|
||||
'name' => $exp->getName(),
|
||||
'delay' => $exp->getDelay(),
|
||||
'repeat' => $exp->getRepeat(),
|
||||
'repeat' => $exp->getRepeatitions(),
|
||||
'enabled' => $exp->getEnabled(),
|
||||
];
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user