/** * @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; }