Esempio n. 1
0
 /**
  * Intended to be run by cron.
  *
  * Looks through recent quotes to process mailers for.  Criteria to be satisfied: a) must be x minutes old (eg,
  * probably abandoned) (also should be no older than y to prevent historic quotes being pinged), b) user must have
  * reached at least step z, and c) no mailer has been sent.
  *
  * Values for x, y and z are set in parameters and are independent of the web lead view and status from IAS.
  *
  * @return void
  */
 public function sendMailers()
 {
     // Prepare web lead summary data source
     if (null == $this->_webLeadSummaries) {
         $this->_webLeadSummaries = new Datasource_Core_WebLeadSummaries();
     }
     // Fetch relevant parameters
     $params = Zend_Registry::get('params');
     $hourOffset = $params->weblead->hourOffset;
     $minLastUpdated = $params->weblead->mailer->abandonedAge;
     // In seconds
     $maxLastUpdated = $params->weblead->mailer->ignoredAge;
     // In seconds
     $mailerAtSteps = array(Model_Core_WebLeadProduct::TCIPLUS => array('continueQuote' => explode(',', $params->weblead->mailer->tenant->continueQuote->steps), 'completeQuote' => explode(',', $params->weblead->mailer->tenant->completeQuote->steps)), Model_Core_WebLeadProduct::LANDLORDSPLUS => array('continueQuote' => explode(',', $params->weblead->mailer->landlord->continueQuote->steps), 'completeQuote' => explode(',', $params->weblead->mailer->landlord->completeQuote->steps)));
     $mailerProduct = array(Model_Core_WebLeadProduct::TCIPLUS => 'tenant', Model_Core_WebLeadProduct::LANDLORDSPLUS => 'landlord');
     $searchCriteria = array('hourOffset' => $hourOffset, 'minLastUpdated' => $minLastUpdated, 'maxLastUpdated' => $maxLastUpdated, 'products' => array(Model_Core_WebLeadProduct::TCIPLUS, Model_Core_WebLeadProduct::LANDLORDSPLUS), 'isMailerSent' => 0);
     // Fetch summaries that match the criteria
     $webLeadSummaries = $this->_webLeadSummaries->searchActiveSummaries($searchCriteria);
     // Early exit if there's nothing to do
     if (count($webLeadSummaries) == 0) {
         return;
     }
     // Loop through summaries looking for those that meet a "mailer at step" requirement
     foreach ($webLeadSummaries as $webLeadSummary) {
         $product = $webLeadSummary->product;
         $maxCompletedStep = $this->getBlobMaxStep($webLeadSummary->webLeadSummaryId);
         foreach ($mailerAtSteps[$product] as $mailerType => $mailerStepFilter) {
             if (in_array($maxCompletedStep, $mailerStepFilter)) {
                 // We need to send a mailer!
                 $mail = new Application_Core_Mail();
                 $link = str_replace('http:', 'https:', $params->homelet->domain) . $params->weblead->mailer->retrieveRelativeUrl;
                 $link = str_replace(array('[quoteNumber]', '[email]'), array($webLeadSummary->quoteNumber, $webLeadSummary->emailAddress), $link);
                 $replacements = array('title' => $webLeadSummary->title, 'firstName' => $webLeadSummary->firstName, 'lastName' => $webLeadSummary->lastName, 'fullName' => "{$webLeadSummary->title} {$webLeadSummary->firstName} {$webLeadSummary->lastName}", 'quoteNumber' => $webLeadSummary->quoteNumber, 'link' => htmlentities($link), 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl);
                 $subjectLine = $params->weblead->mailer->{$mailerProduct[$product]}->{$mailerType}->subject;
                 foreach ($replacements as $key => $val) {
                     $subjectLine = str_replace("[{$key}]", $val, $subjectLine);
                 }
                 $replacements['pageTitle'] = $subjectLine;
                 // If this is a "Complete Quote" mailer then fetch the actual quote to get some values out of it
                 if ('completeQuote' == $mailerType) {
                     $replacements['annualPremium'] = '';
                     $replacements['monthlyPremium'] = '';
                     $replacements['expiryDate'] = '';
                     $quoteManager = new Manager_Insurance_LegacyQuote();
                     $quote = $quoteManager->getQuoteByPolicyNumber($webLeadSummary->quoteNumber);
                     if ($quote) {
                         if ('Annually' == $quote->payBy) {
                             $replacements['annualPremium'] = number_format($quote->quote, 2);
                             $replacements['monthlyPremium'] = number_format($quote->quote / 12, 2);
                         } else {
                             $replacements['annualPremium'] = number_format($quote->quote * 12, 2);
                             $replacements['monthlyPremium'] = number_format($quote->quote, 2);
                         }
                         $replacements['expiryDate'] = $quote->getExpiresAt();
                     }
                 }
                 $template = $params->weblead->mailer->{$mailerProduct[$product]}->{$mailerType}->template;
                 $mail->setTo($webLeadSummary->emailAddress, $replacements['fullName'])->setFrom($params->weblead->mailer->fromAddress, $params->weblead->mailer->fromName)->setSubject($subjectLine)->applyTemplate($template, $replacements, true);
                 $mail->send();
                 // Update web lead summary to mark mailer as sent
                 $webLeadSummary->isMailerSent = true;
                 $this->_webLeadSummaries->updateSummary($webLeadSummary);
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Performs a copy of the quote stored within the MYSQL4 db to MYSQL5.
  */
 protected function legacyQuoteMigration($policyNumber, $customerId)
 {
     // Assume a record has not been configured within the MySQL 5 database.
     // Need to copy data over from the MySQL 4 server to patch the web
     // quote and buy process
     $legacyQuotesDs = new Datasource_Insurance_LegacyQuotes();
     $legacyQuote = $legacyQuotesDs->getByPolicyNumber($policyNumber);
     // copy data into a Model_Insurance_Quote object
     $this->_quoteModel = new Model_Insurance_Quote();
     $this->_quoteModel->legacyID = $policyNumber;
     $this->_quoteModel->legacyCustomerID = $legacyQuote->refNo;
     $this->_quoteModel->customerID = $customerId;
     $this->_quoteModel->agentSchemeNumber = $legacyQuote->agentSchemeNumber;
     $this->_quoteModel->issuedDate = $legacyQuote->issueDate;
     $this->_quoteModel->startDate = $legacyQuote->startDate;
     $this->_quoteModel->endDate = $legacyQuote->endDate;
     $this->_quoteModel->payFrequency = $legacyQuote->payBy;
     $this->_quoteModel->policyNumber = $legacyQuote->policyNumber;
     $this->_quoteModel->premium = $legacyQuote->premium;
     $this->_quoteModel->ipt = $legacyQuote->ipt;
     $this->_quoteModel->policyLength = $legacyQuote->policyLength;
     // store the object to db
     $this->_quoteDataSource->save($this->_quoteModel);
     // properties
     $tenantTypeID = null;
     $agentManaged = null;
     $ownershipLengthID = null;
     $noClaimsYearsID = null;
     $excludeFloodCover = null;
     //        // TODO: Quote products
     //        foreach (explode('|', $legacyQuote->policyOptions) as $option) {
     //            if ($option == 'buildingsp') {
     //                // Buildings
     //            }
     //            else if ($option == 'contentslp') {
     //                // Contents
     //            }
     //            else if ($option == 'limitedcontentsp') {
     //                // Limited contents
     //            }
     //            else if ($option == 'legalexpensesp') {
     //                // Legal expenses
     //            }
     //            else if ($option == 'rentguaranteep') {
     //                // Rent guarantee
     //            }
     //            else if ($option == 'emergencyassistancestandalone' || $option == 'emergencyassistancebahstandalone') {
     //                // Emergency assistance
     //            }
     //
     //            contentslAccidentalDamagep
     //            buildingsAccidentalDamagep
     //        }
     $legacyPropertiesDs = new Manager_Insurance_LegacyQuote();
     $legacyProperties = $legacyPropertiesDs->getProperties($policyNumber);
     foreach ($legacyProperties as $propertyId => $property) {
         // Foreach property, check its content and copy into the web quote process
         if ($propertyId == 3) {
             // No claims period
             switch ($property['propertyValue']) {
                 case 0:
                     $noClaimsYearsID = 1;
                     break;
                     // less than 1 year
                 // less than 1 year
                 case 1:
                     $noClaimsYearsID = 2;
                     break;
                     // 1 year
                 // 1 year
                 case 2:
                     $noClaimsYearsID = 3;
                     break;
                     // 2 years
                 // 2 years
                 case 3:
                     $noClaimsYearsID = 4;
                     break;
                     // 3 years
                 // 3 years
                 case 4:
                     $noClaimsYearsID = 5;
                     break;
                     // more than 3 years
             }
         } else {
             if ($propertyId == 4) {
                 // Managed property
                 switch ($property['propertyValue']) {
                     case 0:
                         $agentManaged = 0;
                         break;
                         // No
                     // No
                     case 1:
                         $agentManaged = 1;
                         break;
                         // Yes
                 }
             } else {
                 if ($propertyId == 5) {
                     //                // TODO: Excess
                     //                switch ($property['propertyValue']) {
                     //                    case 0: break;                              // 0
                     //                    case 1: break;                              // 100
                     //                    case 2: break;                              // 250
                     //                    case 3: break;                              // 500
                     //                    case 4: break;                              // 1000
                     //                }
                 } else {
                     if ($propertyId == 6) {
                         // Tenant type
                         switch ($property['propertyValue']) {
                             case 0:
                                 $tenantTypeID = 1;
                                 break;
                                 // Employed
                             // Employed
                             case 1:
                                 $tenantTypeID = 2;
                                 break;
                                 // Self Employed
                             // Self Employed
                             case 2:
                                 $tenantTypeID = 3;
                                 break;
                                 // Student
                             // Student
                             case 3:
                                 $tenantTypeID = 4;
                                 break;
                                 // Retired
                             // Retired
                             case 4:
                                 $tenantTypeID = 5;
                                 break;
                                 // Unemployed
                             // Unemployed
                             case 5:
                                 $tenantTypeID = 7;
                                 break;
                                 // Housing authority
                             // Housing authority
                             case 6:
                                 $tenantTypeID = 8;
                                 break;
                                 // Unknown
                             // Unknown
                             case 7:
                                 $tenantTypeID = 6;
                                 break;
                                 // Claiming benefits
                         }
                     } else {
                         if ($propertyId == 9) {
                             // Buildings flood risk
                             switch ($property['propertyValue']) {
                                 case 0:
                                     $excludeFloodCover = 1;
                                     break;
                                     // No
                                 // No
                                 case 1:
                                     $excludeFloodCover = 0;
                                     break;
                                     // Yes
                             }
                         } else {
                             if ($propertyId == 11) {
                                 //                // TODO: Buildings cover over 500,000
                                 //                switch ($property['propertyValue']) {
                                 //                    case 0: break;                              // No
                                 //                    case 1: break;                              // Yes
                                 //                }
                             } else {
                                 if ($propertyId == 12) {
                                     // Ownership length
                                     switch ($property['propertyValue']) {
                                         case 0:
                                             $ownershipLengthID = 1;
                                             break;
                                             // 0 years
                                         // 0 years
                                         case 1:
                                             $ownershipLengthID = 2;
                                             break;
                                             // 1 year
                                         // 1 year
                                         case 2:
                                             $ownershipLengthID = 3;
                                             break;
                                             // 2 years
                                         // 2 years
                                         case 3:
                                             $ownershipLengthID = 4;
                                             break;
                                             // 3 years
                                         // 3 years
                                         case 4:
                                             $ownershipLengthID = 5;
                                             break;
                                             // over 3 years
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Populate properties
     $propertiesDs = new Datasource_Insurance_Quote_Properties();
     $propertiesDs->add($this->_quoteModel->ID, $legacyQuote->propertyPostcode, '', '', $legacyQuote->propertyAddress1, $tenantTypeID, $agentManaged, $ownershipLengthID, $noClaimsYearsID, $excludeFloodCover, $legacyQuote->propertyAddress2, $legacyQuote->propertyAddress3, '');
     // TODO: repeat for products, product_metas and properties
 }
 /**
  * Retrieve TCI+ or LI+ quote.
  */
 public function retrieveQuoteAction()
 {
     $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/retrieve-quote' => 'Retrieve Quote'));
     $params = Zend_Registry::get('params');
     $form = new Account_Form_RetrieveQuote();
     $quoteManager = new Manager_Insurance_LegacyQuote();
     $customerManager = new Manager_Core_Customer();
     // If there's a quote number in the GET vars then sanitise and uppercase it, and place it in the form
     if (isset($_GET['number'])) {
         // Sanitise and uppercase supplied quote number, place in form
         $quoteNumber = strtoupper(preg_replace('/[^\\w\\/]/', '', $_GET['number']));
         $form->quote_number->setValue($quoteNumber);
         // Also pre-populate the form with first name and last name if the quote number is valid
         $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
         if ($quote) {
             // Get customer details from quote refNo
             $quoteRefNo = $quote->refNo;
             $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
             if ($customer) {
                 $form->first_name->setValue($customer->getFirstName());
                 $form->last_name->setValue($customer->getLastName());
             }
         }
     }
     // Get email address, place in form if it looks valid
     if (isset($_GET['email'])) {
         $getEmail = $_GET['email'];
         $emailValidator = new Zend_Validate_EmailAddress();
         if ($emailValidator->isValid($getEmail)) {
             $form->email->setValue($getEmail);
         }
     }
     $request = $this->getRequest();
     $postData = $request->getPost();
     // Handle retrieve attempts
     if ($request->isPost()) {
         if ($form->isValid($postData)) {
             // Are we looking up by quote number or by e-mail address?  If a quote number is present it takes
             // precedence
             $quotes = array();
             $customer = null;
             $quoteNumber = $form->quote_number->getValue();
             $email = $form->email->getValue();
             if ('' != $quoteNumber) {
                 $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
                 if ($quote) {
                     // Look up customer from quote retrieved
                     $quoteRefNo = $quote->refNo;
                     $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
                     $quotes = array($quote);
                 }
             } else {
                 // Get all legacy quote IDs by customer e-mail address
                 $legacyIDs = array();
                 // Try to look up a customer record's quotes' IDs by the e-mail provided
                 $newCustomer = $customerManager->getCustomerByEmailAddress($email);
                 if ($newCustomer) {
                     $legacyCustomerMap = new Datasource_Core_CustomerMaps();
                     $legacyIDs = $legacyCustomerMap->getLegacyIDs($newCustomer->getIdentifier(Model_Core_Customer::IDENTIFIER));
                 }
                 // Also check in the legacy DB only to ensure landlords quotes are found
                 $customer = $customerManager->getLegacyCustomerByEmailAddress($email);
                 if ($customer) {
                     $legacyCustomerId = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                     if (!in_array($legacyCustomerId, $legacyIDs)) {
                         $legacyIDs[] = $legacyCustomerId;
                     }
                 }
                 // Retrieve all quotes for the linked customer reference numbers
                 $quoteDatasource = new Datasource_Insurance_LegacyQuotes();
                 $quotes = $quoteDatasource->getActiveQuotes($legacyIDs, '', array('policynumber', 'startdate'));
             }
             // Do we have at least one quote and the customer details
             if (count($quotes) > 0 && $customer) {
                 // Check that the security requirements are met (matching email, first name, last name, postcode and
                 // DOB)
                 if (trim($customer->getEmailAddress()) == trim($form->email->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getFirstName(), $form->first_name->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getLastName(), $form->last_name->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getPostCode(), $form->cor_postcode->getValue()) && Application_Core_Utilities::mysqlDateToUk($customer->getDateOfBirthAt()) == trim($form->date_of_birth_at->getValue())) {
                     // If this is a single quote then generate an auth token and bounce them on
                     if (count($quotes) == 1) {
                         // Ensure there's a quote number to use in the security token (because there won't be one if
                         // it was a single match based only on an e-mail address)
                         if ('' == $quoteNumber) {
                             $quoteNumber = $quotes[0]->policyNumber;
                         }
                         // Generate an authentication token for a single policy
                         $securityManager = new Application_Core_Security($params->myhomelet->retrieveWithoutAccount->macSecret, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
                         $securityData = array('quoteNumber' => $quoteNumber);
                         $authToken = $securityManager->generate($securityData);
                         // Bounce to the right Q&B depending on quote type
                         if ($quotes[0]->getProductName() == 'tenants') {
                             $this->_helper->redirector->gotoUrl('/tenants/insurance-quote/retrieve?auth=' . $authToken);
                             return;
                         } elseif ($quotes[0]->getProductName() == 'landlords') {
                             $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/retrieve?auth=' . $authToken);
                             return;
                         } else {
                             $form->setDescription('Sorry, we don\'t yet allow resuming the type of quote you have - please call us.');
                         }
                     } else {
                         // Generate an authentication token for the customer email
                         $securityManager = new Application_Core_Security($params->myhomelet->retrieveWithoutAccount->macSecret, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
                         $securityData = array('customerEmail' => $email);
                         $authToken = $securityManager->generate($securityData);
                         $this->_helper->redirector->gotoUrl('/my-homelet/retrieve-multiple-quotes?auth=' . $authToken);
                         return;
                     }
                 } else {
                     // Security check failed, show error
                     $form->setDescription('Sorry, we could not find your quote from the details provided - please check them and try again.');
                 }
             } else {
                 // Lookup failed, show error
                 $form->setDescription('Sorry, we could not find your quote from the details provided - please check them and try again.');
             }
         }
     }
     $this->view->form = $form;
 }
 /**
  * Resume an existing quote for customers who either have a temporary auth token for a retrieval with no My HomeLet
  * account, or who are My HomeLet authenticated.  Customers with no form of valid authentication are redirected to
  * the My HomeLet login page.
  *
  * @return void
  */
 public function retrieveAction()
 {
     // Authorisation using no-account My HomeLet retrieval auth token
     if ($this->getRequest()->getParam('auth') != '') {
         $mac = $this->getRequest()->getParam('auth');
         $securityManager = new Application_Core_Security($this->_params->myhomelet->retrieveWithoutAccount->macSecret, $this->_params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $this->_params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
         $dataKeys = array('quoteNumber');
         $securityCheck = $securityManager->authenticate($mac, $dataKeys);
         if (isset($securityCheck['result']) && $securityCheck['result']) {
             $quoteNumber = $securityCheck['data']['quoteNumber'];
             $quoteManager = new Manager_Insurance_LegacyQuote();
             $customerManager = new Manager_Core_Customer();
             $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
             $quoteRefNo = $quote->refNo;
             $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
             $customerID = $referenceNumber = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
             $quoteManager = new Manager_Insurance_LandlordsPlus_Quote(null, $quoteNumber, null, $customerID);
             $quote = $quoteManager->getModel();
             $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
             $pageSession->quoteID = $quote->ID;
             $pageSession->customerRefNo = $referenceNumber;
             //Retrieve the WebLead summary ID so that the WebLead can continue to be updated and important
             //details captured, such as the campaign code.
             $webLeadManager = new Manager_Core_WebLead();
             $pageSession->webLeadSummaryId = $webLeadManager->getSummaryId($quoteNumber);
             $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/step1');
             return;
         }
     }
     // Authorisation using My HomeLet logged in details
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
     if ($auth->hasIdentity()) {
         // Check to see if we have a reference number to load up
         if ($this->getRequest()->getParam('quote') != '') {
             $quoteNumber = $this->getRequest()->getParam('quote');
             // Customer is logged in and is trying to retrieve a specific quote
             // We need to check to make sure they own it
             $customerID = $auth->getStorage()->read()->id;
             // Now we need to get their legacy ID
             $customerManager = new Manager_Core_Customer();
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             $referenceNumber = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
             // Need to find the quote ID by the policy number
             $quotes = new Manager_Insurance_LandlordsPlus_Quote(null, $quoteNumber, null, $customerID);
             $quote = $quotes->getModel();
             $legacyCustomerMap = new Datasource_Core_CustomerMaps();
             $legacyIDs = $legacyCustomerMap->getLegacyIDs($customerID);
             if (in_array($quote->legacyCustomerID, $legacyIDs)) {
                 // This customer does own this reference - so set the page session stuff up and redirect
                 $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
                 $pageSession->quoteID = $quote->ID;
                 $pageSession->customerRefNo = $referenceNumber;
                 //Retrieve the WebLead summary ID so that the WebLead can continue to be updated and important
                 //details captured, such as the campaign code.
                 $webLeadManager = new Manager_Core_WebLead();
                 $pageSession->webLeadSummaryId = $webLeadManager->getSummaryId($quoteNumber);
                 $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/step1');
             }
         }
     }
     $this->_helper->redirector->gotoUrl('/login?referrerUrl=/my-homelet/quotes');
 }