Example #1
0
 public function __construct($enquiryId = null)
 {
     if (is_null($enquiryId)) {
         throw new Zend_Exception("Enquiry identifier is null");
     } else {
         $muntManager = new Manager_ReferencingLegacy_Munt();
         $this->_reference = $muntManager->getReference($enquiryId);
     }
 }
Example #2
0
 /**
  * Inserts a new, empty Reference into the datasource and returns a corresponding object.
  *
  * This method will allocate unique internal and external Reference identifiers
  * to the new Reference.
  *
  * @return Model_Referencing_Reference
  * Holds the details of the newly inserted Reference.
  */
 public function createReference()
 {
     $muntManager = new Manager_ReferencingLegacy_Munt();
     $reference = $muntManager->createReference();
     //Minimal insertion
     $data = array('id' => $reference->internalId, 'external_id' => $reference->externalId);
     if (!$this->insert($data)) {
         // Failed insertion
         Application_Core_Logger::log("Can't create record in table {$this->_name}", 'error');
         $returnVal = null;
     } else {
         $returnVal = $reference;
     }
     return $returnVal;
 }
Example #3
0
 /**
  * Opens a PDF from local storage, populates it with agent details (if
  * needed) and outputs it to either browser or by e-mail.
  *
  * @param string $formName The name of the PDF form, or 'all' for all by e-mail.
  * @param mixed $asn Agent scheme number of agent whose details are to be inserted.
  * @param int $agentUserId Optional user ID - needed for e-mailing forms.
  * @param string $destination Optional output mechanism, if set should be 'browser' or not 'browser'.
  * @param mixed $refno Optional reference number, for a special case PDF that requires applicant data injection.
  */
 public function populateAndOuput($formName, $asn, $agentUserId = null, $destination = 'browser', $refno = null)
 {
     $attachmentList = array();
     switch ($formName) {
         // Forms that require agent details to be injected
         case 'Agent-Company':
         case 'Agent-Guarantor':
         case 'Agent-Individual':
         case 'Agent-Student-guarantor':
         case 'Agent-Unemployed-guarantor':
             // Instantiate agent manager and fetch agent details
             $agentManager = new Manager_Core_Agent();
             $agent = $agentManager->getAgent($asn);
             // Shove agent details through form
             $this->setForm($formName);
             $this->agentPopulate($agent);
             // For "Print Guarantor Form" from ref summary screen:
             if (!is_null($refno)) {
                 // Fetch reference by refno using the Referencing MUNT Manager class
                 $refMuntManager = new Manager_ReferencingLegacy_Munt();
                 $reference = $refMuntManager->getReference($refno);
                 // For safety, ensure reference belongs to this ASN before injecting applicant details
                 if ($reference->customer->customerId == $asn) {
                     $this->applicantPopulate($reference);
                 }
             }
             if ($destination == 'browser') {
                 $this->output('browser');
             } else {
                 $attachmentList[$formName] = $this->output('file');
             }
             break;
             // Forms that are a pass-through
         // Forms that are a pass-through
         case 'Tenant-Declaration':
         case 'Guarantor-Declaration':
             $this->setForm($formName);
             if ($destination == 'browser') {
                 $this->output('browser');
             } else {
                 $attachmentList[$formName] = $this->output('file');
             }
             break;
             // Send all forms - by e-mail only
         // Send all forms - by e-mail only
         case 'all':
             // Instantiate agent manager and fetch agent details
             $agentManager = new Manager_Core_Agent();
             $agent = $agentManager->getAgent($asn);
             // Generate those needing agent data merged in
             foreach (array('Agent-Company', 'Agent-Guarantor', 'Agent-Individual', 'Agent-Student-guarantor', 'Agent-Unemployed-guarantor') as $thisFormName) {
                 $this->setForm($thisFormName);
                 $this->agentPopulate($agent);
                 $attachmentList[$thisFormName] = $this->output('file');
             }
             // Generate straight throughs
             foreach (array('Tenant-Declaration', 'Guarantor-Declaration') as $thisFormName) {
                 $this->setForm($thisFormName);
                 $attachmentList[$thisFormName] = $this->output('file');
             }
             break;
     }
     // If there are attachments, this is/these are to be sent by e-mail
     if (count($attachmentList) > 0) {
         // Instantiate agent user manager to get name and e-mail address
         $agentUserManager = new Manager_Core_Agent_User();
         $agentUser = $agentUserManager->getUser($agentUserId);
         // Generate e-mail
         $mailer = new Application_Core_Mail();
         $mailer->setTo($agentUser->email->emailAddress, $agentUser->name);
         // TODO: Parameterise:
         $mailer->setFrom('*****@*****.**', 'HomeLet Referencing');
         $mailer->setSubject('HomeLet Referencing Application Form');
         $mailer->setBodyText('Please find your HomeLet referencing application forms attached.');
         foreach ($attachmentList as $name => $location) {
             $mailer->addAttachment($location, "{$name}.pdf");
         }
         $mailer->send();
         // Garbage collection
         $this->garbageCollect($attachmentList);
     }
 }
Example #4
0
 /**
  * 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())
 {
     // Check if all 3 pieces of info are supplied
     $asn = isset($formData['letting_agent_asn']) ? preg_replace('/[^\\d]/', '', $formData['letting_agent_asn']) : '';
     $irn = isset($formData['tenant_reference_number']) ? preg_replace('/[^\\d]/', '', $formData['tenant_reference_number']) : '';
     $dob = isset($formData['tenant_dob']) ? preg_replace('/[^\\d\\/]/', '', $formData['tenant_dob']) : '';
     // If the IRN is not actually an IRN, but an IRIS reference number (i.e. prefixed with HLT)
     if (preg_match('/^HLT\\d+$/', $formData['tenant_reference_number'])) {
         return self::IRIS_LOGIN;
     }
     if ($dob != '') {
         try {
             //Check for a valid date of birth. If this causes an exception, end
             //the process here rather than passing up to the overriden method,
             //otherwise the same exception will be thrown again.
             $isDobError = false;
             $dob = new Zend_Date($dob);
         } catch (Zend_Exception $e) {
             $isDobError = true;
         }
         if ($isDobError) {
             $this->getElement('tenant_dob')->addError('Please provide a valid date of birth.');
             // Validate other fields, to keep the error messages consistent
             unset($formData['tenant_dob']);
             $dummy = parent::isValidPartial($formData);
             return false;
         }
     }
     //Continue the validation.
     $displayErrorMessage1 = false;
     $displayErrorMessage2 = false;
     $displayErrorMessage3 = false;
     $displayErrorMessage4 = false;
     if ($asn != '' && $irn != '' && $dob != '') {
         // Check if a record can be found
         $tatManager = new Manager_Referencing_Tat($irn);
         if ($tatManager->isLoginValid($asn, $dob)) {
             // Check if user allowed to login
             if (!$tatManager->isTatApplicable()) {
                 // Can't log in. Check if this is because the TAT has expired.
                 if ($tatManager->isTatExpired()) {
                     $displayErrorMessage1 = true;
                 } else {
                     //If the reference is of type INSIGHT or XPRESS, then provide a specific error message.
                     $referenceManager = new Manager_ReferencingLegacy_Munt();
                     $reference = $referenceManager->getReference($irn);
                     $product = $reference->productSelection->product;
                     if (isset($product->variables[Model_Referencing_ProductVariables::CREDIT_REFERENCE])) {
                         $displayErrorMessage2 = true;
                     } else {
                         //Set the generic form-level error.
                         $displayErrorMessage3 = true;
                     }
                 }
             }
         } else {
             // Can't find a record, set a form-level error
             $displayErrorMessage3 = true;
         }
     } else {
         // One or more fields are empty (when filtered), set a form-level error
         $displayErrorMessage4 = true;
     }
     //Display the error message if appropriate.
     if ($displayErrorMessage1) {
         $this->addError('Unfortunately we only hold information on the Tenant Application Tracker for 30 days and we believe
                          that your application was completed over a month ago. If you have any questions about your tenancy
                          application please speak directly with your letting agent.');
     } else {
         if ($displayErrorMessage2) {
             $this->addError('Oops, we\'re unable to match the information you\'ve entered, please check your details and try again.');
         } else {
             if ($displayErrorMessage3) {
                 $this->addError('I\'m sorry we\'ve been unable to find your application with the details that you\'ve provided. Please check the details that you entered and try again.');
             } else {
                 if ($displayErrorMessage4) {
                     $this->addError('Please ensure you complete all 3 fields before selecting submit.');
                 }
             }
         }
     }
     // 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;
 }
 /**
  * Search in HRT.
  *
  * @param int $currentAgentSchemeNumber
  * @param SearchIndividualApplicationsCriteria $criteria
  * @param int $offset
  * @param int $limit
  * @return array Simple array of 'records' containing an array of ReferencingApplicationFindResult and
  *               'totalRecords' containing an integer of all possible records findable with the current criteria
  */
 private function searchInHrt($currentAgentSchemeNumber, SearchIndividualApplicationsCriteria $criteria, $offset, $limit)
 {
     if ($this->debugMode) {
         error_log('--- Search in HRT method invoked ---');
     }
     $records = array();
     $hrtReferenceManager = new \Manager_ReferencingLegacy_Munt();
     $hrtCriteria = array('refno' => $criteria->getReferenceNumber(), 'firstname' => $criteria->getApplicantFirstName(), 'lastname' => $criteria->getApplicantLastName(), 'address' => $criteria->getPropertyAddress(), 'town' => $criteria->getPropertyTown(), 'postcode' => $criteria->getPropertyPostcode(), 'state' => $criteria->getApplicationStatus(), 'type' => $criteria->getProductType());
     $hrtRows = $hrtReferenceManager->searchLegacyReferences($currentAgentSchemeNumber, $hrtCriteria, \Model_Referencing_SearchResult::STARTDATE_DESC, 0, $limit, $offset);
     foreach ($hrtRows->results as $hrtRow) {
         $status = self::APPLICATION_STATUS_INCOMPLETE;
         if ('Complete' == ucfirst(strtolower(trim($hrtRow['resulttx'])))) {
             $status = self::APPLICATION_STATUS_COMPLETE;
         }
         $model = new ReferencingApplicationFindResult();
         $model->setReferenceNumber($hrtRow['RefNo'])->setReferencingApplicationUuId($hrtRow['RefNo'])->setApplicantFirstName($hrtRow['firstname'])->setApplicantLastName($hrtRow['lastname'])->setStreet($hrtRow['address1'])->setCreatedAt($hrtRow['start_time'])->setStatusId($status)->setDataSource(self::DATA_SOURCE_HRT);
         $records[] = $model;
     }
     // Get total records by passing in a zero for both offset and limit
     $hrtRecordCount = $hrtReferenceManager->searchLegacyReferences($currentAgentSchemeNumber, $hrtCriteria, null, 0, 0, 0);
     $totalRecords = (int) $hrtRecordCount->totalNumberOfResults;
     return array('records' => $records, 'totalRecords' => $totalRecords);
 }
 /**
  * Writes the Reference object to the legacy datasources.
  *
  * @param Model_Referencing_Reference $reference
  * The reference to write to the Munt.
  *
  * @return void
  */
 protected function _pushToMunt(Model_Referencing_Reference $reference)
 {
     // Check the legacy customer id is set
     if ($reference->customer->legacyCustomerId == null && $reference->customer->customerType == Model_Referencing_CustomerTypes::LANDLORD) {
         // Create a new legacy customer for the private landlord
         $customerManager = new Manager_Core_Customer();
         $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $reference->customer->customerId);
         $legacyCustomer = $customerManager->createNewCustomer($customer->getEmailAddress(), Model_Core_Customer::CUSTOMER, true);
         $legacyCustomer->setFirstName($customer->getFirstName());
         $legacyCustomer->setLastName($customer->getLastName());
         $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE1, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1));
         $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE2, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE2));
         $legacyCustomer->setAddressLine(Model_Core_Customer::ADDRESSLINE3, $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE3));
         $legacyCustomer->setTelephone(Model_Core_Customer::TELEPHONE1, $customer->getTelephone(Model_Core_Customer::TELEPHONE1));
         $legacyCustomer->setTelephone(Model_Core_Customer::TELEPHONE2, $customer->getTelephone(Model_Core_Customer::TELEPHONE2));
         $legacyCustomer->setPassword($customer->getPassword());
         $customerManager->updateCustomer($legacyCustomer);
         // Drop the legacy customer refno into the reference customer map object
         $reference->customer->legacyCustomerId = $legacyCustomer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
     }
     $muntManager = new Manager_ReferencingLegacy_Munt();
     $muntManager->updateReference($reference);
 }
 public function resendEmailAction()
 {
     // Pop-up results need pop-up layout
     $this->_helper->layout->setLayout('popup');
     // Get refno from GET var, look up applicant details
     $refno = isset($_GET['refno']) ? $_GET['refno'] : '';
     $refMuntManager = new Manager_ReferencingLegacy_Munt();
     $reference = $refMuntManager->getReference($refno);
     $applicantTypes = array_flip(Model_Referencing_ReferenceSubjectTypes::iterableKeys());
     $applicantType = ucwords(strtolower($applicantTypes[$reference->referenceSubject->type]));
     $applicantType = $applicantType == 'Tenant' ? 'Applicant' : $applicantType;
     // Intantiate form definition
     $pageForm = new Connect_Form_ReferencingResendEmail();
     // Validate form if POSTed
     $request = $this->getRequest();
     if ($request->isPost() && !is_null($request->getParam('fromForm')) && $request->getParam('fromForm') == '1') {
         $postData = $request->getPost();
         if ($pageForm->isValid($postData)) {
             // Instantiate security manager for generating MAC
             $securityManager = new Application_Core_Security($this->_params->connect->ref->security->securityString->user);
             $macToken = $securityManager->generate(array($this->_agentSchemeNumber, $this->_agentId));
             // cURL original page in old ref system, bleurgh
             $baseReferencingUrl = $this->_params->connect->baseUrl->referencing;
             $to = $pageForm->getElement('email')->getValue();
             $url = "{$baseReferencingUrl}frontEnd/emailtenantlink.php?refno={$refno}&tempemail={$to}&brand=default&agentToken={$macToken}";
             // TODO: Use Zend_Http_Client and Zend_Http_Client_Adapter_Curl
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($ch, CURLOPT_AUTOREFERER, true);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
             curl_setopt($ch, CURLOPT_AUTOREFERER, true);
             curl_setopt($ch, CURLOPT_TIMEOUT, 60);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_exec($ch);
             $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             if ($status != 200) {
                 // Show user there was a problem
                 $this->view->error = "({$status}): " . curl_error($ch);
                 $this->_helper->viewRenderer('resend-email-failed');
             } else {
                 curl_close($ch);
                 // TODO: Check for error being returned
                 if (false) {
                     // Show user there was a fatal problem
                     $this->_helper->viewRenderer('resend-email-failed');
                 } else {
                     //Update e-mail address.
                     if ($pageForm->getElement('replace')->getValue() == '1') {
                         //Get the legacy Tenant ID, then use that to identify the
                         //Tenant record to update in the legacy Tenant table.
                         $legacyEnquiryDatasource = new Datasource_ReferencingLegacy_Enquiry();
                         $legacyTenantId = $legacyEnquiryDatasource->getTenantId($reference->externalId);
                         $rsds = new Datasource_ReferencingLegacy_ReferenceSubject();
                         $rsds->updateField($legacyTenantId, Datasource_ReferencingLegacy_ReferenceSubject::FIELD_EMAIL, $to);
                     }
                     // Show user all was successful
                     $this->_helper->viewRenderer('resend-email-confirmation');
                 }
             }
         } else {
             // Show errors back to user
             $allErrors = $pageForm->getMessages();
             foreach ($allErrors as $field => $errors) {
                 foreach ($errors as $errorType => $errorMessage) {
                     $this->_helper->flashmessages->addMessage($errorMessage);
                 }
             }
         }
     } else {
         // Pre-fill in refno, e-mail address and replacement checkbox
         $pageForm->getElement('email')->setValue($reference->referenceSubject->contactDetails->email1);
         $pageForm->getElement('replace')->setValue(1);
     }
     $this->view->refno = $refno;
     $this->view->applicantName = "{$reference->referenceSubject->name->title} {$reference->referenceSubject->name->firstName} {$reference->referenceSubject->name->lastName}";
     $this->view->applicantType = $applicantType;
     $this->view->form = $pageForm;
     $this->view->flashMessages = $this->_helper->flashmessages->getCurrentMessages();
 }
 /**
  * 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);
 }