コード例 #1
0
 /**
  * Renew a policy from the 'temporary' insight_rrp_policy to the policy table
  *
  * @param string $rrpPolicyNumber
  * @param string $newPolicyNumber
  * @param string $termNumber
  * @return bool
  * @throws \RuntimeException
  */
 public function migratePolicy($rrpPolicyNumber, $newPolicyNumber, $termNumber)
 {
     if ($this->policyNumberManager->isRentRecoveryPlusInsightPolicy($rrpPolicyNumber)) {
         $this->setPolicyNumber($newPolicyNumber);
         $disbData = $this->disbursement->getDisbursement($this->appData->getWhiteLabelID(), $this->appData->getRateSetID());
         if (!$disbData) {
             $message = sprintf('Disbursement data not found (WhiteLabelId = %s, RateSetID = %d)', $this->appData->getWhiteLabelID(), $this->appData->getRateSetID());
             throw new \RuntimeException($message);
         }
         $getter = sprintf('getRrpi%s%dm', ReferenceTypes::isFullReference($this->rrpData->getReferenceType()) ? 'FullRef' : 'CreditCheck', $this->appData->getPolicyLength());
         if (PolicyOptionsManager::isOptionSet($this->appData->getPolicyOptions(), $this->container->get('rrp.legacy.const.policy_option_rrp-nilexcess'), $this->appData->getAmountsCovered())) {
             $getter .= '0xs';
         }
         if (!method_exists($disbData, $getter)) {
             $message = sprintf('Unknown disbursement type (%s)', $getter);
             throw new \RuntimeException($message);
         }
         $disbursement = $disbData->{$getter}();
         if (empty($disbursement)) {
             $message = sprintf('Disbursement data not set (WhiteLabelId = %s, RateSetID = %d, %s)', $this->appData->getWhiteLabelID(), $this->appData->getRateSetID(), $getter);
             throw new \RuntimeException($message);
         }
         $propertyRental = PolicyOptionsManager::getOption($this->appData->getPolicyOptions(), $this->getContainer()->get('rrp.legacy.const.policy_option_rrp'), $this->appData->getAmountsCovered());
         if ($propertyRental < RentRecoveryPlus::BAND_A_LIMIT) {
             $band = $disbData::BAND_A;
         } else {
             $band = $disbData::BAND_B;
         }
         $insuranceNetAmount = $disbData->extractBandDisbursement($disbursement, $band);
         // Policy Term
         $termId = $this->policyTerm->updatePolicyTerm($this->appData, $termNumber, array('netPremium' => $insuranceNetAmount, 'collectedPremium' => $this->appData->premium));
         if ($termId) {
             // Write the policy to the datasource
             $this->getAppData()->setStatus($this->container->get('rrp.legacy.const.status_policy'))->setTermId($termId);
             $legacyPolicy = $this->container->get('rrp.legacy.datasource.policy');
             $legacyPolicy->save($this->appData);
             // Delete the legacy insight record.
             $policyConstType = $this->container->get('rrp.legacy.const.quote_policy_number');
             $this->application->remove(array($policyConstType => $rrpPolicyNumber));
             $insightStatusIas = $this->container->get('rrp.legacy.const.insight_status_ias');
             // Now move the RRP / LL Interest parts
             if ($this->rrp->accept($rrpPolicyNumber, $newPolicyNumber, $insightStatusIas)) {
                 if ($this->llInterest->accept($rrpPolicyNumber, $newPolicyNumber)) {
                     /** @var RentRecoveryPlusAnswers $underwriting */
                     $underwriting = UnderwritingDecoratorFactory::getDecorator(UnderwritingDecoratorFactory::UNDERWRITING_RENT_RECOVERY_PLUS, $this->container->get('rrp.config.underwriting_question_set_id'), $this->appData->getIssueDate(), $rrpPolicyNumber);
                     $answers = $underwriting->getAllAnswers();
                     $answers[RentRecoveryPlusAnswers::QUESTION_ID_RENT_IN_ADVANCE] = true;
                     $answers[RentRecoveryPlusAnswers::QUESTION_ID_PRIOR_CLAIMS] = false;
                     $answers[RentRecoveryPlusAnswers::QUESTION_ID_DEPOSIT_SUFFICIENT] = true;
                     $underwriting->setAnswers($answers)->saveAnswers()->changeQuoteToPolicy($newPolicyNumber);
                     $coverOptions = array();
                     foreach ($this->appData->getValidPolicyOptionNames() as $optionName) {
                         if (PolicyOptionsManager::isOptionSet($this->appData->getPolicyOptions(), $optionName, $this->appData->getAmountsCovered())) {
                             $optionId = $this->policyOptions->fetchOptionsByName($optionName);
                             $sumInsured = PolicyOptionsManager::getOption($this->appData->getPolicyOptions(), $optionName, $this->appData->getAmountsCovered());
                             $premium = PolicyOptionsManager::getOption($this->appData->getPolicyOptions(), $optionName, $this->appData->getOptionPremiums());
                             $coverOptions[] = array('policyNumber' => $newPolicyNumber, 'policyOptionID' => $optionId, 'sumInsured' => $sumInsured, 'premium' => $premium);
                         }
                     }
                     $this->policyCover->setCover($newPolicyNumber, $coverOptions);
                     return $newPolicyNumber;
                 }
             }
         }
     }
     return false;
 }
コード例 #2
0
 /**
  * Cancel the policy
  */
 public function rentRecoveryPlusCancelAction()
 {
     $request = $this->getSymfonyRequest();
     $cancellationType = $this->getContainer()->get('rrp.form.cancellation');
     $policyNumber = null;
     $isConfirmed = false;
     if ($request->isMethod('GET')) {
         $policyNumber = $request->query->get('policyNumber');
     } else {
         if ($request->isMethod('POST')) {
             $isConfirmed = $request->request->get('isConfirmed', 0);
             $postedData = $request->request->get($cancellationType->getName());
             if (array_key_exists('policyNumber', $postedData)) {
                 $policyNumber = $postedData['policyNumber'];
             }
         }
     }
     if ($policyNumber) {
         // Ensure date picker CSS and JS are available
         $this->view->headLink()->appendStylesheet('/assets/vendor/jquery-datepicker/css/datePicker.css');
         $this->view->headScript()->appendFile('/assets/vendor/jquery-date/js/date.js');
         $this->view->headScript()->appendFile('/assets/vendor/jquery-datepicker/js/jquery.datePicker.js');
         $message = null;
         $applicationDecoratorClass = $this->getContainer()->get('rrp.application.decorator.class');
         /** @var RRP\Application\Decorators\RentRecoveryPlusPolicy $policy */
         $policy = $applicationDecoratorClass::getDecorator('RentRecoveryPlusPolicy');
         $policy->populateByPolicyNumber($policyNumber);
         if (Manager_Core_PolicyNumber::isQuote($policyNumber)) {
             $message = 'Quotes do not need cancelling';
             $isConfirmed = false;
         } else {
             if ($policy->getAppData()->getPayStatus() == Model_Insurance_RentRecoveryPlus_LegacyPolicy::PAY_STATUS_CANCELLED || strtotime($policy->getAppData()->getCancelledDate()) > 0) {
                 $message = 'This policy has already been cancelled';
                 $isConfirmed = false;
             } else {
                 $cancellationPeriod = $this->_params->connect->settings->rentRecoveryPlus->cancellationPeriod;
                 $now = new \DateTime();
                 $cancellationEndAt = new \DateTime($policy->getAppData()->getStartDate());
                 $cancellationEndAt = $cancellationEndAt->setTime(23, 59, 59)->add(new \DateInterval($cancellationPeriod));
                 if ($cancellationEndAt <= $now) {
                     $claimsDataSource = new Datasource_Insurance_Claims();
                     $claims = $claimsDataSource->getByPolicyNumber($policyNumber);
                     if ($claims) {
                         if ($claims->getClaimstatus() == $claims::CLAIM_STATUS_ACTIVE) {
                             $message = 'This policy has claims outstanding';
                             $isConfirmed = false;
                         }
                     }
                 }
             }
         }
         /** @var \RRP\Model\RentRecoveryPlusCancellation $cancellation */
         $cancellation = $this->getContainer()->get('rrp.model.cancellation');
         $cancellation->setPolicyNumber($policy->getAppData()->getPolicyNumber())->setPolicyExpiresAt($policy->getAppData()->getEndDate());
         $form = $this->getFormFactory()->create($cancellationType, $cancellation);
         if ($isConfirmed) {
             $form->submit($request);
             if (!$form->isValid()) {
                 $isConfirmed = false;
             }
         }
         if ($isConfirmed) {
             /** @var \RRP\Model\RentRecoveryPlusCancellation $cancellation */
             $cancellation = $form->getData();
             $refundValue = $policy->cancel($cancellation->getPolicyEndAt());
             if ($refundValue !== null) {
                 Manager_Insurance_Quote::sendCancellation($policyNumber, null, null, $this->_params->connect->settings->rentRecoveryPlus->systemCsuID, array('refundValue' => $refundValue));
                 $this->renderTwigView('/rentguarantee/rent-recovery-plus-cancellation.html.twig', array('form' => $form->createView(), 'isConfirmed' => $policyNumber, 'queryPhoneNumber' => $this->_params->connect->settings->rentRecoveryPlus->queryPhoneNumber));
                 return;
             }
         } else {
             if (!empty($policyNumber)) {
                 $cancellationDetails = array('queryPhoneNumber' => $this->_params->connect->settings->rentRecoveryPlus->queryPhoneNumber);
                 if ($message) {
                     $cancellationDetails['message'] = $message;
                 } else {
                     $cancellationDetails['form'] = $form->createView();
                 }
                 $this->renderTwigView('/rentguarantee/rent-recovery-plus-cancellation.html.twig', $cancellationDetails);
                 return;
             }
         }
     }
     $this->renderTwigView('/rentguarantee/rent-recovery-plus-error.html.twig');
 }