/**
  * Overridden isValid() method for pre-validation code
  *
  * @param array $formData data typically from a POST or GET request
  *
  * @return bool
  */
 public function isValid($formData = array())
 {
     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
     // If correspondence address is set to be the same as insured address, copy the address values across
     if (isset($formData['cor_same_address']) && $formData['cor_same_address'] == 'yes') {
         // NOTE: THIS BIT OF CODE MEANS BOTH ADDRESS SUBFORMS MUST APPEAR ON THE SAME PAGE
         $formData['cor_house_number_name'] = $formData['ins_house_number_name'];
         $formData['cor_postcode'] = $formData['ins_postcode'];
         $formData['cor_address'] = $formData['ins_address'];
         $findPostcode = $formData['ins_postcode'];
     }
     // If a postcode is present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['cor_postcode']) && trim($formData['cor_postcode']) != '') {
         $postcode = trim($formData['cor_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $cor_address = $this->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 => 'Correspondence address does not match with postcode'));
         $cor_address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number is not required
     if (isset($formData['cor_postcode'])) {
         $this->getElement('cor_house_number_name')->setRequired(false);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 public function isValid($formData = array())
 {
     if (isset($formData['ins_property_postcode']) && trim($formData['ins_property_postcode']) != '') {
         $postcode = trim($formData['ins_property_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         if (isset($postcode) && preg_match('/^IM|^GY|^JE/i', $postcode)) {
             return;
         } else {
             foreach ($addresses as $address) {
                 $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
             }
         }
         $ins_address = $this->getElement('property_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);
     }
     // If a value for an address lookup is present, the house name or number is not required
     if (isset($formData['ins_property_postcode'])) {
         $this->getElement('property_number_name')->setRequired(false);
     }
     return parent::isValid($formData);
 }
Пример #3
0
 public function isValid($formData = array())
 {
     // If a postcode is present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['postcode']) && trim($formData['postcode']) != '') {
         $postcode = trim($formData['postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $address = $this->getElement('address');
         $address->setMultiOptions($addressList);
         $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
         $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Address does not match with postcode'));
         $address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number is not required
     if (isset($formData['address_postcode']) && $formData['address_postcode'] != '') {
         $this->getElement('postcode')->setRequired(false);
         $this->getElement('address')->setRequired(false);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 /**
  * Get a specic property details 
  *
  */
 public function getpropertyAction()
 {
     $addressID = $_POST['addressID'];
     $postcode = new Manager_Core_Postcode();
     $address = $postcode->getPropertyByID($addressID);
     $returnArray = array();
     if (count($address) > 0) {
         $line1 = '';
         // Build an array of up to 5 address lines
         $addressLines = array();
         if ($address['address1'] != '') {
             $addressLines[] = $address['address1'];
         }
         if ($address['address2'] != '') {
             $addressLines[] = $address['address2'];
         }
         if ($address['address3'] != '') {
             $addressLines[] = $address['address3'];
         }
         if ($address['address4'] != '') {
             $addressLines[] = $address['address4'];
         }
         if ($address['address5'] != '') {
             $addressLines[] = $address['address5'];
         }
         // Now we can pop off of this address lines nonsense - to make it just 3 lines
         $line3 = array_pop($addressLines);
         $line2 = array_pop($addressLines);
         while (count($addressLines) > 0) {
             $line1 = array_pop($addressLines) . ', ' . $line1;
         }
         if ($address['buildingName'] != '') {
             $line1 = $address['buildingName'] . ' ' . $line1;
         }
         if ($address['houseNumber'] != '') {
             $line1 = $address['houseNumber'] . ' ' . $line1;
         }
         if ($address['department'] != '') {
             $line1 = $address['department'] . ', ' . $line1;
         }
         if ($address['organisation'] != '') {
             $line1 = $address['organisation'] . ', ' . $line1;
         }
         $line1 = trim($line1, ' ');
         $line1 = trim($line1, ',');
         $postcode = $address['postcode'];
         $returnArray = array('line1' => ucwords(strtolower($line1)), 'line2' => ucwords(strtolower($line2)), 'line3' => ucwords(strtolower($line3)), 'postcode' => strtoupper($postcode), 'landlordsRiskAreas' => $address['landlordsRiskAreas']);
         $output['data'] = $returnArray;
         $output['error'] = '';
     } else {
         $output['data'] = array();
         $output['error'] = "Can't find address";
     }
     echo Zend_Json::encode($output);
 }
Пример #5
0
 /**
  * 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);
             }
         }
     }
 }
 /**
  * This function will add a new note into the agentNotes table
  *
  * @param int schemeNumber
  * @param string note
  * @return boolean
  *
  */
 public function addEnquiry($enquiryData)
 {
     #	Zend_Debug::dump($enquiryData);
     $rsAddress = new Manager_Core_Postcode();
     $riskAddress = $rsAddress->getPropertyByID($enquiryData['ins_address'], false);
     #Zend_Debug::dump($riskAddress);die();
     $insertData = array('agentschemeno' => $enquiryData['agentschemeno'], 'title' => $enquiryData['title'], 'first_name' => $enquiryData['first_name'], 'last_name' => $enquiryData['last_name'], 'phone_number' => $enquiryData['phone_number'], 'mobile_number' => $enquiryData['mobile_number'], 'address_id' => $riskAddress['id'], 'houseNumber' => $riskAddress['houseNumber'], 'buildingName' => $riskAddress['buildingName'], 'address1' => $riskAddress['address1'], 'address2' => $riskAddress['address2'], 'address3' => $riskAddress['address3'], 'address4' => $riskAddress['address4'], 'address5' => $riskAddress['address5'], 'postcode' => $riskAddress['postcode'], 'county' => $riskAddress['county'], 'postcode' => $riskAddress['postcode'], 'organisation' => $riskAddress['organisation'], 'department' => $riskAddress['department'], 'additional_information' => $enquiryData['additional_information'], 'isSent' => 0, 'enquiry_type' => $enquiryData['prospector'], 'created' => new Zend_Db_Expr('NOW()'));
     // Insert the data into a new row in the table
     if ($this->insert($insertData)) {
         return true;
     } else {
         // Failed insertion
         Application_Core_Logger::log("Can't insert  in table {$this->_name} (AGENTSCHEMENUMBER = {$schemeNumber})", 'error');
         return false;
     }
 }
Пример #7
0
 /**
  * Saves the form data to the datastore.
  * 
  * @return void
  */
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     // Create a new Enquiry, or load the existing one.
     $referenceManager = new Manager_Referencing_Reference();
     if (empty($session->referenceId)) {
         $reference = $referenceManager->createReference();
         $session->referenceId = $reference->internalId;
     } else {
         $reference = $referenceManager->getReference($session->referenceId);
     }
     // Set the customer map
     if (empty($reference->customer)) {
         $reference->customer = new Model_Referencing_CustomerMap();
     }
     $reference->customer->customerType = Model_Referencing_CustomerTypes::LANDLORD;
     $reference->customer->customerId = $session->customerId;
     // Format the property details
     $postcodeManager = new Manager_Core_Postcode();
     $propertyAddress = $postcodeManager->getPropertyByID($data['subform_propertyaddress']['property_address'], false);
     $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2'];
     $addressLine2 = $propertyAddress['address4'];
     $town = $propertyAddress['address5'];
     $postCode = $data['subform_propertyaddress']['ins_property_postcode'];
     // Store the property details into the PropertyLease.
     if (empty($reference->propertyLease)) {
         $propertyLeaseManager = new Manager_Referencing_PropertyLease();
         $reference->propertyLease = $propertyLeaseManager->insertPlaceholder($session->referenceId);
     }
     if (empty($reference->propertyLease->address)) {
         $addressManager = new Manager_Core_Address();
         $reference->propertyLease->address = $addressManager->createAddress();
     }
     $reference->propertyLease->address->addressLine1 = $addressLine1;
     $reference->propertyLease->address->addressLine2 = $addressLine2;
     $reference->propertyLease->address->town = $town;
     $reference->propertyLease->address->postCode = $postCode;
     // Store the rental price index details, if provided.
     $this->_savePropertyAspects();
     // Set the remainder of the property lease details.
     $reference->propertyLease->rentPerMonth = new Zend_Currency(array('value' => $data['subform_propertymisc']['total_rent'], 'precision' => 0));
     $reference->propertyLease->tenancyStartDate = new Zend_Date($data['subform_propertymisc']['tenancy_start_date'], Zend_Date::DATES);
     $reference->propertyLease->tenancyTerm = $data['subform_propertymisc']['tenancy_term'];
     $reference->propertyLease->noOfTenants = $data['subform_propertymisc']['no_of_tenants'];
     $referenceManager->updateReference($reference);
 }
 /**
  * Overridden isValid() method for pre-validation code
  *
  * @param array $formData data typically from a POST or GET request
  *
  * @return bool
  */
 public function isValid($formData = array())
 {
     $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
     // If a postcode is present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['cor_postcode']) && trim($formData['cor_postcode']) != '') {
         $postcode = trim($formData['cor_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $cor_address = $this->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 => 'Correspondence address does not match with postcode'));
         $cor_address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number
     // is not required
     if (isset($formData['cor_postcode'])) {
         $this->getElement('cor_house_number_name')->setRequired(false);
     }
     // todo: sort out server-side validation for foreign address stuff
     // If the address is overseas, toggle  the required status for the
     // relevant fields.
     if (isset($formData['cor_foreign_address']) && 1 == $formData['cor_foreign_address']) {
         $this->getElement('cor_address')->setRequired(false);
         $this->getElement('cor_address_postcode')->setRequired(false);
         $this->getElement('cor_address_line1')->setRequired(true);
         $this->getElement('cor_address_line2')->setRequired(true);
         $this->getElement('country')->setRequired(true);
         // Also change the validators for the postcode field
         $this->getElement('cor_postcode')->setValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter zip/postal code for your correspondence address', 'notEmptyInvalid' => 'Please enter a valid zip/postal code for your correspondence address')))));
         $this->getElement('cor_address_postcode')->setValidators(array());
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
Пример #9
0
 /**
  * Saves the form data to the datastore.
  * 
  * @return void
  */
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     // Create the new customer in the legacy datasource only.
     $customerManager = new Manager_Core_Customer();
     $customer = $customerManager->createNewCustomer($data['email'], Model_Core_Customer::CUSTOMER);
     // Update the newly created customer with values submitted on the registration form.
     //$customer->setTitle($data['personal_title']);
     $customer->setTitle($data['title']);
     $customer->setFirstName($data['first_name']);
     $customer->setLastName($data['last_name']);
     $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $data['phone_number']);
     $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $data['mobile_number']);
     $customer->setFax($data['fax_number']);
     $customer->setEmailAddress($data['email']);
     $customer->setPassword($data['password']);
     $customer->setSecurityQuestion($data['security_question']);
     $customer->setSecurityAnswer($data['security_answer']);
     //Address update
     $postcode = new Manager_Core_Postcode();
     $propertyAddress = $postcode->getPropertyByID($data['property_address'], false);
     $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2'];
     $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $addressLine1);
     $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $propertyAddress['address4']);
     $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $propertyAddress['address5']);
     $customer->setPostCode($data['property_postcode']);
     $customer->typeID = Model_Core_Customer::CUSTOMER;
     // Update the customer record
     $customerManager->updateCustomer($customer);
     //		// Log the customer in automatically
     //        $auth = Zend_Auth::getInstance();
     //        $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
     //        $customerManager = new Manager_Core_Customer();
     //        $adapter = $customerManager->getAuthAdapter(array('email' => $data['email'], 'password' => $data['password']));
     //        $auth->authenticate($adapter);
     //        // Writer customer data to session
     //        $storage = $auth->getStorage();
     //        $storage->write($adapter->getResultRowObject(array(
     //            'title',
     //            'first_name',
     //            'last_name',
     //            'email_address',
     //            'id')));
     //Finally, set the necessary session variables.
     $session->awaitingvalidation = 1;
     $session->customerId = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER);
     // Save dpa preferences for direct landlord to insurance dpa system - direct landlords save their customer records to insurance
     $dpaManager = new Manager_Core_DataProtection();
     $item = new Model_Core_DataProtection_Item();
     $item->itemGroupId = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
     $item->entityTypeId = Model_Core_DataProtection_ItemEntityTypes::INSURANCE;
     // Phone and post
     $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST;
     $item->isAllowed = $data['subform_dataprotection']['dpa_phone_post'] == 1 ? true : false;
     $dpaManager->upsertItem($item);
     // Sms and email
     $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL;
     $item->isAllowed = $data['subform_dataprotection']['dpa_sms_email'] == 1 ? true : false;
     $dpaManager->upsertItem($item);
     // Third party sale
     $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY;
     $item->isAllowed = $data['subform_dataprotection']['dpa_resale'] == 1 ? true : false;
     $dpaManager->upsertItem($item);
     // Save insurance renewal mi data, if provided
     if ($this->getElement('insurance_renewal_date')->getValue() != '') {
         $renewalDate = new Zend_Date($this->getElement('insurance_renewal_date')->getValue(), Zend_Date::DAY . '/' . Zend_Date::MONTH . '/' . Zend_Date::YEAR);
         $miInsuranceRenewalDataSource = new Datasource_Referencing_MiInsuranceRenewal();
         $miInsuranceRenewalDataSource->insertMiData($customer->getIdentifier(Model_Core_Customer::IDENTIFIER), $renewalDate);
     }
     // Create sign-up completion email
     $customer->sendAccountValidationEmail();
 }
 /**
  * TODO: Document this
  * @param
  * @return
  * @author John Burrin
  * @since
  */
 public function updatePropertyAction()
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     $customerReferenceNumber = $pageSession->CustomerRefNo;
     $ajaxForm = new Form_PortfolioInsuranceQuote_editPropertyDialog();
     $return = array();
     $request = $this->getRequest();
     $postdata = $request->getPost();
     $return['success'] = false;
     $ajaxForm->isValid($postdata);
     $return['errorObject'] = $ajaxForm->getMessages();
     if ($ajaxForm->isValid($postdata)) {
         $cleanData = $ajaxForm->getValues();
         // According to the Zend manual these *should* be the clean values
         $propertyArray = array();
         $propertyManager = new Manager_Insurance_Portfolio_Property();
         $dataObject = new Model_Insurance_Portfolio_Property();
         if (isset($postdata['propertyid'])) {
             $dataObject->id = $cleanData['propertyid'];
         }
         if (isset($customerReferenceNumber)) {
             $dataObject->refno = $customerReferenceNumber;
         }
         if (isset($postdata['ins_house_number_name'])) {
             $dataObject->building = $cleanData['ins_house_number_name'];
         }
         if (isset($postdata['ins_postcode'])) {
             $dataObject->postcode = $propertyManager->formatPostcode($cleanData['ins_postcode']);
         }
         if (isset($postdata['employment_status'])) {
             $dataObject->tenantOccupation = $cleanData['employment_status'];
         }
         if (isset($postdata['buildings_cover'])) {
             $dataObject->buildingsSumInsured = $cleanData['buildings_cover'];
         }
         if (isset($postdata['buildings_accidental_damage'])) {
             $dataObject->buildingsAccidentalDamage = $cleanData['buildings_accidental_damage'];
         }
         if (isset($postdata['buildings_nil_excess'])) {
             $dataObject->buildingsNilExcess = $cleanData['buildings_nil_excess'];
         }
         if (isset($postdata['contents_cover'])) {
             $dataObject->contentsSumInsured = $cleanData['contents_cover'];
         }
         if (isset($postdata['contents_accidental_damage'])) {
             $dataObject->contentsAccidentalDamage = $cleanData['contents_accidental_damage'];
         }
         if (isset($postdata['contents_nil_excess'])) {
             $dataObject->contentsNilExcess = $cleanData['contents_nil_excess'];
         }
         if (isset($postdata['limited_contents'])) {
             $dataObject->limitedContents = $cleanData['limited_contents'];
         }
         $address = new Manager_Core_Postcode();
         $return['address'] = $address->getPropertyByID($cleanData['ins_address']);
         $dataObject->houseNumber = $return['address']['houseNumber'];
         $dataObject->building = $return['address']['buildingName'];
         $dataObject->address1 = $return['address']['address1'];
         $dataObject->address2 = $return['address']['address2'];
         $dataObject->address3 = $return['address']['address3'];
         $dataObject->address4 = $return['address']['address4'];
         $dataObject->address5 = $return['address']['address5'];
         $dataObject->postcode = $property->formatPostcode($cleanData['ins_postcode']);
         $dataObject->refno = $pageSession->CustomerRefNo;
         $dataObject->tenantOccupation = $dataObject->tenantOccupation;
         // Do the update stuffs
         $propertyManager->save($dataObject);
         // need to tell the view we are on step 2
         $this->view->stepNum = 2;
         // Get the properties to shove back into the page
         $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber);
         $return['html'] = $this->view->partialLoop('portfolio-insurance-quote/partials/property-list.phtml', $propertyArray);
         $return['success'] = true;
         $return['propNumb'] = count($propertyArray->toArray());
     }
     echo Zend_Json::encode($return);
 }
Пример #11
0
 /**
  * Overridden isValid() method for pre-validation code
  *
  * @param array $formData data typically from a POST or GET request
  *
  * @return bool
  */
 public function isValid($formData = array())
 {
     $coverCount = 0;
     if (isset($formData['buildings_accidental_damage']) && $formData['buildings_accidental_damage'] == 1) {
         $coverCount++;
         $this->getElement('buildings_cover')->setRequired(true);
     }
     if (isset($formData['buildings_nil_excess']) && $formData['buildings_nil_excess'] == 1) {
         $coverCount++;
         $this->getElement('buildings_cover')->setRequired(true);
     }
     if (isset($formData['contents_accidental_damage']) && $formData['contents_accidental_damage'] == 1) {
         $coverCount++;
         $this->getElement('contents_cover')->setRequired(true);
     }
     if (isset($formData['contents_nil_excess']) && $formData['contents_nil_excess'] == 1) {
         $coverCount++;
         $this->getElement('contents_cover')->setRequired(true);
     }
     if (isset($formData['limited_contents']) && $formData['contents_cover'] > 0) {
         $coverCount++;
         $limitedContents = $this->getElement('limited_contents');
         $limitedContentsValidator = new Zend_Validate_LessThan(array('max' => 1));
         $limitedContentsValidator->setMessage('&nbsp;Limited Contents cannot be selected with Full Contents', Zend_Validate_LessThan::NOT_LESS);
         $limitedContents->addValidator($limitedContentsValidator, true);
     }
     if (isset($formData['limited_contents']) && $formData['limited_contents'] == 1 || (isset($formData['contents_cover']) && $formData['contents_cover'] > 0 || isset($formData['buildings_cover']) && $formData['buildings_cover'] > 0)) {
         $coverCount++;
     }
     // Set up validation for Building cover maximun
     // value can be empty OR Greater Than 50k and refer after 1000k
     $buildingsCover = $this->getElement('buildings_cover');
     $buildingsValidator = new Zend_Validate_GreaterThan(array('min' => 49999));
     $buildingsValidator->setMessage('Buildings cover must be over £50000', Zend_Validate_GreaterThan::NOT_GREATER);
     $buildingsCover->addValidator($buildingsValidator, true);
     // Set up validation for contents cover maximun
     // value can be empty OR Greater Than 10k and refer after 60k
     $contentsCover = $this->getElement('contents_cover');
     $contentsValidator = new Zend_Validate_GreaterThan(array('min' => 9999));
     $contentsValidator->setMessage('Contents cover must be over £10000', Zend_Validate_GreaterThan::NOT_GREATER);
     $contentsCover->addValidator($contentsValidator, true);
     $formData['covercount'] = $coverCount;
     $covers = $this->getElement('covercount');
     $optionsValidator = new Zend_Validate_GreaterThan(array('min' => 0));
     $optionsValidator->setMessage("You have not selected a cover", Zend_Validate_GreaterThan::NOT_GREATER);
     $covers->addValidator($optionsValidator, true);
     // If a postcode is or was present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['ins_postcode']) && trim($formData['ins_postcode']) != '') {
         $postcode = trim($formData['ins_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $ins_address = $this->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);
     }
     if (isset($formData['ins_address_postcode']) && $formData['ins_address_postcode'] != '') {
         $this->getElement('ins_postcode')->setRequired(false);
         $this->getElement('ins_address')->setRequired(false);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 /**
  * Enter the postal address to send the document to
  *
  * @return void
  */
 public function selectDocumentAddressAction()
 {
     $session = new Zend_Session_Namespace('connect_rg');
     $request = $this->getRequest();
     $documentaddress = new Connect_Form_RentGuarantee_DocumentAddress();
     $documentaddress->populate($request->getPost());
     if ($request->isPost()) {
         if ($request->getParam('formsubmit_back')) {
             $this->_redirect($this->getRequest()->getControllerName() . '/configure-renewal-document');
         } else {
             if ($documentaddress->isValid($request->getPost())) {
                 // Capture target address, obtain data from the postcode
                 // lookup from the database and store the data to the session
                 $postcode = new Manager_Core_Postcode();
                 $postcodedata = $postcode->getPropertyByID($documentaddress->getElement('cor_address')->getValue(), false);
                 $session->documentaddress = $postcodedata;
                 $this->_redirect($this->getRequest()->getControllerName() . '/send-renewal-document');
             }
         }
     }
     $this->view->documentaddress = $documentaddress;
 }
 public function forcePopulate($formData)
 {
     //Populate the form elements with data retrieved from the datasource, unless
     //the user has provided new datas.
     //        $auth = Zend_Auth::getInstance();
     //        $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
     //        $session = $auth->getStorage()->read();
     $session = new Zend_Session_Namespace('referencing_global');
     $customerManager = new Manager_Referencing_Customer();
     $customer = $customerManager->getCustomer($session->customerId);
     if (empty($formData['personal_title'])) {
         $formData['personal_title'] = $customer->getTitle();
     }
     if (empty($formData['first_name'])) {
         $formData['first_name'] = $customer->getFirstName();
     }
     if (empty($formData['last_name'])) {
         $formData['last_name'] = $customer->getLastName();
     }
     if (empty($formData['property_postcode'])) {
         $formData['property_postcode'] = $customer->getPostCode();
     }
     if (empty($formData['telephone_day'])) {
         $formData['telephone_day'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
     }
     if (empty($formData['fax_number'])) {
         $formData['fax_number'] = $customer->getFax();
     }
     if (empty($formData['telephone_evening'])) {
         $formData['telephone_evening'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
     }
     if (empty($formData['email'])) {
         $formData['email'] = $customer->getEmailAddress();
     }
     $postcode = new Manager_Core_Postcode();
     $addresses = $postcode->getPropertiesByPostcode($formData['property_postcode']);
     $filterString = $customer->getAddressLine(1);
     $addressList = array();
     $addressID = 0;
     foreach ($addresses as $address) {
         $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         $cleanAddress = str_replace(",", "", $address['singleLineWithoutPostcode']);
         if (stripos($cleanAddress, $filterString) === 0) {
             $addressID = $address['id'];
         }
     }
     // Add some validation
     $property_address = $this->getElement('property_address');
     $property_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'));
     $property_address->addValidator($validator, true);
     // Set the address to selected
     $property_address->setValue($addressID);
     //Allow Zend to complete the population process.
     $this->populate($formData);
     $this->property_address->setValue($addressID);
 }
Пример #14
0
 public function isValid($formData = array())
 {
     // If a postcode is or was present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['ins_postcode']) && trim($formData['ins_postcode']) != '') {
         $postcode = trim($formData['ins_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $ins_address = $this->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);
         $landlordsRiskAreas = new Datasource_Insurance_LandlordsPlus_RiskAreas();
         try {
             $landlordsRiskAreas = $landlordsRiskAreas->getByPostcode($formData['ins_postcode']);
         } catch (Datasource_Exception_PostcodeNotFoundException $e) {
             // Catch postcode not found exception and rethrow chained risk area not found exception
             throw new LandlordsInsuranceQuote_Form_Exception_RiskAreaNotFoundException($e->getMessage(), $e->getCode(), $e);
         }
         if ($landlordsRiskAreas['floodArea'] != '600') {
             $this->getElement('exclude_flood_cover')->setRequired(false);
         }
     } else {
         $this->getElement('exclude_flood_cover')->setRequired(false);
     }
     if (isset($formData['ins_postcode'])) {
         $this->getElement('ins_address')->setRequired(false);
         $formData['ins_address'] = null;
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 /**
  * 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;
 }
Пример #16
0
 /**
  * Set the address for specified postcode
  *
  * @param array $data, String $type
  *
  * @return array of housename, street, city, town
  *
  */
 public function getPropertyAddress($data, $type)
 {
     $coreAddressManager = new Manager_Core_Postcode();
     $returnArrayValue = array();
     // If there is an address id and a list of properties from post code,
     // we go and get a property by its ID
     if (isset($data[$type . '_address']) && $data[$type . '_address'] != '' && $data[$type . '_address'] != '-') {
         $getAddress = $coreAddressManager->getPropertyByID($data[$type . '_address']);
         $streetLine = '';
         if ($getAddress['buildingName']) {
             $streetLine .= ucwords(strtolower($getAddress['buildingName'])) . ', ';
         }
         if ($getAddress['address1']) {
             $streetLine .= ucwords(strtolower($getAddress['address1'])) . ', ';
         }
         if ($getAddress['address2']) {
             $streetLine .= ucwords(strtolower($getAddress['address2'])) . ', ';
         }
         if ($getAddress['address3']) {
             $streetLine .= ucwords(strtolower($getAddress['address3'])) . ', ';
         }
         if ($getAddress['address4']) {
             //$streetLine .= ucwords(strtolower($getAddress['address4'])) . ', ';
         }
         if ($getAddress['address5']) {
             //$streetLine .= ucwords(strtolower($getAddress['address5'])) . ', ';
         }
         $returnArrayValue = array($type . '_housename' => $getAddress['houseNumber'], $type . '_street' => $streetLine, $type . '_town' => $getAddress['address4'], $type . '_city' => $getAddress['address5'], $type . '_postcode' => $getAddress['postcode']);
     } else {
         $returnArrayValue = array($type . '_housename' => $data[$type . '_housename'], $type . '_street' => $data[$type . '_street'], $type . '_town' => $data[$type . '_town'], $type . '_city' => $data[$type . '_city'], $type . '_postcode' => $data[$type . '_postcode']);
     }
     return $returnArrayValue;
 }
Пример #17
0
 /**
  * Returns a Model_Core_Address built from the form data.
  *
  * Note that the address object will not be reflected in the datasource,
  * and so will not contain an ID. The purpose of this method is to provide
  * a simple means of address extraction so that the address given can be easily
  * examined and tested.
  *
  * @return Model_Core_Address
  * An address built from th details provided on the form.
  */
 public function getAddressFromForm()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     $address = new Model_Core_Address();
     if (isset($data['is_foreign_address']) && 'Yes' == $data['is_foreign_address']) {
         $address->isOverseasAddress = true;
     } else {
         $postcodeManager = new Manager_Core_Postcode();
         $propertyAddress = $postcodeManager->getPropertyByID($data['property_address'], false);
         $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2'];
         $address->addressLine1 = $addressLine1;
         $address->addressLine2 = $propertyAddress['address4'];
         $address->town = $propertyAddress['address5'];
         $address->postCode = $data['property_postcode'];
         $address->isOverseasAddress = false;
     }
     return $address;
 }
Пример #18
0
 /**
  * Validate and return address list for use via AJAX
  * TODO: This is a duplicate of the json Action in the equivalent
  * json module. Refactor when the json problem is resolved.
  *
  * @return void
  */
 public function getpropertiesAction()
 {
     $output = array();
     // Filter input
     $inputPostcode = trim(preg_replace('/[^0-9a-z\\ ]/i', '', $_POST['postcode']));
     if ($inputPostcode != '') {
         $postcode = new Manager_Core_Postcode();
         $addresses = $postcode->getPropertiesByPostcode($inputPostcode);
         $returnArray = array();
         foreach ($addresses as $address) {
             $returnArray[] = array('addressId' => $address['id'], 'addressLine' => $address['singleLineWithoutPostcode']);
         }
         if (isset($returnArray[0]['addressId']) && $returnArray[0]['addressId'] != null && $returnArray[0]['addressId'] != '') {
             if (preg_match('/^IM|^GY|^JE/i', $_POST['postcode']) && preg_match('/ins_postcode|property_postcode/', $_POST['inputId'])) {
                 $output['data'] = array();
                 $output['error'] = "Unfortunately we're unable to offer you a policy, as we're unable to provide cover in the Channel Islands or the Isle of Man. If the property you're looking to insure isn't in the Channel Islands or the Isle of Man then please double check the post code you have entered. If you're still experiencing problems, or if you have any further queries or questions, please call us on 0845 117 6000.";
                 $output['restriction'] = 1;
             } else {
                 $output['data'] = $returnArray;
                 $output['error'] = '';
             }
         } else {
             $output['data'] = array();
             $output['error'] = 'Can\'t find address';
         }
     } else {
         $output['data'] = array();
         $output['error'] = 'Please enter a valid postcode';
     }
     echo Zend_Json::encode($output);
 }
Пример #19
0
 /**
  * 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;
 }
Пример #20
0
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($session->referenceId);
     //Derive the occupation chronology from the current flow item, so that we can locate
     //the relevant occupation to update.
     switch ($session->currentFlowItem) {
         case Model_Referencing_DataEntry_FlowItems::CURRENT_OCCUPATION:
             $chronology = Model_Referencing_OccupationChronology::CURRENT;
             $classification = Model_Referencing_OccupationImportance::FIRST;
             break;
         case Model_Referencing_DataEntry_FlowItems::SECOND_OCCUPATION:
             $chronology = Model_Referencing_OccupationChronology::CURRENT;
             $classification = Model_Referencing_OccupationImportance::SECOND;
             break;
         case Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION:
             $chronology = Model_Referencing_OccupationChronology::FUTURE;
             $classification = Model_Referencing_OccupationImportance::FIRST;
             break;
     }
     //Attept to locate the relevant occupation.
     $occupationManager = new Manager_Referencing_Occupation();
     $thisOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, $chronology, $classification);
     if (empty($thisOccupation)) {
         //The occupation to process does not exist, so create it first.
         $thisOccupation = $occupationManager->createNewOccupation($session->referenceId, $chronology, $classification);
         if (empty($reference->referenceSubject->occupations)) {
             $reference->referenceSubject->occupations = array();
         }
         $reference->referenceSubject->occupations[] = $thisOccupation;
     }
     //Now update $thisOccupation with the occupational details provided by the ReferenceSubject.
     if (empty($thisOccupation->refereeDetails)) {
         $refereeManager = new Manager_Referencing_OccupationReferee();
         $thisOccupation->refereeDetails = $refereeManager->createReferee($thisOccupation->id);
     }
     //Add general details.
     $thisOccupation->refereeDetails->organisationName = $data['company_name'];
     $thisOccupation->refereeDetails->position = $data['contact_position'];
     $thisOccupation->income = new Zend_Currency(array('value' => $data['income'], 'precision' => 0));
     //Add the referee name if required.
     if (empty($thisOccupation->refereeDetails->name)) {
         $nameManager = new Manager_Core_Name();
         $thisOccupation->refereeDetails->name = $nameManager->createName();
     }
     $nameArray = preg_split("/\\s/", $data['contact_name']);
     if (count($nameArray) >= 2) {
         $thisOccupation->refereeDetails->name->firstName = array_shift($nameArray);
         $thisOccupation->refereeDetails->name->lastName = array_pop($nameArray);
     } else {
         if (count($nameArray) == 1) {
             $thisOccupation->refereeDetails->name->firstName = array_shift($nameArray);
         }
     }
     //Capture and process the referee address.
     $postcodeManager = new Manager_Core_Postcode();
     $propertyAddress = $postcodeManager->getPropertyByID($data['property_address'], false);
     $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2'];
     $addressLine2 = $propertyAddress['address4'];
     $town = $propertyAddress['address5'];
     $postCode = $data['property_postcode'];
     if (empty($thisOccupation->refereeDetails->address)) {
         $addressManager = new Manager_Core_Address();
         $thisOccupation->refereeDetails->address = $addressManager->createAddress();
     }
     $thisOccupation->refereeDetails->address->addressLine1 = $addressLine1;
     $thisOccupation->refereeDetails->address->addressLine2 = $addressLine2;
     $thisOccupation->refereeDetails->address->town = $town;
     $thisOccupation->refereeDetails->address->postCode = $postCode;
     //Capture and process the referee contact details.
     if (empty($thisOccupation->refereeDetails->contactDetails)) {
         $contactDetailsManager = new Manager_Core_ContactDetails();
         $thisOccupation->refereeDetails->contactDetails = $contactDetailsManager->createContactDetails();
     }
     $thisOccupation->refereeDetails->contactDetails->telephone1 = $data['telephone_number'];
     $thisOccupation->refereeDetails->contactDetails->fax1 = $data['fax_number'];
     $thisOccupation->refereeDetails->contactDetails->email1 = $data['email'];
     if (!empty($data['tenancy_start_date'])) {
         $thisOccupation->startDate = new Zend_Date($data['tenancy_start_date'], Zend_Date::DATES);
     }
     if (!empty($data['is_permanent'])) {
         if ($data['is_permanent'] == 'Yes') {
             $thisOccupation->isPermanent = true;
         } else {
             $thisOccupation->isPermanent = false;
         }
     }
     //Now capture the optional details and insert into the occupation variables array.
     if (!empty($data['reference_number'])) {
         if (empty($thisOccupation->variables)) {
             $thisOccupation->variables = array();
         }
         $thisOccupation->variables[Model_Referencing_OccupationVariables::PAYROLL_NUMBER] = $data['reference_number'];
     }
     if (!empty($data['position'])) {
         if (empty($thisOccupation->variables)) {
             $thisOccupation->variables = array();
         }
         $thisOccupation->variables[Model_Referencing_OccupationVariables::POSITION] = $data['position'];
     }
     //Identify if a future occupation is applicable and required.
     if (!empty($data['will_change'])) {
         if ($data['will_change'] == 'Yes') {
             //If its going to change then we need to create a future employer record, if not already
             //done so.
             $futureOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST);
             if (empty($futureOccupation)) {
                 $createFutureOccupation = true;
             } else {
                 $createFutureOccupation = false;
             }
             if ($createFutureOccupation) {
                 $futureOccupation = $occupationManager->createNewOccupation($session->referenceId, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST);
                 $futureOccupation->type = Model_Referencing_OccupationTypes::EMPLOYMENT;
                 $reference->referenceSubject->occupations[] = $futureOccupation;
             }
         } else {
             //Delete any future employer records.
             $futureOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST);
             if (!empty($futureOccupation)) {
                 $occupationManager->deleteOccupation($futureOccupation);
             }
         }
     }
     //And update...
     $referenceManager->updateReference($reference);
     return $thisOccupation;
 }