/**
  * Update account and account owners signatures
  *
  * @param ClientAccount $account
  * @param string $type
  * @return \Wealthbot\SignatureBundle\Entity\DocumentSignature
  */
 public function updateAccountSignatureStatusByAccountAndType(ClientAccount $account, $type)
 {
     $signature = $this->signatureManager->findActiveDocumentSignatureBySourceIdAndType($account->getId(), $type);
     if ($signature) {
         $this->updateDocumentSignaturesStatusByEnvelopeId($signature->getDocusignEnvelopeId(), array($signature));
     }
     return $signature;
 }
Example #2
0
 /**
  * Create new workflow
  *
  * @param User $client
  * @param WorkflowableInterface $object
  * @param integer $type
  * @param DocumentSignature|DocumentSignature[] $signatures
  * @param array $objectIds
  * @return Workflow|null
  * @throws \InvalidArgumentException
  */
 public function createWorkflow(User $client, WorkflowableInterface $object, $type, $signatures = null, array $objectIds = null)
 {
     $class = $this->om->getClassMetadata(get_class($object))->getName();
     $workflow = new Workflow();
     $workflow->setClient($client);
     $workflow->setType($type);
     $workflow->setObjectType($class);
     $workflow->setMessageCode($object->getWorkflowMessageCode());
     if (method_exists($object, 'getId') && null !== $object->getId()) {
         $workflow->setObjectId($object->getId());
     }
     if ($type == Workflow::TYPE_PAPERWORK) {
         $documentSignatures = array();
         if (null === $signatures && $object instanceof SignableInterface) {
             $signature = $this->signatureManager->findDocumentSignatureBySource($object);
             if ($signature) {
                 $documentSignatures[] = $signature;
             }
         } else {
             if (is_object($signatures)) {
                 if (!$signatures instanceof DocumentSignature) {
                     throw new \InvalidArgumentException('Parameter signatures must be array or instance of DocumentSignature.');
                 }
                 $documentSignatures[] = $signatures;
             } elseif (is_array($signatures)) {
                 $documentSignatures = $signatures;
             }
         }
         if (count($documentSignatures)) {
             foreach ($documentSignatures as $documentSignature) {
                 $workflow->addDocumentSignature($documentSignature);
             }
             $this->updateClientStatusByDocumentSignatures($workflow);
         }
         if ($object instanceof ClientPortfolio) {
             $this->updateClientStatusByClientPortfolio($workflow, $object);
         }
     } elseif ($object instanceof SystemAccount) {
         $this->updateClientStatusBySystemAccount($workflow, $object);
     }
     if (null !== $objectIds) {
         $workflow->setObjectIds($objectIds);
     }
     if ($object instanceof PaymentWorkflowableInterface) {
         $workflow->setAmount($object->getWorkflowAmount());
     }
     $this->om->persist($workflow);
     $this->om->flush();
     return $workflow;
 }
Example #3
0
 /**
  * Get envelope documents and save them for signatures
  *
  * @param string $envelopeId
  * @param DocumentSignature[] $signatures  must be sorted in the order of creation
  * @throws \RuntimeException
  */
 private function getDocusignDocumentByEnvelopeIdAndSignatures($envelopeId, array $signatures)
 {
     $documents = $this->api->getEnvelopeDocuments($envelopeId);
     if ($documents && count($documents->envelopeDocuments)) {
         foreach ($signatures as $index => $signature) {
             if ($signature->getDocument() && $signature->getDocument()->getFilename()) {
                 continue;
             }
             if (!isset($documents->envelopeDocuments[$index])) {
                 throw new \RuntimeException(sprintf('Document for signature with index: %s does not exist.', $index));
             }
             $documentInfo = $documents->envelopeDocuments[$index];
             $documentBytes = $this->api->getEnvelopeDocument($envelopeId, $documentInfo->documentId);
             $source = $this->signatureManager->getSourceObject($signature);
             $clientAccount = $source->getClientAccount();
             $client = $clientAccount->getClient();
             $filename = $client->getFirstName() . '_' . $client->getMiddleName() . '_' . $client->getLastName() . '_Account' . $clientAccount->getId() . '_' . $documentInfo->name;
             $path = $this->container->getParameter('uploads_dir') . '/tmp';
             if (!is_dir($path)) {
                 mkdir($path);
             }
             $path .= '/' . $filename;
             $fp = fopen($path, 'w+');
             fwrite($fp, $documentBytes);
             fclose($fp);
             $file = new File($path);
             $document = $signature->getDocument();
             $document->setOwner($client->getRia());
             $document->setFile($file);
             $document->setOriginalName($documentInfo->name);
             $document->setType(Document::TYPE_APPLICATION);
             $document->upload();
             if (!$client->getUserDocuments()->contains($document)) {
                 $client->addUserDocument($document);
             }
             $this->em->persist($document);
         }
         $this->em->persist($client);
         $this->em->flush();
         //$this->createWorkflow($signature, $document);
     }
 }
 /**
  * Get document signature activity
  *
  * @param DocumentSignature $signature
  * @return string
  */
 public function getDocumentSignatureActivity(DocumentSignature $signature)
 {
     return $this->manager->getActivity($signature);
 }