/**
  * Initialize the step 4 form
  *
  * @return void
  */
 public function step4Action()
 {
     $pageForm = new Connect_Form_RentGuaranteeClaims_Step4();
     $this->view->headScript()->appendScript('var ajaxValidate = true; var ajaxValidatePage = 4;');
     $supportManager = new Manager_Insurance_RentGuaranteeClaim_SupportingDocument($this->_claimReferenceNumber, $this->_agentSchemeNumber);
     // Prepare upload directories
     $supportManager->prepareUploadDirs();
     if ($this->_request->isPost()) {
         // We need to validate the data
         $this->_formStepAgentPopulate($pageForm);
         $valid = $this->_formStepCommonValidate($pageForm, 4);
         if ($valid) {
             $request = $this->getRequest();
             $mode = $request->getParam('hd_type');
             $agentName = $request->getParam('doc_confirmation_agent_name');
             $landlordPropertyProprietor = $request->getParam('landlord_proprietor_of_property');
             $authConfirmation = $request->getParam('chk_confirm');
             $decConfirmation = $request->getParam('dec1_confirm');
             //update confirmation agent name
             $claimManager = new Manager_Insurance_RentGuaranteeClaim_Claim($this->_claimReferenceNumber);
             $claim = $claimManager->getClaim($this->_claimReferenceNumber, $this->_agentSchemeNumber);
             $claim->setDocConfirmationAgentName($agentName);
             $claim->setLandlordIsPropertyProprietor($landlordPropertyProprietor);
             $claim->setAuthorityConfirmed($authConfirmation);
             $claim->setDeclarationConfirmed($decConfirmation);
             if ($mode == 2) {
                 // submit claim details to KEYHOUSE DB
                 // Mark claim as at stage 1 (claim submitted but not transferred)
                 $claim->setDataComplete(1);
                 $claimManager->updateClaim($claim);
                 //Submit claim data to KEYHOUSE DB
                 $keyhouseManager = new Manager_Insurance_KeyHouse_Claim();
                 $keyhouseManager->submitClaim($this->_claimReferenceNumber);
                 // Display success message
                 $this->submitclaimAction($this->_claimReferenceNumber, 's');
                 return;
             } else {
                 // Mark claim as data incomplete
                 $claim->setDataComplete(0);
                 $claimManager->updateClaim($claim);
                 $this->_helper->redirector->gotoUrl('rentguaranteeclaims/saveclaim');
             }
         }
     } else {
         $this->_formStepCommonPopulate($pageForm, 4);
     }
     // Render the page unless we have been redirected
     $this->view->form = $pageForm;
     $this->view->pageTitle = 'Online Claims - Step4 - Supporting Documents';
     $this->view->headLink()->appendStylesheet('/assets/connect/css/rentguaranteeclaims_supporting_documents.css');
     $this->view->headLink()->appendStylesheet('/assets/vendor/connect/css/jquery.fileupload-ui.css');
     //Get Available document types
     $documentTypes = $supportManager->getDocumentTypes();
     $this->view->document_types = $documentTypes;
     $this->render('step4');
 }
 /**
  * Completes the claim by reference number
  *
  * @param int $refNo rent guarantee claim reference number
  * @return bool success
  */
 public function completeClaimByRefNo($refNo)
 {
     // Completed flag
     $completed = false;
     // This returns the validity status of the claim to update MySQL
     $dsKHClaim = new Datasource_Insurance_KeyHouse_Validation();
     $khResult = $dsKHClaim->getValidatedByRefNo($refNo);
     // Get claim from MySQL
     $claimManager = new Manager_Insurance_RentGuaranteeClaim_Claim($refNo);
     $claim = $claimManager->getKHClaim($refNo);
     // Update claim in MySQL with validity status from SQL Server
     // If validity status has some value
     if (is_object($claim) && $khResult['validity_status'] != '') {
         // Success
         $claim->setSubmittedToKeyHouse(1);
         // Update claim status
         $claimManager->updateClaim($claim);
         // Update validation table
         $validator = new Manager_Insurance_RentGuaranteeClaim_KeyhouseValidation();
         // Insert claim result
         if ($khResult['validity_status'] == "YES") {
             // Send submission confirmation email to agent
             $claimManager->sendConfirmationEmail($refNo, $khResult['kcrn']);
             // Insert results
             $validator->insertData($refNo, 'Success', 'In progress', $khResult['kcrn']);
         } else {
             // Insert results
             $validator->insertData($refNo, 'Failure', $khResult['reason'], 'None');
         }
         // We have success
         $completed = true;
         //}
     }
     // Done.
     return $completed;
 }