public function saveTransaction($data)
 {
     $policyNumberModel = new Datasource_Core_NumberTracker();
     $PaymentNumber = $policyNumberModel->getNextPaymentRefNumber();
     $dataToInsert = array('policynumber' => $data['policynumber'], 'trans_id' => $PaymentNumber, 'prev_trans_id' => 0, 'amount' => $data['amount'], 'auth_code' => $data['auth_code'], 'card_no' => $data['card_no'], 'card_type' => $data['card_type'], 'expiry' => substr($data['expiry'], 0, 2) . "/" . substr($data['expiry'], 2, 2), 'customer' => $data['customer'], 'message' => isset($data['message']) ? $data['message'] : '', 'resp_code' => isset($data['resp_code']) ? $data['resp_code'] : '', 'code' => $data['code'], 'test_status' => isset($data['test_status']) ? $data['test_status'] : 'live', 'deferred' => isset($data['deferred']) ? $data['deferred'] : '', 'hash' => $data['hash'], 'generated_from' => 1, 'entry_date' => date("Y-m-d"));
     $this->insert($dataToInsert);
 }
 /**
  * Saves the direct debit to the dd table 
  *
  * @param Model_Insurance_Directdebit $data
  *
  * @return void
  *
  * Look Ma!!!!, I'm Documenting
  */
 public function save($data)
 {
     $directDebit = new Datasource_Core_DirectDebit_Payment();
     /*
      We will need a payment refno 
     */
     $paymentRefno = new Datasource_Core_NumberTracker();
     $data->paymentRefNo = $paymentRefno->getNextPaymentRefNumber();
     #        $data->paymentDate = date("Y-m-d");
     /*
      Save that bad boy
     */
     $directDebit->saveDetails($data);
 }
 /**
  * Initialise the step 1 form
  *
  * @return void
  */
 public function step1Action()
 {
     // Append the address lookup javascript
     $this->view->headScript()->appendFile('/assets/common/js/addressLookup.js', 'text/javascript');
     // Tell page to use AJAX validation as we go
     $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = 1;');
     $pageForm = new Form_PortfolioInsuranceQuote_Step1();
     if ($this->getRequest()->isPost()) {
         // We need to validate and save the data
         // TODO: Need to re-factor this to make it quicker
         $valid = $this->_formStepCommonValidate($pageForm, 1);
         // As these items aren't stored in the DB, assume that if user has validated step 1 in the past
         // then DPA and IDD are ticked
         $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
         $pageForm->subform_idd->getElement('idd')->setValue($pageSession->step1->idd);
         if ($valid) {
             // Save the data and continue to next step
             $data = $pageForm->getValues();
             // According to the Zend manual these *should* be the clean values
             $pageSession->step1->idd = $data["subform_idd"]["idd"];
             //Capture and store the insurance data protections.
             $this->_saveInsuranceDPA($data["subform_dataprotection"]["dpa_phone_post"], $data["subform_dataprotection"]["dpa_sms_email"], $data["subform_dataprotection"]["dpa_resale"]);
             $customerObject = new Model_Insurance_Portfolio_LegacyCustomer();
             $customerObject->title = $data["subform_personaldetails"]["title"];
             $customerObject->first_name = $data["subform_personaldetails"]["first_name"];
             $customerObject->last_name = $data["subform_personaldetails"]["last_name"];
             // Look up address again to populate dropdown
             $customerObject->address1 = $data["subform_correspondenceaddress"]["cor_address_line1"];
             $customerObject->address2 = $data["subform_correspondenceaddress"]["cor_address_line2"];
             $customerObject->address3 = $data["subform_correspondenceaddress"]["cor_address_line3"];
             $customerObject->postcode = $data["subform_correspondenceaddress"]["cor_postcode"];
             $customerObject->telephone1 = $data["subform_personaldetails"]["phone_number"];
             $customerObject->telephone2 = $data["subform_personaldetails"]["mobile_number"];
             $customerObject->email_address = $data["subform_personaldetails"]["email_address"];
             $customerObject->date_of_birth_at = Application_Core_Utilities::ukDateToMysql($data['subform_personaldetails']['date_of_birth_at']);
             // Check to see if we have a session
             if (!isset($pageSession->CustomerRefNo)) {
                 // We don't have a session so we need to create a new customer/quote entry to save against
                 // Now get the reference number from the newly created customer
                 // This is not a standard referecnce number
                 // Saved customer now create portfolio reference number
                 $NumberTracker = new Datasource_Core_NumberTracker();
                 $customerRefNo = $NumberTracker->getNextPortfolioNumber();
                 $customerObject->refNo = $customerRefNo;
                 $customerManager = new Manager_Insurance_Portfolio_LegacyCustomer();
                 $customerManager->save($customerObject);
                 $this->_customerReferenceNumber = $customerRefNo;
                 $pageSession->CustomerRefNo = $customerRefNo;
             } else {
                 // We are in session so just instantiate the customer manager with the existing reference number
                 $customerManager = new Manager_Insurance_Portfolio_LegacyCustomer();
                 $customerObject->refNo = $pageSession->CustomerRefNo;
             }
             $customerManager->save($customerObject);
             //Record this WebLead, if not already done so. First create or retrieve the
             //WebLead summary.
             $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
             $webLeadManager = new Manager_Core_WebLead();
             if (empty($pageSession->webLeadSummaryId)) {
                 $isNewWebLead = true;
                 $webLeadSummary = $webLeadManager->createNewSummary();
             } else {
                 $isNewWebLead = false;
                 $webLeadSummary = $webLeadManager->getSummary($pageSession->webLeadSummaryId);
             }
             //Create or retrieve the step 1 blob.
             if (!$webLeadManager->getBlobExists($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1)) {
                 $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1);
             } else {
                 $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP1);
             }
             //Update the WebLead summary and store.
             $webLeadSummary->title = $data["subform_personaldetails"]["title"];
             $webLeadSummary->firstName = $data["subform_personaldetails"]["first_name"];
             $webLeadSummary->lastName = $data["subform_personaldetails"]["last_name"];
             if (!empty($data["subform_personaldetails"]["phone_number"])) {
                 $contactNumber = $data["subform_personaldetails"]["phone_number"];
             } else {
                 $contactNumber = $data["subform_personaldetails"]["mobile_number"];
             }
             $webLeadSummary->contactNumber = $contactNumber;
             $webLeadSummary->emailAddress = $data["subform_personaldetails"]["email_address"];
             if ($isNewWebLead) {
                 $webLeadSummary->startTime = $this->_offsetDate();
             }
             $webLeadSummary->lastUpdatedTime = $this->_offsetDate();
             $webLeadSummary->product = Model_Core_WebLeadProduct::PORTFOLIO;
             $webLeadSummary->quoteNumber = $customerRefNo;
             $webLeadManager->updateSummary($webLeadSummary);
             //Update the blob, serialize and store.
             $webLeadBlob->blob = Zend_Json::encode($_POST);
             $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob);
             $webLeadManager->updateBlob($webLeadBlob);
             //Finally, record the WebLead identifier in the page session.
             $pageSession->webLeadSummaryId = $webLeadSummary->webLeadSummaryId;
             //Capture and store the WebLead data protections.
             $this->_saveWebLeadDPA($webLeadSummary->webLeadSummaryId, $data["subform_dataprotection"]["dpa_phone_post"], $data["subform_dataprotection"]["dpa_sms_email"], $data["subform_dataprotection"]["dpa_resale"]);
             $this->_formStepCommonNavigate(1);
             return;
         } elseif (isset($_POST['back'])) {
             $this->_formStepCommonNavigate(1);
             return;
         }
     }
     // Load the element data from the database if we can
     if ($this->_formStepCommonPopulate($pageForm, 1)) {
         // Render the page unless we have been redirected
         $this->view->form = $pageForm;
         $this->render('step');
     }
 }
 /**
  * Generates the next policy/quote number
  *
  * @param $identifier
  * @param int $policyTerm
  * @return string
  * @throws \Exception
  */
 public function generateApplicationNumber($identifier, $policyTerm = 1)
 {
     switch ($identifier) {
         case self::QUOTE_IDENTIFIER:
             continue;
         case self::POLICY_IDENTIFIER:
             break;
         default:
             throw new \Exception('Invalid application type');
     }
     $numberTracker = new \Datasource_Core_NumberTracker();
     $policyNumber = sprintf('%s%s%s%07d/%02d', $identifier, $this->whiteLabelId, $this->typeIdentifier, $numberTracker->getNextNumberByPolicyName($numberTracker::NEXT_POLICY_NUMBER_IDENTIFIER), $policyTerm);
     return $policyNumber;
 }
Exemple #5
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);
     }
 }
Exemple #6
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');
 }