/**
  * Get Employment Data for Client/Spouse
  * @param Client $id
  */
 public function getEmploymentData($id)
 {
     $employment = array();
     $employment['client'] = array();
     $employment['spouse'] = array();
     //Check to see if this client has a spouse
     $clientGateway = new Clients_Model_ClientGateway();
     // retrieve spouse details
     $spouseId = $clientGateway->fetchClientSpouseId($id);
     $clientEmploymentGateway = new Clients_Model_ClientEmploymentGateway();
     //Spouse confirmed
     if ($spouseId) {
         // retrieve spouse details
         $clientEmployment = $clientEmploymentGateway->fetchClientAndSpouseEmployment($id);
         if (count($clientEmployment) == '2') {
             if ($clientEmployment['0']['client_id'] == $id) {
                 $employment['client'] = $clientEmployment['0'];
                 $employment['spouse'] = $clientEmployment['1'];
             } else {
                 $employment['client'] = $clientEmployment['1'];
                 $employment['spouse'] = $clientEmployment['0'];
             }
         } elseif (count($clientEmployment) == '1') {
             if ($clientEmployment['0']['client_id'] == $id) {
                 $employment['client'] = $clientEmployment['0'];
             } else {
                 $employment['spouse'] = $clientEmployment['0'];
             }
         }
     } else {
         $clientEmployment = $clientEmploymentGateway->fetchClientEmployment($id);
         if (is_object($clientEmployment)) {
             $employment['client'] = $clientEmployment->toArray();
         } else {
             $employment['client'] = $clientEmployment;
         }
     }
     return $employment;
 }
 /**
  * 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;
 }
 /**
  * Calculate the number of Years till Retirment
  * @param client $id
  */
 public function getYearsTilRetirment($id)
 {
     $this->checkAcl('read');
     //Get Current Year
     $currentYear = null;
     $date = new DateTime();
     $currentYear = $date->format('Y');
     //Get Client Retirement year from Employment data
     $clientEmploymentGateway = new Clients_Model_ClientEmploymentGateway();
     $retiementYear = $clientEmploymentGateway->fetchClientRetirementYear($id);
     $retYear = DateTime::createFromFormat('Y', $retiementYear['client_employment_retirementyear']);
     if ($retYear >= $currentYear) {
         $yearsTilRet = $date->diff($retYear);
         return $yearsTilRet->y;
     } else {
         return null;
     }
 }