public function init() { // Add declaration question 1 element $this->addElement('radio', 'declaration1', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 1', 'notEmptyInvalid' => 'Please select an answer for declaration question 1')))))); // Add declaration question 2 element $this->addElement('radio', 'declaration2', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 2', 'notEmptyInvalid' => 'Please select an answer for declaration question 2')))))); // Add declaration question 2b element $this->addElement('radio', 'declaration2b', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 2b', 'notEmptyInvalid' => 'Please select an answer for declaration question 2b')))))); // Add declaration question 2c element $this->addElement('radio', 'declaration2c', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 2c', 'notEmptyInvalid' => 'Please select an answer for declaration question 2c')))))); // Add declaration question 2d element $this->addElement('radio', 'declaration2d', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 2d', 'notEmptyInvalid' => 'Please select an answer for declaration question 2d')))))); // Add declaration question 3 element $this->addElement('radio', 'declaration3', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 3', 'notEmptyInvalid' => 'Please select an answer for declaration question 3')))))); // Add declaration question 4 element $this->addElement('radio', 'declaration4', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 4', 'notEmptyInvalid' => 'Please select an answer for declaration question 4')))))); // Add declaration question 6 element $this->addElement('radio', 'declaration6', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 6', 'notEmptyInvalid' => 'Please select an answer for declaration question 6')))))); // Add declaration question 7 element $this->addElement('radio', 'declaration7', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 7', 'notEmptyInvalid' => 'Please select an answer for declaration question 7')))))); // Add declaration question 8 element $this->addElement('radio', 'declaration8', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 8', 'notEmptyInvalid' => 'Please select an answer for declaration question 8')))))); // Add declaration question 9 element $this->addElement('radio', 'declaration9', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 9', 'notEmptyInvalid' => 'Please select an answer for declaration question 9')))))); //Determine if declaration question 10 should be displayed, and if yes, add the element. $session = new Zend_Session_Namespace('landlords_insurance_quote'); $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID); if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE)) { $displayDeclaration10 = true; } else { if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::LEGAL_EXPENSES)) { $displayDeclaration10 = true; } else { $displayDeclaration10 = false; } } if ($displayDeclaration10) { // Add declaration question 10 element $this->addElement('radio', 'declaration10', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 10', 'notEmptyInvalid' => 'Please select an answer for declaration question 10')))))); } // Add declaration question 11 element $this->addElement('radio', 'declaration11', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for declaration question 11', 'notEmptyInvalid' => 'Please select an answer for declaration question 11')))))); //Additional information. $this->addElement('textarea', 'additional_information', array('label' => 'Additional information', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter additional information')))), 'attribs' => array('data-ctfilter' => 'yes', 'class' => 'declarationAnswer form-control'))); // Add declaration confirmation element $this->addElement('radio', 'declaration_confirmation', array('required' => true, 'multiOptions' => array('yes' => 'Yes', 'no' => 'No'), 'separator' => '', 'label_placement' => 'prepend', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select an answer for the confirmation statement', 'notEmptyInvalid' => 'Please select an answer for the confirmation statement'))), array('Identical', true, array('token' => 'yes', 'messages' => array('notSame' => 'Please agree to the confirmation statement')))))); // Set custom subform decorator $this->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/underwriting-questions.phtml')))); $this->setElementDecorators(array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false)))); // Strip all tags to prevent XSS errors - done iteratively so not to overwrite any existing filters foreach ($this->getElements() as $element) { $element->addFilter('StripTags'); } // Grab view and add the page-specific JavaScript into the page head $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $view->headScript()->appendFile('/assets/landlords-insurance-quote/js/underwritingQuestions.js', 'text/javascript'); }
public function isValid($postData) { // If Emergency Assistance is included for free // so we need to make the choice not required for validation purposes $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); if (isset($pageSession->quoteID)) { $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($pageSession->quoteID); if (!$quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER) && !$quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) { $this->getElement('need_boiler_heating')->setRequired(false); } } return parent::isValid($postData); }
public function isValid($postData) { // If building cover is added to the quote this form isn't even shown because Emergency Assistance is included for free // so we need to make the choice not required for validation purposes $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); if (isset($pageSession->quoteID)) { $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($pageSession->quoteID); if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER) || $quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) { $this->getElement('need_emergency_assistance')->setRequired(false); } } return parent::isValid($postData); }
public function isValid($postData) { // If prestige rent guarantee is added to the quote this form isn't even shown because it's included for free // so we need to make the choice not required for validation purposes $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); if (isset($pageSession->quoteID)) { $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($pageSession->quoteID); if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE) || isset($postData['need_prestige_rent_guarantee']) && $postData['need_prestige_rent_guarantee'] == 'yes') { $this->getElement('need_legal_expenses')->setRequired(false); } } return parent::isValid($postData); }
/** * Returns the endorsements required by a quote or policy. * * This method will identify the endorsements that should be applied to * the quote or policy identified by $policyNumber. If any endorsements are * identified, they will be detailed in one or more Model_Insurance_Endorsement * objects, which will then be returned in an array. If the quote / policy does * not merit any endorsements, then null will be returned. * * @param string $policyNumber * The quote or policy number. * * @return mixed * Returns an array of Model_Insurance_Endorsement objects, * or null if no endorsements are applicable. * * @todo * Not yet complete. */ public function getEndorsementsRequired($quoteID) { //Create a quote object from the $policyNumber $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($quoteID); $legacyQuoteId = $quoteManager->getModel()->legacyID; //Extract the postcode from the policyNumber $properties = $quoteManager->getProperties(); $postCode = $properties[0]['postcode']; //Extract the contents cover, if applicable. if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) { $contentsMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER); $contentsCover = $contentsMeta['cover_amount']; } else { $contentsCover = 0; } $params = Zend_Registry::get('params'); $returnArray = array(); //First check for flood endorsements. $termsDatasource = new Datasource_Insurance_LandlordsPlus_Terms(); $floodRiskScore = $termsDatasource->getFloodRiskScore($postCode); if ($floodRiskScore > 0) { //Mandatory/optional endorsement $endorsement = new Model_Insurance_Endorsement(); $endorsement->setPolicyNumber($legacyQuoteId); $endorsementType = new Model_Insurance_EndorsementType(); $endorsementType->setID($params->uw->ed->landlordsp->floodExclusion->id); $endorsementType->setName($params->uw->ed->landlordsp->floodExclusion->name); $endorsement->setEndorsementType($endorsementType); $endorsement->setEffectiveDate(new Zend_Date($quoteManager->getStartDate(), Zend_Date::ISO_8601)); $returnArray[] = $endorsement; } //Next check for subsidence endorsements. $subsidenceRiskScore = $termsDatasource->getSubsidenceRiskScore($postCode); if ($subsidenceRiskScore > 0) { //Mandatory endorsement $endorsement = new Model_Insurance_Endorsement(); $endorsement->setPolicyNumber($legacyQuoteId); $endorsementType = new Model_Insurance_EndorsementType(); $endorsementType->setID($params->uw->ed->landlordsp->subsidence->id); $endorsementType->setName($params->uw->ed->landlordsp->subsidence->name); $endorsement->setEndorsementType($endorsementType); $endorsement->setEffectiveDate(new Zend_Date($quoteManager->getStartDate(), Zend_Date::ISO_8601)); $returnArray[] = $endorsement; } //Next check for minimum standards of security. if ($contentsCover >= $params->uw->et->landlordsp->mandatory->contents) { //Mandatory endorsement $endorsement = new Model_Insurance_Endorsement(); $endorsement->setPolicyNumber($legacyQuoteId); $endorsementType = new Model_Insurance_EndorsementType(); $endorsementType->setID($params->uw->ed->landlordsp->minStandardProtection->id); $endorsementType->setName($params->uw->ed->landlordsp->minStandardProtection->name); $endorsement->setEndorsementType($endorsementType); $endorsement->setEffectiveDate(new Zend_Date($quoteManager->getStartDate(), Zend_Date::ISO_8601)); $returnArray[] = $endorsement; } //Provide a return value consistent with this methods contract. if (empty($returnArray)) { $returnVal = null; } else { $returnVal = $returnArray; } return $returnVal; }
/** * Validate a form page's values via AJAX * * @return void */ public function validatePageAction() { $return = array(); $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); $postData = $this->getRequest()->getParams(); $page = $postData['page']; if ($page == '') { return; } switch ($page) { case '1': $ajaxForm = new LandlordsInsuranceQuote_Form_Step1(); if (isset($postData['through_letting_agent']) && $postData['through_letting_agent'] == 'yes') { $subForm->getElement('letting_agent_name')->setRequired(true); $subForm->getElement('letting_agent_town')->setRequired(true); $subForm->getElement('letting_agent_asn')->setRequired(true); } break; case '2': $ajaxForm = new LandlordsInsuranceQuote_Form_Step2(); $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); if (isset($pageSession->quoteID)) { $quoteID = $pageSession->quoteID; $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($quoteID); $premiums = $quoteManager->calculatePremiums(); // Filter to mirror the subform element definitions. $currencyFilterElements = array('building_value', 'contents_amount'); foreach ($currencyFilterElements as $filterElement) { if (isset($postData[$filterElement])) { $postData[$filterElement] = preg_replace(array('/\\..+$/', '/\\D/'), array('', ''), $postData[$filterElement]); } } // Update the buildings insurance selection for the quote if (isset($postData['need_building_insurance']) && $postData['need_building_insurance'] == 'yes' && $postData['building_built'] != '' && $postData['building_bedrooms'] != '' && $postData['building_type'] != '') { // Add buildings insurance $quoteManager->addBuildingsCover($postData['building_built'], $postData['building_bedrooms'], $postData['building_type'], $postData['building_insurance_excess'], isset($postData['building_accidental_damage']) ? $postData['building_accidental_damage'] : 0, $postData['building_value'] != '' ? $postData['building_value'] : 0); // If we've calculated premiums but not got a dsi value - send a request back to front end for a // manual value if ($postData['override_dsi'] == '1' || $quoteManager->calculateDSI() == 0) { // We've not got a DSI Value - so we need to make the building value a required field $ajaxForm->getSubForm('subform_buildinginsurance')->getElement('building_value')->setRequired(true); $return['rebuildValueRequired'] = true; } else { $return['rebuildValueRequired'] = false; // Remove, re-add and recalculate buildings cover from scratch with given building value forcibly set to zero if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER)) { $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER); $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::EMERGENCY_ASSISTANCE); } $quoteManager->addBuildingsCover($postData['building_built'], $postData['building_bedrooms'], $postData['building_type'], $postData['building_insurance_excess'], isset($postData['building_accidental_damage']) ? $postData['building_accidental_damage'] : 0, 0); } } else { if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER)) { $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER); $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::EMERGENCY_ASSISTANCE); } } // Update the contents insurance selection for the quote if (isset($postData['need_contents_insurance']) && $postData['need_contents_insurance'] == 'yes') { // Add contents insurance if they've chosen whether it's furnished or not if (isset($postData['property_furnished'])) { if ($postData['property_furnished'] == 'yes') { if (isset($postData['contents_accidental_damage']) && isset($postData['contents_amount']) && isset($postData['contents_excess'])) { // Furnished property $quoteManager->addContentsCover(true, $postData['contents_accidental_damage'], $postData['contents_amount'], $postData['contents_excess']); } } elseif ($postData['property_furnished'] == 'no') { // Un-furnished property $quoteManager->addContentsCover(false); } } } else { $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER); $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::UNFURNISHED_CONTENTS_COVER); } if ($premiums != '') { // If this is a flood exclusion area - send that back so the page can display the messages if ($premiums['riskAreas']['floodArea'] == '1000') { $return['floodExcluded'] = true; } else { $return['floodExcluded'] = false; } // If this is a subsidence exclusion area - send that back so the page can display the messages if ($premiums['riskAreas']['subsidenceArea'] == '1000') { $return['subsidenceExcluded'] = true; } else { $return['subsidenceExcluded'] = false; } } } break; case '3': $ajaxForm = new LandlordsInsuranceQuote_Form_Step3(); $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); if (isset($pageSession->quoteID)) { $quoteID = $pageSession->quoteID; $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($quoteID); // Filter to mirror the subform element definitions. $currencyFilterElements = array('rent_amount'); foreach ($currencyFilterElements as $filterElement) { if (isset($postData[$filterElement])) { $postData[$filterElement] = preg_replace(array('/\\..+$/', '/\\D/'), array('', ''), $postData[$filterElement]); } } // Update the Emergency Assistance selection for the quote if (isset($postData['need_emergency_assistance'])) { if ($postData['need_emergency_assistance'] == 'yes') { $quoteManager->addEmergencyAssistance(); } else { $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::EMERGENCY_ASSISTANCE); } } // Update the Boiler & Heating selection for the quote if (isset($postData['need_boiler_heating'])) { if ($postData['need_boiler_heating'] == 'yes') { $quoteManager->addBoilerAndHeatingCover(); } else { $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::BOILER_HEATING); } } // Update the Prestiage Rent Guarantee for the quote if (isset($postData['need_prestige_rent_guarantee'])) { if ($postData['need_prestige_rent_guarantee'] == 'yes') { $quoteManager->addRentGuarantee($postData['rent_amount']); } else { $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE); // Also remove the free Legal Expenses or it causes a few "hiccups" $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::LEGAL_EXPENSES); } } // Update the Legal Expenses selection for the quote if (isset($postData['need_legal_expenses'])) { if ($postData['need_legal_expenses'] == 'yes') { $quoteManager->addLegalExpensesCover(); } else { // Don't remove the legal expenses if they've just been added for free by the rent guarantee product ;) if (!$quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE)) { $quoteManager->removeProduct(Manager_Insurance_LandlordsPlus_Quote::LEGAL_EXPENSES); } } } } break; case '4': $ajaxForm = new LandlordsInsuranceQuote_Form_Step4(); break; case '5': $ajaxForm = new LandlordsInsuranceQuote_Form_Step5(); break; default: return; } $valid = $ajaxForm->isValid($postData); // TODO: Needs to run the LI+ quote manager and calculate premiums so that they can be returned later on if (!$valid) { $errorMessages = $ajaxForm->getMessagesFlattened(); // We need to strip out some complex messages that the end user won't care about if (isset($errorMessages['email_address'])) { if (isset($errorMessages['email_address']['hostnameUnknownTld'])) { unset($errorMessages['email_address']['hostnameUnknownTld']); } if (isset($errorMessages['email_address']['hostnameLocalNameNotAllowed'])) { unset($errorMessages['email_address']['hostnameLocalNameNotAllowed']); } } $return['errorJs'] = $errorMessages; $return['errorCount'] = count($errorMessages); $return['errorHtml'] = $this->view->partial('partials/error-list.phtml', array('errors' => $errorMessages)); } else { $return['errorJs'] = ''; $return['errorCount'] = ''; $return['errorHtml'] = ''; } // Calculate premiums $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); if (isset($pageSession->quoteID)) { $quoteID = $pageSession->quoteID; $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($quoteID); $return['premiums'] = $quoteManager->calculateQuickPremiums(); // Do a little bit of nicer formatting for the front end (add commas to thousands etc..) $return['fees'] = $quoteManager->getFees(); } echo Zend_Json::encode($return); }
/** * 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; }