/**
  * Retrieves the specified reference subject.
  *
  * @param string $referenceSubjectId
  * The unique reference subject identifier.
  *
  * @param string $enquiryId
  * The unique external Enquiry identifier.
  *
  * @return mixed
  * The reference subject details encapsulated in a Model_Referencing_ReferenceSubject
  * object, or null if the reference subject cannot be found.
  */
 public function getReferenceSubject($referenceSubjectId, $enquiryId)
 {
     if (empty($referenceSubjectId)) {
         return null;
     }
     $select = $this->select();
     $select->where('ID = ?', $referenceSubjectId);
     $referenceSubjectRow = $this->fetchRow($select);
     if (empty($referenceSubjectRow)) {
         $returnVal = null;
     } else {
         $referenceSubject = new Model_Referencing_ReferenceSubject();
         $referenceSubject->referenceId = $referenceSubjectRow->ID;
         //Load up the bank account details.
         $bankAccount = new Model_Referencing_BankAccount();
         $bankAccount->referenceId = $referenceSubjectRow->ID;
         $bankAccount->accountNumber = $referenceSubjectRow->accountNo;
         $bankAccount->sortCode = $referenceSubjectRow->sortcodeNo;
         switch ($referenceSubjectRow->bankValidationCheckStatus) {
             case 'N/A':
             case 'No':
             case '':
                 $bankAccount->isValidated = false;
                 break;
             default:
                 $bankAccount->isValidated = true;
         }
         $referenceSubject->bankAccount = $bankAccount;
         //Load the name details.
         $name = new Model_Core_Name();
         $name->title = $referenceSubjectRow->title;
         $name->firstName = $referenceSubjectRow->firstname;
         $name->middleName = $referenceSubjectRow->middlename;
         $name->lastName = $referenceSubjectRow->lastname;
         $name->maidenName = $referenceSubjectRow->maidenname;
         $referenceSubject->name = $name;
         $contactDetails = new Model_Core_ContactDetails();
         $contactDetails->telephone1 = $referenceSubjectRow->tel;
         $contactDetails->telephone2 = $referenceSubjectRow->mobile;
         $contactDetails->email1 = $referenceSubjectRow->email;
         $referenceSubject->contactDetails = $contactDetails;
         if ($referenceSubjectRow->dob != '0000-00-00') {
             $referenceSubject->dob = new Zend_Date($referenceSubjectRow->dob, Zend_Date::ISO_8601);
         }
         $enquiryDatasource = new Datasource_ReferencingLegacy_Enquiry();
         if ($enquiryDatasource->getLegacyReferenceSubjectType($enquiryId) == Model_Referencing_ReferenceSubjectTypes::TENANT) {
             $referenceSubject->type = Model_Referencing_ReferenceSubjectTypes::TENANT;
         } else {
             $referenceSubject->type = Model_Referencing_ReferenceSubjectTypes::GUARANTOR;
         }
         $residenceDatasource = new Datasource_ReferencingLegacy_Residences();
         $referenceSubject->residences = $residenceDatasource->getByEnquiry($enquiryId);
         $occupationDatasource = new Datasource_ReferencingLegacy_Occupations();
         $referenceSubject->occupations = $occupationDatasource->getAllByEnquiry($enquiryId);
         if (!empty($referenceSubjectRow->hasCCJs)) {
             if ($referenceSubjectRow->hasCCJs == 'Yes') {
                 $referenceSubject->hasAdverseCredit = true;
             } else {
                 $referenceSubject->hasAdverseCredit = false;
             }
         }
         if ($referenceSubjectRow->RentShare >= 0) {
             $referenceSubject->shareOfRent = new Zend_Currency(array('value' => $referenceSubjectRow->RentShare, 'precision' => 0));
         }
         $returnVal = $referenceSubject;
     }
     return $returnVal;
 }
Esempio n. 2
0
 /**
  * Copies the referencing data from the new datasources to the old.
  *
  * Allows newly entered references visibility on the HRT.
  *
  * @param Model_Referencing_Reference $reference
  * The Reference to muntify.
  *
  * @return void
  */
 public function updateReference($reference)
 {
     if (!empty($reference->propertyLease->prospectiveLandlord)) {
         // The Enquiry.newllrefno is the prospective landord details stored in
         // the landlordref table.
         $name = $reference->propertyLease->prospectiveLandlord->name;
         $address = $reference->propertyLease->prospectiveLandlord->address;
         $contactDetails = $reference->propertyLease->prospectiveLandlord->contactDetails;
         $landlordRefDatasource = new Datasource_ReferencingLegacy_LandlordRef();
         $muntingEnquiryFields['newllrefno'] = $landlordRefDatasource->insertLandlordRef($name, $address, $contactDetails);
     }
     // The Enquiry.lrefrefno is the current landlord details.
     $muntingEnquiryFields['lrefrefno'] = '';
     if (!empty($reference->referenceSubject->residences)) {
         foreach ($reference->referenceSubject->residences as $residence) {
             if ($residence->chronology == Model_Referencing_ResidenceChronology::CURRENT) {
                 if ($residence->status == Model_Referencing_ResidenceStatus::TENANT) {
                     //If product is a full reference, then record the landlord reference details
                     if ($reference->productSelection->product->variables[Model_Referencing_ProductVariables::FULL_REFERENCE] == 1) {
                         $name = $residence->refereeDetails->name;
                         $address = $residence->refereeDetails->address;
                         $contactDetails = $residence->refereeDetails->contactDetails;
                         $muntingEnquiryFields['lrefrefno'] = $landlordRefDatasource->insertLandlordRef($name, $address, $contactDetails);
                     }
                 }
                 break;
             }
         }
     }
     //The Enquiry.proprefno holds the property lease details.
     $propertyLeaseDatasource = new Datasource_ReferencingLegacy_PropertyLease();
     $muntingEnquiryFields['proprefno'] = $propertyLeaseDatasource->insertPropertyLease($reference->propertyLease);
     //The Enquiry.TenantID holds the ReferenceSubject details.
     $referenceSubjectDatasource = new Datasource_ReferencingLegacy_ReferenceSubject();
     $muntingEnquiryFields['TenantID'] = $referenceSubjectDatasource->insertReferenceSubject($reference->referenceSubject);
     //The Enquiry.ta[1-3]refno hold indexes to the tenant_address table, which holds up to
     //three of the reference subject addresses.
     $currentResidence = 0;
     $firstPreviousResidence = 0;
     $secondPreviousResidence = 0;
     foreach ($reference->referenceSubject->residences as $residence) {
         switch ($residence->chronology) {
             case Model_Referencing_ResidenceChronology::CURRENT:
                 $currentResidence = $residence;
                 break;
             case Model_Referencing_ResidenceChronology::FIRST_PREVIOUS:
                 $firstPreviousResidence = $residence;
                 break;
             case Model_Referencing_ResidenceChronology::SECOND_PREVIOUS:
                 $secondPreviousResidence = $residence;
                 break;
         }
     }
     //Initial settings for the ta[1-3]refnos
     $muntingEnquiryFields['ta1refno'] = 0;
     $muntingEnquiryFields['ta2refno'] = 0;
     $muntingEnquiryFields['ta3refno'] = 0;
     //Cycle through the residences and save each.
     $residenceDatasource = new Datasource_ReferencingLegacy_Residences();
     for ($i = 0; $i < count($reference->referenceSubject->residences); $i++) {
         if (count($reference->referenceSubject->residences) == $i + 1) {
             $isLast = true;
         } else {
             $isLast = false;
         }
         switch ($i) {
             case 0:
                 $muntingEnquiryFields['ta1refno'] = $residenceDatasource->insertResidence($currentResidence, $isLast);
                 break;
             case 1:
                 $muntingEnquiryFields['ta2refno'] = $residenceDatasource->insertResidence($firstPreviousResidence, $isLast);
                 break;
             case 2:
                 $muntingEnquiryFields['ta3refno'] = $residenceDatasource->insertResidence($secondPreviousResidence, $isLast);
                 break;
         }
     }
     //If the first residence is overseas, then ensure its ID is stored the Enquiry.foreignaddress
     //field.
     $muntingEnquiryFields['foreignaddress'] = 0;
     if ($currentResidence->address->isOverseasAddress) {
         $muntingEnquiryFields['foreignaddress'] = $muntingEnquiryFields['ta1refno'];
         $muntingEnquiryFields['ta1refno'] = 0;
     }
     //Update the Enquiry record.
     $this->_pushToEnquiryMunt($reference, $muntingEnquiryFields);
     //Insert the Occupation records
     $this->_pushToEmploymentMunt($reference);
     //Update the progress record
     $progressDatasource = new Datasource_ReferencingLegacy_Progress();
     $progressDatasource->updateProgress($reference);
 }