/**
  * Spouse Action
  */
 public function spouseAction()
 {
     if ($this->_request->getParam('id', null) === null) {
         $this->_redirect('/admin/clients/');
     }
     $identity = Zend_Auth::getInstance()->getIdentity()->toArray();
     if ($identity['role'] === 'Agent') {
         $this->view->agentId = $identity['agent_id'];
     }
     $this->view->clientId = array('client_id' => $this->_request->id);
     $clientGateway = new Clients_Model_ClientGateway();
     $this->view->clientGateway = $clientGateway;
     $spouseData = $clientGateway->fetchClientSpouse($this->_request->id);
     if (is_object($spouseData)) {
         $spouseData = $spouseData->toArray();
     }
     // retrieve spouse details
     if (!$spouseData) {
         $spouseData = $clientGateway->fetchClient($this->_request->id);
         if (is_object($spouseData)) {
             $spouseData = $spouseData->toArray();
         }
         $spouseData["client_id"] = null;
         unset($spouseData["client_fname"]);
         unset($spouseData["client_lname"]);
         unset($spouseData["client_cellphone"]);
         unset($spouseData["client_email"]);
         unset($spouseData["client_spouse"]);
         unset($spouseData["client_datetime"]);
         unset($spouseData["client_active"]);
         unset($spouseData["client_deleted"]);
         unset($spouseData["client_dob"]);
         unset($spouseData["agent_id"]);
     } else {
         $spouseData['client_dob'] = $this->_dateFormatter->viewDateFormat($spouseData['client_dob']);
     }
     $this->view->clientSpouse = $spouseData;
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $this->view->module = $request->getModuleName();
     $this->view->controller = $request->getControllerName();
 }
 /**
  * Overview Index Action
  */
 public function indexAction()
 {
     $financials = array();
     if ($this->_request->getParam('id', null) === null) {
         $this->_redirect('/admin/clients/');
     }
     $this->view->clientId = array('client_id' => $this->_request->id);
     //Fetch Client & Spouse Details
     $clientGateway = new Clients_Model_ClientGateway();
     $clientContact = $clientGateway->fetchClient($this->_request->id);
     if (is_object($clientContact)) {
         $clientContact = $clientContact->toArray();
     }
     $clientContact['client_dob'] = $this->_dateFormatter->viewDateFormat($clientContact['client_dob']);
     $clientSpouse = $clientGateway->fetchClientSpouse($this->_request->id);
     if (is_object($clientSpouse)) {
         $clientSpouse = $clientSpouse->toArray();
     }
     if ($clientSpouse) {
         $clientSpouse['client_dob'] = $this->_dateFormatter->viewDateFormat($clientSpouse['client_dob']);
     }
     //Calculate Asset Totals
     $clientAssetGateway = new Clients_Model_ClientAssetGateway();
     $financials['assetsTotalEquity'] = $clientAssetGateway->calculateAssetsTotalEquity($this->_request->id);
     $financials['assetsTotalEquity'] = number_format($financials['assetsTotalEquity'], 2);
     //Calculate Investment Totals - Investments and Retirement Plans
     $clientInvestmentGateway = new Clients_Model_ClientInvestmentGateway();
     $financials['investmentsTotal'] = $clientInvestmentGateway->calculateInvestmentsTotal($this->_request->id);
     $clientEmploymentGateway = new Clients_Model_ClientEmploymentGateway();
     $financials['investmentsTotal'] += $clientEmploymentGateway->calculateRetirementPlanTotals($this->_request->id);
     $financials['investmentsTotal'] = number_format($financials['investmentsTotal'], 2);
     //Calculate Incomes Total
     $clientIncomeGateway = new Clients_Model_ClientIncomeGateway();
     $incomeTotal = $clientIncomeGateway->calculateIncomeTotals($this->_request->id);
     $empIncomeTotal = $clientEmploymentGateway->calculateEmploymentIncomeTotal($this->_request->id);
     $financials['incomeTotal'] = $incomeTotal + $empIncomeTotal;
     $financials['incomeTotal'] = number_format($financials['incomeTotal'], 2);
     //Calculate Total Monthly Expenses
     $financials['mthlyExpenses'] = $clientEmploymentGateway->calculateRetirementMonthlyExpense($this->_request->id);
     $clientInsuranceGateway = new Clients_Model_ClientInsuranceGateway();
     $financials['mthlyExpenses'] += $clientInsuranceGateway->calculateMonthlyInsuranceExpense($this->_request->id);
     $financials['mthlyExpenses'] += $clientAssetGateway->calculateAssetsTotalMonthlyExpense($this->_request->id);
     $financials['mthlyExpenses'] += $clientInvestmentGateway->calculateInvestmentsMonthlyExpense($this->_request->id);
     $clientExpenseGateway = new Clients_Model_ClientExpenseGateway();
     $financials['mthlyExpenses'] += $clientExpenseGateway->calculateTotalMonthlyExpenses($this->_request->id);
     $financials['mthlyExpenses'] = number_format($financials['mthlyExpenses'], 2);
     //Calculate Total Accumulated Debt
     $financials['debtTotal'] = $clientExpenseGateway->calculateTotalAccumulatedExpenses($this->_request->id);
     $financials['debtTotal'] += $clientAssetGateway->calculateAssetsTotalDebt($this->_request->id);
     $financials['debtTotal'] = number_format($financials['debtTotal'], 2);
     //Calculate Emergency Funds
     $financials['emergencyFunds'] = $clientAssetGateway->calculateAssetEmergencyFunds($this->_request->id);
     $financials['emergencyFunds'] = $clientInvestmentGateway->calculateInvestmentEmergencyFunds($this->_request->id);
     $financials['emergencyFunds'] = number_format($financials['emergencyFunds'], 2);
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $this->view->module = $request->getModuleName();
     $this->view->controller = $request->getControllerName();
     $this->view->clientContact = $clientContact;
     $this->view->clientSpouse = $clientSpouse;
     $this->view->financials = $financials;
 }