Пример #1
0
 /**
  * Helper function for generating claims history summary HTML fragment
  *
  * @return string
  */
 public function yourClaims()
 {
     $output = '';
     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
     // Invoke previous claims manager
     $claimsManager = new Manager_Insurance_PreviousClaims();
     // Fetch all claims
     $claimData = $claimsManager->getPreviousClaims($pageSession->CustomerRefNo);
     // Fetch claim descriptions
     $claimDescriptionsObj = $claimsManager->getPreviousClaimTypes(Model_Insurance_ProductNames::TENANTCONTENTSPLUS);
     // Transform object array into a somewhat more usefully indexed descriptions array
     $claimDescriptions = array();
     foreach ($claimDescriptionsObj as $claimDescriptionObj) {
         $claimDescriptions[$claimDescriptionObj->getClaimTypeID()] = $claimDescriptionObj->getClaimTypeText();
     }
     if (count($claimData) > 0) {
         $output .= '<table class="table table-bordered table-condensed table-possessions">';
         // Container with indent
         $output .= "  <tr>\n";
         // Line container with bottom edge
         $output .= "    <th>Claims you have added to your policy</th>\n";
         $output .= "    <th>Value</th>\n";
         $output .= "    <th></th>\n";
         $output .= "  </tr>\n";
         foreach ($claimData as $key => $claim) {
             $output .= "  <tr>\n";
             // Line container with bottom edge
             $output .= "    <td class=\"description\">" . $claimDescriptions[$claim->getClaimType()->getClaimTypeID()] . '<br />Date: ' . $claim->getClaimMonth() . '/' . $claim->getClaimYear() . "</td>\n";
             $output .= "    <td class=\"price\">&pound;" . number_format($claim->getClaimValue()->getValue()) . "</td>\n";
             $output .= "    <td><a id=\"removeClaim{$key}\" href=\"#\" onclick=\"removeClaimClick({$key}); return false;\" class=\"tertiary-colour\">Remove claim</a></td>\n";
             $output .= "  </tr>\n";
         }
         $output .= '</table>';
     }
     return $output;
 }
Пример #2
0
 /**
  * Validate and handle adding and removing claims via AJAX
  *
  * @return void
  */
 public function claimAction()
 {
     $output = array();
     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
     $ajaxForm = new TenantsInsuranceQuote_Form_Json_Claims();
     $request = $this->getRequest();
     $postdata = $request->getPost();
     $ajaxForm->populate($postdata);
     if ($ajaxForm->isValid($postdata)) {
         // Invoke previous claims manager
         $claimsManager = new Manager_Insurance_PreviousClaims();
         // Check if a new claim's details are being added
         if (isset($postdata['addClaim']) && $postdata['addClaim'] == 1) {
             $cleanData = $ajaxForm->getValues();
             $claim = new Model_Insurance_PreviousClaim();
             $claim->setRefno($pageSession->CustomerRefNo);
             $claimType = new Model_Insurance_PreviousClaimType();
             $claimType->setClaimTypeID($cleanData['subform_importantinformation']['claim_type']);
             $claim->setClaimType($claimType);
             $claim->setClaimMonth($cleanData['subform_importantinformation']['claim_month']);
             $claim->setClaimYear($cleanData['subform_importantinformation']['claim_year']);
             $claim->setClaimValue(new Zend_Currency(array('value' => $cleanData['subform_importantinformation']['claim_value'])));
             $claimsManager->insertPreviousClaim($claim);
         }
         // Check if an existing claim's details are being removed
         if (isset($postdata['removeClaim']) && $postdata['removeClaim'] == 1) {
             // First fetch all claims
             $allClaims = $claimsManager->getPreviousClaims($pageSession->CustomerRefNo);
             // Now iterate through and remove the selected index
             $t_allClaims = array();
             foreach ($allClaims as $key => $claim) {
                 if ($key != $postdata['claimNum']) {
                     $t_allClaims[] = $claim;
                 }
             }
             // Delete all previous claims and replace with new list
             $claimsManager->removeAllPreviousClaims($pageSession->CustomerRefNo);
             $claimsManager->insertPreviousClaims($t_allClaims);
         }
     } else {
     }
     $errorMessages = $ajaxForm->getMessagesFlattened();
     $output['errorJs'] = $errorMessages;
     $output['errorCount'] = count($errorMessages);
     $output['errorHtml'] = $this->view->partial('partials/error-list.phtml', array('errors' => $errorMessages));
     $output['html'] = $this->view->getHelper('yourClaims')->yourClaims();
     echo Zend_Json::encode($output);
 }
Пример #3
0
 public function removePreviousClaimAction()
 {
     $request = $this->getRequest();
     $postData = $request->getPost();
     $refNo = $postData['refNo'];
     $month = $postData['month'];
     $year = $postData['year'];
     $value = $postData['value'];
     $typeId = $postData['typeId'];
     //Remove the previous claim identified by the id
     if (!empty($refNo)) {
         $claimsManager = new Manager_Insurance_PreviousClaims();
         //Build a PreviousClaim object to pass to the PreviousClaims manager
         //to delete.
         $previousClaim = new Model_Insurance_PreviousClaim();
         $previousClaim->setRefno($refNo);
         $previousClaim->setClaimMonth($month);
         $previousClaim->setClaimYear($year);
         $value = new Zend_Currency(array('value' => $value, 'precision' => 2));
         $previousClaim->setClaimValue($value);
         $previousClaimTypes = $claimsManager->getPreviousClaimTypes();
         foreach ($previousClaimTypes as $claimType) {
             if ($typeId == $claimType->getClaimTypeID()) {
                 $previousClaim->setClaimType($claimType);
                 break;
             }
         }
         //Finally, remove the previous claim.
         $claimsManager->removePreviousClaim($previousClaim);
     }
     $claimsArray = $claimsManager->getPreviousClaims($refNo);
     $model = array();
     if (!empty($claimsArray)) {
         foreach ($claimsArray as $claim) {
             $model[] = array('claim' => $claim);
         }
     }
     $return = array();
     $return['html'] = $this->view->partialLoop('partials/claims-list.phtml', $model);
     $return['success'] = true;
     echo Zend_Json::encode($return);
 }
 /**
  * Handles the previous claims pop-up on the Underwriting questions form.
  */
 public function claimsDialogAction()
 {
     $claimsDialogForm = new LandlordsInsuranceQuote_Form_ClaimsDialog();
     // This controller is called within a popup (facebox style) so doesn't require a layout file
     $this->_helper->getHelper('layout')->disableLayout();
     $this->view->form = $claimsDialogForm;
     //Get the customer reference number and use this to retrieve all previous claims.
     $session = new Zend_Session_Namespace('landlords_insurance_quote');
     $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID);
     $customerReferenceNumber = $quoteManager->getLegacyCustomerReference();
     $claimsManager = new Manager_Insurance_PreviousClaims();
     $claimsArray = $claimsManager->getPreviousClaims($customerReferenceNumber);
     //Display the previous claims on the dialog.
     $model = array();
     if (!empty($claimsArray)) {
         foreach ($claimsArray as $claim) {
             $model[] = array('claim' => $claim);
         }
     }
     $this->view->claimsList = $model;
 }
 public function isValid($formData)
 {
     //We only need additional information if some questions have been answered wrongly.
     $additionalInfoIsRequired = false;
     if (!empty($formData['declaration2']) && $formData['declaration2'] == 'no') {
         $additionalInfoIsRequired = true;
     } else {
         if (!empty($formData['declaration2b']) && $formData['declaration2b'] == 'no') {
             $additionalInfoIsRequired = true;
         } else {
             if (!empty($formData['declaration2c']) && $formData['declaration2c'] == 'yes') {
                 $additionalInfoIsRequired = true;
             } else {
                 if (!empty($formData['declaration2d']) && $formData['declaration2d'] == 'yes') {
                     $additionalInfoIsRequired = true;
                 } else {
                     if (!empty($formData['declaration3']) && $formData['declaration3'] == 'no') {
                         $additionalInfoIsRequired = true;
                     } else {
                         if (!empty($formData['declaration4']) && $formData['declaration4'] == 'no') {
                             $additionalInfoIsRequired = true;
                         } else {
                             if (!empty($formData['declaration6']) && $formData['declaration6'] == 'yes') {
                                 $additionalInfoIsRequired = true;
                             } else {
                                 if (!empty($formData['declaration8']) && $formData['declaration8'] == 'yes') {
                                     $additionalInfoIsRequired = true;
                                 } else {
                                     if (!empty($formData['declaration9']) && $formData['declaration9'] == 'yes') {
                                         $additionalInfoIsRequired = true;
                                     } else {
                                         if (!empty($formData['declaration10']) && $formData['declaration10'] == 'no') {
                                             $additionalInfoIsRequired = true;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($additionalInfoIsRequired) {
         $this->getElement('additional_information')->setRequired(true);
     } else {
         $this->getElement('additional_information')->setRequired(false);
     }
     //Superclass validations
     $returnVal = parent::isValid($formData);
     //Some compound processing. If the user has advised they have previous claims, then they must provide
     //details of these. Ensure this is the case.
     $session = new Zend_Session_Namespace('landlords_insurance_quote');
     $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($session->quoteID);
     $customerReferenceNumber = $quoteManager->getLegacyCustomerReference();
     $policyNumber = $quoteManager->getLegacyID();
     if (!empty($formData['declaration7'])) {
         if ($formData['declaration7'] == 'yes') {
             //One or more previous claims must exist.
             $claimsManager = new Manager_Insurance_PreviousClaims();
             $previousClaims = $claimsManager->getPreviousClaims($customerReferenceNumber);
             if (empty($previousClaims)) {
                 //Record error.
                 $this->declaration7->addError('Please provide details of previous claims');
                 $returnVal = false;
             }
         }
     }
     //If the user advised they have bank interest, then they must provide details of these.
     //Ensure this is the case.
     if (!empty($formData['declaration11'])) {
         if ($formData['declaration11'] == 'yes') {
             //One or more bank interests.
             $bankInterestManager = new Manager_Insurance_LegacyBankInterest();
             $bankInterestArray = $bankInterestManager->getAllInterests($policyNumber, $customerReferenceNumber);
             if (empty($bankInterestArray)) {
                 //Record error.
                 $this->declaration11->addError('Please provide details of bank interest');
                 $returnVal = false;
             }
         }
     }
     return $returnVal;
 }