/**
  * Action for the Confirmation of a Successful Credit card Payment
  *
  * @return void
  * @todo The company name need to be fetched from branding
  *
  */
 public function ddconfirmationAction()
 {
     $policyNumber = $this->getRequest()->getParam("pn") ? $this->getRequest()->getParam("pn") : $this->_policyNumber;
     $quoteNumber = str_replace('P', 'Q', $policyNumber);
     // Check to see if this quote has already been converted to a policy - if it has we don't want to do any of the below
     $policyManager = new Manager_Insurance_LegacyPolicy();
     $policy = $policyManager->getByPolicyNumber($policyNumber);
     if (is_null($policy)) {
         $refNo = $this->_customerReferenceNumber;
         $params = Zend_Registry::get('params');
         // Set up the validators and filters
         $filters = array();
         $validators = array();
         $request = $this->getRequest();
         $input = new Zend_Filter_Input($filters, $validators, $request->getParams());
         if ($input->isValid()) {
             // Update Pay Status
             $quote = new Manager_Insurance_TenantsContentsPlus_Quote(null, null, $this->_policyNumber);
             $quoteObject = new Model_Insurance_LegacyQuote();
             $quoteObject = $quote->getQuoteObject();
             $quoteObject->startTime = date("h:j:s");
             $quoteObject->payStatus = "UpToDate";
             $quote->update($quoteObject);
             /*$quoteObject->startTime = date("h:j:s");
             		$quoteObject->payStatus = "UpToDate";
             		$quote->update($quoteObject);*/
             $schedule = new Manager_Insurance_Schedule();
             $schedule->save($refNo, $quote);
             $quoteToPolicyManager = new Manager_Insurance_TenantsContentsPlus_QuoteToPolicy();
             $quoteToPolicyManager->changeQuoteToPolicy($quoteNumber);
             //Update the WebLeads
             $webLeadManager = new Manager_Core_WebLead();
             $webLeadSummary = $webLeadManager->getSummary($this->_webLeadSummaryId);
             $webLeadSummary->quoteNumber = $policyNumber;
             $webLeadSummary->status = Model_Core_WebLeadStatus::COMPLETE;
             $webLeadSummary->completedTime = $this->_offsetDate();
             $webLeadManager->updateSummary($webLeadSummary);
             $agentSchemeNumber = Manager_Core_Agent::filterAsn($quote->getAgentSchemeNumber());
             // Transaction is complete unset the Session to prevent navigation to other steps again
             Zend_Session::namespaceUnset('tenants_insurance_quote');
             // Document management stuff, only runs on first conversion of quote -> policy
             $documentManager = new Manager_Insurance_Document();
             $documentManager->createAndPostDocument($policyNumber, Model_Insurance_TenantsContentsPlus_DocumentTypes::NEW_POLICY_DOCS);
             $documentArray = $documentManager->getDocuments($policyNumber, Model_Insurance_TenantsContentsPlus_DocumentTypes::NEW_POLICY_DOCS);
             $firstDocument = $documentArray[0];
             // Put document number in the view, on any later page loads to the same URL this part will not be available for better security
             if (!is_null($firstDocument)) {
                 $this->view->documentNumber = $firstDocument->request_hash;
             }
         }
     } else {
         $agentSchemeNumber = Manager_Core_Agent::filterAsn($policy->agentSchemeNumber);
     }
     $disbursement = new Manager_Core_Disbursement();
     $disbursement->createTermImage($policyNumber);
     $params = Zend_Registry::get('params');
     // Put domain name of the legacy server in the view
     $this->view->domain = $params->homelet->legacyDomain;
     $whiteLabelManager = new Manager_Core_WhiteLabel();
     $whiteLabelData = new Model_Core_WhiteLabel();
     $whiteLabelData = $whiteLabelManager->fetchByAgentSchemeNumber($agentSchemeNumber);
     $this->view->companyName = $whiteLabelData->companyName;
     $this->view->companyName = "HomeLet";
     // Put Policy number in the view
     $this->view->policyNumber = $policyNumber;
     $this->view->openingTimes = $params->cms->openingtimes->insurance->tenants;
     // Extra values passed into view for Google Analytics commerce tracking:
     if (is_null($policy)) {
         $policy = $policyManager->getByPolicyNumber($policyNumber);
     }
     $this->view->policy = $policy;
     // Policy object
     // todo: Fix disgusting way of passing additional data through two chained views.
     $extraVars = new stdClass();
     $monthMultiplier = strtolower($policy->paySchedule) == 'monthly' ? 12 : 1;
     $extraVars->quoteAnnual = $policy->quote * $monthMultiplier;
     $extraVars->iptAnnual = $policy->ipt * $monthMultiplier;
     $this->view->extraVars = $extraVars;
 }
 /**
  *Step 5 Action
  * @param
  * @return
  * @author John Burrin
  * @since
  */
 public function step5Action()
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     $pageForm = new Form_PortfolioInsuranceQuote_Step5();
     if ($this->_formStepCommonPopulate($pageForm, 5)) {
         $quoteManager = new Manager_Insurance_Portfolio_Quote();
         $quoteData = $quoteManager->quote($this->_customerReferenceNumber);
         $this->_doMail($quoteData);
         // Want to capture all the data and shove it all the old tables (Muntify)
         $quoteManager->convertLegacy($this->_customerReferenceNumber);
         //Update the WebLead summary and create a STEP4 blob.
         $webLeadManager = new Manager_Core_WebLead();
         $webLeadSummary = $webLeadManager->getSummary($pageSession->webLeadSummaryId);
         $webLeadSummary->lastUpdatedTime = $this->_offsetDate();
         $webLeadManager->updateSummary($webLeadSummary);
         //Determine if a new STEP5 blob needs to be created, or an existing one retrieved.
         if ($webLeadManager->getBlobExists($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP5)) {
             $webLeadBlob = $webLeadManager->getBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP5);
         } else {
             $webLeadBlob = $webLeadManager->createNewBlob($webLeadSummary->webLeadSummaryId, Model_Core_WebLeadStep::STEP5);
         }
         //Update the blob and store
         $webLeadBlob->blob = Zend_Json::encode($_POST);
         $webLeadBlob->blobChecksum = crc32($webLeadBlob->blob);
         $webLeadManager->updateBlob($webLeadBlob);
         if ($quoteData['referred'] == true) {
             $this->_helper->redirector->gotoUrl('/portfolio/insurance-quote/referred');
         } else {
             $this->_helper->redirector->gotoUrl('/portfolio/insurance-quote/complete');
         }
         exit;
     }
 }
 /**
  * Action for the Confirmation of a successful direct debit Payment
  *
  * @return void
  */
 public function ddconfirmationAction()
 {
     $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
     $policyNumber = $this->getRequest()->getParam('pn');
     $quoteNumber = str_replace('Q', 'P', $policyNumber);
     // Check to see if this quote has already been converted to a policy - if it has we don't want to do any of the below
     $policyManager = new Manager_Insurance_LegacyPolicy();
     $policy = $policyManager->getByPolicyNumber($policyNumber);
     // My HomeLet registration/login form and processing
     $this->view->form = $this->registrationFormProcess($policyNumber);
     // Set the completed status of the quote to true
     $this->view->completed = true;
     if (is_null($policy)) {
         $refNo = $this->_customerReferenceNumber;
         // Set up the validators and filters
         $filters = array();
         $validators = array();
         $request = $this->getRequest();
         $input = new Zend_Filter_Input($filters, $validators, $request->getParams());
         if ($input->isValid()) {
             // Update Pay Status
             $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($this->_quoteID);
             $quoteNumber = $quoteManager->getPolicyNumber();
             $schedule = new Manager_Insurance_Schedule();
             $schedule->save($refNo, $quoteManager);
             $quoteToPolicyManager = new Manager_Insurance_LandlordsPlus_QuoteToPolicy();
             $quoteToPolicyManager->changeQuoteToPolicy($quoteNumber);
             //Update the WebLeads
             $session = new Zend_Session_Namespace('landlords_insurance_quote');
             $webLeadManager = new Manager_Core_WebLead();
             $webLeadSummary = $webLeadManager->getSummary($session->webLeadSummaryId);
             $webLeadSummary->quoteNumber = $policyNumber;
             $webLeadSummary->status = Model_Core_WebLeadStatus::COMPLETE;
             $webLeadSummary->completedTime = $this->_offsetDate();
             $webLeadManager->updateSummary($webLeadSummary);
             $agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
             // Document management stuff, only runs on first conversion of quote -> policy
             $documentManager = new Manager_Insurance_Document();
             $documentManager->createAndPostDocument($policyNumber, Model_Insurance_LandlordsPlus_DocumentTypes::NEW_POLICY_DOCS);
             $documentArray = $documentManager->getDocuments($policyNumber, Model_Insurance_LandlordsPlus_DocumentTypes::NEW_POLICY_DOCS);
             $firstDocument = $documentArray[0];
             // Put the document number into session so that it can be displayed from this action and later in
             // the registration confirmation action
             if (!is_null($firstDocument)) {
                 $pageSession->documentNumber = $firstDocument->request_hash;
             }
         }
         // If a document number exists from before, pass it into the view
         if (isset($pageSession->documentNumber)) {
             $this->view->documentNumber = $pageSession->documentNumber;
         }
         // Extra values passed into view for Google Analytics commerce tracking:
         if (is_null($policy)) {
             $policy = $policyManager->getByPolicyNumber($policyNumber);
         }
         $this->view->policy = $policy;
         // Policy object
         // todo: Fix disgusting way of passing additional data through two chained views.
         $extraVars = new stdClass();
         $monthMultiplier = strtolower($policy->paySchedule) == 'monthly' ? 12 : 1;
         $extraVars->quoteAnnual = $policy->quote * $monthMultiplier;
         $extraVars->iptAnnual = $policy->ipt * $monthMultiplier;
         $this->view->extraVars = $extraVars;
     } else {
         $agentSchemeNumber = Manager_Core_Agent::filterAsn($policy->agentSchemeNumber);
     }
     // Put Policy number in the view
     $this->view->policyNumber = $policyNumber;
     // Fetch the HOMELETUK.COM legacy domain
     // Please don't change this again it is SUPPOSED to be the old crappy php4 box
     // Put domain name of the legacy server in the view
     $this->view->domain = $this->_params->homelet->legacyDomain;
     $whiteLabelManager = new Manager_Core_WhiteLabel();
     $whiteLabelData = new Model_Core_WhiteLabel();
     $whiteLabelData = $whiteLabelManager->fetchByAgentSchemeNumber($agentSchemeNumber);
     $this->view->companyName = $whiteLabelData->companyName;
     $this->view->companyName = "HomeLet";
 }