/** * Get a specic property details * */ public function getpropertyAction() { $addressID = $_POST['addressID']; $postcode = new Manager_Core_Postcode(); $address = $postcode->getPropertyByID($addressID); $returnArray = array(); if (count($address) > 0) { $line1 = ''; // Build an array of up to 5 address lines $addressLines = array(); if ($address['address1'] != '') { $addressLines[] = $address['address1']; } if ($address['address2'] != '') { $addressLines[] = $address['address2']; } if ($address['address3'] != '') { $addressLines[] = $address['address3']; } if ($address['address4'] != '') { $addressLines[] = $address['address4']; } if ($address['address5'] != '') { $addressLines[] = $address['address5']; } // Now we can pop off of this address lines nonsense - to make it just 3 lines $line3 = array_pop($addressLines); $line2 = array_pop($addressLines); while (count($addressLines) > 0) { $line1 = array_pop($addressLines) . ', ' . $line1; } if ($address['buildingName'] != '') { $line1 = $address['buildingName'] . ' ' . $line1; } if ($address['houseNumber'] != '') { $line1 = $address['houseNumber'] . ' ' . $line1; } if ($address['department'] != '') { $line1 = $address['department'] . ', ' . $line1; } if ($address['organisation'] != '') { $line1 = $address['organisation'] . ', ' . $line1; } $line1 = trim($line1, ' '); $line1 = trim($line1, ','); $postcode = $address['postcode']; $returnArray = array('line1' => ucwords(strtolower($line1)), 'line2' => ucwords(strtolower($line2)), 'line3' => ucwords(strtolower($line3)), 'postcode' => strtoupper($postcode), 'landlordsRiskAreas' => $address['landlordsRiskAreas']); $output['data'] = $returnArray; $output['error'] = ''; } else { $output['data'] = array(); $output['error'] = "Can't find address"; } echo Zend_Json::encode($output); }
/** * Set options * * @param array data An array of reference number, guarantor name, house name, street * town, city, postcode * @return void */ public function insertGuarantors($data, $guarantorId, $referenceNumber) { $dataArray = array(); //delete guarantor information before inserting to avoid dupliaction $this->removeGuarantors($referenceNumber); $totalGuarantors = empty($data['total_guarantors']) ? '0' : $data['total_guarantors']; for ($i = 1; $i <= $totalGuarantors; $i++) { if ($i <= 4) { if (isset($data['guarantor_address_' . $i]) && $data['guarantor_address_' . $i] != '' && $data['guarantor_address_' . $i] != '-') { // Address lookup worked $coreAddressManager = new Manager_Core_Postcode(); $guarantorAddress = $coreAddressManager->getPropertyByID($data['guarantor_address_' . $i]); $address_id = $guarantorAddress['id']; $houseName = $guarantorAddress['houseNumber'] != '' ? $guarantorAddress['houseNumber'] : $guarantorAddress['buildingName']; $street = $guarantorAddress['address1'] != '' ? $guarantorAddress['address1'] : $guarantorAddress['address2']; $town = $guarantorAddress['address4']; $city = $guarantorAddress['address5']; $postcode = $guarantorAddress['postcode']; } else { // Address lookup failed, hence manual entry $address_id = '-'; $houseName = $data['guarantor_housename_' . $i]; $street = $data['guarantor_street_' . $i]; $town = $data['guarantor_town_' . $i]; $city = $data['guarantor_city_' . $i]; $postcode = $data['guarantor_postcode_' . $i]; } $dataArray['reference_number'] = $referenceNumber; $dataArray['guarantor_name'] = $data['guarantor_name_' . $i]; $dataArray['hometelno'] = $data['guarantor_hometelno_' . $i]; $dataArray['worktelno'] = $data['guarantor_worktelno_' . $i]; $dataArray['mobiletelno'] = $data['guarantor_mobiletelno_' . $i]; $dataArray['email'] = $data['guarantor_email_' . $i]; $dataArray['dob'] = Application_Core_Utilities::ukDateToMysql($data['guarantors_dob_' . $i]); $dataArray['address_id'] = $address_id; $dataArray['house_name'] = $houseName; $dataArray['street'] = $street; $dataArray['town'] = $town; $dataArray['city'] = $city; $dataArray['postcode'] = $postcode; $dataArray['homeletrefno'] = $data['guarantor_homeletrefno_' . $i]; if ($guarantorId != '') { $where = $this->getAdapter()->quoteInto('id = ?', $guarantorId); $this->update($data, $where); } else { $this->insert($dataArray); } } } }
/** * This function will add a new note into the agentNotes table * * @param int schemeNumber * @param string note * @return boolean * */ public function addEnquiry($enquiryData) { # Zend_Debug::dump($enquiryData); $rsAddress = new Manager_Core_Postcode(); $riskAddress = $rsAddress->getPropertyByID($enquiryData['ins_address'], false); #Zend_Debug::dump($riskAddress);die(); $insertData = array('agentschemeno' => $enquiryData['agentschemeno'], 'title' => $enquiryData['title'], 'first_name' => $enquiryData['first_name'], 'last_name' => $enquiryData['last_name'], 'phone_number' => $enquiryData['phone_number'], 'mobile_number' => $enquiryData['mobile_number'], 'address_id' => $riskAddress['id'], 'houseNumber' => $riskAddress['houseNumber'], 'buildingName' => $riskAddress['buildingName'], 'address1' => $riskAddress['address1'], 'address2' => $riskAddress['address2'], 'address3' => $riskAddress['address3'], 'address4' => $riskAddress['address4'], 'address5' => $riskAddress['address5'], 'postcode' => $riskAddress['postcode'], 'county' => $riskAddress['county'], 'postcode' => $riskAddress['postcode'], 'organisation' => $riskAddress['organisation'], 'department' => $riskAddress['department'], 'additional_information' => $enquiryData['additional_information'], 'isSent' => 0, 'enquiry_type' => $enquiryData['prospector'], 'created' => new Zend_Db_Expr('NOW()')); // Insert the data into a new row in the table if ($this->insert($insertData)) { return true; } else { // Failed insertion Application_Core_Logger::log("Can't insert in table {$this->_name} (AGENTSCHEMENUMBER = {$schemeNumber})", 'error'); return false; } }
/** * Saves the form data to the datastore. * * @return void */ public function saveData() { $session = new Zend_Session_Namespace('referencing_global'); $data = $this->getValues(); // Create a new Enquiry, or load the existing one. $referenceManager = new Manager_Referencing_Reference(); if (empty($session->referenceId)) { $reference = $referenceManager->createReference(); $session->referenceId = $reference->internalId; } else { $reference = $referenceManager->getReference($session->referenceId); } // Set the customer map if (empty($reference->customer)) { $reference->customer = new Model_Referencing_CustomerMap(); } $reference->customer->customerType = Model_Referencing_CustomerTypes::LANDLORD; $reference->customer->customerId = $session->customerId; // Format the property details $postcodeManager = new Manager_Core_Postcode(); $propertyAddress = $postcodeManager->getPropertyByID($data['subform_propertyaddress']['property_address'], false); $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2']; $addressLine2 = $propertyAddress['address4']; $town = $propertyAddress['address5']; $postCode = $data['subform_propertyaddress']['ins_property_postcode']; // Store the property details into the PropertyLease. if (empty($reference->propertyLease)) { $propertyLeaseManager = new Manager_Referencing_PropertyLease(); $reference->propertyLease = $propertyLeaseManager->insertPlaceholder($session->referenceId); } if (empty($reference->propertyLease->address)) { $addressManager = new Manager_Core_Address(); $reference->propertyLease->address = $addressManager->createAddress(); } $reference->propertyLease->address->addressLine1 = $addressLine1; $reference->propertyLease->address->addressLine2 = $addressLine2; $reference->propertyLease->address->town = $town; $reference->propertyLease->address->postCode = $postCode; // Store the rental price index details, if provided. $this->_savePropertyAspects(); // Set the remainder of the property lease details. $reference->propertyLease->rentPerMonth = new Zend_Currency(array('value' => $data['subform_propertymisc']['total_rent'], 'precision' => 0)); $reference->propertyLease->tenancyStartDate = new Zend_Date($data['subform_propertymisc']['tenancy_start_date'], Zend_Date::DATES); $reference->propertyLease->tenancyTerm = $data['subform_propertymisc']['tenancy_term']; $reference->propertyLease->noOfTenants = $data['subform_propertymisc']['no_of_tenants']; $referenceManager->updateReference($reference); }
/** * Saves the form data to the datastore. * * @return void */ public function saveData() { $session = new Zend_Session_Namespace('referencing_global'); $data = $this->getValues(); // Create the new customer in the legacy datasource only. $customerManager = new Manager_Core_Customer(); $customer = $customerManager->createNewCustomer($data['email'], Model_Core_Customer::CUSTOMER); // Update the newly created customer with values submitted on the registration form. //$customer->setTitle($data['personal_title']); $customer->setTitle($data['title']); $customer->setFirstName($data['first_name']); $customer->setLastName($data['last_name']); $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $data['phone_number']); $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $data['mobile_number']); $customer->setFax($data['fax_number']); $customer->setEmailAddress($data['email']); $customer->setPassword($data['password']); $customer->setSecurityQuestion($data['security_question']); $customer->setSecurityAnswer($data['security_answer']); //Address update $postcode = new Manager_Core_Postcode(); $propertyAddress = $postcode->getPropertyByID($data['property_address'], false); $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2']; $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $addressLine1); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $propertyAddress['address4']); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $propertyAddress['address5']); $customer->setPostCode($data['property_postcode']); $customer->typeID = Model_Core_Customer::CUSTOMER; // Update the customer record $customerManager->updateCustomer($customer); // // Log the customer in automatically // $auth = Zend_Auth::getInstance(); // $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer')); // $customerManager = new Manager_Core_Customer(); // $adapter = $customerManager->getAuthAdapter(array('email' => $data['email'], 'password' => $data['password'])); // $auth->authenticate($adapter); // // Writer customer data to session // $storage = $auth->getStorage(); // $storage->write($adapter->getResultRowObject(array( // 'title', // 'first_name', // 'last_name', // 'email_address', // 'id'))); //Finally, set the necessary session variables. $session->awaitingvalidation = 1; $session->customerId = $customer->getIdentifier(Model_Core_Customer::IDENTIFIER); // Save dpa preferences for direct landlord to insurance dpa system - direct landlords save their customer records to insurance $dpaManager = new Manager_Core_DataProtection(); $item = new Model_Core_DataProtection_Item(); $item->itemGroupId = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER); $item->entityTypeId = Model_Core_DataProtection_ItemEntityTypes::INSURANCE; // Phone and post $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST; $item->isAllowed = $data['subform_dataprotection']['dpa_phone_post'] == 1 ? true : false; $dpaManager->upsertItem($item); // Sms and email $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL; $item->isAllowed = $data['subform_dataprotection']['dpa_sms_email'] == 1 ? true : false; $dpaManager->upsertItem($item); // Third party sale $item->constraintTypeId = Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY; $item->isAllowed = $data['subform_dataprotection']['dpa_resale'] == 1 ? true : false; $dpaManager->upsertItem($item); // Save insurance renewal mi data, if provided if ($this->getElement('insurance_renewal_date')->getValue() != '') { $renewalDate = new Zend_Date($this->getElement('insurance_renewal_date')->getValue(), Zend_Date::DAY . '/' . Zend_Date::MONTH . '/' . Zend_Date::YEAR); $miInsuranceRenewalDataSource = new Datasource_Referencing_MiInsuranceRenewal(); $miInsuranceRenewalDataSource->insertMiData($customer->getIdentifier(Model_Core_Customer::IDENTIFIER), $renewalDate); } // Create sign-up completion email $customer->sendAccountValidationEmail(); }
/** * TODO: Document this * @param * @return * @author John Burrin * @since */ public function updatePropertyAction() { $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote'); $customerReferenceNumber = $pageSession->CustomerRefNo; $ajaxForm = new Form_PortfolioInsuranceQuote_editPropertyDialog(); $return = array(); $request = $this->getRequest(); $postdata = $request->getPost(); $return['success'] = false; $ajaxForm->isValid($postdata); $return['errorObject'] = $ajaxForm->getMessages(); if ($ajaxForm->isValid($postdata)) { $cleanData = $ajaxForm->getValues(); // According to the Zend manual these *should* be the clean values $propertyArray = array(); $propertyManager = new Manager_Insurance_Portfolio_Property(); $dataObject = new Model_Insurance_Portfolio_Property(); if (isset($postdata['propertyid'])) { $dataObject->id = $cleanData['propertyid']; } if (isset($customerReferenceNumber)) { $dataObject->refno = $customerReferenceNumber; } if (isset($postdata['ins_house_number_name'])) { $dataObject->building = $cleanData['ins_house_number_name']; } if (isset($postdata['ins_postcode'])) { $dataObject->postcode = $propertyManager->formatPostcode($cleanData['ins_postcode']); } if (isset($postdata['employment_status'])) { $dataObject->tenantOccupation = $cleanData['employment_status']; } if (isset($postdata['buildings_cover'])) { $dataObject->buildingsSumInsured = $cleanData['buildings_cover']; } if (isset($postdata['buildings_accidental_damage'])) { $dataObject->buildingsAccidentalDamage = $cleanData['buildings_accidental_damage']; } if (isset($postdata['buildings_nil_excess'])) { $dataObject->buildingsNilExcess = $cleanData['buildings_nil_excess']; } if (isset($postdata['contents_cover'])) { $dataObject->contentsSumInsured = $cleanData['contents_cover']; } if (isset($postdata['contents_accidental_damage'])) { $dataObject->contentsAccidentalDamage = $cleanData['contents_accidental_damage']; } if (isset($postdata['contents_nil_excess'])) { $dataObject->contentsNilExcess = $cleanData['contents_nil_excess']; } if (isset($postdata['limited_contents'])) { $dataObject->limitedContents = $cleanData['limited_contents']; } $address = new Manager_Core_Postcode(); $return['address'] = $address->getPropertyByID($cleanData['ins_address']); $dataObject->houseNumber = $return['address']['houseNumber']; $dataObject->building = $return['address']['buildingName']; $dataObject->address1 = $return['address']['address1']; $dataObject->address2 = $return['address']['address2']; $dataObject->address3 = $return['address']['address3']; $dataObject->address4 = $return['address']['address4']; $dataObject->address5 = $return['address']['address5']; $dataObject->postcode = $property->formatPostcode($cleanData['ins_postcode']); $dataObject->refno = $pageSession->CustomerRefNo; $dataObject->tenantOccupation = $dataObject->tenantOccupation; // Do the update stuffs $propertyManager->save($dataObject); // need to tell the view we are on step 2 $this->view->stepNum = 2; // Get the properties to shove back into the page $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber); $return['html'] = $this->view->partialLoop('portfolio-insurance-quote/partials/property-list.phtml', $propertyArray); $return['success'] = true; $return['propNumb'] = count($propertyArray->toArray()); } echo Zend_Json::encode($return); }
/** * Enter the postal address to send the document to * * @return void */ public function selectDocumentAddressAction() { $session = new Zend_Session_Namespace('connect_rg'); $request = $this->getRequest(); $documentaddress = new Connect_Form_RentGuarantee_DocumentAddress(); $documentaddress->populate($request->getPost()); if ($request->isPost()) { if ($request->getParam('formsubmit_back')) { $this->_redirect($this->getRequest()->getControllerName() . '/configure-renewal-document'); } else { if ($documentaddress->isValid($request->getPost())) { // Capture target address, obtain data from the postcode // lookup from the database and store the data to the session $postcode = new Manager_Core_Postcode(); $postcodedata = $postcode->getPropertyByID($documentaddress->getElement('cor_address')->getValue(), false); $session->documentaddress = $postcodedata; $this->_redirect($this->getRequest()->getControllerName() . '/send-renewal-document'); } } } $this->view->documentaddress = $documentaddress; }
/** * Saves the form data to the datastore. * * @return void */ public function saveData() { $session = new Zend_Session_Namespace('referencing_global'); $data = $this->getValues(); //Retrieve the main reference details. $referenceManager = new Manager_Referencing_Reference(); $reference = $referenceManager->getReference($session->referenceId); //Create a new PLL record if not already done so. if (empty($reference->propertyLease->prospectiveLandlord)) { $prospectiveLandlordManager = new Manager_Referencing_ProspectiveLandlord(); $reference->propertyLease->prospectiveLandlord = $prospectiveLandlordManager->insertPlaceholder($session->referenceId); } //Record the PLL's name if (empty($reference->propertyLease->prospectiveLandlord->name)) { $nameManager = new Manager_Core_Name(); $reference->propertyLease->prospectiveLandlord->name = $nameManager->createName(); } $reference->propertyLease->prospectiveLandlord->name->title = $data['personal_title']; $reference->propertyLease->prospectiveLandlord->name->firstName = $data['first_name']; $reference->propertyLease->prospectiveLandlord->name->lastName = $data['last_name']; //Record the PLL's contact details if (empty($reference->propertyLease->prospectiveLandlord->contactDetails)) { $contactDetailsManager = new Manager_Core_ContactDetails(); $reference->propertyLease->prospectiveLandlord->contactDetails = $contactDetailsManager->createContactDetails(); } $reference->propertyLease->prospectiveLandlord->contactDetails->telephone1 = $data['telephone_day']; $reference->propertyLease->prospectiveLandlord->contactDetails->telephone2 = $data['telephone_evening']; $reference->propertyLease->prospectiveLandlord->contactDetails->fax1 = $data['fax_number']; $reference->propertyLease->prospectiveLandlord->contactDetails->email1 = $data['email']; //Record the PLL's address. $postcodeManager = new Manager_Core_Postcode(); $propertyAddress = $postcodeManager->getPropertyByID($data['property_address'], false); $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2']; $addressLine2 = $propertyAddress['address4']; $town = $propertyAddress['address5']; $postCode = $data['property_postcode']; if (empty($reference->propertyLease->prospectiveLandlord->address)) { $addressManager = new Manager_Core_Address(); $reference->propertyLease->prospectiveLandlord->address = $addressManager->createAddress(); } $reference->propertyLease->prospectiveLandlord->address->addressLine1 = $addressLine1; $reference->propertyLease->prospectiveLandlord->address->addressLine2 = $addressLine2; $reference->propertyLease->prospectiveLandlord->address->town = $town; $reference->propertyLease->prospectiveLandlord->address->postCode = $postCode; //And update... both the reference and the PLL customer details, which are held in the //legacy datasources. $referenceManager->updateReference($reference); //Next, update the customer record if the user is a PLL. If the user is a reference subject, //then we do not want to overwrite the PLL (customer) details with the data they have //entered. if ($session->userType == Model_Referencing_ReferenceUserTypes::PRIVATE_LANDLORD) { //Retrieve the primary customer details - ugly I know. $session = new Zend_Session_Namespace('referencing_global'); $customerManager = new Manager_Referencing_Customer(); $customer = $customerManager->getCustomer($session->customerId); $customer->setTitle($data['personal_title']); $customer->setFirstName($data['first_name']); $customer->setLastName($data['last_name']); $customer->setTelephone(Model_Core_Customer::TELEPHONE1, $data['telephone_day']); $customer->setTelephone(Model_Core_Customer::TELEPHONE2, $data['telephone_evening']); $customer->setFax($data['fax_number']); $customer->setEmailAddress($data['email']); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $addressLine1); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $addressLine2); $customer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $town); $customer->setPostCode($postCode); $customerManager->updateCustomer($customer); } }
/** * Initialise the step 3 form [Important Information Form] * * @return void */ public function step3Action() { $pageForm = new TenantsInsuranceQuoteB_Form_Step3(); // Tell page to use AJAX validation as we go $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = 3;'); // Get customer details $customerManager = new Manager_Core_Customer(); $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber); // Hydrate registration form if (isset($pageForm->subform_register) || isset($pageForm->subform_login)) { // Grab a new customer to populate the form $pageSession = new Zend_Session_Namespace('tenants_insurance_quote'); $newCust = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $pageSession->CustomerID); if (isset($pageForm->subform_register)) { if ($newCust) { $pageForm->subform_register->email->setValue($newCust->getEmailAddress()); $pageForm->subform_register->security_question->setValue($newCust->getSecurityQuestion()); $pageForm->subform_register->security_answer->setValue($newCust->getSecurityAnswer()); $emailAddress = $newCust->getEmailAddress(); } else { $pageForm->subform_register->email->setValue($customer->getEmailAddress()); $emailAddress = $customer->getEmailAddress(); } if (!$emailAddress) { $emailAddress = $newCust->getEmailAddress(); } } else { if ($newCust) { $pageForm->subform_login->email->setValue($newCust->getEmailAddress()); } } } if ($this->getRequest()->isPost()) { $valid = $this->_formStepCommonValidate($pageForm, 3); if (isset($pageForm->subform_register)) { $pageForm->subform_register->getElement('email')->setValue($emailAddress); } if ($valid) { $pageSession = new Zend_Session_Namespace('tenants_insurance_quote'); $pageSession->IsNewCustomer = false; $data = $pageForm->getValues(); //Update the WebLead summary and create a STEP3 blob. $webLeadManager = new Manager_Core_WebLead(); $webLeadSummary = $webLeadManager->getSummary($this->_webLeadSummaryId); $webLeadSummary->lastUpdatedTime = $this->_offsetDate(); $webLeadSummary->promotionCode = $data["subform_howhear"]['campaign_code']; $webLeadManager->updateSummary($webLeadSummary); //Determine if a new STEP3 blob needs to be created, or an existing one retrieved. if ($webLeadManager->getBlobExists($this->_webLeadSummaryId, Model_Core_WebLeadStep::STEP3)) { $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP3); } else { $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP3); } //Update the blob and store $webLeadBlob->blob = Zend_Json::encode($_POST); $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob); $webLeadManager->updateBlob($webLeadBlob); // Instantiate the quote manager $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber); // Save new ASN if there is one // Create a postcode model $postcode = new Manager_Core_Postcode(); // Get the address as array for Insured and correspondance address $insuredAddress = $postcode->getPropertyByID($data['subform_insuredaddress']['ins_address'], false); $correspondenceAddress = $postcode->getPropertyByID($data['subform_correspondencedetails']['cor_address'], 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 start and end dates $startDate = $data['subform_policydetails']['policy_start']; $startDate = substr($startDate, 6, 4) . '-' . substr($startDate, 3, 2) . '-' . substr($startDate, 0, 2); $endDate = date('Y-m-d', strtotime(date('Y-m-d', strtotime($startDate)) . ' +1 year -1 day')); $quoteManager->setStartAndEndDates($startDate, $endDate); //Update the customer in the DataStore and the LegacyDataStore. Use the CustomerManager //to do this. //$customerManager = new Manager_Core_Customer(); //First get the existing customer details. //$customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $this->_customerReferenceNumber); //Now modify the details. $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']); $customer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($pageSession->CustomerDob)); //Finally, save the details back to both DataStores. $customerManager->updateCustomer($customer); $premiums = $quoteManager->calculatePremiums(); // Save MI information - how did you hear about us $marketQuestion = new Manager_Core_ManagementInformation(); $marketQuestion->saveMarketingAnswers($this->_policyNumber, $this->_customerReferenceNumber, $data["subform_howhear"]["how_hear"]); // Perform login/register procedure $auth = Zend_Auth::getInstance(); $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer')); if (isset($data['subform_register'])) { // Process registration $params = Zend_Registry::get('params'); $newCustomer = $customerManager->getCustomerByEmailAddress($data['subform_register']['email']); if (!$newCustomer) { $newCustomer = $customerManager->createCustomerFromLegacy($data['subform_register']['email'], $this->_customerReferenceNumber); } // Update customer with password and security data $newCustomer->setTitle($customer->getTitle()); $newCustomer->setFirstName($customer->getFirstName()); $newCustomer->setLastName($customer->getLastName()); $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, ($correspondenceAddress['organisation'] != '' ? "{$correspondenceAddress['organisation']}, " : '') . ($correspondenceAddress['houseNumber'] != '' ? "{$correspondenceAddress['houseNumber']} " : '') . ($correspondenceAddress['buildingName'] != '' ? "{$correspondenceAddress['buildingName']}, " : '') . $correspondenceAddress['address2']); $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $correspondenceAddress['address4']); $newCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $correspondenceAddress['address5']); $newCustomer->setPostCode($correspondenceAddress['postcode']); $newCustomer->setDateOfBirthAt(Application_Core_Utilities::ukDateToMysql($pageSession->CustomerDob)); // assuming that the email is already set and so won't require setting again. // $newCustomer->setEmailAddress($data['subform_register']['email']); $newCustomer->setSecurityQuestion($data['subform_register']['security_question']); $newCustomer->setSecurityAnswer($data['subform_register']['security_answer']); $newCustomer->setPassword($data['subform_register']['password']); $newCustomer->setAccountLoadComplete(true); $newCustomer->typeID = Model_Core_Customer::CUSTOMER; $customerManager->updateCustomer($newCustomer); // Create sign-up completion email $mail = new Application_Core_Mail(); $mail->setTo($data['subform_register']['email'], null); $mail->setFrom('*****@*****.**', 'HomeLet'); $mail->setSubject('My HomeLet account validation'); // Generate activation link $mac = new Application_Core_Security($params->myhomelet->activation_mac_secret, false); $digest = $mac->generate(array('email' => $data['subform_register']['email'])); $activationLink = 'email=' . $data['subform_register']['email'] . '&' . 'mac=' . $digest; // Apply template $mail->applyTemplate('core/account-validation', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $newCustomer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account'), false, '/email-branding/homelet/portal-footer.phtml', '/email-branding/homelet/portal-header.phtml'); $mail->applyTextTemplate('core/account-validationtxt', array('activationLink' => $activationLink, 'homeletWebsite' => $params->homelet->domain, 'firstname' => $newCustomer->getFirstName(), 'templateId' => 'HL2442 12-12', 'heading' => 'Validating your My HomeLet account'), false, '/email-branding/homelet/portal-footer-txt.phtml', '/email-branding/homelet/portal-header-txt.phtml'); // Send email $mail->send(); // Everything has been saved ok so navigate to next step $this->_formStepCommonNavigate(3); } elseif ($auth->hasIdentity()) { $this->_formStepCommonNavigate(3); } //return; } elseif (isset($_POST['back'])) { $this->_formStepCommonNavigate(3); return; } } // Load the element data from the database if we can if ($this->_formStepCommonPopulate($pageForm, 3)) { // Render the page unless we have been redirected $this->view->form = $pageForm; $this->render('step'); } }
/** * Set the address for specified postcode * * @param array $data, String $type * * @return array of housename, street, city, town * */ public function getPropertyAddress($data, $type) { $coreAddressManager = new Manager_Core_Postcode(); $returnArrayValue = array(); // If there is an address id and a list of properties from post code, // we go and get a property by its ID if (isset($data[$type . '_address']) && $data[$type . '_address'] != '' && $data[$type . '_address'] != '-') { $getAddress = $coreAddressManager->getPropertyByID($data[$type . '_address']); $streetLine = ''; if ($getAddress['buildingName']) { $streetLine .= ucwords(strtolower($getAddress['buildingName'])) . ', '; } if ($getAddress['address1']) { $streetLine .= ucwords(strtolower($getAddress['address1'])) . ', '; } if ($getAddress['address2']) { $streetLine .= ucwords(strtolower($getAddress['address2'])) . ', '; } if ($getAddress['address3']) { $streetLine .= ucwords(strtolower($getAddress['address3'])) . ', '; } if ($getAddress['address4']) { //$streetLine .= ucwords(strtolower($getAddress['address4'])) . ', '; } if ($getAddress['address5']) { //$streetLine .= ucwords(strtolower($getAddress['address5'])) . ', '; } $returnArrayValue = array($type . '_housename' => $getAddress['houseNumber'], $type . '_street' => $streetLine, $type . '_town' => $getAddress['address4'], $type . '_city' => $getAddress['address5'], $type . '_postcode' => $getAddress['postcode']); } else { $returnArrayValue = array($type . '_housename' => $data[$type . '_housename'], $type . '_street' => $data[$type . '_street'], $type . '_town' => $data[$type . '_town'], $type . '_city' => $data[$type . '_city'], $type . '_postcode' => $data[$type . '_postcode']); } return $returnArrayValue; }
/** * Saves the form data to the datastore. * * @return void */ public function saveData() { $session = new Zend_Session_Namespace('referencing_global'); $data = $this->getValues(); $referenceManager = new Manager_Referencing_Reference(); $reference = $referenceManager->getReference($session->referenceId); //Locate the current residence object, so that we can attach the current landlords //reference to that. foreach ($reference->referenceSubject->residences as $residence) { if ($residence->chronology == Model_Referencing_ResidenceChronology::CURRENT) { $currentResidence = $residence; break; } } //Create a new residential referee if one does not exist already. if (empty($currentResidence->refereeDetails)) { $refereeManager = new Manager_Referencing_ResidenceReferee(); $currentResidence->refereeDetails = $refereeManager->createReferee($currentResidence->id); } //There is currently no way to capture the type of residential referee, so //assign a default for now. $currentResidence->refereeDetails->type = Model_Referencing_ResidenceRefereeTypes::PRIVATE_LANDLORD; //Record the referee's name. if (empty($currentResidence->refereeDetails->name)) { $nameManager = new Manager_Core_Name(); $currentResidence->refereeDetails->name = $nameManager->createName(); } $currentResidence->refereeDetails->name->title = $data['personal_title']; $currentResidence->refereeDetails->name->firstName = $data['first_name']; $currentResidence->refereeDetails->name->lastName = $data['last_name']; //Record the referee's contact details if (empty($currentResidence->refereeDetails->contactDetails)) { $contactDetailsManager = new Manager_Core_ContactDetails(); $currentResidence->refereeDetails->contactDetails = $contactDetailsManager->createContactDetails(); } $currentResidence->refereeDetails->contactDetails->telephone1 = $data['telephone_day']; $currentResidence->refereeDetails->contactDetails->telephone2 = $data['telephone_evening']; $currentResidence->refereeDetails->contactDetails->fax1 = $data['fax_number']; $currentResidence->refereeDetails->contactDetails->email1 = $data['email']; //Record the referee's address. $postcodeManager = new Manager_Core_Postcode(); $propertyAddress = $postcodeManager->getPropertyByID($data['property_address'], false); $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2']; $addressLine2 = $propertyAddress['address4']; $town = $propertyAddress['address5']; $postCode = $data['property_postcode']; if (empty($currentResidence->refereeDetails->address)) { $addressManager = new Manager_Core_Address(); $currentResidence->refereeDetails->address = $addressManager->createAddress(); } $currentResidence->refereeDetails->address->addressLine1 = $addressLine1; $currentResidence->refereeDetails->address->addressLine2 = $addressLine2; $currentResidence->refereeDetails->address->town = $town; $currentResidence->refereeDetails->address->postCode = $postCode; //Update progress. //And update... $referenceManager->updateReference($reference); }
/** * Returns a Model_Core_Address built from the form data. * * Note that the address object will not be reflected in the datasource, * and so will not contain an ID. The purpose of this method is to provide * a simple means of address extraction so that the address given can be easily * examined and tested. * * @return Model_Core_Address * An address built from th details provided on the form. */ public function getAddressFromForm() { $session = new Zend_Session_Namespace('referencing_global'); $data = $this->getValues(); $address = new Model_Core_Address(); if (isset($data['is_foreign_address']) && 'Yes' == $data['is_foreign_address']) { $address->isOverseasAddress = true; } else { $postcodeManager = new Manager_Core_Postcode(); $propertyAddress = $postcodeManager->getPropertyByID($data['property_address'], false); $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2']; $address->addressLine1 = $addressLine1; $address->addressLine2 = $propertyAddress['address4']; $address->town = $propertyAddress['address5']; $address->postCode = $data['property_postcode']; $address->isOverseasAddress = false; } return $address; }
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()); }
public function saveData() { $session = new Zend_Session_Namespace('referencing_global'); $data = $this->getValues(); $referenceManager = new Manager_Referencing_Reference(); $reference = $referenceManager->getReference($session->referenceId); //Derive the occupation chronology from the current flow item, so that we can locate //the relevant occupation to update. switch ($session->currentFlowItem) { case Model_Referencing_DataEntry_FlowItems::CURRENT_OCCUPATION: $chronology = Model_Referencing_OccupationChronology::CURRENT; $classification = Model_Referencing_OccupationImportance::FIRST; break; case Model_Referencing_DataEntry_FlowItems::SECOND_OCCUPATION: $chronology = Model_Referencing_OccupationChronology::CURRENT; $classification = Model_Referencing_OccupationImportance::SECOND; break; case Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION: $chronology = Model_Referencing_OccupationChronology::FUTURE; $classification = Model_Referencing_OccupationImportance::FIRST; break; } //Attept to locate the relevant occupation. $occupationManager = new Manager_Referencing_Occupation(); $thisOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, $chronology, $classification); if (empty($thisOccupation)) { //The occupation to process does not exist, so create it first. $thisOccupation = $occupationManager->createNewOccupation($session->referenceId, $chronology, $classification); if (empty($reference->referenceSubject->occupations)) { $reference->referenceSubject->occupations = array(); } $reference->referenceSubject->occupations[] = $thisOccupation; } //Now update $thisOccupation with the occupational details provided by the ReferenceSubject. if (empty($thisOccupation->refereeDetails)) { $refereeManager = new Manager_Referencing_OccupationReferee(); $thisOccupation->refereeDetails = $refereeManager->createReferee($thisOccupation->id); } //Add general details. $thisOccupation->refereeDetails->organisationName = $data['company_name']; $thisOccupation->refereeDetails->position = $data['contact_position']; $thisOccupation->income = new Zend_Currency(array('value' => $data['income'], 'precision' => 0)); //Add the referee name if required. if (empty($thisOccupation->refereeDetails->name)) { $nameManager = new Manager_Core_Name(); $thisOccupation->refereeDetails->name = $nameManager->createName(); } $nameArray = preg_split("/\\s/", $data['contact_name']); if (count($nameArray) >= 2) { $thisOccupation->refereeDetails->name->firstName = array_shift($nameArray); $thisOccupation->refereeDetails->name->lastName = array_pop($nameArray); } else { if (count($nameArray) == 1) { $thisOccupation->refereeDetails->name->firstName = array_shift($nameArray); } } //Capture and process the referee address. $postcodeManager = new Manager_Core_Postcode(); $propertyAddress = $postcodeManager->getPropertyByID($data['property_address'], false); $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2']; $addressLine2 = $propertyAddress['address4']; $town = $propertyAddress['address5']; $postCode = $data['property_postcode']; if (empty($thisOccupation->refereeDetails->address)) { $addressManager = new Manager_Core_Address(); $thisOccupation->refereeDetails->address = $addressManager->createAddress(); } $thisOccupation->refereeDetails->address->addressLine1 = $addressLine1; $thisOccupation->refereeDetails->address->addressLine2 = $addressLine2; $thisOccupation->refereeDetails->address->town = $town; $thisOccupation->refereeDetails->address->postCode = $postCode; //Capture and process the referee contact details. if (empty($thisOccupation->refereeDetails->contactDetails)) { $contactDetailsManager = new Manager_Core_ContactDetails(); $thisOccupation->refereeDetails->contactDetails = $contactDetailsManager->createContactDetails(); } $thisOccupation->refereeDetails->contactDetails->telephone1 = $data['telephone_number']; $thisOccupation->refereeDetails->contactDetails->fax1 = $data['fax_number']; $thisOccupation->refereeDetails->contactDetails->email1 = $data['email']; if (!empty($data['tenancy_start_date'])) { $thisOccupation->startDate = new Zend_Date($data['tenancy_start_date'], Zend_Date::DATES); } if (!empty($data['is_permanent'])) { if ($data['is_permanent'] == 'Yes') { $thisOccupation->isPermanent = true; } else { $thisOccupation->isPermanent = false; } } //Now capture the optional details and insert into the occupation variables array. if (!empty($data['reference_number'])) { if (empty($thisOccupation->variables)) { $thisOccupation->variables = array(); } $thisOccupation->variables[Model_Referencing_OccupationVariables::PAYROLL_NUMBER] = $data['reference_number']; } if (!empty($data['position'])) { if (empty($thisOccupation->variables)) { $thisOccupation->variables = array(); } $thisOccupation->variables[Model_Referencing_OccupationVariables::POSITION] = $data['position']; } //Identify if a future occupation is applicable and required. if (!empty($data['will_change'])) { if ($data['will_change'] == 'Yes') { //If its going to change then we need to create a future employer record, if not already //done so. $futureOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST); if (empty($futureOccupation)) { $createFutureOccupation = true; } else { $createFutureOccupation = false; } if ($createFutureOccupation) { $futureOccupation = $occupationManager->createNewOccupation($session->referenceId, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST); $futureOccupation->type = Model_Referencing_OccupationTypes::EMPLOYMENT; $reference->referenceSubject->occupations[] = $futureOccupation; } } else { //Delete any future employer records. $futureOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST); if (!empty($futureOccupation)) { $occupationManager->deleteOccupation($futureOccupation); } } } //And update... $referenceManager->updateReference($reference); return $thisOccupation; }