/** * @todo Remove the hardcoded UW question numbers from this method. */ protected function _processUnderwriting($pageForm) { $returnVal = true; //First, store the underwriting answers. $declaration1 = $pageForm->subform_importantinformation->getElement('declaration1')->getValue(); $declaration2 = $pageForm->subform_importantinformation->getElement('declaration2')->getValue(); $declaration3 = $pageForm->subform_importantinformation->getElement('declaration3')->getValue(); $declaration4 = $pageForm->subform_importantinformation->getElement('declaration4')->getValue(); $underwritingAnswersArray = array(); $underwritingAnswersArray[0] = new Model_Insurance_Answer(); $underwritingAnswersArray[0]->setPolicyNumber($this->_policyNumber); $underwritingAnswersArray[0]->setQuestionNumber(49); $underwritingAnswersArray[0]->setAnswer($declaration1); $underwritingAnswersArray[0]->setDateAnswered(Zend_Date::now()); $underwritingAnswersArray[1] = new Model_Insurance_Answer(); $underwritingAnswersArray[1]->setPolicyNumber($this->_policyNumber); $underwritingAnswersArray[1]->setQuestionNumber(50); $underwritingAnswersArray[1]->setAnswer($declaration2); $underwritingAnswersArray[1]->setDateAnswered(Zend_Date::now()); $underwritingAnswersArray[2] = new Model_Insurance_Answer(); $underwritingAnswersArray[2]->setPolicyNumber($this->_policyNumber); $underwritingAnswersArray[2]->setQuestionNumber(51); $underwritingAnswersArray[2]->setAnswer($declaration3); $underwritingAnswersArray[2]->setDateAnswered(Zend_Date::now()); $underwritingAnswersArray[3] = new Model_Insurance_Answer(); $underwritingAnswersArray[3]->setPolicyNumber($this->_policyNumber); $underwritingAnswersArray[3]->setQuestionNumber(52); $underwritingAnswersArray[3]->setAnswer($declaration4); $underwritingAnswersArray[3]->setDateAnswered(Zend_Date::now()); $answersManager = new Manager_Insurance_Answers(); for ($i = 0; $i < count($underwritingAnswersArray); $i++) { if (!$answersManager->getIsAnswerAlreadyStored($underwritingAnswersArray[$i])) { $answersManager->insertUnderwritingAnswer($underwritingAnswersArray[$i]); } } //Next apply any necessary endorsements. $endorsementsManager = new Manager_Insurance_TenantsContentsPlus_Endorsement(); $endorsements = $endorsementsManager->getEndorsementsRequired($this->_policyNumber); if (!empty($endorsements)) { foreach ($endorsements as $currentEndorsement) { if (!$endorsementsManager->getIsEndorsementAlreadyApplied($currentEndorsement)) { $endorsementsManager->insertEndorsement($currentEndorsement); } } } //Next store any extra information provided by the user. $additionalInfoProvided = array(); $infoSubmitted = $pageForm->subform_importantinformation->getElement('declaration1_details')->getValue(); if (!empty($infoSubmitted)) { $additionalInfoProvided[] = $infoSubmitted; } $infoSubmitted = $pageForm->subform_importantinformation->getElement('declaration3_details')->getValue(); if (!empty($infoSubmitted)) { $additionalInfoProvided[] = $infoSubmitted; } $infoSubmitted = $pageForm->subform_importantinformation->getElement('declaration4_details')->getValue(); if (!empty($infoSubmitted)) { $additionalInfoProvided[] = $infoSubmitted; } if (!empty($additionalInfoProvided)) { //Compile the extra information, if any, into a single string. $compiledInformation = ''; foreach ($additionalInfoProvided as $currentInformation) { if (empty($compiledInformation)) { $compiledInformation = $currentInformation; } else { $compiledInformation .= " {$currentInformation}"; } } $additionalInformationManager = new Manager_Insurance_AdditionalInformation(); if (!$additionalInformationManager->getIsAdditionalInformationAlreadyStored($this->_policyNumber)) { $additionalInformation = new Model_Insurance_AdditionalInformation(); $additionalInformation->setPolicyNumber($this->_policyNumber); $additionalInformation->setAdditionalInformation($compiledInformation); $additionalInformationManager->insertAdditionalInformation($additionalInformation); } } //Update the quote object so that the underwritingQuestionSetID is appropriately set. $quoteManager = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber); $quoteManager->setUnderwritingQuestionSetID(2); //Previous claims are managed on the fly. //Check if a referral is required. $referralsManager = new Manager_Insurance_TenantsContentsPlus_Referral(); if ($referralsManager->getRequiresReferral($this->_policyNumber)) { //Display the referred screen. $returnVal = false; //Update the quote/policy notes. $notesManager = new Manager_Core_Notes(); $notesManager->save($this->_policyNumber, Model_Core_NoteLabels::REFERRED_BY_CUSTOMER); } return $returnVal; }
public function step4Action() { $pageForm = new LandlordsInsuranceQuote_Form_Step4(); // Tell page to use AJAX validation as we go $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = 4;'); // Check to make sure the user has actually added a product - if they haven't stop them going forward $session = new Zend_Session_Namespace('landlords_insurance_quote'); $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID); if ($quoteManager->productCount() == 0 && !isset($_POST['back'])) { $this->view->stepNum = "no-product"; // AJD - Not happy about this, but it's the way HLF was built. $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID); $policyNumber = $quoteManager->getLegacyID(); $this->view->quoteID = $policyNumber; $this->render('no-cover-selected'); return; } elseif ($quoteManager->productCount() == 0 && isset($_POST['back'])) { // No products/options selected, send them back to step 2 $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/step2'); return; } elseif ($this->getRequest()->isPost()) { // We need to validate and save the data $valid = $this->_formStepCommonValidate($pageForm, 4); if ($valid) { //Update the WebLead summary and create a STEP4 blob. $session = new Zend_Session_Namespace('landlords_insurance_quote'); $webLeadManager = new Manager_Core_WebLead(); $webLeadSummary = $webLeadManager->getSummary($session->webLeadSummaryId); $webLeadSummary->lastUpdatedTime = $this->_offsetDate(); $webLeadManager->updateSummary($webLeadSummary); //Determine if a new STEP4 blob needs to be created, or an existing one retrieved. if ($webLeadManager->getBlobExists($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP4)) { $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP4); } else { $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP4); } //Update the blob and store $webLeadBlob->blob = Zend_Json::encode($_POST); $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob); $webLeadManager->updateBlob($webLeadBlob); //Store the underwriting datas not already stored. $pageForm->applyAnswersLogics(); $pageForm->applyAdditionalInformationLogics(); $endorsementManager = new Manager_Insurance_LandlordsPlus_Endorsement(); $endorsements = $endorsementManager->getEndorsementsRequired($session->quoteID); //Look for a flood endorsement, and if found, identify if it is applicable (the //customer may have chosen to pay a premium to cover flood). $finalEndorsementArray = array(); foreach ($endorsements as $currentEndorsement) { if ($currentEndorsement->getEndorsementType()->getName() == Model_Insurance_EndorsementTypes::FLOOD_EXCLUSION) { $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID); $propertiesArray = $quoteManager->getProperties(); if ($propertiesArray[0]['exclude_flood_cover'] == 0) { //Flood cover IS provided, which means the endorsement is not applicable. continue; } } if ($endorsementManager->getIsEndorsementAlreadyApplied($currentEndorsement)) { //No need to add the endorsement again... continue; } $finalEndorsementArray[] = $currentEndorsement; } if (count($finalEndorsementArray) > 0) { $endorsementManager->insertEndorsements($finalEndorsementArray); } //Execute the underwriting referral logics. $referralManager = new Manager_Insurance_LandlordsPlus_Referral(); $reasons = $referralManager->getReferralReasons($session->quoteID); if (!empty($reasons)) { // Notify Underwriting of the referral. $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID); $policyNumber = $quoteManager->getLegacyID(); $refNo = $quoteManager->getLegacyCustomerReference(); $notificationManager = new Manager_Core_Notification(); $notesManager = new Manager_Core_Notes(); $otherReason = ''; for ($i = 0; $i < count($reasons); $i++) { if ('Referral due to buildings type' === $reasons[$i]) { $otherReason = "Policy has been referred due to property type of Other."; break; } } if ($otherReason) { $notesManager->save($policyNumber, "Refer to UW - " . $otherReason); $notificationManager->_reason = "Other"; } else { $notesManager->save($policyNumber, "Refer to UW - The application has fallen outside UW criteria."); } $notificationManager->notifyUnderwriting($policyNumber, $refNo); $referralManager->setToRefer($session->quoteID); //Redirect to referredAction. $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/referred'); return; } // Everything has been saved ok so navigate to next step $this->_formStepCommonNavigate(4); return; } elseif (isset($_POST['back'])) { $this->_formStepCommonNavigate(4); return; } } // If there's no quote manager, then set it up so we can make use of the // QHLI in the templates. if (!isset($quoteManager)) { $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID); } $this->view->qhli = $quoteManager->getLegacyID(); // Load the element data from the database if we can if ($this->_formStepCommonPopulate($pageForm, 4)) { // Render the page unless we have been redirected $this->view->form = $pageForm; $this->render('step'); } }