start save expenses
This commit is contained in:
parent
d81aa1cbe0
commit
f40ae1e1f5
|
@ -100,20 +100,20 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
<tr ng-repeat="e in expenses ">
|
<tr ng-repeat="e in expenses ">
|
||||||
<td>
|
<td>
|
||||||
<input type="text" ng-model="e.name">
|
<input type="text" ng-model="e.name" ng-change="save()">
|
||||||
</td>
|
</td>
|
||||||
<td ng-if="config.showDelays">
|
<td ng-if="config.showDelays">
|
||||||
|
|
||||||
<input type="number" ng-model="e.delay">
|
<input type="number" ng-model="e.delay" ng-change="save()">
|
||||||
</td>
|
</td>
|
||||||
<td ng-if="config.showRepeats">
|
<td ng-if="config.showRepeats">
|
||||||
<input type="number" ng-model="e.repeat">
|
<input type="number" ng-model="e.repeat" ng-change="save()">
|
||||||
</td>
|
</td>
|
||||||
<td ng-if="config.showRepeats" class="text-right padded">
|
<td ng-if="config.showRepeats" class="text-right padded">
|
||||||
{{ e.repeat * e.amount }}
|
{{ e.repeat * e.amount }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="number" ng-model="e.amount">
|
<input type="number" ng-model="e.amount" ng-change="save()">
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right padded">
|
<td class="text-right padded">
|
||||||
<strong>
|
<strong>
|
||||||
|
@ -123,7 +123,7 @@
|
||||||
€
|
€
|
||||||
</td>
|
</td>
|
||||||
<td class="padded">
|
<td class="padded">
|
||||||
<input type="checkbox" ng-model="e.enabled">
|
<input type="checkbox" ng-model="e.enabled" ng-change="save()">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -308,7 +308,12 @@ angular
|
||||||
$scope.manageError)
|
$scope.manageError)
|
||||||
};
|
};
|
||||||
// save TODO
|
// save TODO
|
||||||
|
|
||||||
$scope.save = () => {
|
$scope.save = () => {
|
||||||
|
if($scope.config.loading ){
|
||||||
|
console.log('already saving');
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log('update expenses...');
|
console.log('update expenses...');
|
||||||
$scope.config.loading = true;
|
$scope.config.loading = true;
|
||||||
$http.post('save-my-expenses', {
|
$http.post('save-my-expenses', {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace AppBundle\Controller;
|
namespace AppBundle\Controller;
|
||||||
|
|
||||||
|
use AppBundle\Entity\ExpenseKind;
|
||||||
use AppBundle\Entity\Festival;
|
use AppBundle\Entity\Festival;
|
||||||
use AppBundle\Entity\Product;
|
use AppBundle\Entity\Product;
|
||||||
use AppBundle\Entity\ProductCategory;
|
use AppBundle\Entity\ProductCategory;
|
||||||
|
@ -18,7 +19,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
class DefaultController extends Controller
|
class DefaultController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
private $ownerService;
|
private $ownerService;
|
||||||
private $tokenManager;
|
private $tokenManager;
|
||||||
|
|
||||||
public function __construct(CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService)
|
public function __construct(CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService)
|
||||||
|
@ -120,7 +121,7 @@ class DefaultController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$ownerService = $this->ownerService;
|
$ownerService = $this->ownerService;
|
||||||
$ownerService->setupNewFestival($currentUser);
|
$ownerService->setupNewFestival($currentUser);
|
||||||
$activeFestival = $currentUser->getActiveFestival();
|
$activeFestival = $currentUser->getActiveFestival();
|
||||||
|
|
||||||
$categRepo = $m->getRepository('AppBundle:ProductCategory');
|
$categRepo = $m->getRepository('AppBundle:ProductCategory');
|
||||||
|
@ -138,8 +139,9 @@ class DefaultController extends Controller
|
||||||
'lastFestival' => $activeFestival->makeArray(),
|
'lastFestival' => $activeFestival->makeArray(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get user products
|
* get user expenses
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function getMyExpensesAction()
|
public function getMyExpensesAction()
|
||||||
|
@ -155,7 +157,7 @@ class DefaultController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$ownerService = $this->ownerService;
|
$ownerService = $this->ownerService;
|
||||||
$ownerService->setupNewFestival($currentUser);
|
$ownerService->setupNewFestival($currentUser);
|
||||||
$expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser);
|
$expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser);
|
||||||
|
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
|
@ -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
|
* @param Request $request
|
||||||
* add a selling record corresponding to one client
|
* add a selling record corresponding to one client
|
||||||
|
@ -177,7 +237,7 @@ class DefaultController extends Controller
|
||||||
$m = $this->getDoctrine()->getManager();
|
$m = $this->getDoctrine()->getManager();
|
||||||
$newSellRecord = new SellRecord();
|
$newSellRecord = new SellRecord();
|
||||||
// sort user categories
|
// sort user categories
|
||||||
$myCategories = $m->getRepository('AppBundle:ProductCategory')->findAll();
|
$myCategories = $currentUser->getCategories();
|
||||||
$categoriesByID = [];
|
$categoriesByID = [];
|
||||||
foreach ($myCategories as $my_category) {
|
foreach ($myCategories as $my_category) {
|
||||||
$categoriesByID[$my_category->getId()] = $my_category;
|
$categoriesByID[$my_category->getId()] = $my_category;
|
||||||
|
@ -258,20 +318,20 @@ class DefaultController extends Controller
|
||||||
$m = $this->getDoctrine()->getManager();
|
$m = $this->getDoctrine()->getManager();
|
||||||
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
|
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
|
||||||
$allSellingList = $sellingRepo->findByUser($currentUser->getId());
|
$allSellingList = $sellingRepo->findByUser($currentUser->getId());
|
||||||
$mySellings = array_splice($allSellingList, 0 , 15);
|
$mySellings = array_splice($allSellingList, 0, 15);
|
||||||
$chiffreAffaires = 0;
|
$chiffreAffaires = 0;
|
||||||
|
|
||||||
$myFestivals = $currentUser->getFestivals();
|
$myFestivals = $currentUser->getFestivals();
|
||||||
|
|
||||||
$statisticsFestivals = [
|
$statisticsFestivals = [
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($myFestivals as $festival) {
|
foreach ($myFestivals as $festival) {
|
||||||
$statisticsFestivals[]=[
|
$statisticsFestivals[] = [
|
||||||
'date'=>$festival->getDateCreation(),
|
'date' => $festival->getDateCreation(),
|
||||||
'name'=>$festival->getName(),
|
'name' => $festival->getName(),
|
||||||
'clients_count' => count($festival->getSellRecords()),
|
'clients_count' => count($festival->getSellRecords()),
|
||||||
'chiffreAffaire'=>$festival->getChiffreAffaire(),
|
'chiffreAffaire' => $festival->getChiffreAffaire(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$statisticsSoldProducts = [
|
$statisticsSoldProducts = [
|
||||||
|
@ -279,13 +339,13 @@ class DefaultController extends Controller
|
||||||
];
|
];
|
||||||
|
|
||||||
$statsForFestival = [
|
$statsForFestival = [
|
||||||
['name' => 'festoche bidule', 'clients_count' => 125, 'chiffreAffaire' => 236, 'date'=> new \DateTime()],
|
['name' => 'festoche bidule', 'clients_count' => 125, 'chiffreAffaire' => 236, 'date' => new \DateTime()],
|
||||||
];
|
];
|
||||||
foreach ($allSellingList as $client) {
|
foreach ($allSellingList as $client) {
|
||||||
foreach ($client->getProductsSold() as $product) {
|
foreach ($client->getProductsSold() as $product) {
|
||||||
$chiffreAffaires += $product->getPrice();
|
$chiffreAffaires += $product->getPrice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($mySellings as $client) {
|
foreach ($mySellings as $client) {
|
||||||
foreach ($client->getProductsSold() as $product) {
|
foreach ($client->getProductsSold() as $product) {
|
||||||
$chiffreAffaires += $product->getPrice();
|
$chiffreAffaires += $product->getPrice();
|
||||||
|
@ -526,8 +586,7 @@ class DefaultController extends Controller
|
||||||
->setName($productName)
|
->setName($productName)
|
||||||
->setStockCount(500)
|
->setStockCount(500)
|
||||||
->setUser($currentUser)
|
->setUser($currentUser)
|
||||||
->setPrice($price)
|
->setPrice($price);
|
||||||
;
|
|
||||||
$currentUser->addProduct($newProduct);
|
$currentUser->addProduct($newProduct);
|
||||||
$m->persist($newProduct);
|
$m->persist($newProduct);
|
||||||
}// look for existing products
|
}// look for existing products
|
||||||
|
|
|
@ -34,6 +34,13 @@ class ExpenseKind
|
||||||
* @ORM\Column(name="delay", type="integer", nullable=true)
|
* @ORM\Column(name="delay", type="integer", nullable=true)
|
||||||
*/
|
*/
|
||||||
private $delay;
|
private $delay;
|
||||||
|
/**
|
||||||
|
* line enabled to calculate on
|
||||||
|
*
|
||||||
|
* @ORM\Column(name="enabled", type="boolean", nullable=true)
|
||||||
|
*/
|
||||||
|
private $enabled;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int|null
|
* @var int|null
|
||||||
|
@ -54,6 +61,21 @@ class ExpenseKind
|
||||||
*/
|
*/
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
public function getEnabled()
|
||||||
|
{
|
||||||
|
return $this->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int|null $enabled
|
||||||
|
*/
|
||||||
|
public function setEnabled($enabled)
|
||||||
|
{
|
||||||
|
$this->enabled = $enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id.
|
* Get id.
|
||||||
|
|
|
@ -43,6 +43,27 @@ class SerieFestival {
|
||||||
*/
|
*/
|
||||||
private $dateCreation;
|
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
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -37,7 +37,10 @@ class User extends BaseUser {
|
||||||
private $googleId;
|
private $googleId;
|
||||||
|
|
||||||
private $googleAccessToken;
|
private $googleAccessToken;
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
|
||||||
|
*/
|
||||||
|
private $categories;
|
||||||
/**
|
/**
|
||||||
* templates products
|
* templates products
|
||||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
|
||||||
|
@ -54,23 +57,80 @@ class User extends BaseUser {
|
||||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user")
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user")
|
||||||
*/
|
*/
|
||||||
private $festivals;
|
private $festivals;
|
||||||
|
/**
|
||||||
|
* series of festivals
|
||||||
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SerieFestival", mappedBy="user")
|
||||||
|
*/
|
||||||
|
private $seriesFestivals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current festival we are recording sellings for
|
||||||
|
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Festival")
|
||||||
|
*/
|
||||||
|
private $activeFestival;
|
||||||
|
|
||||||
|
//expenses previsionnel configs
|
||||||
|
/**
|
||||||
|
* @ORM\Column(name="averageSpend", type="float", nullable=true)
|
||||||
|
*/
|
||||||
|
private $averageSpend;
|
||||||
|
/**
|
||||||
|
* @ORM\Column(name="disponibility", type="float", nullable=true)
|
||||||
|
*/
|
||||||
|
private $disponibility;
|
||||||
/**
|
/**
|
||||||
* variabilised products sold
|
* variabilised products sold
|
||||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user")
|
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user")
|
||||||
*/
|
*/
|
||||||
private $expenses;
|
private $expenses;
|
||||||
|
|
||||||
/**
|
|
||||||
* current festival we are recording sellings for
|
|
||||||
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Festival")
|
|
||||||
*/
|
|
||||||
private $activeFestival;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private $categories;
|
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
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue