/** * Fetch spouse retirement plan accounts available for Tx * @param int $id Client id * @param string $status tax status * @return client employment array|null */ public function fetchSpouseRetAccountsAvailForTx($id, $status = 'Qualified') { $moneyAvailForTx = 0; $this->checkAcl('read'); $cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache')->getManager()->getCache('database'); $cacheKey = md5('clientSpouseRetPlanMoneyTx_' . $id); if (!($moneyAvailForTx = $cache->load($cacheKey))) { $spouseTable = new Clients_Model_DbTable_ClientSpouse(); $spouseSelect = $spouseTable->select(); $spouseSelect->where('client_id = ?', $id); $spouseRow = $spouseTable->fetchRow($spouseSelect); //spouse found get spouse id if ($spouseRow) { $spouseRow = $spouseRow->toArray(); } else { $spouseRow['spouse_id'] = ''; } // Pull client and spouse employment $table = new Clients_Model_DbTable_ClientEmployment(); $select = $table->select(); $select->from($table, array('client_employment_txamount'))->where('client_id = ?', $id)->orWhere('client_id = ?', $spouseRow['spouse_id'])->where('client_employment_retirementplantype <> ?', 'None')->where('client_employment_taxstatus = ?', $status)->where('client_employment_txamount > ?', '0'); $rows = $table->fetchAll($select); if (null === $rows) { return null; } $moneyAvailForTx = $rows->toArray(); $cache->save($moneyAvailForTx, $cacheKey, array('clientEmployment')); } return $moneyAvailForTx; }
/** * Fetch client spouse id * @param int|string $id Client id * @return string */ public function fetchClientSpouseId($id) { $this->checkAcl('read'); $cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache')->getManager()->getCache('database'); $cacheKey = md5('clientSpouseBy_' . $id); if (!($spouseRow = $cache->load($cacheKey))) { $spouseTable = new Clients_Model_DbTable_ClientSpouse(); $spouseSelect = $spouseTable->select(); $spouseSelect->where('client_id = ?', $id); $spouseRow = $spouseTable->fetchRow($spouseSelect); //no spouse found return null if (null === $spouseRow) { return null; } // Spouse found so we pull spouse data $spouseRow = $spouseRow->toArray(); $cache->save($spouseRow, $cacheKey, array('clients')); } return $spouseRow['spouse_id']; }