loop save ok

This commit is contained in:
Baptiste Lemoine 2018-08-27 15:20:01 +02:00
parent f40ae1e1f5
commit 3fa2457cbe
5 changed files with 50 additions and 43 deletions

View File

@ -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>

View File

@ -297,6 +297,8 @@ angular
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) {

View File

@ -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,19 +188,23 @@ 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->setDelay($expens['delay']);
$newExpense->setAmount($expens['amount']);
$newExpense->setRepeatitions($expens['repeat']);
$newExpense->setEnabled($expens['enabled']);
@ -206,13 +212,10 @@ class DefaultController extends Controller
}
}
}
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();

View File

@ -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

View File

@ -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(),
];
}