/** * Build the XML structure to be sent to DMS solution * * @param string $policynumber Document policy number * @param $documentname * @param $csuid * @param string $deliverymethod Delivery method required, print, email, fax or none * @param string $deliverytarget Target for delivery on email and fax based delivery methods * @param string $bucketname Bucket for determining the print bucket override * @param string $emailCatTarget Email category target * @param string $emailCat Email category * @param $documentDelivery * @param array $referencefields List of reference fields * @param array $properties List of properties * @param array $variables List of variables * @param null $policycovers * @param null $endorsements * @param null $pedalcycles * @param null $specpossessions * @param null $underwritingquestions * @param null $propertydetails * @param null $inserts * @throws Application_Soap_Fault * @internal param string $documenttype Document type name, or template name * @return array XML string, generated unique reference number */ private function _createAndStoreRequest($policynumber, $documentname, $csuid, $deliverymethod, $deliverytarget, $bucketname, $emailCatTarget, $emailCat, $documentDelivery, $referencefields, $properties = null, $variables = null, $policycovers = null, $endorsements = null, $pedalcycles = null, $specpossessions = null, $underwritingquestions = null, $propertydetails = null, $inserts = null) { $doc = new DOMDocument('1.0', 'utf-8'); $doc->preserveWhiteSpace = true; $doc->formatOutput = true; // Create root element $root = $doc->createElementNS('urn:HomeLetDMSTypes', 'hl:documentRequest'); $doc->appendChild($root); // Create basic data $uniquerequestnode = $doc->createElement('hl:uniqueRequestID'); $root->appendChild($doc->createElement('hl:documentType', $this->_encodechars($documentname))); $root->appendChild($uniquerequestnode); $root->appendChild($doc->createElement('hl:deliveryMethod', $this->_encodechars($deliverymethod))); $root->appendChild($doc->createElement('hl:deliveryTarget', $this->_encodechars($deliverytarget))); $root->appendChild($doc->createElement('hl:BucketOverride', $this->_encodechars($bucketname))); $root->appendChild($doc->createElement('hl:policyNumber', $this->_encodechars($policynumber))); $root->appendChild($doc->createElement('hl:requestTimestamp', gmdate("l dS \\of F Y h:i:s.u A"))); // Adds some entropy to the message // Add reference field agentSchemeNumber if ($referencefields !== null && is_a($referencefields, 'stdClass') && isset($referencefields->agentSchemeNumber) && $referencefields->agentSchemeNumber !== null) { # Add properties if found $root->appendChild($doc->createElement('hl:agentSchemeNumber', $this->_encodechars($referencefields->agentSchemeNumber))); } else { # Missing reference fields, fail with fault error_log(__FILE__ . ':' . __LINE__ . ':Missing reference field agentSchemeNumber in SOAP request; cannot proceed'); throw new Application_Soap_Fault('Missing reference field agentSchemeNumber', 'Server'); } // Add reference field targetPostcode if ($referencefields !== null && is_a($referencefields, 'stdClass') && isset($referencefields->targetPostcode) && $referencefields->targetPostcode !== null) { # Add properties if found $root->appendChild($doc->createElement('hl:targetPostcode', $this->_encodechars(strtoupper($referencefields->targetPostcode)))); } else { # Missing reference fields, fail with fault error_log(__FILE__ . ':' . __LINE__ . ':Missing reference field targetPostcode in SOAP request; cannot proceed'); throw new Application_Soap_Fault('Missing reference field targetPostcode', 'Server'); } // Add cat target & cat name $root->appendChild($doc->createElement('hl:emailCategoryTarget', $this->_encodechars($emailCatTarget))); $root->appendChild($doc->createElement('hl:emailCategory', $this->_encodechars($emailCat))); $root->appendChild($doc->createElement('hl:documentDelivery', $this->_encodechars($documentDelivery))); // Add list of properties $proplistnode = $root->appendChild($doc->createElement('hl:properties')); if ($properties !== null && is_a($properties, 'stdClass') && isset($properties->property) && $properties->property !== null) { foreach ($properties->property as $property) { $propnode = $proplistnode->appendChild($doc->createElement('hl:property')); $propnode->appendChild($doc->createElement('hl:name', $this->_encodechars($property->name))); $propnode->appendChild($doc->createElement('hl:value', $this->_encodechars($property->value))); } } // Add list of variables $varlistnode = $root->appendChild($doc->createElement('hl:variables')); if ($variables !== null && is_a($variables, 'stdClass') && isset($variables->variable) && $variables->variable !== null) { foreach ($variables->variable as $variable) { $varnode = $varlistnode->appendChild($doc->createElement('hl:variable')); $varnode->appendChild($doc->createElement('hl:name', $this->_encodechars($variable->name))); $varnode->appendChild($doc->createElement('hl:value', $this->_encodechars($variable->value))); } // Add specific document retrieval url if ($emailCatTarget == 'AGENT') { $config = Zend_Registry::get('params'); $connectUrl = $config->connectUrl->connectRootUrl . '/insurance/show-policy?policyno=' . $policynumber; $varnode = $varlistnode->appendChild($doc->createElement('hl:variable')); $varnode->appendChild($doc->createElement('hl:name', $this->_encodechars('customer-portal-url'))); $varnode->appendChild($doc->createElement('hl:value', $this->_encodechars($connectUrl))); } elseif ($emailCatTarget == 'LANDLORD' || $emailCatTarget == 'TENANT') { $config = Zend_Registry::get('params'); if (preg_match('/^Q/', $policynumber)) { $portalUrl = $config->homelet->domain . '/my-homelet/quotes?id=' . $policynumber; } else { $portalUrl = $config->homelet->domain . '/my-homelet/policies?id=' . $policynumber; } $varnode = $varlistnode->appendChild($doc->createElement('hl:variable')); $varnode->appendChild($doc->createElement('hl:name', $this->_encodechars('customer-portal-url'))); $varnode->appendChild($doc->createElement('hl:value', $this->_encodechars($portalUrl))); } } // policy covers $coverlistnode = $root->appendChild($doc->createElement('hl:policycovers')); if ($policycovers !== null && is_a($policycovers, 'stdClass') && isset($policycovers->policycover) && $policycovers->policycover !== null) { foreach ($policycovers->policycover as $policycover) { $covernode = $coverlistnode->appendChild($doc->createElement('hl:policycover')); $covernode->appendChild($doc->createElement('hl:cover', $this->_encodechars($policycover->cover))); $covernode->appendChild($doc->createElement('hl:suminsured', $this->_encodechars($policycover->suminsured))); $covernode->appendChild($doc->createElement('hl:excess', $this->_encodechars($policycover->excess))); $covernode->appendChild($doc->createElement('hl:monthlypremium', $this->_encodechars($policycover->monthlypremium))); $covernode->appendChild($doc->createElement('hl:annualpremium', $this->_encodechars($policycover->annualpremium))); $covernode->appendChild($doc->createElement('hl:presentation', $this->_encodechars($policycover->presentation))); $covernode->appendChild($doc->createElement('hl:bulleted', $this->_encodechars($policycover->bulleted))); } } // endorsements $endorsementlistnode = $root->appendChild($doc->createElement('hl:endorsements')); if ($endorsements !== null && is_a($endorsements, 'stdClass') && isset($endorsements->endorsement) && $endorsements->endorsement !== null) { foreach ($endorsements->endorsement as $endorsement) { $endorsementnode = $endorsementlistnode->appendChild($doc->createElement('hl:endorsement')); $endorsementnode->appendChild($doc->createElement('hl:name', 'Endorsement ' . $this->_encodechars($endorsement->endorsement))); if ($endorsement->effectivedate !== '0000-00-00') { // dont send if no effective date $endorsementnode->appendChild($doc->createElement('hl:effective-date', $this->_encodechars($endorsement->effectivedate))); } $endorsementnode->appendChild($doc->createElement('hl:excess', $this->_encodechars($endorsement->excess))); } } // pedal cycles $pedalcyclelistnode = $root->appendChild($doc->createElement('hl:pedalcycles')); if ($pedalcycles !== null && is_a($pedalcycles, 'stdClass') && isset($pedalcycles->pedalcycle) && $pedalcycles->pedalcycle !== null) { foreach ($pedalcycles->pedalcycle as $pedalcycle) { $pedalcyclenode = $pedalcyclelistnode->appendChild($doc->createElement('hl:pedalcycle')); $pedalcyclenode->appendChild($doc->createElement('hl:make', $this->_encodechars($pedalcycle->make))); $pedalcyclenode->appendChild($doc->createElement('hl:model', $this->_encodechars($pedalcycle->model))); $pedalcyclenode->appendChild($doc->createElement('hl:serialno', $this->_encodechars($pedalcycle->serialno))); $pedalcyclenode->appendChild($doc->createElement('hl:value', $this->_encodechars($pedalcycle->value))); } } // specified possessions $specpossessionslistnode = $root->appendChild($doc->createElement('hl:specpossessions')); if ($specpossessions !== null && is_a($specpossessions, 'stdClass') && isset($specpossessions->specpossession) && $specpossessions->specpossession !== null) { foreach ($specpossessions->specpossession as $specpossession) { $specpossessionsnode = $specpossessionslistnode->appendChild($doc->createElement('hl:specpossession')); $specpossessionsnode->appendChild($doc->createElement('hl:description', $this->_encodechars($specpossession->description))); $specpossessionsnode->appendChild($doc->createElement('hl:value', $this->_encodechars($specpossession->value))); $specpossessionsnode->appendChild($doc->createElement('hl:confirmed', $this->_encodechars($specpossession->confirmed))); } } // underwriting questions $underwritingquestionlistnode = $root->appendChild($doc->createElement('hl:underwritingquestions')); if ($underwritingquestions !== null && is_a($underwritingquestions, 'stdClass') && isset($underwritingquestions->underwritingquestion) && $underwritingquestions->underwritingquestion !== null) { foreach ($underwritingquestions->underwritingquestion as $underwritingquestion) { $underwritingquestionnode = $underwritingquestionlistnode->appendChild($doc->createElement('hl:underwritingquestion')); $underwritingquestionnode->appendChild($doc->createElement('hl:question', $this->_encodechars($underwritingquestion->question))); $underwritingquestionnode->appendChild($doc->createElement('hl:answer', $this->_encodechars($underwritingquestion->answer))); } } // property details $propertydetailslistnode = $root->appendChild($doc->createElement('hl:propertydetails')); if ($propertydetails !== null && is_a($propertydetails, 'stdClass') && isset($propertydetails->propertydetail) && $propertydetails->propertydetail !== null) { foreach ($propertydetails->propertydetail as $propertydetail) { $propertydetailnode = $propertydetailslistnode->appendChild($doc->createElement('hl:propertydetail')); $propertydetailnode->appendChild($doc->createElement('hl:detail', $this->_encodechars($propertydetail->detail))); $propertydetailnode->appendChild($doc->createElement('hl:value', $this->_encodechars($propertydetail->value))); } } // Add list of inserts $insertlistnode = $root->appendChild($doc->createElement('hl:inserts')); if ($inserts !== null && is_a($inserts, 'stdClass') && isset($inserts->insert) && $inserts->insert !== null) { foreach ($inserts->insert as $insert) { $insertnode = $insertlistnode->appendChild($doc->createElement('hl:insert')); $insertnode->setAttribute('name', $this->_encodechars($insert->name)); $insertnode->setAttribute('burst', $insert->burst === 1 ? 1 : 0); } } // Generate unique request hash and insert into XML $uniquerequestid = strtoupper(hash('sha256', $doc->saveXML())); // force upper case for Fastant's benefit $uniquerequestnode->appendChild(new DOMText($uniquerequestid)); $xml = $doc->saveXML(); // Get request method id $reqmethod = new Datasource_Insurance_Document_InsuranceRequestMethods(); try { $deliverymethodid = $reqmethod->getRequestMethodId($deliverymethod); } catch (Zend_Db_Exception $ex) { error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage()); throw new Application_Soap_Fault('Failed to get request method id', 'Server'); } // Get Print Bucket override id $bucket = new Datasource_Insurance_Document_InsurancePrintBuckets(); try { if ($bucketname) { $bucketid = $bucket->getBucketId($bucketname); } else { $bucketid = 0; } } catch (Zend_Db_Exception $ex) { error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage()); throw new Application_Soap_Fault('Failed to get print bucket id', 'Server'); } // Fetch the document template id $templates = new Datasource_Insurance_Document_InsuranceTemplates(); try { $templateid = $templates->getTemplateId($documentname); if (!isset($templateid)) { // Failed to fetch template id throw new Application_Soap_Fault('Failed to fetch template Id', 'Server'); } } catch (Zend_Db_Exception $ex) { error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage()); throw new Application_Soap_Fault('Failed to fetch template Id', 'Server'); } // Store the request record $xmlstore = new Datasource_Insurance_Document_InsuranceRequest(); try { if ($xmlstore->storeRequest($policynumber, $templateid, $csuid, $deliverymethodid, $deliverytarget, $uniquerequestid, $xml) === false) { // Failed to store request, return failure to client throw new Application_Soap_Fault('Failed to start document request record', 'Server'); } } catch (Zend_Db_Exception $ex) { error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage()); throw new Application_Soap_Fault('Failed to start document request record', 'Server'); } return array($xml, $uniquerequestid); }
/** * Portal document viewer for policies */ public function viewPolicyDocumentAction() { $request = $this->getRequest(); $policyNumber_encoded = $request->getParam('policy_number'); $policyNumber = base64_decode($policyNumber_encoded); $documentId = $request->getParam('document_id'); list($documentFilename, $attachments) = $this->_fetchDocument($policyNumber, $documentId); if ($documentFilename == null) { // Failed to find policy $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/policies' => 'My Policies', '/my-homelet/policies/' . $policyNumber_encoded => $policyNumber)); $this->render('view-document-not-found'); return; } $documentHistory = new Datasource_Insurance_DocumentHistory(); $document = $documentHistory->getDocument($documentId, $policyNumber); $documentTemplate = new Datasource_Insurance_Document_InsuranceTemplates(); $customers_description = $documentTemplate->getCustomersDescription($documentTemplate->getTemplateId($document->template_name)); $this->_helper->layout()->disableLayout(); $this->view->documentUrl = $documentFilename; $this->view->documentAttachments = $attachments; $this->view->document = $document; $this->view->customers_template_description = $customers_description; $this->render('view-document'); }