/** * Retrieves the specified Reference. * * @param mixed $referenceId * The unique Reference identifier. May be the IRN (internal refno) or the ERN (external * refno). * * @return mixed * The Reference details, encapsulated in a Model_Referencing_Reference object, * or null if the Reference cannot be found. */ public function getEnquiry($referenceId) { $enquiryRow = $this->_getEnquiryRow($referenceId); if (empty($enquiryRow)) { Application_Core_Logger::log(get_class() . '::' . __FUNCTION__ . ':Unable to find Enquiry.'); $returnVal = null; } else { //Populate the details into a Customer object. $reference = new Model_Referencing_Reference(); $reference->internalId = $enquiryRow->ID; $reference->externalId = $enquiryRow->RefNo; $reference->declarationVersion = $enquiryRow->declaration_version; $productDatasource = new Datasource_ReferencingLegacy_Product(); $product = $productDatasource->getProductByID($enquiryRow->ProductID); if (!empty($product)) { $reference->productSelection = new Model_Referencing_ProductSelection(); $reference->productSelection->referenceId = $enquiryRow->ID; $reference->productSelection->product = $product; switch ($enquiryRow->PolicyLength) { case 0: $reference->productSelection->duration = 0; break; case 6: $reference->productSelection->duration = 6; break; case 12: $reference->productSelection->duration = 12; break; default: $reference->productSelection->duration = 0; } } $progressDatasource = new Datasource_ReferencingLegacy_Progress(); $reference->progress = $progressDatasource->getByEnquiry($enquiryRow->RefNo); $propertyLeaseDatasource = new Datasource_ReferencingLegacy_PropertyLease(); $reference->propertyLease = $propertyLeaseDatasource->getPropertyLease($enquiryRow->proprefno, $enquiryRow->RefNo); $referenceSubjectDatasource = new Datasource_ReferencingLegacy_ReferenceSubject(); $reference->referenceSubject = $referenceSubjectDatasource->getReferenceSubject($enquiryRow->TenantID, $enquiryRow->RefNo); //Build the reference status. $referenceStatus = new Model_Referencing_ReferenceStatus(); $referenceStatus->referenceId = $enquiryRow->ID; if ($enquiryRow->nochange == 'cancelled') { $referenceStatus->state = Model_Referencing_ReferenceStates::CANCELLED; } else { $progressManager = new Manager_Referencing_Progress(); $progressItem = $progressManager->findSpecificProgressItem($reference->progress, Model_Referencing_ProgressItemVariables::FINAL_REPORT_BUILT); if ($progressItem == null || $progressItem->itemState == Model_Referencing_ProgressItemStates::INCOMPLETE) { $referenceStatus->state = Model_Referencing_ReferenceStates::INPROGRESS; } else { if (strcasecmp("Incomplete - Awaiting further information", $enquiryRow->conclusion) == 0) { $referenceStatus->state = Model_Referencing_ReferenceStates::INCOMPLETE; $referenceStatus->reasonForState = Model_Referencing_ReferenceStateReasons::AWAITING_FURTHER_INFORMATION; } else { if (strcasecmp("Incomplete - Awaiting Completion of Tenant", $enquiryRow->conclusion) == 0) { $referenceStatus->state = Model_Referencing_ReferenceStates::INCOMPLETE; $referenceStatus->reasonForState = Model_Referencing_ReferenceStateReasons::AWAITING_TENANT_COMPLETION; } else { $referenceStatus->state = Model_Referencing_ReferenceStates::COMPLETE; } } } } $reference->status = $referenceStatus; //Build the reference decision if ($enquiryRow->conclusion == '' || preg_match("/incomplete/i", $enquiryRow->conclusion)) { $reference->decision = null; } else { $decision = new Model_Referencing_Decision(); $decision->referenceId = $enquiryRow->ID; if (preg_match("/not acceptable/i", $enquiryRow->conclusion)) { $decision->decision = Model_Referencing_Decisions::NOT_ACCEPTABLE; $decision->decisionReasons = ''; //TO DO HERE } else { $decision->decision = Model_Referencing_Decisions::ACCEPTABLE; //Add caveats, if applicable $caveats = array(); if (preg_match("/guarantor/i", $enquiryRow->conclusion)) { $decisionCaveat = new Model_Referencing_DecisionCaveat(); $decisionCaveat->caveat = Model_Referencing_DecisionCaveats::WITH_GUARANTOR; //Identify the caveat reasons. $decisionCaveat->caveatReason = null; $caveats[] = $decisionCaveat; } if (preg_match("/condition/i", $enquiryRow->conclusion)) { $decisionCaveat = new Model_Referencing_DecisionCaveat(); $decisionCaveat->caveat = Model_Referencing_DecisionCaveats::WITH_CONDITION; //Identify the caveat reasons. $decisionCaveat->caveatReason = null; $caveats[] = $decisionCaveat; } if (!empty($caveats)) { //Attach the array of caveat(s) to the Decision object. $decision->caveats = $caveats; } } //Attach the Decision object to the Reference object. $reference->decision = $decision; } /* $reference->termsAgreedBy = $enquiryRow->termsagreedby; */ if ($enquiryRow->termsagreedby == 'Tenant') { $reference->completionMethod = Model_Referencing_ReferenceCompletionMethods::TWO_STEP; } else { $reference->completionMethod = Model_Referencing_ReferenceCompletionMethods::ONE_STEP; } //Set the customer details. If the agent is HomeLet Direct, then the customer is a PLL. $agentDatasource = new Datasource_Core_Agents(); $lettingAgent = $agentDatasource->getAgent($enquiryRow->AgentID); $params = Zend_Registry::get('params'); if ($lettingAgent->agentSchemeNumber != $params->homelet->defaultAgent) { $reference->customer = new Model_Referencing_CustomerMap(); $reference->customer->customerType = Model_Referencing_CustomerTypes::AGENT; $reference->customer->customerId = $lettingAgent->agentSchemeNumber; $reference->customer->legacyCustomerId = null; } else { $reference->customer = new Model_Referencing_CustomerMap(); $reference->customer->customerType = Model_Referencing_CustomerTypes::LANDLORD; if ($enquiryRow->landrefno != 0) { $reference->customer->legacyCustomerId = $enquiryRow->landrefno; } } $returnVal = $reference; } return $returnVal; }
/** * 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); }