Exemplo n.º 1
0
 /**
  * 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;
 }