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