/** * @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); }
/** * @return int */ public function considerBalance() { return $this->estimate->getAmount() - $this->considerTotalAmountOfExpensive(); }
/** * @param Estimate $estimate * * @return int */ public function save(Estimate $estimate) { $estimateId = 0; if ($estimate->getEstimateId()) { $update = $this->update()->where(['estimate_id', '=', $estimate->getEstimateId()])->execute(['category_id' => $estimate->getCategoryId(), 'amount' => $estimate->getAmount()]); if ($update) { $estimateId = $estimate->getEstimateId(); } } else { $insert = $this->insert(['budget_id', 'category_id', 'family_id', 'create_user_id', 'amount', 'is_closed'])->values([$estimate->getBudgetId(), $estimate->getCategoryId(), $estimate->getFamilyId(), $estimate->getCreateUserId(), $estimate->getAmount(), $estimate->isClosed()]); if ($insert) { $estimateId = $this->getConnection()->lastInsertId('estimate_id'); } } return $estimateId; }