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;
|
||||
|
@ -18,7 +19,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
|||
class DefaultController extends Controller
|
||||
{
|
||||
|
||||
private $ownerService;
|
||||
private $ownerService;
|
||||
private $tokenManager;
|
||||
|
||||
public function __construct(CsrfTokenManagerInterface $tokenManager = null, OwnerService $ownerService)
|
||||
|
@ -120,7 +121,7 @@ class DefaultController extends Controller
|
|||
}
|
||||
|
||||
$ownerService = $this->ownerService;
|
||||
$ownerService->setupNewFestival($currentUser);
|
||||
$ownerService->setupNewFestival($currentUser);
|
||||
$activeFestival = $currentUser->getActiveFestival();
|
||||
|
||||
$categRepo = $m->getRepository('AppBundle:ProductCategory');
|
||||
|
@ -138,8 +139,9 @@ class DefaultController extends Controller
|
|||
'lastFestival' => $activeFestival->makeArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* get user products
|
||||
* get user expenses
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getMyExpensesAction()
|
||||
|
@ -155,7 +157,7 @@ class DefaultController extends Controller
|
|||
}
|
||||
|
||||
$ownerService = $this->ownerService;
|
||||
$ownerService->setupNewFestival($currentUser);
|
||||
$ownerService->setupNewFestival($currentUser);
|
||||
$expensesOfUser = $ownerService->serializeExpensesOfUser($currentUser);
|
||||
|
||||
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
|
||||
* 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;
|
||||
|
@ -258,20 +318,20 @@ class DefaultController extends Controller
|
|||
$m = $this->getDoctrine()->getManager();
|
||||
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
|
||||
$allSellingList = $sellingRepo->findByUser($currentUser->getId());
|
||||
$mySellings = array_splice($allSellingList, 0 , 15);
|
||||
$mySellings = array_splice($allSellingList, 0, 15);
|
||||
$chiffreAffaires = 0;
|
||||
|
||||
$myFestivals = $currentUser->getFestivals();
|
||||
|
||||
$statisticsFestivals = [
|
||||
];
|
||||
];
|
||||
|
||||
foreach ($myFestivals as $festival) {
|
||||
$statisticsFestivals[]=[
|
||||
'date'=>$festival->getDateCreation(),
|
||||
'name'=>$festival->getName(),
|
||||
$statisticsFestivals[] = [
|
||||
'date' => $festival->getDateCreation(),
|
||||
'name' => $festival->getName(),
|
||||
'clients_count' => count($festival->getSellRecords()),
|
||||
'chiffreAffaire'=>$festival->getChiffreAffaire(),
|
||||
'chiffreAffaire' => $festival->getChiffreAffaire(),
|
||||
];
|
||||
}
|
||||
$statisticsSoldProducts = [
|
||||
|
@ -279,13 +339,13 @@ class DefaultController extends Controller
|
|||
];
|
||||
|
||||
$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 ($client->getProductsSold() as $product) {
|
||||
$chiffreAffaires += $product->getPrice();
|
||||
}
|
||||
}
|
||||
foreach ($allSellingList as $client) {
|
||||
foreach ($client->getProductsSold() as $product) {
|
||||
$chiffreAffaires += $product->getPrice();
|
||||
}
|
||||
}
|
||||
foreach ($mySellings as $client) {
|
||||
foreach ($client->getProductsSold() as $product) {
|
||||
$chiffreAffaires += $product->getPrice();
|
||||
|
@ -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")
|
||||
|
@ -54,23 +57,80 @@ class User extends BaseUser {
|
|||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Festival", mappedBy="user")
|
||||
*/
|
||||
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
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ExpenseKind", mappedBy="user")
|
||||
*/
|
||||
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")
|
||||
*/
|
||||
private $categories;
|
||||
/**
|
||||
* @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