Exemplo n.º 1
0
 /**
  * This will convert all the new data into the old lagacy tables
  * @param
  * @return
  * @author John Burrin
  * @since 1.3
  *
  * Munten ergo sum
  */
 public function convertLegacy($refNo)
 {
     // fetch quote premiums
     $premiums = $this->quote($refNo);
     // Fetch the Landlords details
     $landlord = new Manager_Insurance_Portfolio_LegacyCustomer();
     $landlordDetails = $landlord->fetchByRefNo($refNo);
     // Fetch all the properties
     $propertyManager = new Manager_Insurance_Portfolio_Property();
     $propertyObject = new Model_Insurance_Portfolio_Property();
     $propertyObject = $propertyManager->fetchAllProperties($refNo);
     // populate the legacy portfoliostat table
     $legacyPortfolioStat = new Model_Insurance_Portfolio_LegacyPortfolio();
     $legacyPortfolioStat->agentSchemeNo = 1403796;
     // $legacyPortfolioStat->csuId = "";
     $legacyPortfolioStat->customerRefNo = "";
     $legacyPortfolioStat->date = date("Y-m-d");
     $legacyPortfolioStat->email = $landlordDetails['email_address'];
     $legacyPortfolioStat->heardFrom = "";
     $legacyPortfolioStat->hpc = "";
     $legacyPortfolioStat->name = $landlordDetails['first_name'] . " " . $landlordDetails['last_name'];
     $legacyPortfolioStat->numOfHouse = count($propertyObject);
     $legacyPortfolioStat->policyNumber = "";
     $legacyPortfolioStat->quote = $premiums['premiums']['UserQuoteAnnualPremium'];
     $legacyPortfolioStat->referred = "";
     $legacyPortfolioStat->refNo = $refNo;
     $legacyPortfolioStat->telephone = $landlordDetails['telephone1'];
     // Set up datasources to the risk areas
     $dsBuildingsRiskArea = new Datasource_Insurance_RiskAreas_Buildings();
     $dsContentsRiskArea = new Datasource_Insurance_RiskAreas_LandlordsContents();
     //Save the portfoliostat data
     $legacyPortfolioManager = new Manager_Insurance_Portfolio_LegacyPortfolio();
     $legacyPortfolioManager->save($legacyPortfolioStat);
     $idd = new Datasource_Insurance_IddSupport();
     if (!$idd->isIddSupport($legacyPortfolioStat->refNo)) {
         $inserArray = array();
         $insertArray['policynumber'] = $legacyPortfolioStat->refNo;
         $insertArray['agentschemeno'] = $legacyPortfolioStat->agentSchemeNo;
         $insertArray['csuid'] = 0;
         $fsaAgentStatusDatasource = new Datasource_Fsa_AgentStatus();
         $fsaStatus = $fsaAgentStatusDatasource->getAgentFsaStatus($legacyPortfolioStat->agentSchemeNo);
         if (isset($fsaStatus['status_abbr'])) {
             $insertArray['FSA_status'] = $fsaStatus['status_abbr'];
         } else {
             $insertArray['FSA_status'] = "";
         }
         $insertArray['origsaleid'] = 9;
         $insertArray['callerid'] = 2;
         $idd->setIddSupport($insertArray);
     }
     // Setup an agent manager
     $agent = new Manager_Core_Agent();
     // get polict options
     $ds_rates = new Datasource_Insurance_Portfolio_PortfolioRates();
     $rates = $ds_rates->fetchRates();
     $optionsString = $this->_getPolicyOptions();
     // Save the property data into the legacy portfolio table
     $legacyPropertyManager = new Manager_Insurance_Portfolio_LegacyProperty();
     foreach ($propertyObject as $property) {
         // Create a new Model_Insurance_Portfolio_LegacyProperty Object
         $legacyPropertyObject = new Model_Insurance_Portfolio_LegacyProperty();
         $legacyPropertyObject->amountsCovered = $this->_getAmountsCovered($property);
         $legacyPropertyObject->discount = "";
         $legacyPropertyObject->excessId = "";
         $legacyPropertyObject->ipt = "";
         $legacyPropertyObject->optionDiscounts = "";
         $legacyPropertyObject->optionPremiums = "";
         $legacyPropertyObject->policyNumber = $refNo;
         $legacyPropertyObject->policyOptions = $optionsString;
         $legacyPropertyObject->premium = "";
         $legacyPropertyObject->propAddress1 = $property->address1;
         $legacyPropertyObject->propAddress3 = $property->address2;
         $legacyPropertyObject->propAddress5 = $property->address3;
         $legacyPropertyObject->propPostcode = $property->postcode;
         $legacyPropertyObject->quote = 0.0;
         $legacyPropertyObject->rateSetId = $agent->getRatesetIDByASN($refNo);
         $legacyPropertyObject->riskArea = $dsContentsRiskArea->getCurrentRate($property['postcode']);
         $legacyPropertyObject->riskAreaB = $dsBuildingsRiskArea->getCurrentRate($property['postcode']);
         $legacyPropertyObject->surcharge = "";
         $legacyPropertyManager->save($legacyPropertyObject);
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @todo
  * This constructor calls the _save() method. Not necessarily something calling code will want, if the
  * calling code just wants to use one of the class methods, e.g. changeQuoteToPolicy().
  */
 public function __construct($refNumber = null, $agentSchemeNumber = null, $policyNumber = null)
 {
     Application_Core_Logger::log('Quote Manager Instantiated', 'info');
     $quoteDatasource = new Datasource_Insurance_LegacyQuotes();
     $policyDatasource = new Datasource_Insurance_TenantsContentsPlus_Policies();
     // Try to load the quote from the datasource - if it doesn't exist we just get a blank object back
     if ($policyNumber != null) {
         $this->_quoteModel = $quoteDatasource->getByPolicyNumber($policyNumber);
         $this->_rateSetID = $this->_quoteModel->rateSetID;
     } else {
         $this->_quoteModel = new Model_Insurance_LegacyQuote();
     }
     if (!is_null($agentSchemeNumber)) {
         $this->_quoteModel->agentSchemeNumber = $agentSchemeNumber;
         // Create an Agent Model
         $agent = new Datasource_Core_Agents();
         $this->_quoteModel->agentRateSetID = $agent->getRatesetID($this->_quoteModel->agentSchemeNumber);
     }
     /*
       We also need to set the value of the white label whitelabelID, NOTE: this field
       is a char(2) part of a multiple index and defaults to zero (0)
     */
     $whiteLabelManager = new Manager_Core_WhiteLabel();
     $whiteLabelData = new Model_Core_WhiteLabel();
     $whiteLabelData = $whiteLabelManager->fetchByAgentSchemeNumber($this->_quoteModel->agentSchemeNumber);
     $this->_quoteModel->whiteLabelID = !is_null($whiteLabelData) ? $whiteLabelData->twoLetterCode : 'HL';
     if (!isset($this->_quoteModel->policyNumber) || $this->_quoteModel->policyNumber == '') {
         // Fetch the available policy options for tenantsp
         $policyOptionsManager = new Manager_Insurance_TenantsContentsPlus_Policy_Options();
         $policyOptions = $policyOptionsManager->getOptions();
         // Get the next policy number
         $policyNumberDatasource = new Datasource_Core_NumberTracker();
         $policyNumber = $policyNumberDatasource->getNextPolicyNumber();
         $policyNumber = "QHLI" . $policyNumber . "/01";
         $this->_quoteModel->refNo = $refNumber;
         $this->_quoteModel->policyNumber = $policyNumber;
         $this->_quoteModel->policyName = 'tenantsp';
         $this->_quoteModel->policyOptions = implode('|', $policyOptions);
         $this->_quoteModel->policyType = 'T';
     }
     $idd = new Datasource_Insurance_IddSupport();
     if (!$idd->isIddSupport($this->_quoteModel->policyNumber)) {
         $inserArray = array();
         $insertArray['policynumber'] = $this->_quoteModel->policyNumber;
         $insertArray['agentschemeno'] = $this->_quoteModel->agentSchemeNumber;
         $insertArray['csuid'] = 0;
         $fsaAgentStatusDatasource = new Datasource_Fsa_AgentStatus();
         $fsaStatus = $fsaAgentStatusDatasource->getAgentFsaStatus($this->_quoteModel->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);
     }
     // Now need to push this object into the legacy quote datastore and save it
     $this->_save();
     Application_Core_Logger::log(print_r($this->_quoteModel, true), 'info');
 }
Exemplo n.º 3
0
 /**
  * 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);
     }
 }
 /**
  * collect info for idd document.
  *
  * @todo: Rewrite, restyle.
  *
  * @return void
  */
 private function iddsupport($request)
 {
     $idd = new Datasource_Insurance_IddSupport();
     $insertArray = array();
     if (!is_null($request->getParam('policyno'))) {
         $insertArray['policynumber'] = $request->getParam('policyno');
     } else {
         $insertArray['policynumber'] = "";
     }
     $insertArray['agentschemeno'] = $this->_agentSchemeNumber;
     $insertArray['csuid'] = 0;
     $insertArray['FSA_status'] = $this->_fsastatusabbr;
     $insertArray['origsaleid'] = 10;
     $insertArray['callerid'] = 1;
     $iddid = $idd->setIddSupport($insertArray);
     return $iddid;
 }