/**
  * Generates a unique external Enquiry identifer.
  *
  * @return string
  * Returns a unique external Enquiry identifier.
  */
 protected function _buildUniqueIdentifier()
 {
     $select = $this->select();
     $utils = new Application_Core_Utilities();
     while (true) {
         $legacyIdentifier = $utils->_generateRefno();
         $select->where('RefNo = ? ', (string) $legacyIdentifier);
         $row = $this->fetchRow($select);
         if (empty($row)) {
             //A unique identifier has been found.
             break;
         }
     }
     return $legacyIdentifier;
 }
 /**
  * Add a new job vacancy
  *
  */
 public function addNew($jobTitle, $reportingTo, $location, $startDate, $endDate, $description)
 {
     $mysqlStartDate = Application_Core_Utilities::ukDateToMysql($startDate);
     $mysqlEndDate = Application_Core_Utilities::ukDateToMysql($endDate);
     $data = array('title' => $jobTitle, 'reporting_to' => $reportingTo, 'location' => $location, 'start_date' => $mysqlStartDate, 'end_date' => $mysqlEndDate, 'description' => $description);
     return $this->insert($data);
 }
 /**
  * Set options
  *
  * @param array data An array of reference number, guarantor name, house name, street
  * town, city, postcode
  * @return void
  */
 public function insertGuarantors($data, $guarantorId, $referenceNumber)
 {
     $dataArray = array();
     //delete guarantor information before inserting to avoid dupliaction
     $this->removeGuarantors($referenceNumber);
     $totalGuarantors = empty($data['total_guarantors']) ? '0' : $data['total_guarantors'];
     for ($i = 1; $i <= $totalGuarantors; $i++) {
         if ($i <= 4) {
             if (isset($data['guarantor_address_' . $i]) && $data['guarantor_address_' . $i] != '' && $data['guarantor_address_' . $i] != '-') {
                 // Address lookup worked
                 $coreAddressManager = new Manager_Core_Postcode();
                 $guarantorAddress = $coreAddressManager->getPropertyByID($data['guarantor_address_' . $i]);
                 $address_id = $guarantorAddress['id'];
                 $houseName = $guarantorAddress['houseNumber'] != '' ? $guarantorAddress['houseNumber'] : $guarantorAddress['buildingName'];
                 $street = $guarantorAddress['address1'] != '' ? $guarantorAddress['address1'] : $guarantorAddress['address2'];
                 $town = $guarantorAddress['address4'];
                 $city = $guarantorAddress['address5'];
                 $postcode = $guarantorAddress['postcode'];
             } else {
                 // Address lookup failed, hence manual entry
                 $address_id = '-';
                 $houseName = $data['guarantor_housename_' . $i];
                 $street = $data['guarantor_street_' . $i];
                 $town = $data['guarantor_town_' . $i];
                 $city = $data['guarantor_city_' . $i];
                 $postcode = $data['guarantor_postcode_' . $i];
             }
             $dataArray['reference_number'] = $referenceNumber;
             $dataArray['guarantor_name'] = $data['guarantor_name_' . $i];
             $dataArray['hometelno'] = $data['guarantor_hometelno_' . $i];
             $dataArray['worktelno'] = $data['guarantor_worktelno_' . $i];
             $dataArray['mobiletelno'] = $data['guarantor_mobiletelno_' . $i];
             $dataArray['email'] = $data['guarantor_email_' . $i];
             $dataArray['dob'] = Application_Core_Utilities::ukDateToMysql($data['guarantors_dob_' . $i]);
             $dataArray['address_id'] = $address_id;
             $dataArray['house_name'] = $houseName;
             $dataArray['street'] = $street;
             $dataArray['town'] = $town;
             $dataArray['city'] = $city;
             $dataArray['postcode'] = $postcode;
             $dataArray['homeletrefno'] = $data['guarantor_homeletrefno_' . $i];
             if ($guarantorId != '') {
                 $where = $this->getAdapter()->quoteInto('id = ?', $guarantorId);
                 $this->update($data, $where);
             } else {
                 $this->insert($dataArray);
             }
         }
     }
 }
 /**
  * Set options
  *
  * @param array data An array of reference number, tenant name, house name, street
  * town, city, postcode
  * @return void
  */
 public function insertTenants($data, $referenceNumber)
 {
     $dataArray = array();
     // remove tenants inserted before
     $this->removeTenants($referenceNumber);
     //get guaranor address from already existing postocde address table
     $totalTenants = empty($data['total_tenants']) ? '0' : $data['total_tenants'];
     for ($i = 1; $i <= $totalTenants; $i++) {
         if ($i <= 7) {
             $tenantDOB = Application_Core_Utilities::ukDateToMysql($data['tenants_dob_' . $i]);
             $dataArray['reference_number'] = $referenceNumber;
             $dataArray['tenant_name'] = $data['tenant_name_' . $i];
             $dataArray['tenant_hometelno'] = $data['tenant_hometelno_' . $i];
             $dataArray['tenant_worktelno'] = $data['tenant_worktelno_' . $i];
             $dataArray['tenant_mobiletelno'] = $data['tenant_mobiletelno_' . $i];
             $dataArray['tenant_email'] = $data['tenant_email_' . $i];
             $dataArray['tenant_dob'] = $tenantDOB;
             $dataArray['rg_policy_ref'] = $data['rg_policy_ref_' . $i];
             $this->insert($dataArray);
         }
     }
 }
 /**
  * @param mixed array $data
  */
 private function _update($data)
 {
     if (isset($dataToSave['date_established'])) {
         $dataToSave['date_established'] = Application_Core_Utilities::ukDateToMysql($data['date_established']);
     }
     $dataToSave = array_diff_key($data, array('id' => ""));
     $where = $this->quoteInto('uid = ?', $dataToSave['uid']);
     $this->update($dataToSave, $where);
     return $data['id'];
 }
 /**
  * Private function to handle form population
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     // First of all check that this form should be viewable and the user isn't trying to skip ahead
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     $tooFarAhead = false;
     if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) {
         $tooFarAhead = true;
         $lastCompleted = 1;
     } elseif ($stepNum > 1) {
         // Check to see if any pages previous to the one the user's trying to get to are incomplete
         $tooFarAhead = false;
         for ($i = 1; $i < $stepNum; $i++) {
             if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) {
                 $tooFarAhead = true;
                 $lastCompleted = $i;
                 break;
             }
         }
     }
     if ($tooFarAhead) {
         // Drop user onto page that needs completing
         $this->_helper->redirector->gotoUrl('/portfolio/insurance-quote/step' . $lastCompleted);
         return false;
     }
     // Echo out some debug info if not in production mode
     #Application_Core_Logger::log("Policy Number : " . $this->_policyNumber);
     #Application_Core_Logger::log("Customer Ref No : " . $this->_customerReferenceNumber);
     #Application_Core_Logger::log("Referrer : " . $this->_referrer);
     // Only populate from DB if we are in session and have a reference number
     if (isset($pageSession->CustomerRefNo)) {
         $customerReferenceNumber = $pageSession->CustomerRefNo;
         $policyNumber = $pageSession->PolicyNumber;
         $formData = array();
         // Populate $formData with data from model, if available
         switch ($stepNum) {
             case 1:
                 // Personal Details section
                 $customerManager = new Manager_Insurance_Portfolio_LegacyCustomer();
                 $customer = $customerManager->fetchByRefNo($customerReferenceNumber);
                 $formData['title'] = $customer['title'];
                 $formData['first_name'] = $customer['first_name'];
                 $formData['last_name'] = $customer['last_name'];
                 $formData['phone_number'] = $customer['telephone1'];
                 $formData['mobile_number'] = $customer['telephone2'];
                 $formData['email_address'] = $customer['email_address'];
                 $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($customer['date_of_birth_at']);
                 // Get correspondance Address data
                 // Look up address again to populate dropdown
                 $formData['cor_house_number_name'] = $customer['address1'];
                 // Populate the correspondence address details
                 $formData['cor_address_line1'] = $customer['address1'];
                 $formData['cor_address_line2'] = $customer['address2'];
                 $formData['cor_address_line3'] = $customer['address3'];
                 $formData['cor_address_postcode'] = $customer['postcode'];
                 $formData['cor_postcode'] = $customer['postcode'];
                 $postcodeLookup = new Manager_Core_Postcode();
                 $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['cor_postcode']), $customer['address1']);
                 $addressList = array('' => '--- please select ---');
                 $filterString = is_numeric($formData['cor_house_number_name']) ? $formData['cor_house_number_name'] . ", " : $formData['cor_house_number_name'];
                 foreach ($addresses as $address) {
                     $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                     if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                         $addressID = $address['id'];
                     }
                 }
                 // Add some validation
                 $cor_address = $pageForm->getSubForm('subform_correspondenceaddress')->getElement('cor_address');
                 $cor_address->setMultiOptions($addressList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                 $cor_address->addValidator($validator, true);
                 // Set the address to selected
                 $cor_address->setValue($addressID);
                 // Data Protection section
                 //Extract the DPA values from the session.
                 $dpaManager = new Manager_Core_DataProtection(Manager_Core_DataProtection::USE_SESSION);
                 $dpaItemArray = $dpaManager->getItems(null, Model_Core_DataProtection_ItemEntityTypes::INSURANCE);
                 #Zend_Debug::dump($dpaItemArray);die();
                 foreach ($dpaItemArray as $currentItem) {
                     switch ($currentItem->constraintTypeId) {
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_phone_post'] = 0;
                             } else {
                                 $formData['dpa_phone_post'] = 1;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_sms_email'] = 1;
                             } else {
                                 $formData['dpa_sms_email'] = 0;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_resale'] = 1;
                             } else {
                                 $formData['dpa_resale'] = 0;
                             }
                             break;
                     }
                 }
                 // Initial Disclosure Agreement section
                 // As we have a customer reference number they must have saved step 1 at some point which means
                 // they must have agreed to the IDD section
                 $formData['idd'] = 1;
                 $pageForm->populate($formData);
                 break;
             case 2:
                 // Step needs to retrieve any properties that may have been added to this portfolio quote
                 // This data is NOT form data, just display data since the ajax has added the properties to the
                 // portfolio_properties table
                 $propertyArray = array();
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propNumb = count($propertyArray->toArray());
                 $formData['propNumb'] = count($propertyArray->toArray());
                 $this->view->propertyList = $propertyArray;
                 $this->view->stepNum = 2;
                 $pageForm->populate($formData);
                 break;
             case 3:
                 /*
                   This step display the properties and displays the quote value
                 */
                 $propertyArray = array();
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $this->view->propertyList = $propertyArray;
                 $this->view->stepNum = 3;
                 break;
             case 4:
                 break;
                 /*
                     populates the remove property dialog
                 */
             /*
                 populates the remove property dialog
             */
             case "removePropertyDialog":
                 $request = $this->getRequest();
                 $formData['propertyid'] = $request->getParam('id');
                 $pageForm->populate($formData);
                 break;
             case "editInsuredAddress":
                 $request = $this->getRequest();
                 $formData['propertyid'] = $request->getParam('id');
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObj = $propertyManager->getPropertyById($formData['propertyid']);
                 $formData['ins_house_number_name'] = $propertyObj->houseNumber;
                 $formData['ins_postcode'] = $propertyObj->postcode;
                 // Look up address again to populate dropdown
                 $postcodeLookup = new Manager_Core_Postcode();
                 $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['ins_postcode']));
                 $addressList = array('' => '--- please select ---');
                 $filterString = is_numeric($formData['ins_house_number_name']) ? $formData['ins_house_number_name'] . ", " : $formData['ins_house_number_name'];
                 foreach ($addresses as $address) {
                     $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                     if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                         $addressID = $address['id'];
                     }
                 }
                 // Add some validation
                 $ins_address = $pageForm->getElement('ins_address');
                 $ins_address->setMultiOptions($addressList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                 $ins_address->addValidator($validator, true);
                 // Set the address to selected
                 $ins_address->setValue($addressID);
                 //Zend_Debug::dump($propertyObj);die();
                 // Get Insured Address data
                 // Look up address again to populate dropdown
                 // Populate the correspondence address details
                 $formData['ins_address_line1'] = $propertyObj->address1;
                 $formData['ins_address_line2'] = $propertyObj->address2;
                 $formData['ins_address_line3'] = $propertyObj->address3;
                 $formData['ins_address_postcode'] = $propertyObj->postcode;
                 $formData['employment_status'] = $propertyObj->tenantOccupation;
                 if ($propertyObj->buildingsSumInsured == 0) {
                     $formData['buildings_cover'] = "";
                 } else {
                     $formData['buildings_cover'] = $propertyObj->buildingsSumInsured;
                     $formData['comprehensive_buildings_insurance'] = 1;
                 }
                 if ($propertyObj->buildingsAccidentalDamage == 'Yes') {
                     $formData['buildings_accidental_damage'] = 1;
                 } else {
                     $formData['buildings_accidental_damage'] = 0;
                 }
                 if ($propertyObj->buildingsNilExcess == 'Yes') {
                     $formData['buildings_nil_excess'] = 1;
                 } else {
                     $formData['buildings_nil_excess'] = 0;
                 }
                 if ($propertyObj->contentsSumInsured == 0) {
                     $formData['contents_cover'] = "";
                 } else {
                     $formData['contents_cover'] = $propertyObj->contentsSumInsured;
                     $formData['full_contents_insurance'] = 1;
                 }
                 if ($propertyObj->contentsAccidentalDamage == 'Yes') {
                     $formData['contents_accidental_damage'] = 1;
                 } else {
                     $formData['contents_accidental_damage'] = 0;
                 }
                 if ($propertyObj->contentsNilExcess == 'Yes') {
                     $formData['contents_nil_excess'] = 1;
                 } else {
                     $formData['contents_nil_excess'] = 0;
                 }
                 if ($propertyObj->limitedContents == 'Yes') {
                     $formData['limited_contents'] = 1;
                 } else {
                     $formData['limited_contents'] = 0;
                 }
                 // Populate the form
                 $pageForm->populate($formData);
                 break;
             case "bankInterestDialog":
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propertyArray = $propertyObjects->toArray();
                 $optionList = array('' => '--- please select ---');
                 foreach ($propertyArray as $property) {
                     $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
                 }
                 // Get the subform element for property address that the bank may have interest in
                 $propertyAddressSelect = $pageForm->getSubForm('subform_bank-details-form')->getElement('bank_property');
                 $propertyAddressSelect->setMultiOptions($optionList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Property not in list'));
                 $propertyAddressSelect->addValidator($validator, true);
                 // Set the selected to 0
                 $propertyAddressSelect->setValue('0');
                 // Now fetch any bank interests we have already stored
                 $bankInterestManager = new Manager_Insurance_Portfolio_BankInterest();
                 $this->view->interestList = $bankInterestManager->fetchAllInterests($customerReferenceNumber);
                 $pageForm->populate($formData);
                 break;
             case "additionalDialog":
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propertyArray = $propertyObjects->toArray();
                 $optionList = array('' => '--- please select ---');
                 foreach ($propertyArray as $property) {
                     $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
                 }
                 // Get the subform element for property address that the bank may have interest in
                 $propertyAddressSelect = $pageForm->getElement('property');
                 $propertyAddressSelect->setMultiOptions($optionList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Not in list'));
                 $propertyAddressSelect->addValidator($validator, true);
                 // Set the selected to 0
                 $propertyAddressSelect->setValue('0');
                 // Now fetch any Additionals we have already stored
                 $manager = new Manager_Insurance_Portfolio_AdditionalInformation();
                 $qid = $_GET['qid'];
                 $array = $manager->fetchAllByRefNo($customerReferenceNumber, $qid);
                 $this->view->additionalList = $array;
                 $pageForm->populate($formData);
                 break;
             case "claimsDialog":
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propertyArray = $propertyObjects->toArray();
                 $optionList = array('' => '--- please select ---');
                 foreach ($propertyArray as $property) {
                     $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
                 }
                 // Get the form element for property address
                 $propertyAddressSelect = $pageForm->getSubForm('subform_previous-claims-form')->getElement('claim_property');
                 $propertyAddressSelect->setMultiOptions($optionList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Not in list'));
                 $propertyAddressSelect->addValidator($validator, true);
                 // Set the selected to 0
                 $propertyAddressSelect->setValue('0');
                 $claimTypeList = array('' => '--- please select ---');
                 $claimTypesSelect = $pageForm->getSubForm('subform_previous-claims-form')->getElement('claim_type');
                 $claimTypes = new Datasource_Insurance_PreviousClaimTypes();
                 $claimTypeObjects = $claimTypes->getPreviousClaimTypes(Model_Insurance_ProductNames::LANDLORDSPLUS);
                 foreach ($claimTypeObjects as $ClaimType) {
                     $claimTypeList[$ClaimType->getClaimTypeID()] = $ClaimType->getClaimTypeText();
                 }
                 $claimTypesSelect->setMultiOptions($claimTypeList);
                 $pageForm->populate($formData);
                 // Now fetch any claims we have already stored
                 $claimsManager = new Manager_Insurance_Portfolio_PreviousClaims();
                 //$array = $claimsManager->fetchAllClaims($customerReferenceNumber);
                 $this->view->claimsList = $claimsManager->fetchAllClaims($customerReferenceNumber);
                 $pageForm->populate($formData);
                 break;
         }
     }
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     $tooFarAhead = false;
     return true;
 }
Exemple #7
0
 /**
  * Updates a claim.
  *
  * @param array
  *
  * @return void
  */
 public function updateClaim($claim)
 {
     // These dates are not mandatory
     $tenancyEndDate = $claim->getTenancyEndDate() ? Application_Core_Utilities::ukDateToMysql($claim->getTenancyEndDate()) : null;
     $tenantVacatedDate = $claim->getTenantVacatedDate() ? Application_Core_Utilities::ukDateToMysql($claim->getTenantVacatedDate()) : null;
     $confirmedByTelDate = $claim->getTenantsOccupationOfPropertyConfirmedByTelDate() ? Application_Core_Utilities::ukDateToMysql($claim->getTenantsOccupationOfPropertyConfirmedByTelDate()) : null;
     $confirmedByEmailDate = $claim->getTenantsOccupationOfPropertyConfirmedByEmailDate() ? Application_Core_Utilities::ukDateToMysql($claim->getTenantsOccupationOfPropertyConfirmedByEmailDate()) : null;
     $confirmedByVisitDate = $claim->getTenantsOccupationOfPropertyConfirmedByVisitDate() ? Application_Core_Utilities::ukDateToMysql($claim->getTenantsOccupationOfPropertyConfirmedByVisitDate()) : null;
     $s21NoticeExpiryDate = $claim->getS21NoticeExpiry() ? Application_Core_Utilities::ukDateToMysql($claim->getS21NoticeExpiry()) : null;
     $s8NoticeExpiryDate = $claim->getS8NoticeExpiry() ? Application_Core_Utilities::ukDateToMysql($claim->getS8NoticeExpiry()) : null;
     $data = array('last_updated_date' => date('Y-m-d'), 'agent_name' => $claim->getAgentName(), 'agent_contact_name' => $claim->getAgentContactName(), 'agent_postcode' => $claim->getAgentPostcode(), 'agent_housename' => $claim->getAgentHousename(), 'agent_street' => $claim->getAgentStreet(), 'agent_town' => $claim->getAgentTown(), 'agent_city' => $claim->getAgentCity(), 'agent_telephone' => $claim->getAgentTelephone(), 'agent_fax' => $claim->getAgentFax(), 'agent_email' => $claim->getAgentEmail(), 'agent_isar' => $claim->getIsAr(), 'agent_isdir' => $claim->getIsDir(), 'housing_act_adherence' => $claim->getHousingActAdherence(), 'tenancy_start_date' => Application_Core_Utilities::ukDateToMysql($claim->getTenancyStartDate()), 'tenancy_renewal_date' => $tenancyEndDate, 'original_cover_start_date' => Application_Core_Utilities::ukDateToMysql($claim->getOriginalCoverStartDate()), 'tenancy_address_id' => $claim->getTenancyAddressId(), 'tenancy_postcode' => $claim->getTenancyPostcode(), 'tenancy_housename' => $claim->getTenancyHouseName(), 'tenancy_street' => $claim->getTenancyStreet(), 'tenancy_town' => $claim->getTenancyTown(), 'tenancy_city' => $claim->getTenancyCity(), 'monthly_rent' => $claim->getMonthlyRent(), 'deposit_amount' => $claim->getDepositAmount(), 'rent_arrears' => $claim->getRentArrears() ? $claim->getRentArrears() : NULL, 'tenant_vacated_date' => $tenantVacatedDate, 'first_arrear_date' => $claim->getFirstArrearDate() ? Application_Core_Utilities::ukDateToMysql($claim->getFirstArrearDate()) : NULL, 'deposit_received_date' => Application_Core_Utilities::ukDateToMysql($claim->getDepositReceivedDate()), 'landlord1_name' => $claim->getLandlord1Name(), 'landlord_company_name' => $claim->getLandlordCompanyName(), 'landlord_address_id' => $claim->getLandlordAddressId(), 'landlord_postcode' => $claim->getLandlordPostcode(), 'landlord_housename' => $claim->getLandlordHouseName(), 'landlord_street' => $claim->getLandlordStreet(), 'landlord_town' => $claim->getLandlordTown(), 'landlord_city' => $claim->getLandlordCity(), 'landlord_telephone' => $claim->getLandlordTelephone(), 'landlord_fax' => $claim->getLandlordFax(), 'landlord_email' => $claim->getLandlordEmail(), 'cheque_payable_to' => $claim->getChequePayableTo(), 'additional_information' => $claim->getAdditionalInfo(), 'doc_confirmation_agent_name' => $claim->getDocConfirmationAgentName(), 'submitted_to_keyhouse' => $claim->getSubmittedToKeyHouse(), 'housing_benefit_applied' => $claim->getHousingBenefitApplied(), 'data_complete' => $claim->getDataComplete(), 'tenant_vacated' => $claim->getTenantVacated(), 'recent_complaints' => $claim->getRecentComplaints(), 'recent_complaints_further_details' => $claim->getRecentComplaintsDetails(), 'policy_number' => $claim->getPolicyNumber(), 'grounds_for_claim' => $claim->getGroundsForClaim(), 'grounds_for_claim_further_details' => $claim->getGroundsForClaimDetails(), 'arrears_at_vacant_possession' => $claim->getArrearsAtVacantPossession(), 'tenant_occupation_confirmed_by_tel' => $claim->getTenantsOccupationOfPropertyConfirmedByTel(), 'tenant_occupation_confirmed_by_tel_dateofcontact' => $confirmedByTelDate, 'tenant_occupation_confirmed_by_tel_tenantname' => $claim->getTenantsOccupationOfPropertyConfirmedByTelContact(), 'tenant_occupation_confirmed_by_email' => $claim->getTenantsOccupationOfPropertyConfirmedByEmail(), 'tenant_occupation_confirmed_by_email_dateofcontact' => $confirmedByEmailDate, 'tenant_occupation_confirmed_by_email_tenantname' => $claim->getTenantsOccupationOfPropertyConfirmedByEmailContact(), 'tenant_occupation_confirmed_by_visit' => $claim->getTenantsOccupationOfPropertyConfirmedByVisit(), 'tenant_occupation_confirmed_by_visit_dateofvisit' => $confirmedByVisitDate, 'tenant_occupation_confirmed_by_visit_individualattending' => $claim->getTenantsOccupationOfPropertyConfirmedByVisitIndividual(), 'tenant_occupation_confirmed_by_visit_tenantname' => $claim->getTenantsOccupationOfPropertyConfirmedByVisitContact(), 'tenantsforwarding_address_id' => $claim->getTenantsForwardingAddressId(), 'tenantsforwarding_housename' => $claim->getTenantsForwardingHouseName(), 'tenantsforwarding_street' => $claim->getTenantsForwardingStreet(), 'tenantsforwarding_town' => $claim->getTenantsForwardingTown(), 'tenantsforwarding_city' => $claim->getTenantsForwardingCity(), 'tenantsforwarding_postcode' => $claim->getTenantsForwardingPostcode(), 'section21_served' => $claim->getS21NoticeServed(), 'section21_expiry' => $s21NoticeExpiryDate, 'section21_moneydepositreceived' => $claim->getS21NoticeMoneyDepositReceived(), 'section21_money_held_under_tds_deposit_scheme' => $claim->getS21NoticeMoneyDepositHeldUnderTdsScheme(), 'section21_tds_complied_with' => $claim->getS21NoticeTdsCompliedWith(), 'section21_tds_prescribed_information_to_tenant' => $claim->getS21NoticeTdsPrescribedToTenant(), 'section21_landlord_deposit_in_property_form' => $claim->getS21NoticeLandlordDepositInPropertyForm(), 'section21_returned_at_notice_serve_date' => $claim->getS21NoticePropertyReturnedAtNoticeServeDate(), 'section8_served' => $claim->getS8NoticeServed(), 'section8_expiry' => $s8NoticeExpiryDate, 'section8_demand_letter_sent' => $claim->getS8NoticeDemandLetterSent(), 'section8_over18_occupants' => $claim->getS8NoticeOver18Occupants(), 'payment_account_name' => $claim->getClaimPaymentBankAccountName(), 'payment_account_number' => $claim->getClaimPaymentBankAccountNumber(), 'payment_account_sortcode' => $claim->getClaimPaymentBankAccountSortCode(), 'landlord_property_proprietor' => $claim->getLandlordIsPropertyProprietor(), 'authority_confirmed' => $claim->getAuthorityConfirmed(), 'dec_confirmed' => $claim->getDeclarationConfirmed());
     $where = $this->getAdapter()->quoteInto('reference_number = ?', $claim->_referenceNumber);
     $this->update($data, $where);
 }
Exemple #8
0
 public function getArchiveArticles($month, $year)
 {
     $params = Zend_Registry::get('params');
     $select = $this->select();
     $select->where('date >= ?', date('Y-m-d', strtotime($year . '-' . $month . '-01')));
     $select->where('date < ?', date('Y-m-d', strtotime($year . '-' . $month . '-01 + 1 month')));
     $rows = $this->fetchAll($select);
     $articleArray = $rows->toArray();
     $returnArray = array();
     $stripTags = new Zend_Filter_StripTags(array('br'));
     foreach ($articleArray as $article) {
         array_push($returnArray, array('id' => $article['id'], 'title' => $article['title'], 'summary' => $stripTags->filter(Application_Core_Utilities::word_split($article['content'], $params->cms->newsSummaryWordLimit)) . ' &hellip;', 'content' => $article['content'], 'niceDate' => date('M jS, Y', strtotime($article['date'])), 'date' => $article['date']));
     }
     return $returnArray;
 }
 /**
  * Retrieve TCI+ or LI+ quote.
  */
 public function retrieveQuoteAction()
 {
     $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/retrieve-quote' => 'Retrieve Quote'));
     $params = Zend_Registry::get('params');
     $form = new Account_Form_RetrieveQuote();
     $quoteManager = new Manager_Insurance_LegacyQuote();
     $customerManager = new Manager_Core_Customer();
     // If there's a quote number in the GET vars then sanitise and uppercase it, and place it in the form
     if (isset($_GET['number'])) {
         // Sanitise and uppercase supplied quote number, place in form
         $quoteNumber = strtoupper(preg_replace('/[^\\w\\/]/', '', $_GET['number']));
         $form->quote_number->setValue($quoteNumber);
         // Also pre-populate the form with first name and last name if the quote number is valid
         $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
         if ($quote) {
             // Get customer details from quote refNo
             $quoteRefNo = $quote->refNo;
             $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
             if ($customer) {
                 $form->first_name->setValue($customer->getFirstName());
                 $form->last_name->setValue($customer->getLastName());
             }
         }
     }
     // Get email address, place in form if it looks valid
     if (isset($_GET['email'])) {
         $getEmail = $_GET['email'];
         $emailValidator = new Zend_Validate_EmailAddress();
         if ($emailValidator->isValid($getEmail)) {
             $form->email->setValue($getEmail);
         }
     }
     $request = $this->getRequest();
     $postData = $request->getPost();
     // Handle retrieve attempts
     if ($request->isPost()) {
         if ($form->isValid($postData)) {
             // Are we looking up by quote number or by e-mail address?  If a quote number is present it takes
             // precedence
             $quotes = array();
             $customer = null;
             $quoteNumber = $form->quote_number->getValue();
             $email = $form->email->getValue();
             if ('' != $quoteNumber) {
                 $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
                 if ($quote) {
                     // Look up customer from quote retrieved
                     $quoteRefNo = $quote->refNo;
                     $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
                     $quotes = array($quote);
                 }
             } else {
                 // Get all legacy quote IDs by customer e-mail address
                 $legacyIDs = array();
                 // Try to look up a customer record's quotes' IDs by the e-mail provided
                 $newCustomer = $customerManager->getCustomerByEmailAddress($email);
                 if ($newCustomer) {
                     $legacyCustomerMap = new Datasource_Core_CustomerMaps();
                     $legacyIDs = $legacyCustomerMap->getLegacyIDs($newCustomer->getIdentifier(Model_Core_Customer::IDENTIFIER));
                 }
                 // Also check in the legacy DB only to ensure landlords quotes are found
                 $customer = $customerManager->getLegacyCustomerByEmailAddress($email);
                 if ($customer) {
                     $legacyCustomerId = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                     if (!in_array($legacyCustomerId, $legacyIDs)) {
                         $legacyIDs[] = $legacyCustomerId;
                     }
                 }
                 // Retrieve all quotes for the linked customer reference numbers
                 $quoteDatasource = new Datasource_Insurance_LegacyQuotes();
                 $quotes = $quoteDatasource->getActiveQuotes($legacyIDs, '', array('policynumber', 'startdate'));
             }
             // Do we have at least one quote and the customer details
             if (count($quotes) > 0 && $customer) {
                 // Check that the security requirements are met (matching email, first name, last name, postcode and
                 // DOB)
                 if (trim($customer->getEmailAddress()) == trim($form->email->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getFirstName(), $form->first_name->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getLastName(), $form->last_name->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getPostCode(), $form->cor_postcode->getValue()) && Application_Core_Utilities::mysqlDateToUk($customer->getDateOfBirthAt()) == trim($form->date_of_birth_at->getValue())) {
                     // If this is a single quote then generate an auth token and bounce them on
                     if (count($quotes) == 1) {
                         // Ensure there's a quote number to use in the security token (because there won't be one if
                         // it was a single match based only on an e-mail address)
                         if ('' == $quoteNumber) {
                             $quoteNumber = $quotes[0]->policyNumber;
                         }
                         // Generate an authentication token for a single policy
                         $securityManager = new Application_Core_Security($params->myhomelet->retrieveWithoutAccount->macSecret, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
                         $securityData = array('quoteNumber' => $quoteNumber);
                         $authToken = $securityManager->generate($securityData);
                         // Bounce to the right Q&B depending on quote type
                         if ($quotes[0]->getProductName() == 'tenants') {
                             $this->_helper->redirector->gotoUrl('/tenants/insurance-quote/retrieve?auth=' . $authToken);
                             return;
                         } elseif ($quotes[0]->getProductName() == 'landlords') {
                             $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/retrieve?auth=' . $authToken);
                             return;
                         } else {
                             $form->setDescription('Sorry, we don\'t yet allow resuming the type of quote you have - please call us.');
                         }
                     } else {
                         // Generate an authentication token for the customer email
                         $securityManager = new Application_Core_Security($params->myhomelet->retrieveWithoutAccount->macSecret, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
                         $securityData = array('customerEmail' => $email);
                         $authToken = $securityManager->generate($securityData);
                         $this->_helper->redirector->gotoUrl('/my-homelet/retrieve-multiple-quotes?auth=' . $authToken);
                         return;
                     }
                 } else {
                     // Security check failed, show error
                     $form->setDescription('Sorry, we could not find your quote from the details provided - please check them and try again.');
                 }
             } else {
                 // Lookup failed, show error
                 $form->setDescription('Sorry, we could not find your quote from the details provided - please check them and try again.');
             }
         }
     }
     $this->view->form = $form;
 }
 /**
  * Helper function to populate the zend form elements with database data
  *
  * @param Zend_Form $pageForm form definition for this step
  * @param int $stepNum current step number
  *
  * @return void
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
     // First of all check that this form should be viewable and the user isn't trying to skip ahead
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     // Check to see if the user is trying to skip ahead in the quote
     $tooFarAhead = false;
     if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) {
         $tooFarAhead = true;
         $lastCompleted = 1;
     } elseif ($stepNum > 1) {
         // Check to see if any pages previous to the one the user's trying to get to are incomplete
         $tooFarAhead = false;
         for ($i = 1; $i < $stepNum; $i++) {
             if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) {
                 $tooFarAhead = true;
                 $lastCompleted = $i;
                 break;
                 break;
             }
         }
     }
     if ($tooFarAhead) {
         // Drop user onto page that needs completing
         $this->_helper->redirector->gotoUrl('/tenants/insurance-quote-b/step' . $lastCompleted);
         return false;
     }
     // Now check to see if they need to login (using an existing email address without being logged in)
     if ($stepNum > 1) {
         // Before we do ANYTHING we need to check to see if the email address entered matches a customer record
         // we already have - if it does we need to ask them to login before they proceed.
         $customerReferenceNumber = $pageSession->CustomerRefNo;
         $customerManager = new Manager_Core_Customer();
         $legacyCustomer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerReferenceNumber);
         $emailAddress = $legacyCustomer->getEmailAddress();
         $customer = $customerManager->getCustomerByEmailAddress($emailAddress);
         if ($customer) {
             // There is already a customer entry for this email address - so we need to see if they are logged in
             // if not we need to force them to login
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             /*if ($auth->hasIdentity()) {
             					$loggedInEmail = $auth->getStorage()->read()->email_address;
             					if ($loggedInEmail != $customer->getEmailAddress()) {
             						// They are logged in but not who they should be to do this quote
             						$this->_helper->redirector->gotoUrl('/account/login?refer=tenants-insurance&step='. $stepNum);
             
             						return false;
             					}
             				} else {
             					// They aren't logged in and need to
             					$this->_helper->redirector->gotoUrl('/account/login?refer=tenants-insurance&step='. $stepNum);
             
             					return false;
             				}*/
         }
     }
     // Echo out some debug info if not in production mode
     Application_Core_Logger::log("Policy Number : " . $this->_policyNumber);
     Application_Core_Logger::log("Customer Ref No : " . $this->_customerReferenceNumber);
     Application_Core_Logger::log("agentSchemeNumber : " . $this->_agentSchemeNumber);
     $formData = array();
     // If step 1 and not in session (so producing a quick quote) - we need to pre-populate
     // a few bits if the customer is already logged into the site
     if ($stepNum == 1 && !isset($pageSession->CustomerRefNo)) {
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
         if ($auth->hasIdentity()) {
             // Customer is logged in and starting a new quote - so we need to pre-populate the customers details from stored details
             $customerID = $auth->getStorage()->read()->id;
             $customerManager = new Manager_Core_Customer();
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             // Get the customer's legacy record too as DoB is only in the old system
             $legacyCustomer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerID);
             $formData['title'] = $customer->getTitle();
             $formData['first_name'] = $customer->getFirstName();
             $formData['last_name'] = $customer->getLastName();
             $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
             $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
             $formData['email_address'] = $customer->getEmailAddress();
             // Fetch DoB from old customer manager
             $formData['date_of_birth_at'] = $legacyCustomer->getDateOfBirth();
             $pageForm->populate($formData);
         }
     }
     // Only populate from DB if we are in session and have a reference number
     if (isset($pageSession->CustomerRefNo)) {
         $customerReferenceNumber = $pageSession->CustomerRefNo;
         $policyNumber = $pageSession->PolicyNumber;
         // Populate $formData with data from model, if available
         switch ($stepNum) {
             case 1:
                 // Personal Details section
                 $customerManager = new Manager_Core_Customer();
                 $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerReferenceNumber);
                 $titleOptions = TenantsInsuranceQuoteB_Form_Subforms_PersonalDetails::$titles;
                 if (in_array($customer->getTitle(), $titleOptions)) {
                     $formData['title'] = $customer->getTitle();
                 } else {
                     $formData['title'] = "Other";
                     $formData['other_title'] = $customer->getTitle();
                 }
                 $formData['first_name'] = $customer->getFirstName();
                 $formData['last_name'] = $customer->getLastName();
                 $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
                 $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
                 $formData['email_address'] = $customer->getEmailAddress();
                 $dob = $customer->getDateOfBirthAt();
                 if (null != $dob && '0000-00-00' != $dob) {
                     $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($dob);
                 }
                 // Data Protection section
                 $dpaManager = new Manager_Core_DataProtection();
                 $dpaItems = $dpaManager->getItems($customerReferenceNumber, Model_Core_DataProtection_ItemEntityTypes::INSURANCE);
                 foreach ($dpaItems as $currentItem) {
                     switch ($currentItem->constraintTypeId) {
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_phone_post'] = 0;
                             } else {
                                 $formData['dpa_phone_post'] = 1;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_sms_email'] = 0;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             } else {
                                 $formData['dpa_sms_email'] = 1;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_resale'] = 1;
                             } else {
                                 $formData['dpa_resale'] = 0;
                             }
                             break;
                     }
                 }
                 // Contents Insurance section
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 // If we've retrieved this quote we need to setup some session variables to match the quote (agent scheme number mostly)
                 $session = new Zend_Session_Namespace('homelet_global');
                 $session->agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
                 $contentsSI = $quoteManager->getCoverAmount(Manager_Insurance_TenantsContentsPlus_Quote::CONTENTS);
                 // TODO: Remove the hard-coded contents insured splits - should be loaded from DB
                 if ($contentsSI == '5000' || $contentsSI == '7500' || $contentsSI == '10000' || $contentsSI == '15000') {
                     $formData['contents_cover_a'] = $contentsSI;
                 } else {
                     $formData['contents_cover_a'] = '15000+';
                     $formData['contents_cover_b'] = $contentsSI;
                 }
                 // Shares section
                 $sharersManager = new Manager_Insurance_TenantsContentsPlus_Sharers();
                 $existingSharers = $sharersManager->getSharers($policyNumber);
                 $formData['policy_sharers'] = 0;
                 if ($existingSharers) {
                     if ($existingSharers->getSharerOccupation(1) != '') {
                         $formData['policy_sharers'] = 1;
                         $formData['policy_sharer1_occupation'] = $existingSharers->getSharerOccupation(1);
                     }
                     if ($existingSharers->getSharerOccupation(2) != '') {
                         $formData['policy_sharers'] = 2;
                         $formData['policy_sharer2_occupation'] = $existingSharers->getSharerOccupation(2);
                     }
                 }
                 for ($i = 1; $i <= $pageForm->maxSharers; $i++) {
                     $formData["policy_sharer{$i}_occupation"] = $existingSharers->getSharerOccupation($i);
                 }
                 // Decide max number of sharers allowed based on contents insured value
                 $contentsAmount = new Zend_Currency(array('value' => $contentsSI, 'precision' => 0));
                 $sharersAllowed = $sharersManager->getNoOfSharersAllowed($contentsAmount);
                 // Push this into Javascript on the page
                 $this->view->headScript()->appendScript("var sharersAllowed = {$sharersAllowed};");
                 // Initial Disclosure Agreement section
                 // As we have a customer reference number they must have saved step 1 at some point which means
                 // they must have agreed to the IDD section
                 $formData['idd'] = 1;
                 break;
             case 2:
                 // Unspecified Possessions section
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 $unspecSI = $quoteManager->getCoverAmount(Manager_Insurance_TenantsContentsPlus_Quote::UNSPECIFIEDPOSSESSIONS);
                 // If step has been completed before we can assume some defaults that we'll over-write later
                 if (isset($pageSession->completed[2]) && $pageSession->completed[2] == true or $quoteManager->getPropertyPostcode() != '') {
                     $formData['away_from_home'] = 'no';
                     $formData['above_x'] = 'no';
                     $formData['bicycle'] = 'no';
                 }
                 // TODO: Re-factor this so that it doesn't use hardcoded pricing breaks anymore
                 if ($unspecSI > 0) {
                     $formData['away_from_home'] = 'yes';
                     $formData['possessions_cover'] = $unspecSI;
                 }
                 //TODO: This should be talking to the quote manager NOT directly to the datasource
                 $possessions = new Datasource_Insurance_Policy_SpecPossessions($pageSession->PolicyNumber);
                 if ($possessions->countPossessions() > 0) {
                     $formData['above_x'] = 'yes';
                 }
                 // Bicycle section
                 //TODO: This should be talking to the quote manager NOT directly to the datasource
                 $bicycle = new Datasource_Insurance_Policy_Cycles($this->_customerReferenceNumber, $this->_policyNumber);
                 if ($bicycle->countBikes() > 0) {
                     $formData['bicycle'] = 'yes';
                 }
                 break;
             case 3:
                 // Insured Address section
                 // Fetch previously stored address
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 $addressArray = $quoteManager->getPropertyAddress();
                 if ($addressArray['postcode'] != '') {
                     if (strpos($addressArray['address1'], ',') !== false) {
                         $formData['ins_house_number_name'] = preg_replace('/,.*$/', '', $addressArray['address1']);
                     } else {
                         $formData['ins_house_number_name'] = preg_replace('/ .*$/', '', $addressArray['address1']);
                     }
                     $formData['ins_postcode'] = $addressArray['postcode'];
                     // Look up address again to populate dropdown
                     $postcodeLookup = new Manager_Core_Postcode();
                     $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['ins_postcode']));
                     $addressList = array('' => '--- please select ---');
                     $filterString = is_numeric($formData['ins_house_number_name']) ? $formData['ins_house_number_name'] . ", " : $formData['ins_house_number_name'];
                     foreach ($addresses as $address) {
                         $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                         if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                             $addressID = $address['id'];
                         }
                     }
                     // Add some validation
                     $ins_address = $pageForm->getSubForm('subform_insuredaddress')->getElement('ins_address');
                     $ins_address->setMultiOptions($addressList);
                     $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                     $ins_address->addValidator($validator, true);
                     // Set the address to selected
                     $ins_address->setValue($addressID);
                     $addressID = null;
                     // Make sure we don't use this again for the correspondance address!
                     // Upsell Message section
                     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
                     $session = new Zend_Session_Namespace('homelet_global');
                     $agentSchemeNumber = $session->agentSchemeNumber;
                 }
                 // Correspondance Address section
                 $customerManager = new Manager_Core_Customer();
                 $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber);
                 $addressLine1 = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1);
                 $addressPostcode = $customer->getPostCode();
                 if ($addressPostcode != '') {
                     if (strpos($addressLine1, ',') !== false) {
                         $formData['cor_house_number_name'] = preg_replace('/,.*$/', '', $addressLine1);
                     } else {
                         $formData['cor_house_number_name'] = preg_replace('/ .*$/', '', $addressLine1);
                     }
                     $formData['cor_postcode'] = $addressPostcode;
                     // TODO: Surely if this postcode and house number matches the previous one
                     // we can just tick the YES box and hide the correspondance address form??
                     $postcodeLookup = new Manager_Core_Postcode();
                     $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['cor_postcode']));
                     $addressList = array('' => '--- please select ---');
                     $filterString = is_numeric($formData['cor_house_number_name']) ? $formData['cor_house_number_name'] . ", " : $formData['cor_house_number_name'];
                     foreach ($addresses as $address) {
                         $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                         if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                             $addressID = $address['id'];
                         }
                     }
                     $cor_address = $pageForm->getSubForm('subform_correspondencedetails')->getElement('cor_address');
                     $cor_address->setMultiOptions($addressList);
                     $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                     $cor_address->addValidator($validator, true);
                     $cor_address->setValue($addressID);
                 }
                 if ($addressPostcode != '' && $addressArray['postcode'] != '') {
                     if ($cor_address->getValue() == $ins_address->getValue()) {
                         $formData['cor_same_address'] = 'yes';
                     } else {
                         $formData['cor_same_address'] = 'no';
                     }
                 }
                 // Letting Agent section
                 // If the agent scheme number is not our default one - load the agent details
                 $params = Zend_Registry::get('params');
                 $agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
                 // How did you hear about us section
                 $marketQuestion = new Manager_Core_ManagementInformation();
                 $formData['how_hear'] = $marketQuestion->getMarketingAnswers($this->_policyNumber);
                 //Campaign code section
                 $webLeadManager = new Manager_Core_WebLead();
                 $webLeadSummary = $webLeadManager->getSummary($this->_webLeadSummaryId);
                 $formData['campaign_code'] = $webLeadSummary->promotionCode;
                 // Start and end date
                 $startDate = $quoteManager->getStartDate();
                 if ($startDate != '' && $startDate != '0000-00-00') {
                     $formData['policy_start'] = substr($startDate, 8, 2) . '/' . substr($startDate, 5, 2) . '/' . substr($startDate, 0, 4);
                 }
                 break;
             case 4:
                 // Important Information section
                 // If this page has previously passed validation, we know what the answers
                 //   given must have been without hitting the DB (as anything else refers)
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum]) {
                     $formData['declaration1'] = 'no';
                     $formData['declaration2'] = 'no';
                     $formData['declaration3'] = 'no';
                     $formData['declaration4'] = 'no';
                     $formData['declaration_confirmation'] = 'yes';
                     // If the step is completed we can also assume they said yes to the declaration agreement
                     $formData['declaration_statement'] = 1;
                 }
                 break;
             case 5:
                 // Not sure if we should really be loading payment methods back in
                 // surely it would be best to just let them choose again
                 break;
             case 'dd':
                 $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
                 $this->view->payMonthly = strtolower($quoteManager->getPayBy()) == 'monthly';
                 break;
         }
         $pageForm->populate($formData);
         // Populate the quick quote box
         $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
         $premiums = $quoteManager->calculatePremiums();
         $fees = $quoteManager->getFees();
         $this->view->premiums = $premiums;
         $this->view->fees = $fees;
     } else {
         // Not in session but there are some defaults we need to set for step 1
         // TODO: Write the javascript better so we don't need to do fudges like this
         $this->view->headScript()->appendScript("var sharersAllowed = 0;");
     }
     return true;
 }
 /**
  * Set options
  *
  * @param array data An array of rent payment id, reference number, date due, amount due
  * amount paid, date paid & arrear amount
  * @return void
  */
 public function updateRentalPayments($data)
 {
     $dataArray = array();
     foreach ($data->updateRecords as $updatePayment) {
         $dateDue = Application_Core_Utilities::ukDateToMysql($updatePayment->date_due);
         if (strtoupper($updatePayment->date_paid) === self::DATE_PAID_NOT_APPLICABLE) {
             $datePaid = '';
         } else {
             $datePaid = Application_Core_Utilities::ukDateToMysql($updatePayment->date_paid);
         }
         $dataArray['id'] = $updatePayment->id;
         $dataArray['reference_number'] = $updatePayment->reference_number;
         $dataArray['date_due'] = $dateDue;
         $dataArray['amount_due'] = $updatePayment->amount_due;
         $dataArray['amount_paid'] = $updatePayment->amount_paid;
         $dataArray['date_paid'] = $datePaid;
         $where = $this->getAdapter()->quoteInto('id = ?', $dataArray['id'] . 'AND' . 'reference_number = ?', $dataArray['reference_number']);
         $this->update($dataArray, $where);
     }
     return true;
 }
 /**
  * Creates a new customer in both the DataStore and the LegacyDataStore,
  * and returns an object representation of this. The object will encapsulate both
  * the customer identifier, and the legacy customer identifier.
  * 
  * @param string $emailAddress
  * The customer's email address. No validation checking is performed on this,
  * other than to check for a non-empty string.
  *
  * @param integer $customerType
  * Indicates the customer type, typically a tenant, landlord or agent. Must
  * correspond to a relevant const exposed by the Model_Core_Customer
  * class: AGENT, LANDLORD or TENANT.
  *
  * @param boolean $legacyOnly
  * If this is set to true then the customer record is only created in the legacy system!
  *
  * @return Model_Core_Customer
  * Returns a Customer object encapsulating the customer details.
  *
  * @throws Zend_Exception
  * Throws a Zend_Exception if parameters are missing, or if the $customerType
  * is invalid.
  *
  * @todo
  * Email the customer to let them know an account has been created and tell
  * them there randomly generated password. Not sure if we need to get email
  * content written by compliance or marketing?
  */
 public function createNewCustomer($emailAddress, $customerType, $legacyOnly = false)
 {
     //Validate the data passed in.
     if (empty($emailAddress) || empty($customerType)) {
         throw new Zend_Exception('Required parameters missing');
     }
     switch ($customerType) {
         case Model_Core_Customer::AGENT:
         case Model_Core_Customer::CUSTOMER:
             //All is well.
             break;
         default:
             throw new Zend_Exception('Invalid customer type specified.');
     }
     //Save the customer into the DataStore and LegacyDataStore. To do this
     //first obtain the email address, password, customer type (tenant, landlord,
     //agent) and an unused legacy identifier (customerRefno).
     $passwordUtil = new Application_Core_Password();
     $password = $passwordUtil->generate();
     $utils = new Application_Core_Utilities();
     while (true) {
         $legacyIdentifier = $utils->_generateRefno();
         if ($this->_legacyCustomerModel->getConfirmCustomerExists($legacyIdentifier)) {
             continue;
         }
         //A unique identifier has been found.
         break;
     }
     //And create:
     $this->_legacyCustomerModel->insertCustomer($emailAddress, $password, $legacyIdentifier);
     if (!$legacyOnly) {
         $identifier = $this->_customerModel->insertCustomer($emailAddress, $password, $customerType);
         //Next link the LegacyDataStore and the DataStore.
         $customerMap = new Datasource_Core_CustomerMaps();
         $customerMap->insertMap($legacyIdentifier, $identifier);
     }
     //Finally, encapsulate the customer details in a Model_Insurance_Common_Customer_DomainObjects_Customer
     //object and return.
     $customer = new Model_Core_Customer();
     if (!$legacyOnly) {
         $customer->setIdentifier(Model_Core_Customer::IDENTIFIER, $identifier);
     }
     $customer->setIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER, $legacyIdentifier);
     $customer->setEmailAddress($emailAddress);
     $customer->setPassword($password);
     return $customer;
 }
 /**
  * Get all testimonials that match any entry in a list of tags
  *
  * @param int testimonialID
  * @return array
  */
 public function getByTags($tagsArray)
 {
     $select = $this->select();
     $select->setIntegrityCheck(false);
     $select->from(array('t' => 'testimonials'), array('id', 'person', 'quote'));
     $select->joinInner(array('ttm' => 'testimonial_tags_map'), 'ttm.testimonial_id = t.id', array());
     $select->joinInner(array('tt' => 'testimonial_tags'), 'tt.id = ttm.testimonial_tag_id', array());
     $select->where('tt.tag = ?', $tagsArray[0]);
     unset($tagsArray[0]);
     foreach ($tagsArray as $tag) {
         $select->orWhere('tt.tag = ?', $tag);
     }
     $select->orWhere('tt.tag = ?', 'global');
     $testimonials = $this->fetchAll($select);
     $returnArray = array();
     foreach ($testimonials as $testimonial) {
         $returnArray[] = array('id' => $testimonial->id, 'person' => $testimonial->person, 'quote' => $testimonial->quote, 'shortQuote' => Application_Core_Utilities::word_split($testimonial->quote, 10) . '&hellip;');
     }
     return $returnArray;
 }
 /**
  * Helper function to populate the zend form elements with database data
  *
  * @param Zend_Form $pageForm form definition for this step
  * @param int $stepNum current step number
  *
  * @return void
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     // Check to see if the user is trying to skip ahead in the quote
     $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
     $tooFarAhead = false;
     if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) {
         $tooFarAhead = true;
         $lastCompleted = 1;
     } elseif ($stepNum > 1) {
         // Check to see if any pages previous to the one the user's trying to get to are incomplete
         $tooFarAhead = false;
         for ($i = 1; $i < $stepNum; $i++) {
             if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) {
                 $tooFarAhead = true;
                 $lastCompleted = $i;
                 break;
             }
         }
     }
     if ($tooFarAhead) {
         // Drop user onto page that needs completing
         $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/step' . $lastCompleted);
         return false;
     }
     if ($stepNum > 1) {
         // Before we do ANYTHING we need to check to see if the email address entered matches a customer record
         // we already have - if it does we need to ask them to login before they proceed.
         $customerReferenceNumber = $this->_customerReferenceNumber;
         $customerManager = new Manager_Core_Customer();
         $legacyCustomer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerReferenceNumber);
         $emailAddress = $legacyCustomer->getEmailAddress();
         $customer = $customerManager->getCustomerByEmailAddress($emailAddress);
         if ($customer) {
             // There is already a customer entry for this email address - so we need to see if they are logged in
             // if not we need to force them to login
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             if ($auth->hasIdentity()) {
                 $loggedInEmail = $auth->getStorage()->read()->email_address;
                 if ($loggedInEmail != $customer->getEmailAddress()) {
                     // They are logged in but not who they should be to do this quote
                     $this->_helper->redirector->gotoUrl('/account/login?refer=landlords-insurance&step=' . $stepNum);
                     return false;
                 }
             } else {
                 // TODO: Check that removing the login redirection will not break other processes
                 // They aren't logged in and need to
                 /*$this->_helper->redirector->gotoUrl('/account/login?refer=landlords-insurance&step='. $stepNum);
                 		return false;*/
             }
         }
     }
     $formData = array();
     // If step 1 and not in session (so producing a quick quote) - we need to pre-populate
     // a few bits if the customer is already logged into the site
     if ($stepNum == 1 && !isset($pageSession->CustomerRefNo)) {
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
         if ($auth->hasIdentity()) {
             // Customer is logged in and starting a new quote - so we need to pre-populate the customers details from stored details
             $customerID = $auth->getStorage()->read()->id;
             $customerManager = new Manager_Core_Customer();
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             $formData['title'] = $customer->getTitle();
             $formData['first_name'] = $customer->getFirstName();
             $formData['last_name'] = $customer->getLastName();
             $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
             $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
             $formData['email_address'] = $customer->getEmailAddress();
             $formData['date_of_birth_at'] = $customer->getDateOfBirthAt();
             $pageForm->populate($formData);
         }
     }
     if (isset($this->_quoteID) && $this->_quoteID > 0) {
         $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($this->_quoteID);
         $premiums = $quoteManager->calculatePremiums();
         if ($premiums != '') {
             $this->view->premiums = array('annual' => $premiums['totalGrossAnnualPremium'] + $premiums['totalGrossAnnualIPT'], 'monthly' => $premiums['totalGrossMonthlyPremium'] + $premiums['totalGrossMonthlyIPT']);
             $this->view->premiumsFull = $premiums;
         }
         $fees = $quoteManager->getFees();
         $this->view->fees = $fees;
         switch ($stepNum) {
             case 1:
                 $customerManager = new Manager_Core_Customer();
                 $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteManager->getLegacyCustomerReference());
                 // Populate the customer details
                 $titleOptions = LandlordsInsuranceQuote_Form_Subforms_PersonalDetails::$titles;
                 if (in_array($customer->getTitle(), $titleOptions)) {
                     $formData['title'] = $customer->getTitle();
                 } else {
                     $formData['title'] = "Other";
                     $formData['other_title'] = $customer->getTitle();
                 }
                 $formData['first_name'] = $customer->getFirstName();
                 $formData['last_name'] = $customer->getLastName();
                 $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
                 $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
                 $formData['email_address'] = $customer->getEmailAddress();
                 $dob = $customer->getDateOfBirthAt();
                 if (null != $dob && '0000-00-00' != $dob) {
                     $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($dob);
                 }
                 // Populate the correspondence address details
                 $formData['cor_address_line1'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1);
                 $formData['cor_address_line2'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE2);
                 $formData['cor_address_line3'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE3);
                 $formData['cor_address_postcode'] = $customer->getPostcode();
                 $formData['country'] = $customer->getCountry();
                 // Populate the insured property address details
                 $properties = $quoteManager->getProperties();
                 if (count($properties) > 0) {
                     $formData['ins_address_line1'] = $properties[0]['line_1'];
                     $formData['ins_address_line2'] = $properties[0]['line_2'];
                     $formData['ins_address_line3'] = $properties[0]['town'];
                     $formData['ins_address_postcode'] = $properties[0]['postcode'];
                     $formData['owned_for'] = $properties[0]['ownership_length_id'];
                     $formData['no_claims'] = $properties[0]['no_claims_years_id'];
                     $formData['tenants_type'] = $properties[0]['tenant_type_id'];
                     $formData['have_letting_agent'] = $quoteManager->getAgentSchemeNumber() != Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber()) ? 'yes' : 'no';
                     $formData['through_letting_agent'] = $properties[0]['letting_agent_managed'] ? 'yes' : 'no';
                     // Check to see if this postcode is in a flood risk area - if it is then populate the exclude flood cover data
                     // Populating this will also cause the question to be shown on the front end
                     $landlordsRiskAreas = new Datasource_Insurance_LandlordsPlus_RiskAreas();
                     $riskAreas = $landlordsRiskAreas->getByPostcode($properties[0]['postcode']);
                     if ($riskAreas['floodArea'] == '600') {
                         $formData['exclude_flood_cover'] = $properties[0]['exclude_flood_cover'] ? 'no' : 'yes';
                         // Backwards true/false stuff - I'm sooo sorry :(
                     }
                 }
                 // Populate agent details if one has been chosen
                 $agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
                 $defaultASN = $this->_params->homelet->defaultAgent;
                 if ($formData['have_letting_agent'] == 'yes') {
                     $agents = new Datasource_Core_Agents();
                     $agent = $agents->getAgent($agentSchemeNumber);
                     $formData['letting_agent_name'] = $agent->name;
                     $formData['letting_agent_town'] = $agent->town;
                     $formData['letting_agent_asn'] = $agent->agentSchemeNumber;
                     // Fix for Redmine Ref. #10511:
                     $agentDropdown = $pageForm->subform_lettingagent->letting_agent;
                     $agentDropdown->setMultiOptions(array($agent->agentSchemeNumber => $agent->name . ', ' . $agent->town));
                     $formData['letting_agent'] = $agent->agentSchemeNumber;
                 }
                 // Load the policy start date
                 $startDate = $quoteManager->getStartDate();
                 if ($startDate != '' && $startDate != '0000-00-00') {
                     $formData['policy_start'] = substr($startDate, 8, 2) . '/' . substr($startDate, 5, 2) . '/' . substr($startDate, 0, 4);
                 }
                 // If step1 has been marked complete - we can assume they said yes to the IDD question
                 $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['idd'] = true;
                 }
                 // Data Protection section
                 $customerReferenceNumber = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                 $dpaManager = new Manager_Core_DataProtection();
                 $dpaItems = $dpaManager->getItems($customerReferenceNumber, Model_Core_DataProtection_ItemEntityTypes::INSURANCE);
                 foreach ($dpaItems as $currentItem) {
                     switch ($currentItem->constraintTypeId) {
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_phone_post'] = 0;
                             } else {
                                 $formData['dpa_phone_post'] = 1;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_sms_email'] = 0;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             } else {
                                 $formData['dpa_sms_email'] = 1;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_resale'] = 1;
                             } else {
                                 $formData['dpa_resale'] = 0;
                             }
                             break;
                     }
                 }
             case 2:
                 // If step2 has been marked complete - we can assume they said no to the questions unless
                 // they've been set in the quote manager
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['need_building_insurance'] = 'no';
                     $formData['need_contents_insurance'] = 'no';
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER)) {
                     $formData['need_building_insurance'] = 'yes';
                     $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER);
                     $formData['building_built'] = $productMeta['build_year'];
                     $formData['building_bedrooms'] = $productMeta['bedroom_quantity'];
                     $formData['building_type'] = $productMeta['building_type'];
                     $formData['building_insurance_excess'] = $productMeta['excess'];
                     $formData['building_accidental_damage'] = $productMeta['accidental_damage'];
                     $quote = $quoteManager->getModel();
                     if ((int) $productMeta['rebuild_value'] > 0) {
                         // There's a manually entered rebuild value - need to work out if it is because they
                         // chose £500k+ - or if it's because we don't have a dsi
                         $premiums = $quoteManager->calculatePremiums();
                         if ($premiums['calculatedDSIValue'] > 0) {
                             $formData['override_dsi'] = 1;
                         }
                         $formData['building_value'] = $productMeta['rebuild_value'];
                     }
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER) || $quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::UNFURNISHED_CONTENTS_COVER)) {
                     $formData['need_contents_insurance'] = 'yes';
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) {
                         $formData['property_furnished'] = 'yes';
                         $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER);
                         $formData['contents_amount'] = $productMeta['cover_amount'];
                         $formData['contents_excess'] = $productMeta['excess'];
                         $formData['contents_accidental_damage'] = $productMeta['accidental_damage'];
                     } else {
                         $formData['property_furnished'] = 'no';
                     }
                 }
                 break;
             case 3:
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['need_emergency_assistance'] = 'no';
                     $formData['need_prestige_rent_guarantee'] = 'no';
                     $formData['need_legal_expenses'] = 'no';
                     $formData['need_boiler_heating'] = 'no';
                 }
                 // If we have contents/buildings cover then EAS is already included for free so we can hide the form
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER) || $quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) {
                     // Change the subforms view script to one that just says it's already included for free
                     // yeah yeah.. this aint pretty :(
                     $emergencyAssistanceForm = $pageForm->getSubForm('subform_emergencyassistance');
                     $emergencyAssistanceForm->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/emergency-assistance-free.phtml'))));
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BOILER_HEATING)) {
                         $formData['need_boiler_heating'] = 'yes';
                     }
                 } else {
                     // We can allow stand-alone EAS - so we hide the boiler and heating section
                     // yes... this is waaay too complex... I know :(
                     $pageForm->removeSubForm('subform_boilerheating');
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::EMERGENCY_ASSISTANCE)) {
                         $formData['need_emergency_assistance'] = 'yes';
                     }
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE)) {
                     $formData['need_prestige_rent_guarantee'] = 'yes';
                     $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE);
                     $formData['rent_amount'] = $productMeta['monthly_rent'];
                 } elseif ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::LEGAL_EXPENSES)) {
                     $formData['need_legal_expenses'] = 'yes';
                 }
                 break;
             case 4:
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     // Load underwriting answers from the database as they've already been answered
                     $answersManager = new Manager_Insurance_Answers();
                     $quote = $quoteManager->getModel();
                     $policyNumber = $quote->legacyID;
                     $customerReferenceNumber = $quote->legacyCustomerID;
                     $answers = $answersManager->getUnderwritingAnswers($policyNumber);
                     foreach ($answers as $answer) {
                         switch ($answer->getQuestionNumber()) {
                             case '53':
                                 $formData['declaration1'] = $answer->getAnswer();
                                 break;
                             case '54':
                                 $formData['declaration2'] = $answer->getAnswer();
                                 break;
                             case '55':
                                 $formData['declaration2b'] = $answer->getAnswer();
                                 break;
                             case '56':
                                 $formData['declaration2c'] = $answer->getAnswer();
                                 break;
                             case '57':
                                 $formData['declaration2d'] = $answer->getAnswer();
                                 break;
                             case '58':
                                 $formData['declaration3'] = $answer->getAnswer();
                                 break;
                             case '59':
                                 $formData['declaration4'] = $answer->getAnswer();
                                 break;
                             case '60':
                                 $formData['declaration6'] = $answer->getAnswer();
                                 break;
                             case '61':
                                 $formData['declaration7'] = $answer->getAnswer();
                                 break;
                             case '62':
                                 $formData['declaration8'] = $answer->getAnswer();
                                 break;
                             case '63':
                                 $formData['declaration9'] = $answer->getAnswer();
                                 break;
                             case '64':
                                 $formData['declaration10'] = $answer->getAnswer();
                                 break;
                         }
                     }
                     // Also need to see if they said yes or no to bank interest on the propery…
                     $bankInterestManager = new Manager_Insurance_LegacyBankInterest();
                     $bankInterestArray = $bankInterestManager->getAllInterests($policyNumber, $customerReferenceNumber);
                     $model = array();
                     if (!empty($bankInterestArray)) {
                         $formData['declaration11'] = 'yes';
                     } else {
                         $formData['declaration11'] = 'no';
                     }
                     // They must have agreed to the declaration or they wouldn't have been able to continue
                     $formData['declaration_confirmation'] = 'yes';
                 }
                 break;
             case 5:
                 // Payment Selection section
                 if (isset($pageSession->paymentSelectionDetails) && is_array($pageSession->paymentSelectionDetails)) {
                     $formData = $pageSession->paymentSelectionDetails;
                 }
                 break;
         }
     }
     $pageForm->populate($formData);
     return true;
 }
 /**
  * @param mixed array $data
  */
 private function _update($data)
 {
     //Zend_Debug::dump($data);
     //	die("UPDATE");
     if (isset($data['birth_date'])) {
         $data['birth_date'] = Application_Core_Utilities::ukDateToMysql($data['birth_date']);
     }
     $dataToSave = array_diff_key($data, array('id' => ""));
     $where = $this->quoteInto('uid = ?', $data['uid']);
     if ($lastId = $this->update($dataToSave, $where)) {
         return $lastId;
     } else {
         // Error
         Application_Core_Logger::log("Could not update table {$this->_name}", 'error');
         return false;
     }
 }