/** * RRP Inception Form */ public function rentRecoveryPlusAction() { // Ensure address lookup JS is available $this->view->headScript()->appendFile('/assets/connect/js/rentguaranteeclaims/addressLookup.js'); // Ensure date picker CSS and JS are available $this->view->headLink()->appendStylesheet('/assets/vendor/jquery-datepicker/css/datePicker.css'); $this->view->headScript()->appendFile('/assets/vendor/jquery-date/js/date.js'); $this->view->headScript()->appendFile('/assets/vendor/jquery-datepicker/js/jquery.datePicker.js'); $request = $this->getSymfonyRequest(); $data = null; $policyNumberManager = new Manager_Core_PolicyNumber(); if ($request->isMethod('GET')) { $quoteNumber = $request->get('policyNumber'); if ($policyNumberManager->isRentRecoveryPlusQuote($quoteNumber)) { $applicationDecoratorClass = $this->getContainer()->get('rrp.application.decorator.class'); /** @var RRP\Application\Decorators\RentRecoveryPlusQuote $quote */ $quote = $applicationDecoratorClass::getDecorator('RentRecoveryPlusQuote'); $data = $quote->getApplicationData($quoteNumber); } } $form = $this->_getRentRecoveryPlusApplicationForm($data, array('currentAsn' => $this->_agentSchemeNumber)); if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { if ($request->isXmlHttpRequest()) { $update = true; } else { $update = $form->get('update')->isClicked(); } if (!$update) { /** @var RRP\Model\RentRecoveryPlusApplication $application */ $application = $form->getData(); $applicationDecoratorClass = $this->getContainer()->get('rrp.application.decorator.class'); /** @var RRP\Application\Decorators\RentRecoveryPlusQuote $quote */ $quote = $applicationDecoratorClass::getDecorator('RentRecoveryPlusQuote'); $quote->setFromApplication($application); if ($quote->getAppData()->getRefNo() === null) { $customerManager = new Manager_Core_Customer(); $sudoEmailAddress = $customerManager->generateAgentSudoEmailAddress($this->_agentSchemeNumber); $customer = $customerManager->getCustomerByEmailAddress($sudoEmailAddress); $isNewCustomer = false; if (!$customer) { $isNewCustomer = true; $customer = $customerManager->createNewCustomer($sudoEmailAddress, Model_Core_Customer::AGENT, true); $customer->setLastName($this->_agentObj->name); if ($this->_agentObj->contact[0]->address->flatNumber) { $line1 = $this->_agentObj->contact[0]->address->flatNumber . ' '; } else { if ($this->_agentObj->contact[0]->address->houseName) { $line1 = $this->_agentObj->contact[0]->address->houseName . ' '; } else { if ($this->_agentObj->contact[0]->address->houseNumber) { $line1 = $this->_agentObj->contact[0]->address->houseNumber . ' '; } else { $line1 = ''; } } } if ($this->_agentObj->contact[0]->address->addressLine1 && $this->_agentObj->contact[0]->address->addressLine2) { $line1 .= $this->_agentObj->contact[0]->address->addressLine1 . ', ' . $this->_agentObj->contact[0]->address->addressLine2; } else { if ($this->_agentObj->contact[0]->address->addressLine1) { $line1 .= $this->_agentObj->contact[0]->address->addressLine1; } else { if ($this->_agentObj->contact[0]->address->addressLine2) { $line1 .= $this->_agentObj->contact[0]->address->addressLine2; } } } $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $line1); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $this->_agentObj->contact[0]->address->town); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $this->_agentObj->contact[0]->address->county); $customer->setPostCode($this->_agentObj->contact[0]->address->postCode); $customer->setCountry($this->_agentObj->contact[0]->address->country); $customerManager->updateCustomer($customer); } // Now get the reference number from the newly created customer $refNo = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER); $quote->getAppData()->setRefNo($refNo); if ($isNewCustomer) { $customerManager->updateCustomerAgentSchemeNumber($this->_agentSchemeNumber, $refNo); } if ($application->getPolicyNumber()) { $policyNumber = $application->getPolicyNumber(); } else { $policyNumber = $policyNumberManager->generateApplicationNumber(Manager_Core_PolicyNumber::QUOTE_IDENTIFIER); } $quote->setDefaults($policyNumber, $application->getReferenceType(), $application->getIsContinuationOfExistingPolicy(), $application->getPropertyLetType(), $application->getPropertyDeposit(), Model_Insurance_RentRecoveryPlus_LegacyPolicy::STATUS_QUOTE)->getAppData()->setAgentSchemeNumber($this->_agentSchemeNumber)->setUnderwritingQuestionSetID($this->_params->connect->settings->rentRecoveryPlus->underwritingQuestionSetID)->setRiskArea($this->_params->connect->settings->rentRecoveryPlus->riskArea); } else { $policyNumber = $quote->getAppData()->getPolicyNumber(); } $this->referralModel->setPolicyNumber($policyNumber); $this->rateManager = $this->initialiseRateManager($application); $quote->setPolicyOptions($application->getPropertyRental(), $this->rateManager->getPremium(), $this->rateManager->getNilExcessOption())->getAppData()->setPremium($this->rateManager->getPremium())->setIpt($this->rateManager->getIpt())->setQuote($this->rateManager->getQuote())->setRateSetID($this->rateManager->getRateSetID()); // Does the given reference satisfy the policy criteria for this particular reference? $referralRequired = false; $reference = $this->getReferenceFromSession($application->getReferenceNumber()); $referenceSatisfiesCriteria = $this->referenceSatisfiesCriteria($reference); // Does the application satisfy the application criteria? $this->referralModel->setFromApplication($application, $this->rateManager->getPremium()); $applicationSatisfiesCriteria = $this->applicationSatisfiesCriteria(); if (!$referenceSatisfiesCriteria || !$applicationSatisfiesCriteria) { // Fire a POLICY_REFERRED event to handle all referral related actions. $referredEvent = new ReferredEvent($this->referralModel); $this->eventDispatcher->dispatch(RRPEvents::POLICY_REFERRED, $referredEvent); // Mark this application as referred. $quote->getAppData()->setPayStatus(Model_Insurance_RentRecoveryPlus_LegacyPolicy::PAY_STATUS_REFERRED); $referralRequired = true; } if ($application->getIsContinuationOfExistingPolicy()) { $mailManager = new Application_Core_Mail(); if ($application->getIsExistingPolicyToBeCancelled()) { $subject = str_replace('{$existingPolicyRef}', $application->getExistingPolicyRef(), $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailSubject); $message = $this->getContainer()->get('twig')->render('rent-recovery-plus-cancel-existing-mail.plain.twig', array('agentName' => $this->_agentObj->name, 'agentSchemeNumber' => $this->_agentSchemeNumber, 'policyNumber' => $policyNumber)); $mailManager->setTo($this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailToAddress, $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailToName)->setFrom($this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailFromAddress, $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailFromName)->setSubject($subject)->setBodyText($message); } else { $subject = str_replace('{$existingPolicyRef}', $application->getExistingPolicyRef(), $this->_params->connect->settings->rentRecoveryPlus->cancelExisting->emailSubject); $message = $this->getContainer()->get('twig')->render('rent-recovery-plus-keep-existing-mail.plain.twig', array('agentName' => $this->_agentObj->name, 'agentSchemeNumber' => $this->_agentSchemeNumber, 'existingPolicyRef' => $application->getExistingPolicyRef())); $mailManager->setTo($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailToAddress, $this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailToName)->setFrom($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailFromAddress, $this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailFromName)->setSubject($subject)->setBodyText($message); if (isset($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailCcAddress)) { $mailManager->setCC($this->_params->connect->settings->rentRecoveryPlus->keepExisting->emailCcAddress); } } $mailManager->send(); } if (!$quote->save()) { return $this->renderTwigView('/rentguarantee/rent-recovery-plus-error.html.twig'); } if ($referralRequired) { // Render the referral text to the user. return $this->renderTwigView('/rentguarantee/rent-recovery-plus-referral.html.twig', array('policyNumber' => $policyNumber)); } if ($application->getIsPayMonthly()) { $paymentDetails = sprintf('This will appear on your invoices as %d monthly payments of' . ' £%.02f plus £%.02f (IPT at %d%%). Total monthly payment £%.02f. ', $application->getPolicyLength(), $this->rateManager->getPremium(), $this->rateManager->getIpt(), $this->rateManager->getIptPercent(), $this->rateManager->getQuote()); } else { $paymentDetails = sprintf('This will appear on your next invoices as £%.02f plus £%.02f (IPT at %d%%). Total £%.02f. ', $this->rateManager->getPremium(), $this->rateManager->getIpt(), $this->rateManager->getIptPercent(), $this->rateManager->getQuote()); } return $this->renderTwigView('/rentguarantee/rent-recovery-plus-quote.html.twig', array('policyNumber' => $policyNumber, 'paymentDetails' => $paymentDetails)); } } } if ($this->getRequest()->isXmlHttpRequest()) { $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout->disableLayout(); } $agent = new Datasource_Core_AgentUser(); if ($agent->canDisplayRRPI($this->_agentSchemeNumber, $this->_agentUserName)) { $this->renderTwigView('/rentguarantee/rent-recovery-plus-application.html.twig', array('form' => $form->createView())); } else { $this->renderTwigView('/rentguarantee/rent-recovery-plus-information.html.twig'); } }
/** * 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(); }
/** * Register action * * @return void */ public function registerAction() { $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/register' => 'Register')); $params = Zend_Registry::get('params'); $form = new Account_Form_Register(); // Populate the form with the security question options $securityQuestionModel = new Datasource_Core_SecurityQuestion(); $securityQuestionOptions = $securityQuestionModel->getOptions(); foreach ($securityQuestionOptions as $option) { $form->security_question->addMultiOption($option['id'], $option['question']); } if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { $customermgr = new Manager_Core_Customer(); // Detect if the customer has already registered with this email address $customer = $customermgr->getCustomerByEmailAddress($form->email->getValue()); if ($customer) { // Customer already exists, flag form in error // Ideally this should go in the form as an overridden validation method, but this would // tightly couple the form to the customer manager anyway, which itself is bad. // Alternatively I could inject the found customer object into the form, but then this doesn't change // much to using the code here anyway. $form->email->addError('This email is already in use. Have you signed up before?')->markAsError(); } else { // Create customer. Because this is the generic registration page, we use a generic customer type $customer = $customermgr->createNewCustomer($form->email->getValue(), Model_Core_Customer::CUSTOMER); // Update customer with password and security data $customer->setTitle($form->title->getValue()); $customer->setFirstName($form->first_name->getValue()); $customer->setLastName($form->last_name->getValue()); $customer->setSecurityQuestion($form->security_question->getValue()); $customer->setSecurityAnswer($form->security_answer->getValue()); $customer->setPassword($form->password->getValue()); $customer->setAccountLoadComplete(true); $customer->typeID = Model_Core_Customer::CUSTOMER; $customermgr->updateCustomer($customer); // Create sign-up completion email $customer->sendAccountValidationEmail(); // Forward request to registration confirmation page $this->_helper->redirector->gotoUrl('/my-homelet/registration-awaiting-confirmation'); } } } $this->view->form = $form; }
private function saveStep1(Zend_Form $pageForm) { // Get sub forms $subFormPersonalDetails = $pageForm->getSubForm('subform_personaldetails'); $subFormDataProtection = $pageForm->getSubForm('subform_dataprotection'); $subFormContentsInsurance = $pageForm->getSubForm('subform_contentsinsurance'); $subFormSharers = $pageForm->getSubForm('subform_sharers'); $pageSession = new Zend_Session_Namespace('tenants_insurance_quote'); $customerManager = new Manager_Core_Customer(); $auth = Zend_Auth::getInstance(); $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer')); // TODO: This should check reference number exists, not just property! if (!isset($this->_customerReferenceNumber)) { // Do we already have a legacy customer with this email address? $customer = $customerManager->getCustomerByEmailAddress($subFormPersonalDetails->getElement('email_address')->getValue()); if (!$customer) { // We don't have a session so we need to create a legacy customer/quote entry to save against // All new customers are now of type Model_Core_Customer::CUSTOMER $customer = $customerManager->createNewCustomer($subFormPersonalDetails->getElement('email_address')->getValue(), Model_Core_Customer::CUSTOMER); $legacyCustomer = $customer; if (!isset($pageSession->IsNewCustomer)) { $pageSession->IsNewCustomer = true; } } else { if (!isset($pageSession->IsNewCustomer)) { $pageSession->IsNewCustomer = false; } $legacyCustomer = $customerManager->createNewCustomer($subFormPersonalDetails->getElement('email_address')->getValue(), Model_Core_Customer::CUSTOMER, true); } $customerManager->linkLegacyToNew($legacyCustomer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER), $customer->getIdentifier(Model_Core_Customer::IDENTIFIER)); // Now get the reference number from the newly created customer $customerRefNo = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER); $this->_customerReferenceNumber = $customerRefNo; $pageSession->CustomerRefNo = $customerRefNo; $pageSession->CustomerID = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER); } else { // We are in session so just instantiate the customer manager with the existing reference number $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber); $customerRefNo = $pageSession->CustomerRefNo; $pageSession->CustomerID = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER); if (!isset($pageSession->IsNewCustomer)) { $pageSession->IsNewCustomer = false; } } $pageSession->CustomerEmail = $subFormPersonalDetails->getElement('email_address')->getValue(); $pageSession->CustomerDob = $subFormPersonalDetails->getElement('date_of_birth_at')->getValue(); if (!$auth->hasIdentity()) { // Update the customer record with the form data, but only if they are a new customer // Existing customers must phone us. // Note that no message stating this is given to the end user if ($subFormPersonalDetails->getElement('title')->getValue() != "Other") { $customer->setTitle($subFormPersonalDetails->getElement('title')->getValue()); } else { $customer->setTitle($subFormPersonalDetails->getElement('other_title')->getValue()); } $customer->setFirstName($subFormPersonalDetails->getElement('first_name')->getValue()); $customer->setLastName($subFormPersonalDetails->getElement('last_name')->getValue()); $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $subFormPersonalDetails->getElement('phone_number')->getValue()); $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $subFormPersonalDetails->getElement('mobile_number')->getValue()); $customer->setEmailAddress($subFormPersonalDetails->getElement('email_address')->getValue()); $customer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($subFormPersonalDetails->getElement('date_of_birth_at')->getValue())); $customer->setIsForeignAddress(false); } // TODO: Make this all better... $customerManager->updateCustomer($customer); // 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->linkLegacyToNew($customerRefNo, $customerID); // See if we have an agent scheme number, if so use it $session = new Zend_Session_Namespace('homelet_global'); $agentSchemeNumber = $session->agentSchemeNumber; // Instantiate the quote manager - if this is a new customer it will automatically create a new quote // otherwise it will use the existing quote $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote($customerRefNo, $agentSchemeNumber, $pageSession->PolicyNumber); // Set the contents SI - this does an automatic save if (is_numeric($subFormContentsInsurance->getElement('contents_cover_a')->getValue())) { $contentsSI = $subFormContentsInsurance->getElement('contents_cover_a')->getValue(); } else { $contentsSI = $subFormContentsInsurance->getElement('contents_cover_b')->getValue(); } $quoteManager->setCoverAmount($contentsSI, Manager_Insurance_TenantsContentsPlus_Quote::CONTENTS); // Grab the policy number for the quote and save it to the session $policyNumber = $quoteManager->getPolicyNumber(); $pageSession = new Zend_Session_Namespace('tenants_insurance_quote'); $pageSession->PolicyNumber = $policyNumber; $this->_policyNumber = $policyNumber; // Set the contact preferences $contactPreferences = new Model_Core_CustomerContactPreferences(); $contactPreferences->addPreference(Model_Core_CustomerContactPreferences::EMAIL_METHOD); $quoteManager->setContactPreference($contactPreferences); $quoteManager->setIssueDate(Zend_Date::now()->toString('YYYY-MM-dd')); //Save the sharer details. $contentsSICurrency = new Zend_Currency(array('value' => $contentsSI, 'precision' => 2)); $sharersManager = new Manager_Insurance_TenantsContentsPlus_Sharers(); $noOfSharersAllowed = $sharersManager->getNoOfSharersAllowed($contentsSICurrency); switch ($noOfSharersAllowed) { case 1: $sharers = new Model_Insurance_TenantsContentsPlus_Sharers($this->_policyNumber); $sharers->setSharerOccupation(Model_Insurance_TenantsContentsPlus_Sharers::SHARER_01, $subFormSharers->getElement('policy_sharer1_occupation')->getValue()); $sharersManager->insertSharers($sharers); break; case 2: $sharers = new Model_Insurance_TenantsContentsPlus_Sharers($this->_policyNumber); $sharers->setSharerOccupation(Model_Insurance_TenantsContentsPlus_Sharers::SHARER_01, $subFormSharers->getElement('policy_sharer1_occupation')->getValue()); $sharers->setSharerOccupation(Model_Insurance_TenantsContentsPlus_Sharers::SHARER_02, $subFormSharers->getElement('policy_sharer2_occupation')->getValue()); $sharersManager->insertSharers($sharers); break; } //Record this WebLead, if not already done so. First create or //retrieve the WebLead summary. $webLeadManager = new Manager_Core_WebLead(); if (empty($this->_webLeadSummaryId)) { $isNewWebLead = true; $webLeadSummary = $webLeadManager->createNewSummary(); } else { $isNewWebLead = false; $webLeadSummary = $webLeadManager->getSummary($this->_webLeadSummaryId); } //Create or retrieve the step 1 blob. if (!$webLeadManager->getBlobExists($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1)) { $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1); } else { $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1); } //Update the WebLead summary and store. $webLeadSummary->title = $subFormPersonalDetails->getElement('title')->getValue(); $webLeadSummary->firstName = $subFormPersonalDetails->getElement('first_name')->getValue(); $webLeadSummary->lastName = $subFormPersonalDetails->getElement('last_name')->getValue(); if ($subFormPersonalDetails->getElement('phone_number')->getValue() != '') { $contactNumber = $subFormPersonalDetails->getElement('phone_number')->getValue(); } else { $contactNumber = $subFormPersonalDetails->getElement('mobile_number')->getValue(); } $webLeadSummary->contactNumber = $contactNumber; $webLeadSummary->emailAddress = $subFormPersonalDetails->getElement('email_address')->getValue(); if ($isNewWebLead) { $webLeadSummary->startTime = $this->_offsetDate(); } $webLeadSummary->lastUpdatedTime = $this->_offsetDate(); $webLeadSummary->product = Model_Core_WebLeadProduct::TCIPLUS; $webLeadSummary->quoteNumber = $pageSession->PolicyNumber; $webLeadManager->updateSummary($webLeadSummary); //Update the blob, serialize and store. $webLeadBlob->blob = Zend_Json::encode($_POST); $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob); $webLeadManager->updateBlob($webLeadBlob); //Record the WebLead identifier in the page session. $pageSession->webLeadSummaryId = $webLeadSummary->webLeadSummaryId; //Capture and store the insurance and WebLead data protections. $this->_saveDPA($customerRefNo, Model_Core_DataProtection_ItemEntityTypes::INSURANCE, $subFormDataProtection->getElement('dpa_phone_post')->getValue(), $subFormDataProtection->getElement('dpa_sms_email')->getValue(), $subFormDataProtection->getElement('dpa_resale')->getValue()); $this->_saveDPA($webLeadSummary->webLeadSummaryId, Model_Core_DataProtection_ItemEntityTypes::WEBLEAD, $subFormDataProtection->getElement('dpa_phone_post')->getValue(), $subFormDataProtection->getElement('dpa_sms_email')->getValue(), $subFormDataProtection->getElement('dpa_resale')->getValue()); }
/** * Writes the Reference object to the legacy datasources. * * @param Model_Referencing_Reference $reference * The reference to write to the Munt. * * @return void */ protected function _pushToMunt(Model_Referencing_Reference $reference) { // Check the legacy customer id is set if ($reference->customer->legacyCustomerId == null && $reference->customer->customerType == Model_Referencing_CustomerTypes::LANDLORD) { // Create a new legacy customer for the private landlord $customerManager = new Manager_Core_Customer(); $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $reference->customer->customerId); $legacyCustomer = $customerManager->createNewCustomer($customer->getEmailAddress(), Model_Core_Customer::CUSTOMER, true); $legacyCustomer->setFirstName($customer->getFirstName()); $legacyCustomer->setLastName($customer->getLastName()); $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1)); $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE2)); $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE3)); $legacyCustomer->setTelephone(Model_Core_Customer::TELEPHONE1, $customer->getTelephone(Model_Core_Customer::TELEPHONE1)); $legacyCustomer->setTelephone(Model_Core_Customer::TELEPHONE2, $customer->getTelephone(Model_Core_Customer::TELEPHONE2)); $legacyCustomer->setPassword($customer->getPassword()); $customerManager->updateCustomer($legacyCustomer); // Drop the legacy customer refno into the reference customer map object $reference->customer->legacyCustomerId = $legacyCustomer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER); } $muntManager = new Manager_ReferencingLegacy_Munt(); $muntManager->updateReference($reference); }
public function saveStep1(Zend_Form $pageForm) { // Get sub forms $subFormPersonalDetails = $pageForm->getSubForm('subform_personaldetails'); $subFormDataProtection = $pageForm->getSubForm('subform_dataprotection'); $subFormCorrespondenceDetails = $pageForm->getSubForm('subform_correspondencedetails'); $subFormInsuredAddress = $pageForm->getSubForm('subform_insuredaddress'); $subFormPolicyDetails = $pageForm->getSubForm('subform_policydetails'); $subFormIdd = $pageForm->getSubForm('subform_idd'); if (isset($this->_quoteID) && !is_null($this->_quoteID)) { $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($this->_quoteID); } else { // Create a new quote $quoteManager = new Manager_Insurance_LandlordsPlus_Quote(); $this->_quoteID = $quoteManager->getModel()->ID; // Save the ID in the session for future use $session = new Zend_Session_Namespace('landlords_insurance_quote'); $session->quoteID = $this->_quoteID; } // Check to see if we have a session $customerManager = new Manager_Core_Customer(); // Check to see if we are already logged in $auth = Zend_Auth::getInstance(); $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer')); $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); $pageSession->quoteID = $this->_quoteID; if (!isset($this->_customerReferenceNumber)) { // Do we already have a legacy customer with this email address? $customer = $customerManager->getLegacyCustomerByEmailAddress($subFormPersonalDetails->getElement('email_address')->getValue()); // We don't have a session so we need to create a legacy customer/quote entry to save against if (!$customer) { $customer = $customerManager->createNewCustomer($subFormPersonalDetails->getElement('email_address')->getValue(), Model_Core_Customer::CUSTOMER, true); } // Now get the reference number from the newly created customer $customerRefNo = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER); $this->_customerReferenceNumber = $customerRefNo; $pageSession->customerRefNo = $customerRefNo; } else { // We are in session so just instantiate the customer manager with the existing reference number $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber); $customerRefNo = $pageSession->customerRefNo; } $pageSession->CustomerDob = $subFormPersonalDetails->getElement('date_of_birth_at')->getValue(); $quoteManager->setLegacyCustomerReference($customerRefNo); //Capture and store the insurance data protections. if ($subFormDataProtection->getElement('dpa_phone_post')->getValue() == 1) { $dpaPhonePost = 1; } else { $dpaPhonePost = 0; } if ($subFormDataProtection->getElement('dpa_sms_email')->getValue() == 1) { $dpaSMSEmail = 1; } else { $dpaSMSEmail = 0; } if ($subFormDataProtection->getElement('dpa_resale')->getValue() == 1) { $dpaResale = 1; } else { $dpaResale = 0; } // Update the customer record with the form data if ($subFormPersonalDetails->getElement('title')->getValue() != "Other") { $customer->setTitle($subFormPersonalDetails->getElement('title')->getValue()); } else { $customer->setTitle($subFormPersonalDetails->getElement('other_title')->getValue()); } $customer->setFirstName($subFormPersonalDetails->getElement('first_name')->getValue()); $customer->setLastName($subFormPersonalDetails->getElement('last_name')->getValue()); $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $subFormPersonalDetails->getElement('phone_number')->getValue()); $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $subFormPersonalDetails->getElement('mobile_number')->getValue()); $customer->setEmailAddress($subFormPersonalDetails->getElement('email_address')->getValue()); $customer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($subFormPersonalDetails->getElement('date_of_birth_at')->getValue())); $customer->setCountry($subFormCorrespondenceDetails->getElement('country')->getValue()); if ($subFormCorrespondenceDetails->getElement('cor_foreign_address')->getValue() == 1) { $customer->setIsForeignAddress(true); } else { $customer->setIsForeignAddress(false); } $customerManager->updateCustomer($customer); if ($auth->hasIdentity()) { // Customer is logged in - so we need to link the new customer to the old $customerID = $auth->getStorage()->read()->id; $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID); $customerManager->linkLegacyToNew($customerRefNo, $customerID); } // Update the customer with the new correspondence address $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $subFormCorrespondenceDetails->getElement('cor_address_line1')->getValue()); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $subFormCorrespondenceDetails->getElement('cor_address_line2')->getValue()); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $subFormCorrespondenceDetails->getElement('cor_address_line3')->getValue()); $customer->setPostCode($subFormCorrespondenceDetails->getElement('cor_address_postcode')->getValue()); // Whether a new customer or an existing customer without a DoB stored, allow the DoB supplied in the form to be // stored if what's there now is blank if (null === $customer->getDateOfBirthAt() || '0000-00-00' == $customer->getDateOfBirthAt()) { $customer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($subFormPersonalDetails->getElement('date_of_birth_at')->getValue())); } $customerManager->updateCustomer($customer); // Update the quote with new values and save it $quoteManager->setStartDate(Application_Core_Utilities::ukDateToMysql($subFormPolicyDetails->getElement('policy_start')->getValue())); $quoteManager->setEndDate(Application_Core_Utilities::ukDateToMysql($subFormPolicyDetails->getElement('policy_end')->getValue())); // Check to see if the property is a 1000 flood area - if it is force the exclude_flood_cover flag $riskAreasDatasource = new Datasource_Insurance_LandlordsPlus_RiskAreas(); $riskAreas = $riskAreasDatasource->getByPostcode($subFormInsuredAddress->getElement('ins_address_postcode')->getValue()); if ($riskAreas['floodArea'] = '1000') { $subFormInsuredAddress->getElement('exclude_flood_cover')->setValue(true); } // Add property details $quoteManager->addProperty($subFormInsuredAddress->getElement('ins_address_postcode')->getValue(), $subFormInsuredAddress->getElement('ins_address_line3')->getValue(), '', $subFormInsuredAddress->getElement('ins_address_line1')->getValue(), $subFormInsuredAddress->getElement('tenants_type')->getValue(), $subFormInsuredAddress->getElement('through_letting_agent')->getValue() == 'yes' ? true : false, $subFormInsuredAddress->getElement('owned_for')->getValue(), $subFormInsuredAddress->getElement('no_claims')->getValue(), $subFormInsuredAddress->getElement('exclude_flood_cover')->getValue() == 'no' ? true : false, $subFormInsuredAddress->getElement('ins_address_line2')->getValue()); // Set the new letting agent details if we have them $session = new Zend_Session_Namespace('homelet_global'); $agentSchemeNumber = $session->agentSchemeNumber; // Store result to quote manager and session $quoteManager->setAgentSchemeNumber($agentSchemeNumber); $quoteManager->save(); $session->agentSchemeNumber = $agentSchemeNumber; // Set the contact preferences $contactPreferences = new Model_Core_CustomerContactPreferences(); $contactPreferences->addPreference(Model_Core_CustomerContactPreferences::EMAIL_METHOD); $quoteManager->setContactPreference($contactPreferences); //Record this WebLead, if not already done so. First create or //retrieve the WebLead summary. $webLeadManager = new Manager_Core_WebLead(); if (empty($pageSession->webLeadSummaryId)) { $isNewWebLead = true; $webLeadSummary = $webLeadManager->createNewSummary(); } else { $isNewWebLead = false; $webLeadSummary = $webLeadManager->getSummary($pageSession->webLeadSummaryId); } //Create or retrieve the step 1 blob. if (!$webLeadManager->getBlobExists($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1)) { $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1); } else { $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1); } //Update the WebLead summary and store. $webLeadSummary->title = $subFormPersonalDetails->getElement('title')->getValue(); $webLeadSummary->firstName = $subFormPersonalDetails->getElement('first_name')->getValue(); $webLeadSummary->lastName = $subFormPersonalDetails->getElement('last_name')->getValue(); if ($subFormPersonalDetails->getElement('phone_number')->getValue() != '') { $contactNumber = $subFormPersonalDetails->getElement('phone_number')->getValue(); } else { $contactNumber = $subFormPersonalDetails->getElement('mobile_number')->getValue(); } $webLeadSummary->contactNumber = $contactNumber; $webLeadSummary->emailAddress = $subFormPersonalDetails->getElement('email_address')->getValue(); if ($isNewWebLead) { $webLeadSummary->startTime = $this->_offsetDate(); } $webLeadSummary->lastUpdatedTime = $this->_offsetDate(); $webLeadSummary->product = Model_Core_WebLeadProduct::LANDLORDSPLUS; $webLeadSummary->quoteNumber = $quoteManager->getLegacyID(); $webLeadManager->updateSummary($webLeadSummary); //Update the blob, serialize and store. $webLeadBlob->blob = Zend_Json::encode($_POST); $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob); $webLeadManager->updateBlob($webLeadBlob); //Finally, record the WebLead identifier in the page session. $pageSession->webLeadSummaryId = $webLeadSummary->webLeadSummaryId; //Capture and store the Insurance and WebLead data protections. $this->_saveDPA($customerRefNo, Model_Core_DataProtection_ItemEntityTypes::INSURANCE, $dpaPhonePost, $dpaSMSEmail, $dpaResale); $this->_saveDPA($webLeadSummary->webLeadSummaryId, Model_Core_DataProtection_ItemEntityTypes::WEBLEAD, $dpaPhonePost, $dpaSMSEmail, $dpaResale); }
private function saveStep1(Zend_Form $pageForm) { // Get sub forms $subFormPersonalDetails = $pageForm->getSubForm('subform_personaldetails'); $subFormInsuredAddress = $pageForm->getSubForm('subform_insuredaddress'); $subFormCorrespondenceDetails = $pageForm->getSubForm('subform_correspondencedetails'); $subFormDataProtection = $pageForm->getSubForm('subform_dataprotection'); $pageSession = new Zend_Session_Namespace('tenants_insurance_quote'); $customerManager = new Manager_Core_Customer(); $auth = Zend_Auth::getInstance(); $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer')); // TODO: This should check reference number exists, not just property! if (!isset($this->_customerReferenceNumber)) { // Do we already have a legacy customer with this email address? $customer = $customerManager->getCustomerByEmailAddress($subFormPersonalDetails->getElement('email_address')->getValue()); if (!$customer) { // We don't have a session so we need to create a legacy customer/quote entry to save against // All new customers are now of type Model_Core_Customer::CUSTOMER $customer = $customerManager->createNewCustomer($subFormPersonalDetails->getElement('email_address')->getValue(), Model_Core_Customer::CUSTOMER); $legacyCustomer = $customer; if (!isset($pageSession->IsNewCustomer)) { $pageSession->IsNewCustomer = true; } } else { if (!isset($pageSession->IsNewCustomer)) { $pageSession->IsNewCustomer = false; } $legacyCustomer = $customerManager->createNewCustomer($subFormPersonalDetails->getElement('email_address')->getValue(), Model_Core_Customer::CUSTOMER, true); } $customerManager->linkLegacyToNew($legacyCustomer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER), $customer->getIdentifier(Model_Core_Customer::IDENTIFIER)); // Now get the reference number from the newly created customer $customerRefNo = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER); $this->_customerReferenceNumber = $customerRefNo; $pageSession->CustomerRefNo = $customerRefNo; $pageSession->CustomerID = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER); } else { // We are in session so just instantiate the customer manager with the existing reference number $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber); $customerRefNo = $pageSession->CustomerRefNo; $pageSession->CustomerID = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER); if (!isset($pageSession->IsNewCustomer)) { $pageSession->IsNewCustomer = false; } } $pageSession->CustomerEmail = $subFormPersonalDetails->getElement('email_address')->getValue(); $pageSession->CustomerDob = $subFormPersonalDetails->getElement('date_of_birth_at')->getValue(); if (!$auth->hasIdentity()) { // Update the customer record with the form data, but only if they are a new customer // Existing customers must phone us. // Note that no message stating this is given to the end user if ($subFormPersonalDetails->getElement('title')->getValue() != "Other") { $customer->setTitle($subFormPersonalDetails->getElement('title')->getValue()); } else { $customer->setTitle($subFormPersonalDetails->getElement('other_title')->getValue()); } $customer->setFirstName($subFormPersonalDetails->getElement('first_name')->getValue()); $customer->setLastName($subFormPersonalDetails->getElement('last_name')->getValue()); $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $subFormPersonalDetails->getElement('phone_number')->getValue()); $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $subFormPersonalDetails->getElement('mobile_number')->getValue()); $customer->setEmailAddress($subFormPersonalDetails->getElement('email_address')->getValue()); $customer->setIsForeignAddress(false); } // Whether a new customer or an existing customer without a DoB stored, allow the DoB supplied in the form to be // stored if what's there now is blank if (null === $customer->getDateOfBirthAt() || '0000-00-00' == $customer->getDateOfBirthAt()) { $customer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($subFormPersonalDetails->getElement('date_of_birth_at')->getValue())); } // TODO: Make this all better... $customerManager->updateCustomer($customer); // 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->linkLegacyToNew($customerRefNo, $customerID); // See if we have an agent scheme number, if so use it $session = new Zend_Session_Namespace('homelet_global'); $agentSchemeNumber = $session->agentSchemeNumber; // Instantiate the quote manager - if this is a new customer it will automatically create a new quote // otherwise it will use the existing quote $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote($customerRefNo, $agentSchemeNumber, $pageSession->PolicyNumber); // Grab the policy number for the quote and save it to the session $policyNumber = $quoteManager->getPolicyNumber(); $pageSession = new Zend_Session_Namespace('tenants_insurance_quote'); $pageSession->PolicyNumber = $policyNumber; $this->_policyNumber = $policyNumber; // Save the addresses // Create a postcode model $postcode = new Manager_Core_Postcode(); // Get the addresses as arrays for insured and correspondence addresses $insuredAddressId = $subFormInsuredAddress->getElement('ins_address')->getValue(); $insuredAddress = $postcode->getPropertyByID($insuredAddressId, false); $correspondenceAddressId = $subFormCorrespondenceDetails->getElement('cor_address')->getValue(); $correspondenceAddress = $postcode->getPropertyByID($correspondenceAddressId, false); // Update the property address in the quote $quoteManager->setPropertyAddress(($insuredAddress['organisation'] != '' ? "{$insuredAddress['organisation']}, " : '') . ($insuredAddress['buildingName'] != '' ? "{$insuredAddress['buildingName']}, " : '') . ($insuredAddress['houseNumber'] != '' ? "{$insuredAddress['houseNumber']} " : '') . $insuredAddress['address2'], $insuredAddress['address4'], $insuredAddress['address5'], $insuredAddress['postcode']); // Update the customer address in the customer record $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, ($correspondenceAddress['organisation'] != '' ? "{$correspondenceAddress['organisation']}, " : '') . ($correspondenceAddress['houseNumber'] != '' ? "{$correspondenceAddress['houseNumber']} " : '') . ($correspondenceAddress['buildingName'] != '' ? "{$correspondenceAddress['buildingName']}, " : '') . $correspondenceAddress['address2']); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $correspondenceAddress['address4']); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $correspondenceAddress['address5']); $customer->setPostCode($correspondenceAddress['postcode']); // Save the customer record details $customerManager->updateCustomer($customer); // Set the contact preferences $contactPreferences = new Model_Core_CustomerContactPreferences(); $contactPreferences->addPreference(Model_Core_CustomerContactPreferences::EMAIL_METHOD); $quoteManager->setContactPreference($contactPreferences); $quoteManager->setIssueDate(Zend_Date::now()->toString('YYYY-MM-dd')); //Record this WebLead, if not already done so. First create or //retrieve the WebLead summary. $webLeadManager = new Manager_Core_WebLead(); if (empty($this->_webLeadSummaryId)) { $isNewWebLead = true; $webLeadSummary = $webLeadManager->createNewSummary(); } else { $isNewWebLead = false; $webLeadSummary = $webLeadManager->getSummary($this->_webLeadSummaryId); } //Create or retrieve the step 1 blob. if (!$webLeadManager->getBlobExists($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1)) { $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1); } else { $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1); } //Update the WebLead summary and store. $webLeadSummary->title = $subFormPersonalDetails->getElement('title')->getValue(); $webLeadSummary->firstName = $subFormPersonalDetails->getElement('first_name')->getValue(); $webLeadSummary->lastName = $subFormPersonalDetails->getElement('last_name')->getValue(); if ($subFormPersonalDetails->getElement('phone_number')->getValue() != '') { $contactNumber = $subFormPersonalDetails->getElement('phone_number')->getValue(); } else { $contactNumber = $subFormPersonalDetails->getElement('mobile_number')->getValue(); } $webLeadSummary->contactNumber = $contactNumber; $webLeadSummary->emailAddress = $subFormPersonalDetails->getElement('email_address')->getValue(); if ($isNewWebLead) { $webLeadSummary->startTime = $this->_offsetDate(); } $webLeadSummary->lastUpdatedTime = $this->_offsetDate(); $webLeadSummary->product = Model_Core_WebLeadProduct::TCIPLUS; $webLeadSummary->quoteNumber = $pageSession->PolicyNumber; $webLeadManager->updateSummary($webLeadSummary); //Update the blob, serialize and store. $webLeadBlob->blob = Zend_Json::encode($_POST); $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob); $webLeadManager->updateBlob($webLeadBlob); //Record the WebLead identifier in the page session. $pageSession->webLeadSummaryId = $webLeadSummary->webLeadSummaryId; //Capture and store the insurance and WebLead data protections. $this->_saveDPA($customerRefNo, Model_Core_DataProtection_ItemEntityTypes::INSURANCE, $subFormDataProtection->getElement('dpa_phone_post')->getValue(), $subFormDataProtection->getElement('dpa_sms_email')->getValue(), $subFormDataProtection->getElement('dpa_resale')->getValue()); $this->_saveDPA($webLeadSummary->webLeadSummaryId, Model_Core_DataProtection_ItemEntityTypes::WEBLEAD, $subFormDataProtection->getElement('dpa_phone_post')->getValue(), $subFormDataProtection->getElement('dpa_sms_email')->getValue(), $subFormDataProtection->getElement('dpa_resale')->getValue()); }