/**
  * Retrieves an existing additional information record.
  *
  * Attempts to retrieve an existing additional information record associated
  * with the quote / policy number passed in. Returns the data encapsulated
  * in an Model_Insurance_AdditionalInformation object.
  *
  * @param string $policyNumber
  * Search for records matching this quote / policy number.
  *
  * @return Model_Insurance_AdditionalInformation
  * Returns this object populated with relevant information, or null if no
  * relevant information has been stored.
  */
 public function getAdditionalInformation($policyNumber)
 {
     $select = $this->select();
     $select->where('policynumber = ?', $policyNumber);
     $additionalInfo = $this->fetchRow($select);
     if (!empty($additionalInfo)) {
         $additionalInformation = new Model_Insurance_AdditionalInformation();
         $additionalInformation->setPolicyNumber($policyNumber);
         $additionalInformation->setAdditionalInformation($additionalInfo->additionalinfo);
         $returnVal = $additionalInformation;
     } else {
         // No warning given as this is a common/normal scenario
         $returnVal = null;
     }
     return $returnVal;
 }
 /**
  * @todo Remove the hardcoded UW question numbers from this method.
  */
 protected function _processUnderwriting($pageForm)
 {
     $returnVal = true;
     //First, store the underwriting answers.
     $declaration1 = $pageForm->subform_importantinformation->getElement('declaration1')->getValue();
     $declaration2 = $pageForm->subform_importantinformation->getElement('declaration2')->getValue();
     $declaration3 = $pageForm->subform_importantinformation->getElement('declaration3')->getValue();
     $declaration4 = $pageForm->subform_importantinformation->getElement('declaration4')->getValue();
     $underwritingAnswersArray = array();
     $underwritingAnswersArray[0] = new Model_Insurance_Answer();
     $underwritingAnswersArray[0]->setPolicyNumber($this->_policyNumber);
     $underwritingAnswersArray[0]->setQuestionNumber(49);
     $underwritingAnswersArray[0]->setAnswer($declaration1);
     $underwritingAnswersArray[0]->setDateAnswered(Zend_Date::now());
     $underwritingAnswersArray[1] = new Model_Insurance_Answer();
     $underwritingAnswersArray[1]->setPolicyNumber($this->_policyNumber);
     $underwritingAnswersArray[1]->setQuestionNumber(50);
     $underwritingAnswersArray[1]->setAnswer($declaration2);
     $underwritingAnswersArray[1]->setDateAnswered(Zend_Date::now());
     $underwritingAnswersArray[2] = new Model_Insurance_Answer();
     $underwritingAnswersArray[2]->setPolicyNumber($this->_policyNumber);
     $underwritingAnswersArray[2]->setQuestionNumber(51);
     $underwritingAnswersArray[2]->setAnswer($declaration3);
     $underwritingAnswersArray[2]->setDateAnswered(Zend_Date::now());
     $underwritingAnswersArray[3] = new Model_Insurance_Answer();
     $underwritingAnswersArray[3]->setPolicyNumber($this->_policyNumber);
     $underwritingAnswersArray[3]->setQuestionNumber(52);
     $underwritingAnswersArray[3]->setAnswer($declaration4);
     $underwritingAnswersArray[3]->setDateAnswered(Zend_Date::now());
     $answersManager = new Manager_Insurance_Answers();
     for ($i = 0; $i < count($underwritingAnswersArray); $i++) {
         if (!$answersManager->getIsAnswerAlreadyStored($underwritingAnswersArray[$i])) {
             $answersManager->insertUnderwritingAnswer($underwritingAnswersArray[$i]);
         }
     }
     //Next apply any necessary endorsements.
     $endorsementsManager = new Manager_Insurance_TenantsContentsPlus_Endorsement();
     $endorsements = $endorsementsManager->getEndorsementsRequired($this->_policyNumber);
     if (!empty($endorsements)) {
         foreach ($endorsements as $currentEndorsement) {
             if (!$endorsementsManager->getIsEndorsementAlreadyApplied($currentEndorsement)) {
                 $endorsementsManager->insertEndorsement($currentEndorsement);
             }
         }
     }
     //Next store any extra information provided by the user.
     $additionalInfoProvided = array();
     $infoSubmitted = $pageForm->subform_importantinformation->getElement('declaration1_details')->getValue();
     if (!empty($infoSubmitted)) {
         $additionalInfoProvided[] = $infoSubmitted;
     }
     $infoSubmitted = $pageForm->subform_importantinformation->getElement('declaration3_details')->getValue();
     if (!empty($infoSubmitted)) {
         $additionalInfoProvided[] = $infoSubmitted;
     }
     $infoSubmitted = $pageForm->subform_importantinformation->getElement('declaration4_details')->getValue();
     if (!empty($infoSubmitted)) {
         $additionalInfoProvided[] = $infoSubmitted;
     }
     if (!empty($additionalInfoProvided)) {
         //Compile the extra information, if any, into a single string.
         $compiledInformation = '';
         foreach ($additionalInfoProvided as $currentInformation) {
             if (empty($compiledInformation)) {
                 $compiledInformation = $currentInformation;
             } else {
                 $compiledInformation .= " {$currentInformation}";
             }
         }
         $additionalInformationManager = new Manager_Insurance_AdditionalInformation();
         if (!$additionalInformationManager->getIsAdditionalInformationAlreadyStored($this->_policyNumber)) {
             $additionalInformation = new Model_Insurance_AdditionalInformation();
             $additionalInformation->setPolicyNumber($this->_policyNumber);
             $additionalInformation->setAdditionalInformation($compiledInformation);
             $additionalInformationManager->insertAdditionalInformation($additionalInformation);
         }
     }
     //Update the quote object so that the underwritingQuestionSetID is appropriately set.
     $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
     $quoteManager->setUnderwritingQuestionSetID(2);
     //Previous claims are managed on the fly.
     //Check if a referral is required.
     $referralsManager = new Manager_Insurance_TenantsContentsPlus_Referral();
     if ($referralsManager->getRequiresReferral($this->_policyNumber)) {
         //Display the referred screen.
         $returnVal = false;
         //Update the quote/policy notes.
         $notesManager = new Manager_Core_Notes();
         $notesManager->save($this->_policyNumber, Model_Core_NoteLabels::REFERRED_BY_CUSTOMER);
     }
     return $returnVal;
 }