コード例 #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
ファイル: Quote.php プロジェクト: AlexEvesDeveloper/hl-stuff
 /**
  * Save the quote into the legacy database tables
  *
  * @munt 10
  */
 protected function _saveToLegacy()
 {
     // Insert/Update the legacy customer table
     // Check to see if we already have a legacy identifier
     if (is_null($this->_quoteModel->legacyID) || $this->_quoteModel->legacyID == '') {
         // This is the first save to legacy so we need to generate a new unique ID
         // I say unique.. but ermm.. well you'll see *sigh*
         $numberTracker = new Datasource_Core_NumberTracker();
         $this->_quoteModel->legacyID = 'QHLI' . (string) $numberTracker->getNextPolicyNumber() . '/01';
         $this->_quoteDataSource->save($this->_quoteModel);
         // Do a quick save now we have a legacy quote number
     }
     $this->_quoteModel->policyNumber = $this->_quoteModel->legacyID;
     $this->_quoteModel->policyLength = 12;
     // Insert/Update the legacy quote table
     $legacyQuote = new Model_Insurance_LegacyQuote();
     $legacyQuote->policyNumber = $this->getLegacyID();
     // Quote number
     $legacyQuote->refNo = $this->getLegacyCustomerReference();
     // Customer reference number
     $legacyQuote->agentSchemeNumber = $this->getAgentSchemeNumber();
     // Todo: This should be the agent scheme number for the selected agent!
     $legacyQuote->policyName = 'landlordsp';
     // Landlords+ quote/policy
     $legacyQuote->issueDate = date('Y-m-d');
     // Issued date - today
     $legacyQuote->startDate = $this->getStartDate();
     $legacyQuote->endDate = $this->getEndDate();
     $legacyQuote->policyType = 'L';
     $legacyQuote->policyLength = 12;
     $legacyQuote->payStatus = $this->_quoteModel->status;
     if ($this->getPayFrequency() == "ANNUALLY") {
         $legacyQuote->payBy = "Annually";
     }
     $idd = new Datasource_Insurance_IddSupport();
     if (!$idd->isIddSupport($legacyQuote->policyNumber)) {
         $inserArray = array();
         $insertArray['policynumber'] = $legacyQuote->policyNumber;
         $insertArray['agentschemeno'] = $legacyQuote->agentSchemeNumber;
         $insertArray['csuid'] = 0;
         $fsaAgentStatusDatasource = new Datasource_Fsa_AgentStatus();
         $fsaStatus = $fsaAgentStatusDatasource->getAgentFsaStatus($legacyQuote->agentSchemeNumber);
         if (isset($fsaStatus['status_abbr'])) {
             $insertArray['FSA_status'] = $fsaStatus['status_abbr'];
         } else {
             $insertArray['FSA_status'] = "";
         }
         $insertArray['origsaleid'] = 9;
         $insertArray['callerid'] = 2;
         $idd->setIddSupport($insertArray);
     }
     $properties = $this->getProperties();
     $legacyQuote->propertyAddress1 = $properties[0]['line_1'];
     $legacyQuote->propertyAddress2 = $properties[0]['line_2'];
     $legacyQuote->propertyAddress3 = $properties[0]['town'];
     $legacyQuote->propertyPostcode = $properties[0]['postcode'];
     // Build the policy options pipe delimitted nonsense!!! FML
     $premiums = $this->calculatePremiums();
     if ($premiums != '') {
         // Depending on if this is an annual or monthly quote we have to save different values in the database :(
         if ($this->getPayFrequency() == "ANNUALLY") {
             $legacyQuote->premium = $premiums['totalGrossAnnualPremium'];
             $legacyQuote->quote = $premiums['totalGrossAnnualPremium'] + $premiums['totalGrossAnnualIPT'];
             $legacyQuote->ipt = $premiums['totalGrossAnnualIPT'];
         } else {
             $legacyQuote->premium = $premiums['totalGrossMonthlyPremium'];
             $legacyQuote->quote = $premiums['totalGrossMonthlyPremium'] + $premiums['totalGrossMonthlyIPT'];
             $legacyQuote->ipt = $premiums['totalGrossMonthlyIPT'];
         }
         $this->_quoteModel->premium = $premiums['totalGrossMonthlyPremium'];
         $this->_quoteModel->ipt = $premiums['totalGrossAnnualIPT'];
         $legacyQuote->riskArea = $premiums['riskAreas']['buildingsAreaID'];
         $legacyQuote->termid = $this->setPolicyTerm();
     }
     $mult = 1;
     if ($this->getPayFrequency() == 'MONTHLY') {
         $mult = 12;
     }
     $policyOptions = '';
     $amountsCovered = '';
     $optionPremiums = '';
     $pItemHist = new Datasource_Insurance_Policy_PolicyTermItemHist();
     $cover = new Model_Insurance_Cover();
     // Get IPT percentage
     $propertiesDatasource = new Datasource_Insurance_Quote_Properties();
     $properties = $propertiesDatasource->getByQuoteID($this->_quoteModel->ID);
     $postcode = $properties[0]['postcode'];
     $taxDatasource = new Datasource_Core_Tax();
     $tax = $taxDatasource->getTaxbyTypeAndPostcode('ipt', $postcode);
     $ipt = 1 + $tax['rate'] / 100;
     if ($premiums != '') {
         if ($this->hasProduct(self::BUILDING_COVER) && $this->isValidValue($premiums['netBuilding'])) {
             $policyOptions .= 'buildingsp|';
             $amountsCovered .= $premiums['rebuildValue'] > 0 ? $premiums['rebuildValue'] : $premiums['calculatedDSIValue'];
             $amountsCovered .= '|';
             $optionPremiums .= round($premiums['annualBuilding'] / $mult, 2) . '|';
             $cover->policyOptionID = 33;
             $cover->sumInsured = $premiums['rebuildValue'] > 0 ? $premiums['rebuildValue'] : $premiums['calculatedDSIValue'];
             $cover->grosspremium = round($premiums['annualBuilding'] * $ipt, 2);
             $cover->premium = $premiums['annualBuilding'];
             $cover->netpremium = $premiums['netBuilding'];
             $cover->ipt = $cover->grosspremium - $cover->premium;
             $pItemHist->setItemHist($legacyQuote, $cover);
             if ($this->isValidValue($premiums['netBuildingAD'])) {
                 $policyOptions .= 'buildingsAccidentalDamagep|';
                 $amountsCovered .= $premiums['rebuildValue'] > 0 ? $premiums['rebuildValue'] : $premiums['calculatedDSIValue'];
                 $amountsCovered .= '|';
                 $optionPremiums .= round($premiums['annualBuildingAD'] / $mult, 2) . '|';
                 $cover->policyOptionID = 37;
                 $cover->grosspremium = round($premiums['annualBuildingAD'] * $ipt, 2);
                 $cover->premium = $premiums['annualBuildingAD'];
                 $cover->netpremium = $premiums['netBuildingAD'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
             if ($this->isValidValue($premiums['netBFlood'])) {
                 $policyOptions .= 'buildingslflood|';
                 $amountsCovered .= $premiums['rebuildValue'] > 0 ? $premiums['rebuildValue'] : $premiums['calculatedDSIValue'];
                 $amountsCovered .= '|';
                 $optionPremiums .= round($premiums['annualBFlood'] / $mult, 2) . '|';
                 $cover->policyOptionID = 31;
                 $cover->grosspremium = round($premiums['annualBFlood'] * $ipt, 2);
                 $cover->premium = $premiums['annualBFlood'];
                 $cover->netpremium = $premiums['netBFlood'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
         }
         if ($this->hasProduct(self::UNFURNISHED_CONTENTS_COVER) && $this->isValidValue($premiums['netLContent'])) {
             $policyOptions .= 'limitedcontentsp|';
             $amountsCovered .= '5000|';
             $optionPremiums .= round($premiums['annualLContent'] / $mult, 2) . '|';
             $cover->policyOptionID = 39;
             $cover->sumInsured = 5000;
             $cover->grosspremium = round($premiums['annualLContent'] * $ipt, 2);
             $cover->premium = $premiums['annualLContent'];
             $cover->netpremium = $premiums['netLContent'];
             $cover->ipt = $cover->grosspremium - $cover->premium;
             $pItemHist->setItemHist($legacyQuote, $cover);
         }
         if ($this->hasProduct(self::CONTENTS_COVER) && $this->isValidValue($premiums['netContent'])) {
             $policyOptions .= 'contentslp|';
             $meta = $this->getProductMeta(self::CONTENTS_COVER);
             $amountsCovered .= $meta['cover_amount'] . '|';
             $optionPremiums .= round($premiums['annualContent'] / $mult, 2) . '|';
             $cover->sumInsured = $meta['cover_amount'];
             $cover->policyOptionID = 34;
             $cover->grosspremium = round($premiums['annualContent'] * $ipt, 2);
             $cover->premium = $premiums['annualContent'];
             $cover->netpremium = $premiums['netContent'];
             $cover->ipt = $cover->grosspremium - $cover->premium;
             $pItemHist->setItemHist($legacyQuote, $cover);
             if ($this->isValidValue($premiums['netContentsAD'])) {
                 $policyOptions .= 'contentslAccidentalDamagep|';
                 $amountsCovered .= $meta['cover_amount'] . '|';
                 $optionPremiums .= round($premiums['annualContentsAD'] / $mult, 2) . '|';
                 $cover->policyOptionID = 38;
                 $cover->grosspremium = round($premiums['annualContentsAD'] * $ipt, 2);
                 $cover->premium = $premiums['annualContentsAD'];
                 $cover->netpremium = $premiums['netContentsAD'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
             if ($this->isValidValue($premiums['netBFlood'])) {
                 $policyOptions .= 'contentslflood|';
                 $amountsCovered .= $meta['cover_amount'] . '|';
                 $optionPremiums .= round($premiums['annualCFlood'] / $mult, 2) . '|';
                 $cover->policyOptionID = 32;
                 $cover->grosspremium = round($premiums['annualCFlood'] * $ipt, 2);
                 $cover->premium = $premiums['annualCFlood'];
                 $cover->netpremium = $premiums['netCFlood'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
         }
         // ** RENT GUARANTEE ** //
         if ($this->hasProduct(self::RENT_GUARANTEE) && $this->isValidValue($premiums['netAnnualRentGuarantee'])) {
             $policyOptions .= 'rentguaranteep|';
             $meta = $this->getProductMeta(self::RENT_GUARANTEE);
             $amountsCovered .= $meta['monthly_rent'] . '|';
             $optionPremiums .= round($premiums['grossAnnualRentGuarantee'] / $mult, 2) . '|';
             $cover->policyOptionID = 36;
             $cover->sumInsured = $meta['monthly_rent'];
             $cover->grosspremium = round($premiums['grossAnnualRentGuarantee'] * $ipt, 2);
             $cover->premium = $premiums['grossAnnualRentGuarantee'];
             $cover->netpremium = $premiums['netAnnualRentGuarantee'];
             $cover->ipt = $cover->grosspremium - $cover->premium;
             $pItemHist->setItemHist($legacyQuote, $cover);
         }
         // ** LEGAL EXPENSES ** //
         if ($this->hasProduct(self::LEGAL_EXPENSES) && $this->isValidValue($premiums['netAnnualLegalExpensesCover'])) {
             $policyOptions .= 'legalexpensesp|';
             $amountsCovered .= '50000|';
             $optionPremiums .= round($premiums['grossAnnualLegalExpensesCover'] / $mult, 2) . '|';
             $cover->policyOptionID = 35;
             $cover->sumInsured = 50000;
             $cover->grosspremium = round($premiums['grossAnnualLegalExpensesCover'] * $ipt, 2);
             $cover->premium = $premiums['grossAnnualLegalExpensesCover'];
             $cover->netpremium = $premiums['netAnnualLegalExpensesCover'];
             $cover->ipt = $cover->grosspremium - $cover->premium;
             $pItemHist->setItemHist($legacyQuote, $cover);
         }
         // ** EMERGENCY ASSISTANCE ** //
         if ($this->hasProduct(self::EMERGENCY_ASSISTANCE)) {
             if ($this->isValidValue($premiums['netEA'])) {
                 $policyOptions .= 'emergencyassistance|';
                 $amountsCovered .= '1500|';
                 $optionPremiums .= round($premiums['annualEA'] / $mult, 2) . '|';
                 $cover->policyOptionID = 4;
                 $cover->sumInsured = 1500;
                 $cover->grosspremium = round($premiums['annualEA'] * $ipt, 2);
                 $cover->premium = $premiums['annualEA'];
                 $cover->netpremium = $premiums['netEA'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
             if ($this->isValidValue($premiums['netEAB'])) {
                 $policyOptions .= 'emergencyassistancebahbuildings|';
                 $amountsCovered .= '0|';
                 $optionPremiums .= round($premiums['annualEAB'] / $mult, 2) . '|';
                 $cover->policyOptionID = 28;
                 $cover->sumInsured = 0;
                 $cover->grosspremium = round($premiums['annualEAB'] * $ipt, 2);
                 $cover->premium = $premiums['annualEAB'];
                 $cover->netpremium = $premiums['netEAB'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
             if ($this->isValidValue($premiums['netEAS'])) {
                 $policyOptions .= 'emergencyassistancestandalone|';
                 $amountsCovered .= '1500|';
                 $optionPremiums .= round($premiums['annualEAS'] / $mult, 2) . '|0|';
                 $cover->policyOptionID = 30;
                 $cover->sumInsured = 1500;
                 $cover->grosspremium = round($premiums['annualEAS'] * $ipt, 2);
                 $cover->premium = $premiums['annualEAS'];
                 $cover->netpremium = $premiums['netEAS'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
             if ($this->isValidValue($premiums['netEABS'])) {
                 $policyOptions .= 'emergencyassistancebahstandalone|';
                 $amountsCovered .= '0|';
                 $optionPremiums .= round($premiums['annualEABS'] / $mult, 2) . '|';
                 $cover->policyOptionID = 29;
                 $cover->sumInsured = 0;
                 $cover->grosspremium = round($premiums['annualEABS'] * $ipt, 2);
                 $cover->premium = $premiums['annualEABS'];
                 $cover->netpremium = $premiums['netEABS'];
                 $cover->ipt = $cover->grosspremium - $cover->premium;
                 $pItemHist->setItemHist($legacyQuote, $cover);
             }
         }
         // We also have to populate the POLICYVARIABLE table for MTA/Renewals *arrghghh*
         // NOTE: This code is seriously ugly due to time restraints. Intention is to re-write it
         //       when we re-write the admin suites so we don't have to maintain horrible legacy systems!
         /* POLICY VARIABLES */
         $policyVariables = array();
         $policyNumber = $this->getPolicyNumber();
         // Policy Risk Area - 1
         $policyVariables[] = array('policyVariableDefID' => 1, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $premiums['riskAreas']['buildingsAreaID']);
         // No claims discount - 3
         // Possible options 0=0, 1=1, 2=2, 3=3, 4=3+
         $properties = $this->getProperties();
         $ncbID = $properties[0]['no_claims_years_id'];
         $policyVariables[] = array('policyVariableDefID' => 3, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $ncbID - 1);
         // Managed property - 4
         // Possible options 0=No, 1=Yes
         $policyVariables[] = array('policyVariableDefID' => 4, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $properties[0]['letting_agent_managed']);
         if ($this->hasProduct(self::BUILDING_COVER)) {
             // Year of Construction - 2
             $policyVariables[] = array('policyVariableDefID' => 2, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $premiums['dsiData']['yearBuiltID']);
             // Buildings excess - 5
             // Possible options 0=0, 1=100, 2=250, 3=500, 4=1000
             $buildingExcessID = 0;
             $buildingMeta = $this->getProductMeta(self::BUILDING_COVER);
             $buildingExcess = $buildingMeta['excess'];
             switch ($buildingExcess) {
                 case '0':
                     $buildingExcessID = 0;
                     break;
                 case '100':
                     $buildingExcessID = 1;
                     break;
                 case '250':
                     $buildingExcessID = 2;
                     break;
                 case '500':
                     $buildingExcessID = 3;
                     break;
                 case '1000':
                     $buildingExcessID = 4;
                     break;
             }
             $policyVariables[] = array('policyVariableDefID' => 5, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $buildingExcessID);
         }
         // Tenant type - 6
         // Possible options
         // 		0=Employed
         //		1=Self Employed
         //		2=Student
         //		3=Retired
         //		4=Unemployed
         //		5=Housing Authority
         //		6=Unknown
         //		7=Claiming Benefit
         $tenantTypeID = 7;
         // NOTE : This is the worst code I've EVER written Argghhh
         switch ($properties[0]['tenant_type_id']) {
             case 1:
                 $tenantTypeID = 0;
                 break;
             case 2:
                 $tenantTypeID = 1;
                 break;
             case 3:
                 $tenantTypeID = 2;
                 break;
             case 4:
                 $tenantTypeID = 3;
                 break;
             case 5:
                 $tenantTypeID = 4;
                 break;
             case 6:
                 $tenantTypeID = 7;
                 break;
             case 7:
                 $tenantTypeID = 5;
                 break;
             case 8:
                 $tenantTypeID = 6;
                 break;
         }
         $policyVariables[] = array('policyVariableDefID' => 6, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $tenantTypeID);
         // Contents area - 7
         $policyVariables[] = array('policyVariableDefID' => 7, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $premiums['riskAreas']['contentsAreaID']);
         // Contents excess - 8
         // Possible options 0=0, 1=100, 2=250, 3=500, 4=1000
         if ($this->hasProduct(self::CONTENTS_COVER)) {
             $contentsMeta = $this->getProductMeta(self::CONTENTS_COVER);
             switch ($contentsMeta['excess']) {
                 case '0':
                     $buildingExcessID = 0;
                     break;
                 case '100':
                     $buildingExcessID = 1;
                     break;
                 case '250':
                     $buildingExcessID = 2;
                     break;
                 case '500':
                     $buildingExcessID = 3;
                     break;
                 case '1000':
                     $buildingExcessID = 4;
                     break;
             }
             $policyVariables[] = array('policyVariableDefID' => 8, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $buildingExcessID);
         }
         // Building flood risk - 9
         // Possible options 0=No, 1=Yes
         $policyVariables[] = array('policyVariableDefID' => 9, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $premiums['riskAreas']['floodArea'] == 0 ? 0 : 1);
         // Contents flood risk - 10
         // Possible options 0=No, 1=Yes
         $policyVariables[] = array('policyVariableDefID' => 10, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $premiums['riskAreas']['floodArea'] == 0 ? 0 : 1);
         // Buildings cover over 500,000 - 11
         // Possible options 0=No, 1=Yes
         $buildingValue = $premiums['rebuildValue'] > 0 ? $premiums['rebuildValue'] : $premiums['calculatedDSIValue'];
         $policyVariables[] = array('policyVariableDefID' => 11, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $buildingValue <= 500000 ? 0 : 1);
         // Years owned property - 12
         // Possible options
         //		0 = 0
         //		1 = 1
         //		2 = 2
         //		3 = 3
         // 		4 = 3+
         $yearsOwnedID = $properties[0]['ownership_length_id'];
         $policyVariables[] = array('policyVariableDefID' => 12, 'policyNumber' => $policyNumber, 'timestamp' => date('Y-m-d h:i:s'), 'value' => $yearsOwnedID - 1);
         /********************/
         // Save the policy variables
         $legacyPolicyVariables = new Datasource_Insurance_LandlordsPlus_Legacy_PolicyVariables();
         $legacyPolicyVariables->save($policyVariables);
     }
     $legacyQuote->policyOptions = trim($policyOptions, '|');
     $legacyQuote->amountsCovered = trim($amountsCovered, '|');
     $legacyQuote->optionPremiums = trim($optionPremiums, '|');
     $policyCover = new Datasource_Insurance_Policy_Cover();
     $policyCover->populateFromLegacy($legacyQuote->policyNumber, $legacyQuote->policyOptions, $legacyQuote->amountsCovered, $legacyQuote->optionPremiums);
     $legacyQuoteDatasource = new Datasource_Insurance_LegacyQuotes();
     $legacyQuoteDatasource->save($legacyQuote);
     if ($premiums != '' && $this->hasProduct(self::BUILDING_COVER)) {
         // We also need to populate the legacy SIVALUE table or MTA's & Renewals don't work :(
         $buildingMeta = $this->getProductMeta(self::BUILDING_COVER);
         $sivalueData = array();
         $sivalueData['policynumber'] = $this->getPolicyNumber();
         // If SI is derived siTypeID = 1, if it's manual then siTypeID = 2
         if (isset($buildingMeta['rebuild_value']) && $buildingMeta['rebuild_value'] > 0) {
             $sivalueData['siTypeID'] = 2;
             $sivalueData['siValue'] = $premiums['rebuildValue'];
         } else {
             $sivalueData['siTypeID'] = 1;
             $sivalueData['siValue'] = $premiums['calculatedDSIValue'];
         }
         // policyOptionID is always 33 - Landlords Buildings+
         $sivalueData['policyOptionID'] = 33;
         // startdate and enddate are entered here too! *sigh*
         $sivalueData['startdate'] = $this->getStartDate();
         $sivalueData['enddate'] = $this->getEndDate();
         // dsiArea
         $sivalueData['dsiArea'] = $premiums['dsiData']['areaID'];
         // dsiYearBuiltID
         $sivalueData['dsiYearBuiltID'] = $premiums['dsiData']['yearBuiltID'];
         // dsiPropertyTypeID
         $sivalueData['dsiPropertyTypeID'] = $premiums['dsiData']['dsiPropertyTypeID'];
         // dsiBedroomNumID
         $sivalueData['dsiBedroomNumID'] = $premiums['dsiData']['dsiBedroomQuantityID'];
         $siValueDatasource = new Datasource_Insurance_LandlordsPlus_Legacy_Sivalue();
         $siValueDatasource->save($sivalueData);
     }
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function accept($policyNumber, $mtaId)
 {
     /** @var \RRP\Application\Decorators\RentRecoveryPlusPolicy $policy */
     $policy = ApplicationDecoratorFactory::getDecorator('RentRecoveryPlusPolicy');
     $policy->populateByPolicyNumber($policyNumber);
     $this->legacyMtaData = $this->legacyMta->getByMtaID($mtaId);
     $this->rrpMtaData = $this->rrpMta->getRentRecoveryPlusMta($mtaId);
     $proRataPremium = $policy->getAppData()->getPremium() + $this->legacyMtaData->getPremium();
     $proRataQuote = $policy->getAppData()->getQuote() + $this->legacyMtaData->getQuote();
     $proRataIpt = $policy->getAppData()->getIpt() + $this->legacyMtaData->getIpt();
     $propertyRental = PolicyOptionsManager::getOption($this->legacyMtaData->getPolicyOptions(), $this->getContainer()->get('rrp.legacy.const.policy_option_rrp'), $this->legacyMtaData->getAmountscovered());
     $isNilExcess = PolicyOptionsManager::isOptionSet($this->legacyMtaData->getPolicyOptions(), $this->getContainer()->get('rrp.legacy.const.policy_option_rrp-nilexcess'), $this->legacyMtaData->getAmountscovered());
     $policyPremium = PolicyOptionsManager::getOption($policy->getAppData()->getPolicyOptions(), $this->getContainer()->get('rrp.legacy.const.policy_option_rrp'), $policy->getAppData()->getOptionPremiums());
     $mtaPremium = PolicyOptionsManager::getOption($this->legacyMtaData->getPolicyOptions(), $this->getContainer()->get('rrp.legacy.const.policy_option_rrp'), $this->legacyMtaData->getOptionPremiums());
     $optionPremiums = PolicyOptionsManager::addPolicyOption($policyPremium + $mtaPremium);
     if ($isNilExcess) {
         $policyNilExcessOption = PolicyOptionsManager::getOption($policy->getAppData()->getPolicyOptions(), $this->getContainer()->get('rrp.legacy.const.policy_option_rrp-nilexcess'), $policy->getAppData()->getOptionPremiums());
         $mtaNilExcessOption = PolicyOptionsManager::getOption($this->legacyMtaData->getPolicyOptions(), $this->getContainer()->get('rrp.legacy.const.policy_option_rrp-nilexcess'), $this->legacyMtaData->getOptionPremiums());
         $optionPremiums = PolicyOptionsManager::addPolicyOption($policyNilExcessOption + $mtaNilExcessOption, $optionPremiums);
     }
     $policy->getAppData()->setPolicyOptions($this->legacyMtaData->getPolicyOptions())->setAmountsCovered($this->legacyMtaData->getAmountscovered())->setOptionPremiums($optionPremiums)->setPremium($proRataPremium)->setQuote($proRataQuote)->setIpt($proRataIpt);
     $policy->getRrpData()->setClaimInfo($this->rrpMtaData->getClaimInfo());
     $disbData = $this->disbursement->getDisbursement($policy->getAppData()->getWhiteLabelID(), $policy->getAppData()->getRateSetID());
     if (!$disbData) {
         $message = sprintf('Disbursement data not found (WhiteLabelId = %s, RateSetID = %d)', $policy->getAppData()->getWhiteLabelID(), $policy->getAppData()->getRateSetID());
         throw new \RuntimeException($message);
     }
     $getter = sprintf('getRrpi%s%dm', ReferenceTypes::isFullReference($policy->getRrpData()->getReferenceType()) ? 'FullRef' : 'CreditCheck', $policy->getAppData()->getPolicyLength());
     if ($isNilExcess) {
         $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)', $policy->getAppData()->getWhiteLabelID(), $policy->getAppData()->getRateSetID(), $getter);
         throw new \RuntimeException($message);
     }
     $termData = $this->policyTerm->getPolicyTerm($policy->getAppData()->getPolicyNumber(), $policy->getAppData()->getStartDate());
     if (!$termData->id) {
         throw new \RuntimeException('Invalid Term Id');
     }
     if ($propertyRental < RentRecoveryPlus::BAND_A_LIMIT) {
         $band = $disbData::BAND_A;
         $transBand = RentRecoveryPlus::BAND_A;
     } else {
         $band = $disbData::BAND_B;
         $transBand = RentRecoveryPlus::BAND_B;
     }
     $insuranceNetAmount = $disbData->extractBandDisbursement($disbursement, $band);
     $proRataCalcs = new ProRataCalculations($policy->getAppData()->getStartDate(), $this->legacyMtaData->getDateOnRisk());
     $netPremium = $proRataCalcs->getProRata($policy->getAppData()->getPolicyLength(), $policy->getAppData()->getPolicyLength(), $insuranceNetAmount, $termData->netPremium);
     $this->policyTerm->updatePolicyTerm($policy->getAppData(), $termData->term, array('netPremium' => $netPremium));
     $this->policyNotes->addNote($policyNumber, $this->legacyMtaData->getDisplayNotes());
     if ($policy->save()) {
         if ($this->legacyMta->updateStatus($policyNumber, $mtaId, $this->mtaStatusLive)) {
             $coverOptions = array();
             foreach ($policy->getAppData()->getValidPolicyOptionNames() as $optionName) {
                 if (PolicyOptionsManager::isOptionSet($policy->getAppData()->getPolicyOptions(), $optionName, $policy->getAppData()->getAmountsCovered())) {
                     $optionId = $this->policyOptions->fetchOptionsByName($optionName);
                     $sumInsured = PolicyOptionsManager::getOption($policy->getAppData()->getPolicyOptions(), $optionName, $policy->getAppData()->getAmountsCovered());
                     $premium = PolicyOptionsManager::getOption($policy->getAppData()->getPolicyOptions(), $optionName, $policy->getAppData()->getOptionPremiums());
                     $coverOptions[] = array('policyNumber' => $policyNumber, 'policyOptionID' => $optionId, 'sumInsured' => $sumInsured, 'premium' => $premium);
                 }
             }
             $this->policyCover->setCover($policyNumber, $coverOptions);
             if ($this->legacyMtaData->getPremium() == 0) {
                 //If no premium change there's no need to store anything in the transaction
                 return true;
             }
             $transaction = TransactionDecoratorFactory::getDecorator(TransactionDecoratorFactory::TRANSACTION_UPDATE, $policy->getAppData()->getPremium(), $insuranceNetAmount, $termData->id, $mtaId, $transBand, $this->legacyMtaData->getDateOnRisk(), $policy->getAppData());
             $transaction->processAllTransactions();
             return true;
         }
     }
     return false;
 }
コード例 #4
0
ファイル: Quote.php プロジェクト: AlexEvesDeveloper/hl-stuff
 /**
  * Set cover amount
  *
  * @param int $sumInsured
  * @return void
  */
 public function setCoverAmount($sumInsured, $type)
 {
     // Get the current amounts covered
     $amountsCovered = explode('|', $this->_quoteModel->amountsCovered);
     $amountsCovered[$type] = $sumInsured;
     $this->_quoteModel->amountsCovered = implode('|', $amountsCovered);
     // Re-calculate priced
     $this->calculatePremiums();
     if (!is_null($this->_quoteModel->policyNumber) && $this->_quoteModel->policyNumber != '') {
         // We have a policy number so we need to update the legacy policy cover table
         $optionPremiums = explode('|', $this->_quoteModel->optionPremiums);
         // We also have to update the legacy policy cover table
         $policyCover = new Datasource_Insurance_Policy_Cover();
         $policyOptions = new Datasource_Insurance_Policy_Options('T');
         $options = $policyOptions->fetchOptions();
         $optionIDsArray = array();
         foreach ($options as $option) {
             $optionIDsArray[$option->policyOption] = $option->policyOptionID;
         }
         // Contents cover
         $coverArray[] = array('policyOptionID' => $optionIDsArray['contentstp'], 'sumInsured' => is_null($amountsCovered[self::CONTENTS]) ? 0 : $amountsCovered[self::CONTENTS], 'premium' => is_null($optionPremiums[self::CONTENTS]) ? 0 : $optionPremiums[self::CONTENTS], 'policyNumber' => $this->_quoteModel->policyNumber);
         $coverArray[] = array('policyOptionID' => $optionIDsArray['pedalcyclesp'], 'sumInsured' => is_null($amountsCovered[self::PEDALCYCLES]) ? 0 : $amountsCovered[self::PEDALCYCLES], 'premium' => is_null($optionPremiums[self::PEDALCYCLES]) ? 0 : $optionPremiums[self::PEDALCYCLES], 'policyNumber' => $this->_quoteModel->policyNumber);
         $coverArray[] = array('policyOptionID' => $optionIDsArray['specpossessionsp'], 'sumInsured' => is_null($amountsCovered[self::SPECIFIEDPOSSESSIONS]) ? 0 : $amountsCovered[self::SPECIFIEDPOSSESSIONS], 'premium' => is_null($optionPremiums[self::SPECIFIEDPOSSESSIONS]) ? 0 : $optionPremiums[self::SPECIFIEDPOSSESSIONS], 'policyNumber' => $this->_quoteModel->policyNumber);
         $coverArray[] = array('policyOptionID' => $optionIDsArray['possessionsp'], 'sumInsured' => is_null($amountsCovered[self::UNSPECIFIEDPOSSESSIONS]) ? 0 : $amountsCovered[self::UNSPECIFIEDPOSSESSIONS], 'premium' => is_null($optionPremiums[self::UNSPECIFIEDPOSSESSIONS]) ? 0 : $optionPremiums[self::UNSPECIFIEDPOSSESSIONS], 'policyNumber' => $this->_quoteModel->policyNumber);
         $policyCover->setCover($this->_quoteModel->policyNumber, $coverArray);
     }
     $this->_save();
 }