start save expenses
This commit is contained in:
parent
d81aa1cbe0
commit
f40ae1e1f5
@ -100,20 +100,20 @@
|
||||
</tbody>
|
||||
<tr ng-repeat="e in expenses ">
|
||||
<td>
|
||||
<input type="text" ng-model="e.name">
|
||||
<input type="text" ng-model="e.name" ng-change="save()">
|
||||
</td>
|
||||
<td ng-if="config.showDelays">
|
||||
|
||||
<input type="number" ng-model="e.delay">
|
||||
<input type="number" ng-model="e.delay" ng-change="save()">
|
||||
</td>
|
||||
<td ng-if="config.showRepeats">
|
||||
<input type="number" ng-model="e.repeat">
|
||||
<input type="number" ng-model="e.repeat" ng-change="save()">
|
||||
</td>
|
||||
<td ng-if="config.showRepeats" class="text-right padded">
|
||||
{{ e.repeat * e.amount }}
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" ng-model="e.amount">
|
||||
<input type="number" ng-model="e.amount" ng-change="save()">
|
||||
</td>
|
||||
<td class="text-right padded">
|
||||
<strong>
|
||||
@ -123,7 +123,7 @@
|
||||
€
|
||||
</td>
|
||||
<td class="padded">
|
||||
<input type="checkbox" ng-model="e.enabled">
|
||||
<input type="checkbox" ng-model="e.enabled" ng-change="save()">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -308,7 +308,12 @@ angular
|
||||
$scope.manageError)
|
||||
};
|
||||
// save TODO
|
||||
|
||||
$scope.save = () => {
|
||||
if($scope.config.loading ){
|
||||
console.log('already saving');
|
||||
return;
|
||||
}
|
||||
console.log('update expenses...');
|
||||
$scope.config.loading = true;
|
||||
$http.post('save-my-expenses', {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\ExpenseKind;
|
||||
use AppBundle\Entity\Festival;
|
||||
use AppBundle\Entity\Product;
|
||||
use AppBundle\Entity\ProductCategory;
|
||||
@ -138,8 +139,9 @@ class DefaultController extends Controller
|
||||
'lastFestival' => $activeFestival->makeArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* get user products
|
||||
* get user expenses
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getMyExpensesAction()
|
||||
@ -163,6 +165,64 @@ class DefaultController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* recieve the json containing the expanse config of a user
|
||||
* @param Request $request
|
||||
* @return JsonResponse the list of expanses
|
||||
*/
|
||||
public function saveExpensesAction(Request $request)
|
||||
{
|
||||
|
||||
$json = json_decode($request->getContent(), true);
|
||||
$currentUser = $this->getUser();
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$myExpenses = $currentUser->getExpenses();
|
||||
$categoriesByID = [];
|
||||
|
||||
foreach ($myExpenses as $expense) {
|
||||
$categoriesByID[$expense->getId()] = $expense;
|
||||
}
|
||||
// loop on the json config for expanse
|
||||
// save the user configuration
|
||||
foreach ($json['expenses'] as $expens) {
|
||||
|
||||
if($expens['id']){
|
||||
$foundExpense = $categoriesByID[$expens['id']];
|
||||
if($foundExpense){
|
||||
$foundExpense->setName($expens['name']);
|
||||
$foundExpense->setAmount($expens['amount']);
|
||||
$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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($json['config'] as $conf) {
|
||||
|
||||
}
|
||||
$nexExpense = new ExpenseKind();
|
||||
|
||||
$m->persist($nexExpense);
|
||||
|
||||
$m->persist($currentUser);
|
||||
$m->flush();
|
||||
$expensesOfUser = $currentUser->getExpenses();
|
||||
|
||||
return new JsonResponse([
|
||||
'expenses' => $expensesOfUser,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* add a selling record corresponding to one client
|
||||
@ -177,7 +237,7 @@ class DefaultController extends Controller
|
||||
$m = $this->getDoctrine()->getManager();
|
||||
$newSellRecord = new SellRecord();
|
||||
// sort user categories
|
||||
$myCategories = $m->getRepository('AppBundle:ProductCategory')->findAll();
|
||||
$myCategories = $currentUser->getCategories();
|
||||
$categoriesByID = [];
|
||||
foreach ($myCategories as $my_category) {
|
||||
$categoriesByID[$my_category->getId()] = $my_category;
|
||||
@ -526,8 +586,7 @@ class DefaultController extends Controller
|
||||
->setName($productName)
|
||||
->setStockCount(500)
|
||||
->setUser($currentUser)
|
||||
->setPrice($price)
|
||||
;
|
||||
->setPrice($price);
|
||||
$currentUser->addProduct($newProduct);
|
||||
$m->persist($newProduct);
|
||||
}// look for existing products
|
||||
|
@ -34,6 +34,13 @@ class ExpenseKind
|
||||
* @ORM\Column(name="delay", type="integer", nullable=true)
|
||||
*/
|
||||
private $delay;
|
||||
/**
|
||||
* line enabled to calculate on
|
||||
*
|
||||
* @ORM\Column(name="enabled", type="boolean", nullable=true)
|
||||
*/
|
||||
private $enabled;
|
||||
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
@ -54,6 +61,21 @@ class ExpenseKind
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $enabled
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id.
|
||||
|
@ -43,6 +43,27 @@ class SerieFestival {
|
||||
*/
|
||||
private $dateCreation;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="festivals")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $user
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
@ -37,7 +37,10 @@ class User extends BaseUser {
|
||||
private $googleId;
|
||||
|
||||
private $googleAccessToken;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
|
||||
*/
|
||||
private $categories;
|
||||
/**
|
||||
* templates products
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
|
||||
@ -55,10 +58,10 @@ class User extends BaseUser {
|
||||
*/
|
||||
private $festivals;
|
||||
/**
|
||||
* variabilised products sold
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user")
|
||||
* series of festivals
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SerieFestival", mappedBy="user")
|
||||
*/
|
||||
private $expenses;
|
||||
private $seriesFestivals;
|
||||
|
||||
/**
|
||||
* current festival we are recording sellings for
|
||||
@ -66,11 +69,68 @@ class User extends BaseUser {
|
||||
*/
|
||||
private $activeFestival;
|
||||
|
||||
//expenses previsionnel configs
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
|
||||
* @ORM\Column(name="averageSpend", type="float", nullable=true)
|
||||
*/
|
||||
private $categories;
|
||||
private $averageSpend;
|
||||
/**
|
||||
* @ORM\Column(name="disponibility", type="float", nullable=true)
|
||||
*/
|
||||
private $disponibility;
|
||||
/**
|
||||
* variabilised products sold
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user")
|
||||
*/
|
||||
private $expenses;
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAverageSpend()
|
||||
{
|
||||
return $this->averageSpend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $averageSpend
|
||||
*/
|
||||
public function setAverageSpend($averageSpend)
|
||||
{
|
||||
$this->averageSpend = $averageSpend;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDisponibility()
|
||||
{
|
||||
return $this->disponibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $disponibility
|
||||
*/
|
||||
public function setDisponibility($disponibility)
|
||||
{
|
||||
$this->disponibility = $disponibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSeriesFestivals()
|
||||
{
|
||||
return $this->seriesFestivals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $seriesFestivals
|
||||
*/
|
||||
public function setSeriesFestivals($seriesFestivals)
|
||||
{
|
||||
$this->seriesFestivals = $seriesFestivals;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user