/**
  * @param int $budgetId
  * @return BudgetReport|null
  */
 public function generate($budgetId)
 {
     $budget = $this->budgetRepository->getBudgetById($budgetId);
     if (!$budget) {
         // @todo need throw exception
         return null;
     }
     $user = $this->userRepository->getUserById($budget->getCreateUserId());
     if (!$user) {
         // @todo need throw exception
         return null;
     }
     $estimates = $this->estimateRepository->getEstimatesByBudgetId($budget->getBudgetId());
     $categoryIds = [];
     foreach ($estimates as $estimate) {
         $categoryIds[] = $estimate->getCategoryId();
     }
     $budgetEstimates = [];
     if (!empty($categoryIds)) {
         $categories = $this->categoryRepository->getListOfCategoriesByIds($categoryIds);
         foreach ($estimates as $estimate) {
             if (empty($categories[$estimate->getCategoryId()])) {
                 // @todo need throw exception
                 continue;
             }
             $category = $categories[$estimate->getCategoryId()];
             $filterCriteria = new FilterCriteria();
             $filterCriteria->setFamilyId($budget->getFamilyId());
             $filterCriteria->setCategoryId($category->getCategoryId());
             $filterCriteria->setOperationType(Operation::OPERATION_TYPE_EXPENSE);
             $filterCriteria->setStartDate($budget->getStartDate());
             $filterCriteria->setEndDate($budget->getEndDate());
             $budgetEstimates[] = new BudgetEstimate($estimate, $category, $this->operationFilter->filter($filterCriteria));
         }
     }
     return new BudgetReport($budget, $user, $budgetEstimates);
 }
Exemple #2
0
 /**
  * @param int $userId
  *
  * @return Category[]
  */
 public function getListOfCategoryByUserId($userId)
 {
     $family = $this->familyRepository->getFamilyByUserId($userId);
     return $this->categoryRepository->getListOfCategoriesByFamilyId($family->getFamilyId());
 }