/** * Send a document request for a new document immediately. For use when a document is required immediately (e.g. web front end) * * @param string $policynumber Policy number for request * @param string $documentname Document type name, or template name * @param int $csuid Csu ID number * @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 name for determining the print bucket override * @param string $emailCatTarget Email category target * @param string $emailCat Email category * @param array $referencefields List of reference fields * @param array $properties List of properties * @param array $variables List of variables * @param array $policycovers List of policy covers * @param array $endorsements List of endorsements * @param array $pedalcycles List of pedalcycles * @param null $specpossessions * @param array $underwritingquestions List of underwriting questions * @param array $propertydetails List of property details * @param array $inserts List of inserts * * @throws Application_Soap_Fault * @return int */ public function createDocument($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) { list($xml, $uniquerequestid) = $this->_createAndStoreRequest($policynumber, $documentname, $csuid, $deliverymethod, $deliverytarget, $bucketname, $emailCatTarget, $emailCat, $documentDelivery, $referencefields, $properties, $variables, $policycovers, $endorsements, $pedalcycles, $specpossessions, $underwritingquestions, $propertydetails, $inserts); // Authenticate with document production server $this->_remoteServerAuthentication(); $this->httpclient->setParameterPost(array('PHPSESSID' => $this->sessionid, 'action' => 'ComposeDoc', 'CustomerCode' => $this->customercode, 'DocTypeName' => $documentname, 'VarDocData' => base64_encode($xml))); try { $response = $this->httpclient->request('POST'); } catch (Zend_Http_Client_Exception $ex) { error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage()); throw new Application_Soap_Fault('Failure calling DMS server', 'Server'); } $this->_debugRequest($this->httpclient); if (is_string($response)) { $response = Zend_Http_Response::fromString($response); } else { if (!$response instanceof Zend_Http_Response) { // Some other response returned, don't know how to process. // The request is queued, so return a fault. error_log(__FILE__ . ':' . __LINE__ . ':DMS server returned unknown response'); throw new Application_Soap_Fault('DMS server returned unknown response', 'Server'); } } try { $response = $response->getBody(); $createresponse = Zend_Json::decode($response); } catch (Exception $ex) { // Problem requesting service, report the problem back but keep the queue record error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage()); throw new Application_Soap_Fault('DMS server returned invalid response', 'Server'); } // Check login response if ($createresponse == null) { // Problem requesting document generation with DMS server error_log(__FILE__ . ':' . __LINE__ . ':Failed to request document generation from DMS server for request'); throw new Application_Soap_Fault('Failed to request document generation from DMS server for request', 'Server'); } // Check create response if ($createresponse['Status'] != 'DocComp_OK' && $createresponse['Status'] != 'DocComp_WRN') { // Problem creating document. Report failure but keep the queue record error_log(__FILE__ . ':' . __LINE__ . ':Failed to request document generation from DMS server for request: ' . $createresponse['MsgID'] . ':' . $createresponse['MsgText']); $status = new stdClass(); $status->status = 'QUEUED'; $status->uniqueRequestID = $uniquerequestid; return $status; } // Move the queue record from the queue table into the history table try { // Retrieve queue record $xmlstore = new Datasource_Insurance_Document_InsuranceRequest(); $queuerecord = $xmlstore->retrieveRequest($uniquerequestid); // Insert into history $historystore = new Datasource_Insurance_Document_InsuranceRequestHistory(); $historystore->storeQueueRecord($queuerecord); // Delete previous request $xmlstore->deleteRequest($uniquerequestid); } catch (Zend_Db_Exception $ex) { error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage()); throw new Application_Soap_Fault('Failed to move document request to history', 'Server'); } $status = new stdClass(); $status->status = 'CREATED'; $status->uniqueRequestID = $uniquerequestid; return $status; }