Esempio n. 1
0
 /**
  * @param Request $request
  */
 public function saveAction(Request $request)
 {
     if ($request->isPost() && $request->hasRequest('estimate')) {
         /** @var EstimateRepository $estimateRepository */
         $estimateRepository = $this->getDbFacade()->getEntityRepository(EstimateRepository::class);
         /** @var FamilyRepository $familyRepository */
         $familyRepository = $this->getDbFacade()->getEntityRepository(FamilyRepository::class);
         $estimateManager = new EstimateManager($estimateRepository, $familyRepository);
         /** @var AuthUser $user */
         $user = $this->getUser();
         $estimate = new Estimate($request->getRequest('estimate'));
         $estimateManager->save($estimate, $user);
         $this->redirect('budget/view', ['id' => $estimate->getBudgetId()]);
     }
     $this->redirect('budget/view');
 }
Esempio n. 2
0
 /**
  * Выводит список расходов/доходов для управления.
  *
  * @param Request $request
  *
  * @return string Список расходов/доходов.
  */
 public function listAction(Request $request)
 {
     if (!$this->getUser()->isAuth()) {
         $this->redirect('user/login');
     }
     $filterCriteria = new FilterCriteria();
     $filterCriteria->setOrderBy('operation_id', OrderByExpressionInterface::ORDER_DESC);
     /** @var FamilyRepository $familyRepository */
     $familyRepository = $this->getDbFacade()->getEntityRepository(FamilyRepository::class);
     $family = $familyRepository->getFamilyByUserId($this->getUser()->getUserId());
     $filterCriteria->setFamilyId($family->getFamilyId());
     if ($request->hasRequest('operationFilter')) {
         $filterCriteria->setApplyFilter(true);
         $operationFilter = $request->getRequest('operationFilter');
         if (isset($operationFilter['categoryId'])) {
             $filterCriteria->setCategoryId($operationFilter['categoryId']);
         }
         if (isset($operationFilter['period'])) {
             $filterCriteria->setPeriod($operationFilter['period']);
         }
         if (isset($operationFilter['operationType'])) {
             $filterCriteria->setOperationType($operationFilter['operationType']);
         }
         if (isset($operationFilter['startDate'])) {
             $filterCriteria->setStartDate($operationFilter['startDate']);
         }
         if (isset($operationFilter['endDate'])) {
             $filterCriteria->setEndDate($operationFilter['endDate']);
         }
     }
     /** @var OperationRepository $operationRepository */
     $operationRepository = $this->getDbFacade()->getEntityRepository(OperationRepository::class);
     $paginator = new Paginator(new PaginationFactory(), new PaginationViewer($this->view));
     $pagination = null;
     try {
         $pagination = $paginator->build(self::SHOW_OPERATIONS_ON_PER_PAGE, $operationRepository->getOperationsCountByFamilyId($family->getFamilyId()), (int) $request->getQuery('page'));
         $filterCriteria->setRange(new RangeStruct($pagination->getPerPage(), $pagination->getOffset()));
     } catch (\InvalidArgumentException $exc) {
         // @todo Need add logging
     }
     $operationFilterService = new OperationFilter($operationRepository);
     $operations = $operationFilterService->filter($filterCriteria);
     /** @var UserRepository $userRepository */
     $userRepository = $this->getDbFacade()->getEntityRepository(UserRepository::class);
     $familyManager = new FamilyManager($familyRepository, $userRepository);
     $users = $familyManager->getUsersOfFamilyByUserId($this->getUser()->getUserId());
     /** @var CategoryRepository $categoryRepository */
     $categoryRepository = $this->getDbFacade()->getEntityRepository(CategoryRepository::class);
     $categories = $categoryRepository->getListOfCategoriesByFamilyId($family->getFamilyId());
     return $this->view->render('operation/list', ['users' => $users, 'filterCriteria' => $filterCriteria, 'categories' => $categories, 'operations' => $operations, 'pagination' => $pagination]);
 }