private function _doMail($data)
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     $customerRefNo = $pageSession->CustomerRefNo;
     // Get Customer
     $customerManager = new Manager_Insurance_Portfolio_LegacyCustomer();
     $customerObject = new Model_Insurance_Portfolio_LegacyCustomer();
     $customerObject = $customerManager->fetchByRefNo($customerRefNo);
     // Get Properties
     $propertyManager = new Manager_Insurance_Portfolio_Property();
     $properties = array();
     // Fetch all the properties related to this customer refNo
     $properties = $propertyManager->fetchAllProperties($customerRefNo)->toArray();
     $propertyHtml = $this->view->partialLoop('portfolio-insurance-quote/partials/email-templates/property-details.phtml', $properties);
     // Fetch claims releted to this customer refNo
     $claimsManager = new Manager_Insurance_Portfolio_PreviousClaims();
     $claims = $claimsManager->fetchWithClaimTypes($customerRefNo);
     $claimsHtml = $this->view->partialLoop('portfolio-insurance-quote/partials/email-templates/claims.phtml', $claims);
     // Fetch bank interest related to this customer refNo
     $bankInterestManager = new Manager_Insurance_Portfolio_BankInterest();
     $bankInterest = $bankInterestManager->fetchAllInterests($customerRefNo);
     $bankInterestHtml = $this->view->partialLoop('portfolio-insurance-quote/partials/email-templates/bank-interest.phtml', $bankInterest);
     $uwManager = new Manager_Insurance_Portfolio_UnderwritingAnswers();
     $uwAnswers = $uwManager->fetchByRefNo($customerRefNo);
     // Merge the claim and Interest info into the UW template
     $uwQuestionsHtml = $this->view->partial('portfolio-insurance-quote/partials/email-templates/uw-questions.phtml', array('claimsHtml' => $claimsHtml, 'bankInterestHtml' => $bankInterestHtml, 'uwAnswers' => $uwAnswers->toArray()));
     // Merge all the html together
     $mailBody = $this->view->partial('portfolio-insurance-quote/partials/email-templates/emailQuote.phtml', array('theData' => $data, 'theCustomer' => $customerObject->toArray(), 'propertyHtml' => $propertyHtml, 'uwQuestionsHtml' => $uwQuestionsHtml));
     // Get some parameter stuffs
     $params = Zend_Registry::get('params');
     $emailArray = explode(",", $params->email->portfolioAdmin);
     $toAddress = $emailArray[0];
     $ccAddress = $emailArray[1];
     $fromAddress = $params->email->noreply;
     // Mail that bad boy
     if (isset($data['referred'])) {
         $referred = " - REFERRED";
     }
     $email = new Application_Core_Mail();
     $email->setFrom($fromAddress, "PORTFOLIO NEW BUSINESS {$referred}");
     $email->setTo($toAddress, "Underwriting");
     $email->setCC($ccAddress);
     $email->setSubject("Portfolio Website Query - ref: {$customerRefNo}");
     $email->setBodyHtml($mailBody);
     $email->send();
     return;
 }
예제 #2
0
 public function quote($refNo)
 {
     $buildingAreaSum = array(0, 0, 0, 0, 0, 0, 0, 0);
     $buildingAreaPremium = array(0, 0, 0, 0, 0, 0, 0, 0);
     $contentsAreaSum = array(0, 0, 0, 0, 0, 0, 0);
     $contentsAreaPremium = array(0, 0, 0, 0, 0, 0, 0);
     $professionalprop = 0;
     $total_sum_buildings = 0;
     $total_sum_contents = 0;
     $limited_contents_cost = 0;
     $professionalRate = 0;
     $buildingsAccidentalDamage = 0;
     $buildingsNoExcess = 0;
     $contentsAccidentalDamage = 0;
     $contentsNoExcess = 0;
     $limited_contents_cost = 0;
     $bReferred = false;
     $has_claims = 0;
     $tenantnum = 0;
     // Fetch some rates information
     // Agents Rate ID
     $agent = new Manager_Core_Agent();
     # TODO: need to reove this schemenumber
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     $session = new Zend_Session_Namespace('homelet_global');
     $this->_agentsRateID = $agent->getRatesetIDByASN($session->referrer);
     $portfolioRates = new Datasource_Insurance_Portfolio_PortfolioRates();
     $this->_rates = $this->_fetchRates();
     $this->_factors = $this->_fetchFactors();
     // Fetch some fees information
     // Monthly admin fee
     $propertyManager = new Manager_Insurance_Portfolio_Property();
     $properties = array();
     // Fetch all the properties related to this customer refNo
     $properties = $propertyManager->fetchAllProperties($refNo)->toArray();
     $tenantnum = count($properties);
     if ($tenantnum < 2) {
         header("location: /portfolio/insurance-quote/step2");
         return;
     }
     $dsBuildingsRiskArea = new Datasource_Insurance_RiskAreas_Buildings();
     $dsContentsRiskArea = new Datasource_Insurance_RiskAreas_LandlordsContents();
     // Now iterate thru the properties
     foreach ($properties as $property) {
         // Calculate Buildings
         $riskAreaB = $dsBuildingsRiskArea->getCurrentRate($property['postcode']);
         $arrayNum = $riskAreaB - 1;
         // array sets first location to 0
         if ($riskAreaB >= 1 && $riskAreaB <= 7) {
             if ($property['tenantOccupation'] != "DSS") {
                 $buildingAreaSum[$arrayNum] += $property['buildingsSumInsured'];
             } else {
                 $buildingAreaSum[7] += $property['buildingsSumInsured'];
             }
             $total_sum_buildings += $property['buildingsSumInsured'];
         }
         if ($property['buildingsAccidentalDamage'] == "Yes" && $property['tenantOccupation'] != "DSS") {
             $buildingsAccidentalDamage += $property['buildingsSumInsured'];
         }
         if ($property['buildingsNilExcess'] == "Yes" && $property['tenantOccupation'] != "DSS") {
             $buildingsNoExcess += $property['buildingsSumInsured'];
         }
         // End Calculate Buildings
         // Calculate Contents
         if ($property['limitedContents'] != "Yes") {
             // If Contents Insurance for Unfurnished Properties was not selected
             $contentsRiskArea = $dsContentsRiskArea->getCurrentRate($property['postcode']);
             $arrayNum = $contentsRiskArea - 1;
             if ($contentsRiskArea >= 1 && $contentsRiskArea <= 5) {
                 if ($property['tenantOccupation'] != "DSS") {
                     $contentsAreaSum[$arrayNum] += $property['contentsSumInsured'];
                 } else {
                     $contentsAreaSum[5] += $property['contentsSumInsured'];
                 }
                 $total_sum_contents += $property['contentsSumInsured'];
             }
             if ($property['contentsAccidentalDamage'] == "Yes" && $property['tenantOccupation'] != "DSS") {
                 $contentsAccidentalDamage += $property['contentsSumInsured'];
             }
             if ($property['contentsNilExcess'] == "Yes" && $property['tenantOccupation'] != "DSS") {
                 $contentsNoExcess += $property['contentsSumInsured'];
             }
         } else {
             // calculate the cost of limited contents
             $limited_contents_cost += $this->_rates['limited_contents_price'];
         }
         // Count Professional Tenants
         switch ($property['tenantOccupation']) {
             case "Employed":
             case "Retired":
             case "Self Employed":
                 $professionalprop++;
                 break;
             case "DSS":
                 // If the occupier is classified as DSS and the user has opted for contents insurance
                 // then the referral display should be shown instead of the calculated premium
                 $tenantnum = $tenantnum == 1 ? 1 : $tenantnum--;
                 if ($limited_contents_cost > 0 || $total_sum_contents > 0) {
                     $bReferred = true;
                 }
                 break;
             default:
                 //$bReferred = true; // non-proffessional tenants no longer need referring
                 break;
         }
     }
     // Calculate Premiums
     /* buildings premiums ---------------------------------- */
     $buildings_premium = 0;
     for ($i = 0; $i <= 7; $i++) {
         $buildingAreaPremium[$i] = $buildingAreaSum[$i] / 100 * $this->_rates['buildingNet'][$i];
         $buildings_premium += $buildingAreaPremium[$i];
     }
     $buildingsAD_premium = $buildingsAccidentalDamage == "" ? 0 : $buildingsAccidentalDamage / 100 * $this->_rates['buildingsAD_multiplyer'];
     $buildingsNE_premium = $buildingsNoExcess == "" ? 0 : $buildingsNoExcess / 100 * $this->_rates['buildingsNE_multiplyer'];
     $buildingsEX_premium = $buildingsAD_premium + $buildingsNE_premium;
     $premium = $buildings_premium;
     $premium += $buildingsEX_premium;
     /* contents premiums ---------------------------------- */
     $contents_premium = 0;
     for ($i = 0; $i <= 4; $i++) {
         $contentsAreaPremium[$i] = $contentsAreaSum[$i] / 100 * $this->_rates['contentsNet'][$i];
         $contents_premium += $contentsAreaPremium[$i];
     }
     $contentsAD_premium = $contentsAccidentalDamage == "" ? 0 : $contentsAccidentalDamage / 100 * $this->_rates['contentsAD_multiplyer'];
     $contentsNE_premium = $contentsNoExcess == "" ? 0 : $contentsNoExcess / 100 * $this->_rates['contentsNE_multiplyer'];
     $contentsEX_premium = $contentsAD_premium + $contentsNE_premium;
     $premium += $contents_premium;
     $premium += $contentsEX_premium;
     $total_premium = $premium;
     //------------------------------------------
     // Calculate Tenancy
     //------------------------------------------
     $professionalRate = $professionalprop / $tenantnum * 100;
     $excess = 0;
     if ($professionalRate >= 85) {
         $total_premium *= $this->_factors['professionalRate']["85-100"];
     } else {
         if ($professionalRate >= 70) {
             $total_premium *= $this->_factors['professionalRate']["70-84"];
         } else {
             if ($professionalRate >= 50) {
                 $total_premium *= $this->_factors['professionalRate']["50-69"];
             } else {
                 if ($professionalRate >= 40) {
                     $excess = 500;
                     $total_premium *= $this->_factors['professionalRate']["40-49"];
                 } else {
                     if ($professionalRate >= 30) {
                         $excess = 500;
                         $total_premium *= $this->_factors['professionalRate']["30-39"];
                     } else {
                         if ($professionalRate >= 20) {
                             $excess = 750;
                             $total_premium *= $this->_factors['professionalRate']["20-29"];
                         } else {
                             if ($professionalRate >= 10) {
                                 $excess = 750;
                                 $total_premium *= $this->_factors['professionalRate']["10-19"];
                             } else {
                                 $excess = 750;
                                 $total_premium *= $this->_factors['professionalRate']["0-9"];
                             }
                         }
                     }
                 }
             }
         }
     }
     $tenantPremium = $total_premium;
     //------------------------------------------
     // Calculate Claims
     //------------------------------------------
     #$previousClaims = explode("|","|||||||||||||||");
     $claimsManager = new Manager_Insurance_Portfolio_PreviousClaims();
     $claimsAmount = $claimsManager->getClaimsTotal($refNo);
     #$claimsAmount = $previousClaims[3]+$previousClaims[7]+$previousClaims[11]+$previousClaims[15];
     if ($claimsAmount > 0 && $total_premium > 0) {
         $number_of_years = 3;
         $claimsRatio = $claimsAmount / ($total_premium * $number_of_years);
         // Covers three years
         $bReferred = true;
         $has_claims = true;
     } else {
         $claimsRatio = 0;
     }
     if ($claimsRatio == 0) {
         $claimsExperience = $total_premium * $this->_factors['claimRate']["0-0"];
     } else {
         if ($claimsRatio < 25) {
             $claimsExperience = $total_premium * $this->_factors['claimRate']["1-24"];
         } else {
             if ($claimsRatio < 50) {
                 $claimsExperience = $total_premium * $this->_factors['claimRate']["25-49"];
             } else {
                 if ($claimsRatio < 60) {
                     $claimsExperience = $total_premium * $this->_factors['claimRate']["50-59"];
                 } else {
                     if ($claimsRatio < 70) {
                         $claimsExperience = $total_premium * $this->_factors['claimRate']["60-69"];
                     } else {
                         if ($claimsRatio < 80) {
                             $claimsExperience = $total_premium * $this->_factors['claimRate']["70-79"];
                         } else {
                             if ($claimsRatio < 90) {
                                 $claimsExperience = $total_premium * $this->_factors['claimRate']["80-89"];
                             } else {
                                 if ($claimsRatio < 100) {
                                     $claimsExperience = $total_premium * $this->_factors['claimRate']["90-99"];
                                 } else {
                                     if ($claimsRatio < 120) {
                                         $claimsExperience = $total_premium * $this->_factors['claimRate']["100-119"];
                                     } else {
                                         if ($claimsRatio < 140) {
                                             $claimsExperience = $total_premium * $this->_factors['claimRate']["120-139"];
                                         } else {
                                             if ($claimsRatio < 160) {
                                                 $claimsExperience = $total_premium * $this->_factors['claimRate']["140-159"];
                                             } else {
                                                 $claimsExperience = $total_premium;
                                                 $bReferred = true;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // discounts on total sums
     if ($total_sum_buildings < 1000000) {
         // less than 1 million
         $sumInsuredDiscount = $this->_factors['sumInsuredDiscRate']["0-999999"];
     } else {
         if ($total_sum_buildings < 2000000) {
             // less than 2 million
             $sumInsuredDiscount = $this->_factors['sumInsuredDiscRate']["1000000-1999999"];
         } else {
             if ($total_sum_buildings < 3000000) {
                 // less than 3 million
                 $sumInsuredDiscount = $this->_factors['sumInsuredDiscRate']["2000000-2999999"];
             } else {
                 if ($total_sum_buildings >= 3000000) {
                     // greater than 3 million
                     $sumInsuredDiscount = $this->_factors['sumInsuredDiscRate']["3000000-0"];
                 }
             }
         }
     }
     $netPremium = $sumInsuredDiscount * $claimsExperience;
     // Net Rates
     if ($total_sum_buildings) {
         $netRateA = $total_sum_buildings * $this->_factors['netRate_multiplyer'] / 100;
         $netRateB = $netPremium;
         $netRateBmultiply = $netRateB / $total_sum_buildings * 100;
         $loadingDiscount = $netRateBmultiply / $this->_factors['netRate_multiplyer'] * 100 - 100;
     }
     //	PREMIUM SUMMARY
     //////////////////////////////////////////////////////////////////////
     // Gross Premium Details
     $gross = $total_sum_buildings * $this->_factors['gross_premium_multiplyer'] / 100;
     $grossExcIPTmultiply = $this->_factors['gross_premium_multiplyer'] * $loadingDiscount / 100 + $this->_factors['gross_premium_multiplyer'];
     $grossExcIPT = $total_sum_buildings * $grossExcIPTmultiply / 100;
     $grossIncIPT = $grossExcIPT * 105 / 100;
     $grossIPT = $grossIncIPT - $grossExcIPT;
     // Gross Premium with 45 % commission
     // Annual calculation
     $UserQuoteAnnualPremium = $netPremium * $this->_factors['commission'];
     $UserQuoteAnnualPremium += $limited_contents_cost;
     $UserQuoteAnnualIPT = $UserQuoteAnnualPremium * $this->_factors['ipt_multiplyer'];
     //Monthly Calculation
     $UserQuoteMonthlyPremium = $netPremium * $this->_factors['commission'];
     $UserQuoteMonthlyPremium += $limited_contents_cost;
     $UserQuoteMonthlyPremium = $UserQuoteMonthlyPremium / 12;
     $UserQuoteMonthlyIPT = $UserQuoteMonthlyPremium * $this->_factors['ipt_multiplyer'];
     // Insurer Disbursement details
     $IPTonGross = $UserQuoteAnnualIPT;
     $UWTotal = $netPremium + $IPTonGross;
     $netnetPremium = $netPremium * $this->_factors['netnetPremium_multiplyer'];
     $UWPremium = $netnetPremium + $IPTonGross;
     // USER QUOTE based on chosen payment method
     $frmPayment = "Monthly";
     $UserQuotePremium = $frmPayment == "Annually" ? sprintf("%01.2f", $UserQuoteAnnualPremium) : sprintf("%01.2f", $UserQuoteMonthlyPremium);
     $UserQuoteIPT = $frmPayment == "Annually" ? sprintf("%01.2f", $UserQuoteAnnualIPT) : sprintf("%01.2f", $UserQuoteMonthlyIPT);
     $UserQuoteService = $frmPayment == "Annually" ? 0.0 : $this->_factors['serviceCharge'];
     $UserQuote = $UserQuotePremium + $UserQuoteIPT + $UserQuoteService;
     $premiums = array();
     $premiums['UserQuoteAnnualPremium'] = round($UserQuoteAnnualPremium, 2);
     $premiums['UserQuoteMonthlyPremium'] = round($UserQuoteMonthlyPremium, 2);
     $premiums['UserQuoteAnnualIPT'] = round($UserQuoteAnnualIPT, 2);
     $premiums['UserQuoteMonthlyIPT'] = round($UserQuoteMonthlyIPT, 2);
     $premiums['UserQuoteAnnualPremiumInc'] = $premiums['UserQuoteAnnualPremium'] + $premiums['UserQuoteAnnualIPT'];
     $premiums['UserQuoteMonthlyPremiumInc'] = $premiums['UserQuoteMonthlyPremium'] + $premiums['UserQuoteMonthlyIPT'] + $this->_factors['serviceCharge'];
     $returnArray = array('premiums' => $premiums, 'referred' => $bReferred, 'has_claims' => $has_claims, 'buildingAreaSum' => $buildingAreaSum, 'buildings_premium' => $buildings_premium, 'buildingAreaPremium' => $buildingAreaPremium, 'contentsAreaSum' => $contentsAreaSum, 'contentsAreaPremium' => $contentsAreaPremium, 'contents_premium' => $contents_premium, 'tenantnum' => $tenantnum, 'professionalprop' => $professionalprop, 'professionalRate' => $professionalRate, 'total_sum_buildings' => $total_sum_buildings, 'total_sum_contents' => $total_sum_contents, 'limited_contents_cost' => $limited_contents_cost, 'buildingsAccidentalDamage' => $buildingsAccidentalDamage, 'buildingsNoExcess' => $buildingsNoExcess, 'contentsAccidentalDamage' => $contentsAccidentalDamage, 'contentsNoExcess' => $contentsNoExcess, 'gross' => $gross, 'grossExcIPTmultiply' => $grossExcIPTmultiply, 'grossExcIPT' => $grossExcIPT, 'grossIncIPT' => $grossIncIPT, 'grossIPT' => $grossIPT, 'premium' => $premium, 'excess' => $excess, 'sumInsuredDiscount' => $sumInsuredDiscount, 'UserQuoteAnnualPremium' => $UserQuoteAnnualPremium, 'UserQuoteAnnualIPT' => $UserQuoteAnnualIPT, 'UserQuoteMonthlyPremium' => $UserQuoteMonthlyPremium, 'UserQuoteMonthlyIPT' => $UserQuoteMonthlyIPT, 'IPTonGross' => $IPTonGross, 'UWTotal' => $UWTotal, 'netnetPremium' => $netnetPremium, 'UWPremium' => $UWPremium, 'netRateA' => $netRateA, 'netRateB' => $netRateB, 'netRateBmultiply' => $netRateBmultiply, 'loadingDiscount' => $loadingDiscount, 'claimsExperience' => $claimsExperience, 'professionalRate' => $professionalRate, 'tenantPremium' => $tenantPremium, 'claimsAmount' => $claimsAmount, 'claimsRatio' => $claimsRatio, 'buildingsAD_premium' => $buildingsAD_premium, 'buildingsNE_premium' => $buildingsNE_premium, 'buildingsEX_premium' => $buildingsEX_premium, 'contentsAD_premium' => $contentsAD_premium, 'contentsNE_premium' => $contentsNE_premium, 'contentsEX_premium' => $contentsEX_premium, 'UserQuotePremium' => $UserQuotePremium, 'UserQuoteIPT' => $UserQuoteIPT, 'UserQuoteService' => $UserQuoteService, 'UserQuote' => $UserQuote, 'Additional' => $pageSession->step3, 'Dpa' => $pageSession->step1, 'agentschemeno' => $session->referrer, 'csuid' => $session->csu, 'origin' => $session->origin);
     return $returnArray;
 }
 /**
  * remove Previous claims add previous claims to the previous claims table (?)
  * @param POST vars
  * @return JSON Encoded html
  * @author John Burrin
  * @since 1.3
  * http://homelet.centos5.dev/json/portfolio-portfolio/remove-previous-claim
  */
 public function removePreviousClaimAction()
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     $customerReferenceNumber = $pageSession->CustomerRefNo;
     $ajaxForm = new Form_PortfolioInsuranceQuote_claimsDialog();
     $return = array();
     $request = $this->getRequest();
     $postdata = $request->getPost();
     $return['success'] = false;
     if ($ajaxForm->isValid($postdata)) {
         $claimsManager = new Manager_Insurance_Portfolio_PreviousClaims();
         $claimsManager->removeClaim($postdata['id']);
         // Do the update stuffs
         // Get the properties to shove back into the page
         $claimsArray = $claimsManager->fetchAllClaims($customerReferenceNumber);
         if ($claimsArray->count() > 0) {
             $return['html'] = $this->view->partialLoop('portfolio-insurance-quote/partials/claims-list.phtml', $claimsArray);
         } else {
             $return['html'] = '<em>None</em>';
         }
         $return['success'] = true;
     } else {
         // TODO: This shouldn't do this should it?
         Zend_Debug::dump($ajaxForm->getMessages());
     }
     echo Zend_Json::encode($return);
 }