/** * 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; }
/** * 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); }