/**
  * Sends an initial notification to the reference subject (tenant or guarantor).
  * 
  * The initital notification sent to the reference subject advises them that their
  * reference is on the system and they can track it.
  *
  * @param mixed $enquiryId
  * The unique Enquiry identifier (internal or external). May be integer or string.
  *
  * @return boolean
  * Returns true on succesful sending of the notification, false otherwise.
  */
 public function sendTatInvitation()
 {
     //Get the general parameters.
     $params = Zend_Registry::get('params');
     $metaData = array();
     $emailFromName = $params->tat->email->fromname;
     $emailFrom = $params->tat->email->from;
     $emailSubject = $params->tat->email->subject;
     $metaData['tatUrl'] = $params->url->tenantsTrackApplicationFromEmail;
     $metaData['homeLetUrl'] = $params->homelet->domain . '/';
     // Ensure enquiry ID given out is an internal one
     $metaData['tenantIrn'] = $this->_reference->internalId;
     //Set the destination email address.
     $referenceSubjectContact = $this->_reference->referenceSubject->contactDetails;
     if (!empty($referenceSubjectContact->email1)) {
         $emailTo = $referenceSubjectContact->email1;
     } else {
         if (!empty($referenceSubjectContact->email2)) {
             $emailTo = $referenceSubjectContact->email2;
         } else {
             return false;
         }
     }
     //Set the reference subject name into the email body.
     $referenceSubjectName = $this->_reference->referenceSubject->name;
     $referenceSubjectNameString = $referenceSubjectName->firstName . ' ' . $referenceSubjectName->lastName;
     $metaData['tenantName'] = $referenceSubjectNameString;
     //Set the property address into the email body.
     $propertyAddress = $this->_reference->propertyLease->address;
     $propertyAddressString = '';
     $propertyAddressString .= $propertyAddress->addressLine1 != '' ? "{$propertyAddress->addressLine1}\n" : '';
     $propertyAddressString .= $propertyAddress->addressLine2 != '' ? "{$propertyAddress->addressLine2}\n" : '';
     $propertyAddressString .= $propertyAddress->town != '' ? "{$propertyAddress->town}\n" : '';
     $propertyAddressString .= $propertyAddress->postCode != '' ? "{$propertyAddress->postCode}\n" : '';
     $metaData['propertyAddress'] = nl2br(substr($propertyAddressString, 0, -1));
     $metaData['propertyAddressTxt'] = $propertyAddressString;
     //Put the letting agent name and ASN into the email body.
     if ($this->_reference->customer->customerType == Model_Referencing_CustomerTypes::LANDLORD) {
         $agentId = $params->homelet->defaultAgent;
     } else {
         $agentId = $this->_reference->customer->customerId;
     }
     $agentDatasource = new Datasource_Core_Agents();
     $lettingAgent = $agentDatasource->getAgent($agentId);
     $lettingAgentNameString = $lettingAgent->name;
     $metaData['lettingAgentName'] = $lettingAgentNameString;
     $metaData['lettingAgentAsn'] = $lettingAgent->agentSchemeNumber;
     //Prepare the email.
     $emailer = new Application_Core_Mail();
     $emailer->setTo($emailTo, $emailFromName);
     $emailer->setFrom($emailFrom, $emailFromName);
     $emailer->setSubject($emailSubject);
     $emailer->applyTemplate('tenants_tatInvitation', $metaData, false, '/email-branding/homelet/generic-with-signature-footer.phtml');
     $emailer->applyTextTemplate('tenants_tatInvitationTxt', $metaData, false, '/email-branding/homelet/generic-with-signature-footer-txt.phtml');
     //Send, update and return
     $success = $emailer->send();
     if ($success) {
         //Update the notification log.
         $tatInvitationDatasource = new Datasource_Referencing_TatInvitation();
         $tatInvitationDatasource->insertInvitation($this->_reference->externalId);
         $returnVal = true;
     } else {
         $returnVal = false;
     }
     return $returnVal;
 }
Exemple #2
0
 /**
  * Returns a TAT object encapsulating details of the Enquiry.
  *
  * @param void
  * The unique Enquiry identifier (internal or external). May be integer or string.
  *
  * @return mixed
  * Returns a Model_Referencing_Tat object holds details of the reference,
  * or null if not found.
  */
 public function getTat()
 {
     $tat = new Model_Referencing_Tat();
     //Set the isInvitationSent attribute.
     $tatDatasource = new Datasource_Referencing_TatInvitation();
     $tat->isInvitationSent = $tatDatasource->getIsTatInvitationSent($this->_reference->externalId);
     //Set the referenceSubject attribute.
     $referenceSubject = $this->_reference->referenceSubject;
     $tat->referenceSubject = $referenceSubject;
     //Set the propertyLease attribute.
     $tat->propertyLease = $this->_reference->propertyLease;
     //Arrive at the Enquiry state by a cascade: Start by assuming the Enquiry state is complete.
     $tat->enquiryStatus = Model_Referencing_TatStates::REFERENCE_COMPLETE;
     //Next identify if the state should be changed to 'In Progress' based on the
     //current Enquiry conclusion
     switch ($this->_reference->status->state) {
         case Model_Referencing_ReferenceStates::INPROGRESS:
         case Model_Referencing_ReferenceStates::INCOMPLETE:
             $tat->enquiryStatus = Model_Referencing_TatStates::REFERENCE_INPROGRESS;
             break;
     }
     $progressItem = Manager_Referencing_Progress::findSpecificProgressItem($this->_reference->progress, Model_Referencing_ProgressItemVariables::FINISHED);
     //Finally, override the conclusion if the progress result is not complete.
     if ($progressItem->itemState != Model_Referencing_ProgressItemStates::COMPLETE) {
         //The progress object also has to indicate complete - this will allow us to detect
         //references that have been reopened.
         $tat->enquiryStatus = Model_Referencing_TatStates::REFERENCE_INPROGRESS;
     }
     //Set the occupation attributes.
     foreach ($referenceSubject->occupations as $occupation) {
         //Set the occupation reference status.
         if (empty($occupation->referencingDetails)) {
             $isReferencedString = Model_Referencing_TatStates::REFERENCE_ITEM_NOTAPPLICABLE;
         } else {
             if ($occupation->isComplete) {
                 $isReferencedString = Model_Referencing_TatStates::REFERENCE_ITEM_COMPLETE;
             } else {
                 $isReferencedString = Model_Referencing_TatStates::REFERENCE_ITEM_INPROGRESS;
             }
         }
         //Now identify which occupation we are dealing with.
         if ($occupation->chronology == Model_Referencing_OccupationChronology::FUTURE) {
             $tat->futureOccupationReferenceStatus = $isReferencedString;
         } else {
             if ($occupation->chronology == Model_Referencing_OccupationChronology::CURRENT) {
                 if ($occupation->importance == Model_Referencing_OccupationImportance::FIRST) {
                     $tat->currentOccupationReferenceStatus = $isReferencedString;
                 } else {
                     $tat->secondOccupationReferenceStatus = $isReferencedString;
                 }
             }
         }
     }
     //Some of the occupation attributes may not be applicable. Set them to N/A as appropriate.
     if (empty($tat->currentOccupationReferenceStatus)) {
         $tat->currentOccupationReferenceStatus = Model_Referencing_TatStates::REFERENCE_ITEM_NOTAPPLICABLE;
     }
     if (empty($tat->secondOccupationReferenceStatus)) {
         $tat->secondOccupationReferenceStatus = Model_Referencing_TatStates::REFERENCE_ITEM_NOTAPPLICABLE;
     }
     if (empty($tat->futureOccupationReferenceStatus)) {
         $tat->futureOccupationReferenceStatus = Model_Referencing_TatStates::REFERENCE_ITEM_NOTAPPLICABLE;
     }
     //Set the landlord attribute.
     $residenceManager = new Manager_Referencing_Residence();
     $currentResidence = $residenceManager->findSpecificResidence($this->_reference->referenceSubject->residences, Model_Referencing_ResidenceChronology::CURRENT);
     if ($currentResidence->status != Model_Referencing_ResidenceStatus::TENANT) {
         $tat->currentResidentialReferenceStatus = Model_Referencing_TatStates::REFERENCE_ITEM_NOTAPPLICABLE;
     } else {
         if (empty($currentResidence->referencingDetails)) {
             $tat->currentResidentialReferenceStatus = Model_Referencing_TatStates::REFERENCE_ITEM_INPROGRESS;
         } else {
             if ($currentResidence->referencingDetails->submissionType == null) {
                 $tat->currentResidentialReferenceStatus = Model_Referencing_TatStates::REFERENCE_ITEM_INPROGRESS;
             } else {
                 $tat->currentResidentialReferenceStatus = Model_Referencing_TatStates::REFERENCE_ITEM_COMPLETE;
             }
         }
     }
     //Set the missing information attribute.
     /*
             $productName = $enquiry->productSelection->product->name;
             $flowManager = Manager_Referencing_DataEntry_Flow_FlowFactory::createFlowManager($productName);
     		$missingInformationManager = new Manager_Referencing_DataEntry_MissingInformation_Despatcher();
     		$missingInfoList = array();
     		do {
     
     	$missingInfoSubList = $missingInformationManager->getMissingInformation($enquiry->externalId, $flowManager->currentFlowItem);
     	if(!empty($missingInfoSubList)) {
     
     		foreach($missingInfoSubList as $subListItem) {
     
     			$missingInfoList[] = $subListItem;
     		}
     	}
     }
     while($flowManager->moveToNext($enquiryId));
     $tat->missingInformation = $missingInfoList;
     */
     //Use the legacy missing information manager until the new one is fully operational.
     $missingInformationManager = new Manager_Referencing_DataEntry_MissingInformation_Legacy();
     $tat->missingInformation = $missingInformationManager->getMissingInformation($this->_reference);
     //Set the tat notifications.
     $tatNotifications = new Datasource_Referencing_TatNotification();
     $tat->tatNotifications = $tatNotifications->getByEnquiry($this->_reference->externalId);
     return $tat;
 }