Exemplo n.º 1
0
 /**
  * @param Estimate $estimate
  * @param AuthUser $user
  *
  * @return Estimate|null
  */
 public function save(Estimate $estimate, AuthUser $user)
 {
     if (empty($estimate->getEstimateId())) {
         $estimate->setCreateUserId($user->getUserId());
         $family = $this->familyRepository->getFamilyByUserId($user->getUserId());
         $estimate->setFamilyId($family->getFamilyId());
     }
     $estimate->setIsClosed(false);
     $estimateId = $this->estimateRepository->save($estimate);
     if (!$estimateId) {
         return null;
     }
     return $this->estimateRepository->getEstimateById($estimateId);
 }
Exemplo n.º 2
0
 /**
  * @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);
 }