public function removeAdditionalAction() { $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote'); $customerReferenceNumber = $pageSession->CustomerRefNo; $return = array(); $request = $this->getRequest(); $postdata = $request->getPost(); $return['success'] = false; $interestManager = new Manager_Insurance_Portfolio_AdditionalInformation(); $interestManager->removeAdditional($postdata['id']); // Do the update stuffs // Get the properties to shove back into the page $interestArray = $interestManager->fetchAllByRefNo($customerReferenceNumber); $return['html'] = $this->view->partialLoop('portfolio-insurance-quote/partials/additional-list.phtml', $interestArray); $return['success'] = true; echo Zend_Json::encode($return); }
/** * Private function to handle form population */ private function _formStepCommonPopulate($pageForm, $stepNum) { $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote'); // First of all check that this form should be viewable and the user isn't trying to skip ahead $this->view->stepNum = $stepNum; $this->view->stepMax = $this->_stepMax; $tooFarAhead = false; if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) { $tooFarAhead = true; $lastCompleted = 1; } elseif ($stepNum > 1) { // Check to see if any pages previous to the one the user's trying to get to are incomplete $tooFarAhead = false; for ($i = 1; $i < $stepNum; $i++) { if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) { $tooFarAhead = true; $lastCompleted = $i; break; } } } if ($tooFarAhead) { // Drop user onto page that needs completing $this->_helper->redirector->gotoUrl('/portfolio/insurance-quote/step' . $lastCompleted); return false; } // Echo out some debug info if not in production mode #Application_Core_Logger::log("Policy Number : " . $this->_policyNumber); #Application_Core_Logger::log("Customer Ref No : " . $this->_customerReferenceNumber); #Application_Core_Logger::log("Referrer : " . $this->_referrer); // Only populate from DB if we are in session and have a reference number if (isset($pageSession->CustomerRefNo)) { $customerReferenceNumber = $pageSession->CustomerRefNo; $policyNumber = $pageSession->PolicyNumber; $formData = array(); // Populate $formData with data from model, if available switch ($stepNum) { case 1: // Personal Details section $customerManager = new Manager_Insurance_Portfolio_LegacyCustomer(); $customer = $customerManager->fetchByRefNo($customerReferenceNumber); $formData['title'] = $customer['title']; $formData['first_name'] = $customer['first_name']; $formData['last_name'] = $customer['last_name']; $formData['phone_number'] = $customer['telephone1']; $formData['mobile_number'] = $customer['telephone2']; $formData['email_address'] = $customer['email_address']; $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($customer['date_of_birth_at']); // Get correspondance Address data // Look up address again to populate dropdown $formData['cor_house_number_name'] = $customer['address1']; // Populate the correspondence address details $formData['cor_address_line1'] = $customer['address1']; $formData['cor_address_line2'] = $customer['address2']; $formData['cor_address_line3'] = $customer['address3']; $formData['cor_address_postcode'] = $customer['postcode']; $formData['cor_postcode'] = $customer['postcode']; $postcodeLookup = new Manager_Core_Postcode(); $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['cor_postcode']), $customer['address1']); $addressList = array('' => '--- please select ---'); $filterString = is_numeric($formData['cor_house_number_name']) ? $formData['cor_house_number_name'] . ", " : $formData['cor_house_number_name']; foreach ($addresses as $address) { $addressList[$address['id']] = $address['singleLineWithoutPostcode']; if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) { $addressID = $address['id']; } } // Add some validation $cor_address = $pageForm->getSubForm('subform_correspondenceaddress')->getElement('cor_address'); $cor_address->setMultiOptions($addressList); $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList))); $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode')); $cor_address->addValidator($validator, true); // Set the address to selected $cor_address->setValue($addressID); // Data Protection section //Extract the DPA values from the session. $dpaManager = new Manager_Core_DataProtection(Manager_Core_DataProtection::USE_SESSION); $dpaItemArray = $dpaManager->getItems(null, Model_Core_DataProtection_ItemEntityTypes::INSURANCE); #Zend_Debug::dump($dpaItemArray);die(); foreach ($dpaItemArray as $currentItem) { switch ($currentItem->constraintTypeId) { case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST: if ($currentItem->isAllowed) { $formData['dpa_phone_post'] = 0; } else { $formData['dpa_phone_post'] = 1; } break; case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL: if ($currentItem->isAllowed) { $formData['dpa_sms_email'] = 1; } else { $formData['dpa_sms_email'] = 0; } break; case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY: if ($currentItem->isAllowed) { $formData['dpa_resale'] = 1; } else { $formData['dpa_resale'] = 0; } break; } } // Initial Disclosure Agreement section // As we have a customer reference number they must have saved step 1 at some point which means // they must have agreed to the IDD section $formData['idd'] = 1; $pageForm->populate($formData); break; case 2: // Step needs to retrieve any properties that may have been added to this portfolio quote // This data is NOT form data, just display data since the ajax has added the properties to the // portfolio_properties table $propertyArray = array(); $propertyManager = new Manager_Insurance_Portfolio_Property(); $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber); $propNumb = count($propertyArray->toArray()); $formData['propNumb'] = count($propertyArray->toArray()); $this->view->propertyList = $propertyArray; $this->view->stepNum = 2; $pageForm->populate($formData); break; case 3: /* This step display the properties and displays the quote value */ $propertyArray = array(); $propertyManager = new Manager_Insurance_Portfolio_Property(); $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber); $this->view->propertyList = $propertyArray; $this->view->stepNum = 3; break; case 4: break; /* populates the remove property dialog */ /* populates the remove property dialog */ case "removePropertyDialog": $request = $this->getRequest(); $formData['propertyid'] = $request->getParam('id'); $pageForm->populate($formData); break; case "editInsuredAddress": $request = $this->getRequest(); $formData['propertyid'] = $request->getParam('id'); $propertyManager = new Manager_Insurance_Portfolio_Property(); $propertyObj = $propertyManager->getPropertyById($formData['propertyid']); $formData['ins_house_number_name'] = $propertyObj->houseNumber; $formData['ins_postcode'] = $propertyObj->postcode; // Look up address again to populate dropdown $postcodeLookup = new Manager_Core_Postcode(); $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['ins_postcode'])); $addressList = array('' => '--- please select ---'); $filterString = is_numeric($formData['ins_house_number_name']) ? $formData['ins_house_number_name'] . ", " : $formData['ins_house_number_name']; foreach ($addresses as $address) { $addressList[$address['id']] = $address['singleLineWithoutPostcode']; if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) { $addressID = $address['id']; } } // Add some validation $ins_address = $pageForm->getElement('ins_address'); $ins_address->setMultiOptions($addressList); $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList))); $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode')); $ins_address->addValidator($validator, true); // Set the address to selected $ins_address->setValue($addressID); //Zend_Debug::dump($propertyObj);die(); // Get Insured Address data // Look up address again to populate dropdown // Populate the correspondence address details $formData['ins_address_line1'] = $propertyObj->address1; $formData['ins_address_line2'] = $propertyObj->address2; $formData['ins_address_line3'] = $propertyObj->address3; $formData['ins_address_postcode'] = $propertyObj->postcode; $formData['employment_status'] = $propertyObj->tenantOccupation; if ($propertyObj->buildingsSumInsured == 0) { $formData['buildings_cover'] = ""; } else { $formData['buildings_cover'] = $propertyObj->buildingsSumInsured; $formData['comprehensive_buildings_insurance'] = 1; } if ($propertyObj->buildingsAccidentalDamage == 'Yes') { $formData['buildings_accidental_damage'] = 1; } else { $formData['buildings_accidental_damage'] = 0; } if ($propertyObj->buildingsNilExcess == 'Yes') { $formData['buildings_nil_excess'] = 1; } else { $formData['buildings_nil_excess'] = 0; } if ($propertyObj->contentsSumInsured == 0) { $formData['contents_cover'] = ""; } else { $formData['contents_cover'] = $propertyObj->contentsSumInsured; $formData['full_contents_insurance'] = 1; } if ($propertyObj->contentsAccidentalDamage == 'Yes') { $formData['contents_accidental_damage'] = 1; } else { $formData['contents_accidental_damage'] = 0; } if ($propertyObj->contentsNilExcess == 'Yes') { $formData['contents_nil_excess'] = 1; } else { $formData['contents_nil_excess'] = 0; } if ($propertyObj->limitedContents == 'Yes') { $formData['limited_contents'] = 1; } else { $formData['limited_contents'] = 0; } // Populate the form $pageForm->populate($formData); break; case "bankInterestDialog": $propertyManager = new Manager_Insurance_Portfolio_Property(); $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber); $propertyArray = $propertyObjects->toArray(); $optionList = array('' => '--- please select ---'); foreach ($propertyArray as $property) { $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode']; } // Get the subform element for property address that the bank may have interest in $propertyAddressSelect = $pageForm->getSubForm('subform_bank-details-form')->getElement('bank_property'); $propertyAddressSelect->setMultiOptions($optionList); $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList))); $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Property not in list')); $propertyAddressSelect->addValidator($validator, true); // Set the selected to 0 $propertyAddressSelect->setValue('0'); // Now fetch any bank interests we have already stored $bankInterestManager = new Manager_Insurance_Portfolio_BankInterest(); $this->view->interestList = $bankInterestManager->fetchAllInterests($customerReferenceNumber); $pageForm->populate($formData); break; case "additionalDialog": $propertyManager = new Manager_Insurance_Portfolio_Property(); $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber); $propertyArray = $propertyObjects->toArray(); $optionList = array('' => '--- please select ---'); foreach ($propertyArray as $property) { $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode']; } // Get the subform element for property address that the bank may have interest in $propertyAddressSelect = $pageForm->getElement('property'); $propertyAddressSelect->setMultiOptions($optionList); $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList))); $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Not in list')); $propertyAddressSelect->addValidator($validator, true); // Set the selected to 0 $propertyAddressSelect->setValue('0'); // Now fetch any Additionals we have already stored $manager = new Manager_Insurance_Portfolio_AdditionalInformation(); $qid = $_GET['qid']; $array = $manager->fetchAllByRefNo($customerReferenceNumber, $qid); $this->view->additionalList = $array; $pageForm->populate($formData); break; case "claimsDialog": $propertyManager = new Manager_Insurance_Portfolio_Property(); $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber); $propertyArray = $propertyObjects->toArray(); $optionList = array('' => '--- please select ---'); foreach ($propertyArray as $property) { $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode']; } // Get the form element for property address $propertyAddressSelect = $pageForm->getSubForm('subform_previous-claims-form')->getElement('claim_property'); $propertyAddressSelect->setMultiOptions($optionList); $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList))); $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Not in list')); $propertyAddressSelect->addValidator($validator, true); // Set the selected to 0 $propertyAddressSelect->setValue('0'); $claimTypeList = array('' => '--- please select ---'); $claimTypesSelect = $pageForm->getSubForm('subform_previous-claims-form')->getElement('claim_type'); $claimTypes = new Datasource_Insurance_PreviousClaimTypes(); $claimTypeObjects = $claimTypes->getPreviousClaimTypes(Model_Insurance_ProductNames::LANDLORDSPLUS); foreach ($claimTypeObjects as $ClaimType) { $claimTypeList[$ClaimType->getClaimTypeID()] = $ClaimType->getClaimTypeText(); } $claimTypesSelect->setMultiOptions($claimTypeList); $pageForm->populate($formData); // Now fetch any claims we have already stored $claimsManager = new Manager_Insurance_Portfolio_PreviousClaims(); //$array = $claimsManager->fetchAllClaims($customerReferenceNumber); $this->view->claimsList = $claimsManager->fetchAllClaims($customerReferenceNumber); $pageForm->populate($formData); break; } } $this->view->stepNum = $stepNum; $this->view->stepMax = $this->_stepMax; $tooFarAhead = false; return true; }
/** * Overridden isValid() method for pre-validation code * * @param array $formData data typically from a POST or GET request * * @return bool * */ public function isValid($formData = array()) { $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote'); // Check if this is an AJAX request, and ignore unneeded fields for validation by making them non-mandatory $additionalManager = new Manager_Insurance_Portfolio_AdditionalInformation(); if (isset($formData['declaration1']) && $formData['declaration1'] == "no") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 1); if (!$additionCheck) { $this->getElement('additionCheck1')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 1'); } } if (isset($formData['declaration2']) && $formData['declaration2'] == "no") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 2); if (!$additionCheck) { $this->getElement('additionCheck2')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 2'); } } if (isset($formData['declaration3']) && $formData['declaration3'] == "no") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 3); if (!$additionCheck) { $this->getElement('additionCheck3')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 2b'); } } if (isset($formData['declaration4']) && $formData['declaration4'] == "yes") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 4); if (!$additionCheck) { $this->getElement('additionCheck4')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 2c'); } } if (isset($formData['declaration5']) && $formData['declaration5'] == "yes") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 5); if (!$additionCheck) { $this->getElement('additionCheck5')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 2d'); } } if (isset($formData['declaration6']) && $formData['declaration6'] == "no") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 6); if (!$additionCheck) { $this->getElement('additionCheck6')->setRequired(true)->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 3'); } } if (isset($formData['declaration7']) && $formData['declaration7'] == "no") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 7); if (!$additionCheck) { $this->getElement('additionCheck7')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 4'); } } if (isset($formData['declaration8']) && $formData['declaration8'] == "yes") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 8); if (!$additionCheck) { $this->getElement('additionCheck8')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 5'); } } if (isset($formData['declaration9']) && $formData['declaration9'] == "yes") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 9); if (!$additionCheck) { $this->getElement('additionCheck9')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 6'); } } /* if(isset($formData['declaration10']) && $formData['declaration10'] == "yes"){ $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo,10); if(!$additionCheck){ $this->getElement('additionCheck10')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 7'); } } */ if (isset($formData['declaration11']) && $formData['declaration11'] == "yes") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 11); if (!$additionCheck) { $this->getElement('additionCheck11')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 8'); } } if (isset($formData['declaration12']) && $formData['declaration12'] == "yes") { $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo, 12); if (!$additionCheck) { $this->getElement('additionCheck12')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 9'); } } /* if(isset($formData['declaration13']) && $formData['declaration13'] == "yes"){ $additionCheck = $additionalManager->hasAdditions($pageSession->CustomerRefNo,13); if(!$additionCheck){ $this->getElement('additionCheck13')->setRequired(true)->addErrorMessage('You must add a additional Information for declaration question 10'); } } */ // Call original isValid() return parent::isValid($formData); }