/**
  * Identifies the missing information in the product data entry flow.
  *
  * @param string $enquiryId
  * The unique external Enquiry identifier.
  *
  * @return mixed
  * Returns an array of missing information strings, if missing information is
  * found. Else returns null.
  */
 public function getMissingInformation($enquiryId)
 {
     $referenceManager = new Manager_Referencing_Reference();
     $enquiry = $referenceManager->getReference($enquiryId);
     $productSelection = $enquiry->productSelection;
     $missingInfo = array();
     //Make sure product selected, and if rent guarantee then a duration is selected
     if (empty($productSelection)) {
         $missingInfo[] = 'Product not selected';
     } else {
         $product = $productSelection->product;
         if ($product->durationType == Model_Referencing_ProductDurationTypes::VARIABLE) {
             //The duration must be specified
             if (empty($productSelection->duration)) {
                 $missingInfo[] = 'Product duration not selected';
             }
         }
     }
     //Finalize
     if (empty($missingInfo)) {
         $returnVal = null;
     } else {
         $returnVal = $missingInfo;
     }
     return $returnVal;
 }
 /**
  * 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);
 }
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($session->referenceId);
     // Update the completion method (complete now, or email link to tenant).
     $reference->completionMethod = $data['completion_method'];
     // Update the reference subject.
     if (empty($reference->referenceSubject)) {
         $referenceSubjectManager = new Manager_Referencing_ReferenceSubject();
         $reference->referenceSubject = $referenceSubjectManager->insertPlaceholder($session->referenceId);
     }
     // Reference subject name details
     if (empty($reference->referenceSubject->name)) {
         $nameManager = new Manager_Core_Name();
         $reference->referenceSubject->name = $nameManager->createName();
     }
     $reference->referenceSubject->name->title = $data['personal_title'];
     $reference->referenceSubject->name->firstName = $data['first_name'];
     $reference->referenceSubject->name->lastName = $data['last_name'];
     //Reference subject contact details
     if (empty($reference->referenceSubject->contactDetails)) {
         $contactDetailsManager = new Manager_Core_ContactDetails();
         $reference->referenceSubject->contactDetails = $contactDetailsManager->createContactDetails();
     }
     $reference->referenceSubject->contactDetails->email1 = $data['email'];
     //Misc details.
     $reference->referenceSubject->type = Model_Referencing_ReferenceSubjectTypes::TENANT;
     $reference->referenceSubject->shareOfRent = new Zend_Currency(array('value' => $data['share_of_rent'], 'precision' => 0));
     //Product details.
     if (empty($reference->productSelection)) {
         $productSelectionManager = new Manager_Referencing_ProductSelection();
         $reference->productSelection = $productSelectionManager->insertPlaceholder($session->referenceId);
     }
     $productDatasource = new Datasource_Referencing_Product();
     $reference->productSelection->product = $productDatasource->getById($data['product_choice']);
     if (empty($data['product_duration'])) {
         $reference->productSelection->duration = 0;
     } else {
         $reference->productSelection->duration = $data['product_duration'];
     }
     // And update...
     $referenceManager->updateReference($reference);
     // Ensure the product selection by the user is updated in the session, ensuring correct
     // navigations...
     $session->productName = $reference->productSelection->product->key;
 }
 /**
  * Identifies the missing information in the prospective landlord data entry flow.
  *
  * @param string $enquiryId
  * The unique external Enquiry identifier.
  *
  * @return mixed
  * Returns an array of missing information strings, if missing information is
  * found. Else returns null.
  */
 public function getMissingInformation($enquiryId)
 {
     $referenceManager = new Manager_Referencing_Reference();
     $enquiry = $referenceManager->getReference($enquiryId);
     $prospectiveLandlord = $enquiry->propertyLease->prospectiveLandlord;
     $missingInfo = array();
     if (empty($prospectiveLandlord)) {
         //Prospective landlord details are optional except on rentguarantee
         //products.
         $product = $enquiry->productSelection->product;
         if ($product->isRentGuarantee) {
             $missingInfo[] = 'No prospective landlord details';
         }
     } else {
         //Check the name.
         if (empty($prospectiveLandlord->name->firstName)) {
             if (empty($prospectiveLandlord->name->lastName)) {
                 $missingInfo[] = 'Prospective landlord: name';
             }
         }
         //Contact details are optional.
         //Check the address
         $address = $prospectiveLandlord->address;
         if (empty($address->flatNumber)) {
             if (empty($address->houseName)) {
                 if (empty($address->houseNumber)) {
                     if (empty($address->addressLine1)) {
                         $missingInfo[] = 'Prospective landlord address: 1st line';
                     }
                 }
             }
         }
         if (empty($address->town)) {
             $missingInfo[] = 'Prospective landlord address: town';
         }
         if (empty($address->postCode)) {
             $missingInfo[] = 'Prospective landlord address: postcode';
         }
     }
     //Finalize
     if (empty($missingInfo)) {
         $returnVal = null;
     } else {
         $returnVal = $missingInfo;
     }
     return $returnVal;
 }
 /**
  * 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);
 }
 /**
  * Identifies the missing information in the property lease data entry flow.
  *
  * @param string $enquiryId
  * The unique external Enquiry identifier.
  *
  * @return mixed
  * Returns an array of missing information strings, if missing information is
  * found. Else returns null.
  */
 public function getMissingInformation($enquiryId)
 {
     $referenceManager = new Manager_Referencing_Reference();
     $enquiry = $referenceManager->getReference($enquiryId);
     $propertyLease = $enquiry->propertyLease;
     $missingInfo = array();
     //Check the address details.
     if (empty($propertyLease->address->flatNumber)) {
         if (empty($propertyLease->address->houseName)) {
             if (empty($propertyLease->address->houseNumber)) {
                 if (empty($propertyLease->address->addressLine1)) {
                     $missingInfo[] = 'Property address: 1st line';
                 }
             }
         }
     }
     if (empty($propertyLease->address->town)) {
         $missingInfo[] = 'Property address: town';
     }
     if (empty($propertyLease->address->postCode)) {
         $missingInfo[] = 'Property address: postcode';
     }
     //Check the remaining details.
     if (empty($propertyLease->rentPerMonth)) {
         $missingInfo[] = 'Rental amount';
     }
     if (empty($propertyLease->tenancyTerm)) {
         $missingInfo[] = 'Tenancy term';
     }
     if (empty($propertyLease->noOfTenants)) {
         $missingInfo[] = 'Number of tenants';
     }
     if (empty($propertyLease->tenancyStartDate)) {
         $missingInfo[] = 'Tenancy start date';
     }
     //Finalize
     if (empty($missingInfo)) {
         $returnVal = null;
     } else {
         $returnVal = $missingInfo;
     }
     return $returnVal;
 }
 /**
  * Identifies the missing information in the reference subject data entry flow.
  *
  * @param string $enquiryId
  * The unique external Enquiry identifier.
  *
  * @return mixed
  * Returns an array of missing information strings, if missing information is
  * found. Else returns null.
  */
 public function getMissingInformation($enquiryId)
 {
     $referenceManager = new Manager_Referencing_Reference();
     $enquiry = $referenceManager->getReference($enquiryId);
     $referenceSubject = $enquiry->referenceSubject;
     $missingInfo = array();
     if (empty($referenceSubject)) {
         $missingInfo[] = 'Applicant details missing';
     } else {
         if (empty($referenceSubject->name->title)) {
             $missingInfo[] = 'Applicant details: title';
         }
         if (empty($referenceSubject->name->firstName)) {
             $missingInfo[] = 'Applicant details: first name';
         }
         if (empty($referenceSubject->name->lastName)) {
             $missingInfo[] = 'Applicant details: last name';
         }
         if (empty($referenceSubject->dob)) {
             $missingInfo[] = 'Applicant details: date of birth';
         }
         if (empty($referenceSubject->contactDetails->telephone1)) {
             if (empty($referenceSubject->contactDetails->telephone2)) {
                 $missingInfo[] = 'Applicant details: contact number';
             }
         }
         if (empty($referenceSubject->hasAdverseCredit)) {
             if ($referenceSubject->hasAdverseCredit !== false) {
                 $missingInfo[] = 'Applicant details: adverse credit confirmation';
             }
         }
     }
     //Finalize
     if (empty($missingInfo)) {
         $returnVal = null;
     } else {
         $returnVal = $missingInfo;
     }
     return $returnVal;
 }
 /**
  * Overridden isValid() method for pre-validation code
  *
  * @param array $formData data typically from a POST or GET request
  *
  * @return bool
  */
 public function isValid($formData = array())
 {
     // If a landline phone number is given, mobile is not mandatory
     if (isset($formData['telephone_day']) && '' != trim($formData['telephone_day'])) {
         $this->getElement('mobile_number')->setRequired(false);
     }
     // If a mobile phone number is given, landline is not mandatory
     if (isset($formData['mobile_number']) && '' != trim($formData['mobile_number'])) {
         $this->getElement('telephone_day')->setRequired(false);
     }
     // If a occupational_type is 3 or 7, occupational_type is mandatory
     if (isset($formData['occupational_type'])) {
         if ('3' == trim($formData['occupational_type']) || '7' == trim($formData['occupational_type'])) {
             $this->getElement('is_future_employment_secured')->setRequired(true);
         } else {
             $this->getElement('is_future_employment_secured')->setRequired(false);
         }
     }
     // Redmine ref #6195: Check that tenant will be greater than 18 years of age when the tenancy begins.  Code is "inspired" by legacy Referencing/src/ref-www/frontEnd/validate/tenantDetails.php
     // Get tenancy start date
     $session = new Zend_Session_Namespace('referencing_global');
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($session->referenceId);
     $startTime = $reference->propertyLease->tenancyStartDate->getTimestamp();
     // 18 years is 567648000 seconds
     $dobTime = $formData['tenancy_start_date'];
     // This is actually the DoB from the form.  wtf?
     $dobStamp = mktime(0, 0, 0, substr($dobTime, 3, 2), substr($dobTime, 0, 2), substr($dobTime, 6, 4));
     if ($startTime - $dobStamp < 567648000) {
         $badValidator = new Zend_Validate_ForceError();
         $badValidator->setMessages(array(Zend_Validate_ForceError::MSG_NOTVALID => 'This tenant will not be 18 years old at the start of the tenancy. We are unable to complete this reference. Please note that you must provide a correct Date of Birth or the results of your reference will be inaccurate and any associated insurance product will be invalidated.'));
         $this->getElement('tenancy_start_date')->addValidator($badValidator);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 /**
  * Reference list action
  *
  */
 public function referencesAction()
 {
     $this->_setMetaTitle('My HomeLet | References');
     $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/references' => 'My References'));
     // Get the customer session
     $customerSession = $this->auth->getStorage()->read();
     $request = $this->getRequest();
     // Search and ordering
     $filteredOrderBy = array();
     $orderBy = $request->getParam('order');
     $refnoSearch = $request->getParam('id');
     // Validate order by to restricted fields to those displayed on the front end
     if (is_array($orderBy)) {
         foreach ($orderBy as $orderByField => $orderByDirection) {
             if (in_array($orderByField, array('start_date', 'lastname', 'address1', 'externalrefno', 'status'))) {
                 // Copy field into new array
                 $filteredOrderBy[$orderByField] = $orderByDirection;
             }
         }
     }
     // Get list of external reference numbers
     $referencesAndReports = array();
     $referenceManager = new Manager_Referencing_Reference();
     $referenceIds = $referenceManager->getAllReferenceIds($customerSession->id);
     // Get all reference details
     $legacyRefManager = new Manager_ReferencingLegacy_Munt();
     $references = $legacyRefManager->getAllReferences($referenceIds, $refnoSearch, $filteredOrderBy);
     foreach ($references as $reference) {
         $report = $legacyRefManager->getLatestReport($reference->externalId);
         array_push($referencesAndReports, array('reference' => $reference, 'report' => $report));
     }
     $this->view->references = $referencesAndReports;
 }
 /**
  * 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);
     }
 }
 /**
  * Called from the legacy HRT system when the PLL's reference fails for some reason.
  * 
  * This can be called only after payment has been attempted.
  */
 public function noticeAction()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     if (empty($session->referenceId)) {
         //User is logged in, but they do not have a reference number, so ignore this and go to
         //the start of the data entry process.
         return $this->_helper->redirector('property-lease');
     }
     //Retrieve the latest notice flagged against the reference.
     $noticeManager = new Manager_Referencing_UserNotices();
     $notice = $noticeManager->getLatestNotice($session->referenceId);
     if (empty($notice)) {
         //Not notices flagged against the reference, so go to the start page of the
         //data entry process.
         return $this->_helper->redirector('property-lease');
     }
     //Retrieve the referencing details so that relevant details can be replaced into the
     //notice.
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($session->referenceId);
     //Replace placeholders appropriate.
     $notice = preg_replace("/\\[--EXTERNALID--\\]/", $reference->externalId, $notice);
     $notice = preg_replace("/\\[--INTERNALID--\\]/", $reference->internalId, $notice);
     $this->view->notice = $notice;
     //Tell page to use AJAX validation as we go
     $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = 1;');
 }
 /**
  * Retrieve a referencing report
  */
 public function viewReferencingReportAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $refNo = $request->getParam('refno');
     $download = $request->getParam('download');
     $reporttype = '';
     $reportkey = $request->getParam('report');
     // Validate the refNo parameter
     preg_match('/([0-9]*\\.[0-9]*)/', $refNo, $refNo);
     if (count($refNo) == 2) {
         $refNo = $refNo[1];
     } else {
         // Fails validation, return error
         $this->render('view-document-not-found');
         return;
     }
     // Validate direct landlord is the correct owner of the reference
     // Get the customer session
     $customerSession = $this->auth->getStorage()->read();
     // Get list of external reference numbers
     $referenceManager = new Manager_Referencing_Reference();
     $referenceIds = $referenceManager->getAllReferenceIds($customerSession->id);
     if (!in_array($refNo, $referenceIds)) {
         // This reference does not belong to the customer
         $this->render('view-document-not-found');
         return;
     }
     // Get Latest report
     $legacyRefManager = new Manager_ReferencingLegacy_Munt();
     $report = $legacyRefManager->getLatestReport($refNo);
     // Check the $reportkey parameter against the key provided by the report object returned.
     // If they dont match, display a notice page that the report is out of date.
     if ($reportkey != '' && $report->validationKey != $reportkey) {
         $this->view->download = $download == 'true' ? 'true' : 'false';
         $this->view->report = $report;
         $this->render('reference-report-outofdate');
         return;
     }
     // Set the report type of that of the report object
     $reporttype = $report->reportType;
     $params = Zend_Registry::get('params');
     $baseRefUrl = $params->baseUrl->referencing;
     $reportUri = $baseRefUrl . 'cgi-bin/refviewreport.pl?refno=' . $refNo . '&repType=' . $reporttype;
     //error_log('debug: ' . $reportUri);
     $filename = $this->_buildReportAttachementFilename('Report', $refNo);
     // Get the latest report
     $reportDatasource = new Datasource_ReferencingLegacy_ReportHistory();
     $timegenerated = $reportDatasource->getTimeReportGenerated($refNo, $reporttype);
     // Check report file cache
     if (Application_Cache_Referencing_ReportFileCache::getInstance()->has($filename, $timegenerated)) {
         // Return from cache
         $pdfContent = Application_Cache_Referencing_ReportFileCache::getInstance()->get($filename, $timegenerated);
         $this->getResponse()->appendBody($pdfContent);
     } else {
         // Request report from legacy
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $reportUri);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($curl, CURLOPT_TIMEOUT, 50);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         $pdfContent = curl_exec($curl);
         curl_close($curl);
         if (!$pdfContent) {
             $this->render('view-document-not-found');
             return;
         }
         // Cache result
         Application_Cache_Referencing_ReportFileCache::getInstance()->set($filename, $pdfContent, $timegenerated);
         $this->getResponse()->appendBody($pdfContent);
     }
     // Create filename
     // AJD - Why is this being done again? Also - it doesn't follow the new filename schema. Address must not be used.
     /*$referenceManager = new Manager_Referencing_Reference();
       $reference = $referenceManager->getReference($refNo);
       $filename = ucfirst(strtolower($reporttype)) . ', ' . $reference->propertyLease->address->addressLine1 . ', ' . $reference->propertyLease->address->addressLine2 . '.pdf';
       $filename = preg_replace('/&|\\//', '', $filename);*/
     // Apply appropriate headers
     //        $response->setHeader('Pragma', '');
     //        $response->setHeader('Cache-Control', '');
     if ($download == 'true') {
         // Downloading
         header('Pragma: ');
         // Remove pragma
         header('Cache-Control: ');
         // Remove cache control
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename=' . $filename);
         //           $response->setHeader('Content-Description', 'File Transfer');
         //           $response->setHeader('Content-Type', 'application/octet-stream');
         //           $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
     } else {
         header('Pragma: ');
         // Remove pragma
         header('Cache-Control: ');
         header('Content-Type: application/pdf');
         // Viewing
         //            $response->setHeader('Content-Type', 'text/plain');
     }
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
 }
Example #13
0
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($session->referenceId);
     //Derive the residence chronology from the current flow item, so that we can locate
     //the relevant residence to update.
     switch ($session->currentFlowItem) {
         case Model_Referencing_DataEntry_FlowItems::FIRST_RESIDENCE:
             $chronology = Model_Referencing_ResidenceChronology::CURRENT;
             break;
         case Model_Referencing_DataEntry_FlowItems::SECOND_RESIDENCE:
             $chronology = Model_Referencing_ResidenceChronology::FIRST_PREVIOUS;
             break;
         case Model_Referencing_DataEntry_FlowItems::THIRD_RESIDENCE:
             $chronology = Model_Referencing_ResidenceChronology::SECOND_PREVIOUS;
             break;
     }
     //Attept to locate the relevant residence.
     $residenceManager = new Manager_Referencing_Residence();
     $thisResidence = $residenceManager->findSpecificResidence($reference->referenceSubject->residences, $chronology);
     if (empty($thisResidence)) {
         //The residence to process does not exist, so create it first.
         $thisResidence = $residenceManager->insertPlaceholder($session->referenceId, $chronology);
         if (empty($reference->referenceSubject->residences)) {
             $reference->referenceSubject->residences = array();
         }
         $reference->referenceSubject->residences[] = $thisResidence;
     }
     //Update thisResidence to reflect the user inputs.
     if (isset($data['is_foreign_address']) && 'Yes' == $data['is_foreign_address']) {
         // Needed by the HRT system to recognise foreign addresses
         $thisResidence->address->addressLine1 = 'Abroad';
         $thisResidence->address->town = 'Abroad';
         $thisResidence->address->postCode = '1001';
         $thisResidence->address->isOverseasAddress = true;
     } else {
         //Format the property details.
         $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($thisResidence->address)) {
             $addressManager = new Manager_Core_Address();
             $thisResidence->address = $addressManager->createAddress();
         }
         $thisResidence->address->addressLine1 = $addressLine1;
         $thisResidence->address->addressLine2 = $addressLine2;
         $thisResidence->address->town = $town;
         $thisResidence->address->postCode = $postCode;
         $thisResidence->address->isOverseasAddress = false;
     }
     $thisResidence->durationAtAddress = $data['duration_at_address'];
     //months
     //Finally, identify if the ReferenceSubject should be classed as a foreign national,
     //which is when they have spent the 6 months or more abroad.
     if ($this->_isOverseas($reference)) {
         $reference->referenceSubject->isForeignNational = true;
     } else {
         $reference->referenceSubject->isForeignNational = false;
     }
     //Update the datasources.
     $referenceManager->updateReference($reference);
 }
Example #14
0
 /**
  * Full description given in superclass.
  */
 public function moveToNext($referenceId = null)
 {
     $isMoved = true;
     switch ($this->currentFlowItem) {
         case Model_Referencing_DataEntry_FlowItems::PROPERTY_LEASE:
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::PRODUCT;
             break;
         case Model_Referencing_DataEntry_FlowItems::PRODUCT:
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::PROSPECTIVE_LANDLORD;
             break;
         case Model_Referencing_DataEntry_FlowItems::PROSPECTIVE_LANDLORD:
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::REFERENCE_SUBJECT;
             break;
         case Model_Referencing_DataEntry_FlowItems::REFERENCE_SUBJECT:
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::FIRST_RESIDENCE;
             break;
         case Model_Referencing_DataEntry_FlowItems::FIRST_RESIDENCE:
         case Model_Referencing_DataEntry_FlowItems::SECOND_RESIDENCE:
         case Model_Referencing_DataEntry_FlowItems::THIRD_RESIDENCE:
             //Determine which residence is next, if any.
             $residenceFlowManager = new Manager_Referencing_DataEntry_Flow_ResidentialFlow();
             $nextFlowItem = $residenceFlowManager->moveToNextResidence($this->currentFlowItem, $referenceId);
             if (!empty($nextFlowItem)) {
                 $this->currentFlowItem = $nextFlowItem;
                 break;
             }
             //Determine if the current landlord is next.
             $referenceManager = new Manager_Referencing_Reference();
             $reference = $referenceManager->getReference($referenceId);
             $referenceSubject = $reference->referenceSubject;
             $residenceArray = $referenceSubject->residences;
             $isMovedToCurrentLandlord = false;
             foreach ($residenceArray as $residence) {
                 if ($residence->chronology == Model_Referencing_ResidenceChronology::CURRENT) {
                     if ($residence->status == Model_Referencing_ResidenceStatus::TENANT) {
                         $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::CURRENT_LANDLORD;
                         $isMovedToCurrentLandlord = true;
                     }
                     break;
                 }
             }
             if ($isMovedToCurrentLandlord) {
                 break;
             }
             //Determine which occupation is next.
             $occupationFlowManager = new Manager_Referencing_DataEntry_Flow_OccupationalFlow();
             $nextFlowItem = $occupationFlowManager->moveToNextOccupation($this->currentFlowItem, $referenceId);
             if (!empty($nextFlowItem)) {
                 $this->currentFlowItem = $nextFlowItem;
                 break;
             }
             //Move to terms.
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::TERMS;
             break;
         case Model_Referencing_DataEntry_FlowItems::CURRENT_LANDLORD:
             //Determine which occupation is next.
             $occupationFlowManager = new Manager_Referencing_DataEntry_Flow_OccupationalFlow();
             $nextFlowItem = $occupationFlowManager->moveToNextOccupation($this->currentFlowItem, $referenceId);
             if (!empty($nextFlowItem)) {
                 $this->currentFlowItem = $nextFlowItem;
                 break;
             }
             //Move to terms.
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::TERMS;
             break;
         case Model_Referencing_DataEntry_FlowItems::CURRENT_OCCUPATION:
         case Model_Referencing_DataEntry_FlowItems::SECOND_OCCUPATION:
         case Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION:
             //Determine which occupation is next.
             $occupationFlowManager = new Manager_Referencing_DataEntry_Flow_OccupationalFlow();
             $nextFlowItem = $occupationFlowManager->moveToNextOccupation($this->currentFlowItem, $referenceId);
             if (!empty($nextFlowItem)) {
                 $this->currentFlowItem = $nextFlowItem;
                 break;
             }
             //Move to terms.
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::TERMS;
             break;
         case Model_Referencing_DataEntry_FlowItems::TERMS:
             $this->currentFlowItem = Model_Referencing_DataEntry_FlowItems::PRICE_CONFIRMATION;
             break;
         case Model_Referencing_DataEntry_FlowItems::PRICE_CONFIRMATION:
             $isMoved = false;
             break;
         default:
             throw new Zend_Exception('Unknown flow');
     }
     return $isMoved;
 }
 /**
  * Executes checks when the user is a PLL finalizing an email-link-to-tenant.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param string $customerToken
  * @param string $refNo
  *
  * @return boolean
  */
 protected function _privateLandlordLinkPreDespatch(Zend_Controller_Request_Abstract $request, $customerToken, $refNo)
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($refNo);
     //Check the validity of the access.
     $params = Zend_Registry::get('params');
     $hashingString = $params->pll->emailLink->security->securityString;
     $leeWay = $params->pll->emailLink->security->securityTokenTimeLeewayUser;
     $securityManager = new Application_Core_Security($hashingString, true, $leeWay);
     $securityCheck = $securityManager->authenticate($customerToken, array('refNo', 'customerId'));
     if ($securityCheck['result']) {
         //Ensure the customer identifier extracted from the $customerToken matches the identifier
         //stored in the reference.
         $customerId = $securityCheck['data']['customerId'];
         if ($customerId != $reference->customer->customerId) {
             $session->security->error = 'Customer identifier does not match';
             return false;
         }
     } else {
         // Something went wrong, eg, hash didn't match or time was out of bounds
         $session->security->error = $securityCheck['error'];
         return false;
     }
     //Log the customer in.
     $customerManager = new Manager_Referencing_Customer();
     $customer = $customerManager->getCustomer($customerId);
     $loginManager = new Manager_Referencing_Login();
     $loginManager->logUserIn($customer->getEmailAddress(), $customer->getPassword());
     //Set the relevant session variables so that the PLL can proceed the reference.
     $session->referenceId = $reference->internalId;
     $session->productName = $reference->productSelection->product->key;
     $session->userType = Model_Referencing_ReferenceUserTypes::PRIVATE_LANDLORD;
     $session->customerToken = $customerToken;
     $session->refNo = $refNo;
     return true;
 }
Example #16
0
 /**
  * Identifies the missing information in the residence data entry flow.
  *
  * @param integer $chronology
  * The chronology of the residence. Must correspond to one of the consts exposed by
  * the Model_Referencing_ResidenceChronology class.
  * 
  * @param string $enquiryId
  * The unique external Enquiry identifier.
  *
  * @return mixed
  * Returns an array of missing information strings, if missing information is
  * found. Else returns null.
  */
 public function getMissingInformation($chronology, $enquiryId)
 {
     $referenceManager = new Manager_Referencing_Reference();
     $enquiry = $referenceManager->getReference($enquiryId);
     $residenceArray = $enquiry->referenceSubject->residences;
     $missingInfo = array();
     //Prepare the label used in the missing information message.
     switch ($chronology) {
         case Model_Referencing_ResidenceChronology::CURRENT:
             $label = 'Current';
             break;
         case Model_Referencing_ResidenceChronology::FIRST_PREVIOUS:
             $label = 'Previous';
             break;
         case Model_Referencing_ResidenceChronology::SECOND_PREVIOUS:
             $label = 'Second previous';
             break;
     }
     if (empty($residenceArray)) {
         $missingInfo[] = "{$label} residence details missing";
     } else {
         foreach ($residenceArray as $residence) {
             //Look for the appropriate residence.
             if ($residence->chronology != $chronology) {
                 continue;
             }
             //Current residence found. Check the data provided.
             if (empty($residence->duration)) {
                 $missingInfo[] = "{$label} residence: duration";
             }
             if (empty($residence->address->isOverseasAddress)) {
                 if ($residence->address->isOverseasAddress !== false) {
                     $missingInfo[] = "{$label} residence: is overseas confirmation";
                 }
             }
             //Check the address
             $address = $residence->address;
             if (empty($address->flatNumber)) {
                 if (empty($address->houseName)) {
                     if (empty($address->houseNumber)) {
                         if (empty($address->addressLine1)) {
                             $missingInfo[] = "{$label} residence: 1st line";
                         }
                     }
                 }
             }
             if (empty($address->town)) {
                 $missingInfo[] = "{$label} residence: town";
             }
             if (empty($address->postCode)) {
                 $missingInfo[] = "{$label} residence: postcode";
             }
             //Processing complete.
             break;
         }
     }
     //Finalize
     if (empty($missingInfo)) {
         $returnVal = null;
     } else {
         $returnVal = $missingInfo;
     }
     return $returnVal;
 }
 public function moveToNextOccupation($currentFlowItem, $referenceId)
 {
     //Determine if the current flow item is something other than an
     //occupation.
     $isOccupation = false;
     $isCurrentOccupation = false;
     $isSecondOccupation = false;
     $isFutureOccupation = false;
     switch ($currentFlowItem) {
         case Model_Referencing_DataEntry_FlowItems::CURRENT_OCCUPATION:
             $isOccupation = true;
             $isCurrentOccupation = true;
             break;
         case Model_Referencing_DataEntry_FlowItems::SECOND_OCCUPATION:
             $isOccupation = true;
             $isSecondOccupation = true;
             break;
         case Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION:
             $isOccupation = true;
             $isFutureOccupation = true;
             break;
     }
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($referenceId);
     if (!$isOccupation) {
         //Do we have a current occupation?
         $occupationArray = $reference->referenceSubject->occupations;
         foreach ($occupationArray as $occupation) {
             if ($occupation->chronology == Model_Referencing_OccupationChronology::CURRENT) {
                 //Match found. See if we can despatch to it.
                 if ($this->_isDespatchAllowed($occupation, $reference)) {
                     return Model_Referencing_DataEntry_FlowItems::CURRENT_OCCUPATION;
                 }
                 break;
             }
         }
         //Do we have a future occupation?
         foreach ($occupationArray as $occupation) {
             if ($occupation->chronology == Model_Referencing_OccupationChronology::FUTURE) {
                 //Match found. See if we can despatch to it.
                 if ($this->_isDespatchAllowed($occupation, $reference)) {
                     return Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION;
                 }
                 break;
             }
         }
         //No occupations applicable.
         return null;
     }
     if ($isCurrentOccupation) {
         //Do we have a second occupation?
         $occupationArray = $reference->referenceSubject->occupations;
         foreach ($occupationArray as $occupation) {
             if ($occupation->chronology == Model_Referencing_OccupationChronology::CURRENT) {
                 if ($occupation->importance == Model_Referencing_OccupationImportance::SECOND) {
                     //Match found. See if we can despatch to it.
                     if ($this->_isDespatchAllowed($occupation, $reference)) {
                         return Model_Referencing_DataEntry_FlowItems::SECOND_OCCUPATION;
                     }
                     break;
                 }
             }
         }
         //Do we have a future occupation?
         foreach ($occupationArray as $occupation) {
             if ($occupation->chronology == Model_Referencing_OccupationChronology::FUTURE) {
                 //Match found. See if we can despatch to it.
                 if ($this->_isDespatchAllowed($occupation, $reference)) {
                     return Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION;
                 }
                 break;
             }
         }
         //No occupations applicable.
         return null;
     }
     if ($isSecondOccupation) {
         //Do we have a future occupation?
         $occupationArray = $reference->referenceSubject->occupations;
         foreach ($occupationArray as $occupation) {
             if ($occupation->chronology == Model_Referencing_OccupationChronology::FUTURE) {
                 //Match found. See if we can despatch to it.
                 if ($this->_isDespatchAllowed($occupation, $reference)) {
                     return Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION;
                 }
                 break;
             }
         }
         //No occupations applicable.
         return null;
     }
     //If here then the current flow item is the future occupation. No other occupations
     //are available to despatch to, so return null.
     return null;
 }
 /**
  * Identifies the missing information in the current landlord data entry flow.
  *
  * @param string $enquiryId
  * The unique external Enquiry identifier.
  *
  * @return mixed
  * Returns an array of missing information strings, if missing information is
  * found. Else returns null.
  */
 public function getMissingInformation($enquiryId)
 {
     //Identify if current landlord referee details are applicable.
     $referenceManager = new Manager_Referencing_Reference();
     $enquiry = $referenceManager->getReference($enquiryId);
     $currentResidence = null;
     foreach ($enquiry->referenceSubject->residences as $residence) {
         if ($residence->chronology == Model_Referencing_ResidenceChronology::CURRENT) {
             $currentResidence = $residence;
             break;
         }
     }
     if ($currentResidence->status != Model_Referencing_ResidenceStatus::TENANT) {
         //The landlord referee details are not applicable, therefore return.
         return null;
     }
     //The current landlord referee details are applicable, so retrieve and process.
     $currentLandlord = $currentResidence->refereeDetails;
     $missingInfo = array();
     if (empty($currentLandlord)) {
         //Current landlord details are optional except on full referencing
         //products.
         $product = $enquiry->productSelection->product;
         if ($product->referencingType == Model_Referencing_ProductReferencingTypes::FULL_REFERENCE) {
             $missingInfo[] = 'No current landlord details';
         }
     } else {
         //Check the type
         if (empty($currentLandlord->type)) {
             $missingInfo[] = 'Current landlord: type';
         }
         //Check the name.
         if (empty($currentLandlord->name->firstName)) {
             if (empty($currentLandlord->name->lastName)) {
                 $missingInfo[] = 'Current landlord: name';
             }
         }
         //Contact details are optional.
         //Check the address
         $address = $currentLandlord->address;
         if (empty($address->flatNumber)) {
             if (empty($address->houseName)) {
                 if (empty($address->houseNumber)) {
                     if (empty($address->addressLine1)) {
                         $missingInfo[] = 'Current landlord address: 1st line';
                     }
                 }
             }
         }
         if (empty($address->town)) {
             $missingInfo[] = 'Current landlord address: town';
         }
         if (empty($address->postCode)) {
             $missingInfo[] = 'Current landlord address: postcode';
         }
     }
     //Finalize
     if (empty($missingInfo)) {
         $returnVal = null;
     } else {
         $returnVal = $missingInfo;
     }
     return $returnVal;
 }
Example #19
0
 public function saveData()
 {
     $session = new Zend_Session_Namespace('referencing_global');
     $data = $this->getValues();
     $referenceManager = new Manager_Referencing_Reference();
     $reference = $referenceManager->getReference($session->referenceId);
     //Derive the occupation chronology from the current flow item, so that we can locate
     //the relevant occupation to update.
     switch ($session->currentFlowItem) {
         case Model_Referencing_DataEntry_FlowItems::CURRENT_OCCUPATION:
             $chronology = Model_Referencing_OccupationChronology::CURRENT;
             $classification = Model_Referencing_OccupationImportance::FIRST;
             break;
         case Model_Referencing_DataEntry_FlowItems::SECOND_OCCUPATION:
             $chronology = Model_Referencing_OccupationChronology::CURRENT;
             $classification = Model_Referencing_OccupationImportance::SECOND;
             break;
         case Model_Referencing_DataEntry_FlowItems::FUTURE_OCCUPATION:
             $chronology = Model_Referencing_OccupationChronology::FUTURE;
             $classification = Model_Referencing_OccupationImportance::FIRST;
             break;
     }
     //Attept to locate the relevant occupation.
     $occupationManager = new Manager_Referencing_Occupation();
     $thisOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, $chronology, $classification);
     if (empty($thisOccupation)) {
         //The occupation to process does not exist, so create it first.
         $thisOccupation = $occupationManager->createNewOccupation($session->referenceId, $chronology, $classification);
         if (empty($reference->referenceSubject->occupations)) {
             $reference->referenceSubject->occupations = array();
         }
         $reference->referenceSubject->occupations[] = $thisOccupation;
     }
     //Now update $thisOccupation with the occupational details provided by the ReferenceSubject.
     if (empty($thisOccupation->refereeDetails)) {
         $refereeManager = new Manager_Referencing_OccupationReferee();
         $thisOccupation->refereeDetails = $refereeManager->createReferee($thisOccupation->id);
     }
     //Add general details.
     $thisOccupation->refereeDetails->organisationName = $data['company_name'];
     $thisOccupation->refereeDetails->position = $data['contact_position'];
     $thisOccupation->income = new Zend_Currency(array('value' => $data['income'], 'precision' => 0));
     //Add the referee name if required.
     if (empty($thisOccupation->refereeDetails->name)) {
         $nameManager = new Manager_Core_Name();
         $thisOccupation->refereeDetails->name = $nameManager->createName();
     }
     $nameArray = preg_split("/\\s/", $data['contact_name']);
     if (count($nameArray) >= 2) {
         $thisOccupation->refereeDetails->name->firstName = array_shift($nameArray);
         $thisOccupation->refereeDetails->name->lastName = array_pop($nameArray);
     } else {
         if (count($nameArray) == 1) {
             $thisOccupation->refereeDetails->name->firstName = array_shift($nameArray);
         }
     }
     //Capture and process the referee address.
     $postcodeManager = new Manager_Core_Postcode();
     $propertyAddress = $postcodeManager->getPropertyByID($data['property_address'], false);
     $addressLine1 = ($propertyAddress['organisation'] != '' ? "{$propertyAddress['organisation']}, " : '') . ($propertyAddress['houseNumber'] != '' ? "{$propertyAddress['houseNumber']} " : '') . ($propertyAddress['buildingName'] != '' ? "{$propertyAddress['buildingName']}, " : '') . $propertyAddress['address2'];
     $addressLine2 = $propertyAddress['address4'];
     $town = $propertyAddress['address5'];
     $postCode = $data['property_postcode'];
     if (empty($thisOccupation->refereeDetails->address)) {
         $addressManager = new Manager_Core_Address();
         $thisOccupation->refereeDetails->address = $addressManager->createAddress();
     }
     $thisOccupation->refereeDetails->address->addressLine1 = $addressLine1;
     $thisOccupation->refereeDetails->address->addressLine2 = $addressLine2;
     $thisOccupation->refereeDetails->address->town = $town;
     $thisOccupation->refereeDetails->address->postCode = $postCode;
     //Capture and process the referee contact details.
     if (empty($thisOccupation->refereeDetails->contactDetails)) {
         $contactDetailsManager = new Manager_Core_ContactDetails();
         $thisOccupation->refereeDetails->contactDetails = $contactDetailsManager->createContactDetails();
     }
     $thisOccupation->refereeDetails->contactDetails->telephone1 = $data['telephone_number'];
     $thisOccupation->refereeDetails->contactDetails->fax1 = $data['fax_number'];
     $thisOccupation->refereeDetails->contactDetails->email1 = $data['email'];
     if (!empty($data['tenancy_start_date'])) {
         $thisOccupation->startDate = new Zend_Date($data['tenancy_start_date'], Zend_Date::DATES);
     }
     if (!empty($data['is_permanent'])) {
         if ($data['is_permanent'] == 'Yes') {
             $thisOccupation->isPermanent = true;
         } else {
             $thisOccupation->isPermanent = false;
         }
     }
     //Now capture the optional details and insert into the occupation variables array.
     if (!empty($data['reference_number'])) {
         if (empty($thisOccupation->variables)) {
             $thisOccupation->variables = array();
         }
         $thisOccupation->variables[Model_Referencing_OccupationVariables::PAYROLL_NUMBER] = $data['reference_number'];
     }
     if (!empty($data['position'])) {
         if (empty($thisOccupation->variables)) {
             $thisOccupation->variables = array();
         }
         $thisOccupation->variables[Model_Referencing_OccupationVariables::POSITION] = $data['position'];
     }
     //Identify if a future occupation is applicable and required.
     if (!empty($data['will_change'])) {
         if ($data['will_change'] == 'Yes') {
             //If its going to change then we need to create a future employer record, if not already
             //done so.
             $futureOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST);
             if (empty($futureOccupation)) {
                 $createFutureOccupation = true;
             } else {
                 $createFutureOccupation = false;
             }
             if ($createFutureOccupation) {
                 $futureOccupation = $occupationManager->createNewOccupation($session->referenceId, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST);
                 $futureOccupation->type = Model_Referencing_OccupationTypes::EMPLOYMENT;
                 $reference->referenceSubject->occupations[] = $futureOccupation;
             }
         } else {
             //Delete any future employer records.
             $futureOccupation = $occupationManager->findSpecificOccupation($reference->referenceSubject->occupations, Model_Referencing_OccupationChronology::FUTURE, Model_Referencing_OccupationImportance::FIRST);
             if (!empty($futureOccupation)) {
                 $occupationManager->deleteOccupation($futureOccupation);
             }
         }
     }
     //And update...
     $referenceManager->updateReference($reference);
     return $thisOccupation;
 }