Browse Source

alguns ajustes iniciais para alterar os icones quando o botao de enviar for precionado

1.8.1-crm-simplesip
Douglas.Strappasson 8 months ago
parent
commit
df517b39d0
  1. 15
      crm/Utils.php
  2. 16
      crm/controller/ContractController.php
  3. 70
      crm/repositories/ContractRepositories.php
  4. 31
      crm/service/ClickSignService.php
  5. 19
      crm/service/ContractService.php
  6. 7
      crm/web/contractsSelect.php
  7. 7
      crm/web/js/ApiConsumer.js
  8. 102
      crm/web/js/clickSign.js
  9. 20
      imgSite/edit.svg
  10. 19
      imgSite/error_sync.svg
  11. 16
      imgSite/sended.svg
  12. 22
      imgSite/wait.svg

15
crm/Utils.php

@ -21,12 +21,25 @@ class Utils
{ {
$link = ""; $link = "";
$imgDef = empty($imagem) ? "imgSite/send.svg" : $imagem; $imgDef = empty($imagem) ? "imgSite/send.svg" : $imagem;
$img = "<img src=\"$imgDef\" width=\"16\" height=\"16\" border=\"0\" title=\"Enviar para assinatura\">"; $img = "<img src=\"$imgDef\" width=\"16\" height=\"16\" id=\"$idContract\" border=\"0\" title=\"Enviar para assinatura\">";
$link = "<a class=\"botao-enviar\" data-id=\"$idContract\">$img</a>"; $link = "<a class=\"botao-enviar\" data-id=\"$idContract\">$img</a>";
return $link; return $link;
} }
/**
* gera o icone para envio de documentos para assinatura.
*/
public static function getLinkIconSended($imagem = "")
{
$link = "";
$imgDef = empty($imagem) ? "imgSite/sended.svg" : $imagem;
$img = "<img src=\"$imgDef\" width=\"16\" height=\"16\" border=\"0\" title=\"Enviar para assinatura\">";
$link = "<a class=\"icon-sended\">$img</a>";
return $link;
}
public static function getStringCurrentDate() public static function getStringCurrentDate()
{ {
$locale = 'pt_BR'; $locale = 'pt_BR';

16
crm/controller/ContractController.php

@ -5,7 +5,21 @@ require_once __DIR__ . '../../Utils.php';
Utils::printToLog('ContractController executando.', __LINE__); Utils::printToLog('ContractController executando.', __LINE__);
header("Content-Type:application/json"); header("Content-Type:application/json");
if (isset($_GET['id_contrato']) && $_GET['id_contrato'] != "") { if (isset($_GET["id_contrato"]) && isset($_GET["sended_status"])) {
if (ContractService::isSendedContractToClicksign($contractId)) {
Utils::printToLog("O status do contrato id: $contractId é: enviado!");
$response = array(
"sended" => "true"
);
}
Utils::printToLog("O status do contrato id: $contractId é: não enviado!");
$response = array(
"sended" => "false"
);
echo json_encode($response);
} else if (isset($_GET['id_contrato']) && $_GET['id_contrato'] != "") {
$contractId = $_GET['id_contrato']; $contractId = $_GET['id_contrato'];
Utils::printToLog("Requisicao GET recebida do salesforce com id do contrato.\nid do contrato: " . $contractId); Utils::printToLog("Requisicao GET recebida do salesforce com id do contrato.\nid do contrato: " . $contractId);
$response = mb_convert_encoding(ContractService::saveSalesforceContract($contractId), 'UTF-8', 'ISO-8859-1'); $response = mb_convert_encoding(ContractService::saveSalesforceContract($contractId), 'UTF-8', 'ISO-8859-1');

70
crm/repositories/ContractRepositories.php

@ -86,7 +86,9 @@ class ContractRepositories extends Repositories
aditional_signatorys TEXT, aditional_signatorys TEXT,
customer_signed_signas VARCHAR(30), customer_signed_signas VARCHAR(30),
company_signed_signas VARCHAR(30), company_signed_signas VARCHAR(30),
templates VARCHAR(255) templates VARCHAR(255),
sended_to_clicksign BOOLEAN,
signed_by_everyone BOOLEAN
); );
END IF; END IF;
END $$; END $$;
@ -287,4 +289,70 @@ class ContractRepositories extends Repositories
return false; return false;
} }
} }
public function setSendedToClicksign($contractId)
{
$sql = "UPDATE crm_contract
SET sended_to_clicksign = 'true'
WHERE id_contract = '{$contractId}';";
try {
$result = $this->execQueryOnDataBase($sql);
if ($result) {
Utils::printToLog("Query executada com sucesso: " . $sql, __LINE__);
return true;
}
throw new Exception("Nao foi possivel executar a query: " . $sql);
} catch (Exception $exception) {
$errorInformation = $exception->getMessage();
Utils::printToLog($errorInformation, __LINE__);
return false;
}
}
public function getSendedToClicksign($contractId)
{
$sql = "SELECT sended_to_clicksign
FROM crm_contract
WHERE id_contract = '{$contractId}';";
try {
$result = $this->execQueryOnDataBase($sql);
if ($result) {
Utils::printToLog("Query executada com sucesso: " . $sql, __LINE__);
return pg_fetch_assoc($result);
}
throw new Exception("Nao foi possivel executar a query: " . $sql);
} catch (Exception $exception) {
$errorInformation = $exception->getMessage();
Utils::printToLog($errorInformation, __LINE__);
return false;
}
}
public function getProcessingSentToClicksign($contractId)
{
$sql = "SELECT processing_send_clicksign
FROM crm_contract
WHERE id_contract = '{$contractId}';";
try {
$result = $this->execQueryOnDataBase($sql);
if ($result) {
Utils::printToLog("Query executada com sucesso: " . $sql, __LINE__);
return pg_fetch_assoc($result);
}
throw new Exception("Nao foi possivel executar a query: " . $sql);
} catch (Exception $exception) {
$errorInformation = $exception->getMessage();
Utils::printToLog($errorInformation, __LINE__);
return false;
}
}
} }

31
crm/service/ClickSignService.php

@ -5,13 +5,13 @@ require_once __DIR__ . '/TemplatesService.php';
require_once __DIR__ . '/UserService.php'; require_once __DIR__ . '/UserService.php';
require_once __DIR__ . '/../Utils.php'; require_once __DIR__ . '/../Utils.php';
require_once __DIR__ . '/../consumer/ClickSignConsumer.php'; require_once __DIR__ . '/../consumer/ClickSignConsumer.php';
require_once __DIR__ . '/../repositories/ContractRepositories.php';
class ClickSignService class ClickSignService
{ {
private static $clickSignConsumer = null; private static $clickSignConsumer = null;
private static $contract = null; private static $contract = null;
private static $documentKey = null; private static $documentKey = null;
private static $error = null;
private static $signersToSend = []; private static $signersToSend = [];
private static $allSignersOnClicksign = []; private static $allSignersOnClicksign = [];
private static $signersOfContract = []; private static $signersOfContract = [];
@ -146,18 +146,35 @@ class ClickSignService
foreach ($signersToSend as $signer) { foreach ($signersToSend as $signer) {
$signerKey = $signer['key']; $signerKey = $signer['key'];
$signAs = $signer['signas']; $signAs = $signer['signas'];
self::addSignatarioOnDocumentService($signerKey, $signAs); $signerName = $signer['nome'];
}
if (!self::addSignatarioOnDocumentService($signerKey, $signAs)){
throw new \Exception("Houve uma falha ao enviar o signatário $signerName para assinatura!");
}
}
self::setSendedToClicksignService($contractId);
return 'Contrato enviado para assinatura com sucesso!'; return 'Contrato enviado para assinatura com sucesso!';
} else { } else {
throw new \Exception('Ouve uma falhaaaa!!!'); throw new \Exception('Houve uma falha ao enviar o contrato para assinatura!');
} }
} catch (\Exception $e) { } catch (\Exception $e) {
// Tratar a exceção aqui return $e->getMessage();
self::$error = 'Ocorreu um erro: ' . $e->getMessage(); }
return self::$error; }
private static function setSendedToClicksignService($contractId)
{
$contractRepositories = new ContractRepositories();
$setSended = $contractRepositories->setSendedToClicksign($contractId);
if ($setSended) {
return true;
} }
Utils::printToLog("Falha ao definir o a flag do contrato como enviado no banco de dados: contract_id = $contractId");
throw new \Exception('Falha ao definir o a flag do contrato como enviado no banco de dados.');
} }
private static function sendDataToModelService() private static function sendDataToModelService()

19
crm/service/ContractService.php

@ -106,4 +106,23 @@ class ContractService
return false; return false;
} }
public static function isSendedContractToClicksign($contractId)
{
if (!self::$contractRepo){
self::$contractRepo = new ContractRepositories();
}
$response = self::$contractRepo->getSendedToClicksign($contractId);
if ($response){
if ($response['sended_to_clicksign'] == true){
return true;
} else {
return false;
}
}
Utils::printToLog("Não foi possível obter o valor da flag de envio do contrato! \n" . print_r($response, true), __LINE__);
return false;
}
} }

7
crm/web/contractsSelect.php

@ -26,7 +26,12 @@ if ($result) {
$lastModifiedDate = date('d/m/Y - H:i:s', strtotime($row['last_modified_date'])); $lastModifiedDate = date('d/m/Y - H:i:s', strtotime($row['last_modified_date']));
$edit = GetLinkFormUpdate("&id_contract=" . $idContract, "updContrato", "imgSite/edit.svg"); $edit = GetLinkFormUpdate("&id_contract=" . $idContract, "updContrato", "imgSite/edit.svg");
$send = Utils::getLinkFormEnviar($idContract, "imgSite/send.svg");
if ($contractService->isSendedContractToClicksign($idContract)){
$send = Utils::getLinkIconSended();
} else {
$send = Utils::getLinkFormEnviar($idContract, "imgSite/send.svg");
}
$htmlRows .= " $htmlRows .= "
<tr> <tr>

7
crm/web/js/ApiConsumer.js

@ -38,4 +38,11 @@ export default class ApiConsumer {
window.alert("ERRO! Javascript nao conseguiu recuperar lista de signatarios adicionais do contrato.\nContacte o administrador do sistema."); window.alert("ERRO! Javascript nao conseguiu recuperar lista de signatarios adicionais do contrato.\nContacte o administrador do sistema.");
return await response.json(); return await response.json();
}; };
static getSendedStatus = async (contractId) => {
const response = await fetch(`/crm/controller/ClickSignController.php?idContract=${contractId}&sended_status=true`);
if (!response.ok)
window.alert("ERRO! Javascript nao conseguiu recuperar o status de envio do contrato.\nContacte o administrador do sistema.");
return await response.json();
};
} }

102
crm/web/js/clickSign.js

@ -1,23 +1,95 @@
// Use um seletor de classe comum para todos os botões import ApiConsumer from "./ApiConsumer.js";
document.addEventListener('click', async function(event) {
const botao = event.target.closest('.botao-enviar'); document.addEventListener('click', async function (event) {
const botao = event.target.closest('.botao-enviar');
let imgElement;
if (botao) { if (botao) {
try { try {
const idContract = botao.dataset.id; // Verificar se a requisição já está em andamento
const url = `/crm/controller/ClickSignController.php?idContract=${idContract}`; if (botao.dataset.processando === 'true') {
const response = await fetch(url); alert('Aguarde o fim do processamento de envio.');
return;
if (!response.ok) { }
throw new Error(`Erro na requisição: ${response.statusText}`);
botao.dataset.processando = 'true';
imgElement = botao.querySelector('img');
var originalTitle = imgElement.getAttribute('title');
// Alterar o ícone imediatamente após o clique
if (imgElement) {
// Salvar o src original para restaurar mais tarde
const srcOriginal = imgElement.src;
// Alterar o src da imagem para 'imgSite/wait.svg'
imgElement.src = 'imgSite/wait.svg';
// Alterar o título da imagem enquanto processa o envio
imgElement.setAttribute('title', 'Processando envio...');
const idContract = botao.dataset.id;
const url = `/crm/controller/ClickSignController.php?idContract=${idContract}`;
// Configurar o tempo limite para 30 segundos (em milissegundos)
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => reject(new Error('Tempo limite de 30 segundos excedido')), 30000);
});
// Executar a requisição e o timeout em paralelo e esperar pelo primeiro que for resolvido
const response = await Promise.race([fetch(url), timeoutPromise]);
if (!response.ok) {
throw new Error(`Erro na requisição: ${response.statusText}`);
}
const data = await response.json();
alert(data['response']);
console.log('Resposta do PHP:', data);
if (isSendedToClicksign(idContract)) {
imgElement.src = 'imgSite/sended.svg';
imgElement.setAttribute('title', 'Documento já enviado!');
} else {
// Restaurar o ícone original e o título da imagem após a resposta terminar
imgElement.src = srcOriginal;
imgElement.setAttribute('title', originalTitle);
}
} else {
console.error('Elemento de imagem não encontrado dentro do botão.');
} }
const data = await response.json();
alert(data['response']);
console.log('Resposta do PHP:', data);
} catch (error) { } catch (error) {
console.error('Erro:', error.message); console.error('Erro:', error.message);
const srcError = 'imgSite/error_sync.svg';
// Em caso de erro, altera o ícone e o título da imagem
if (imgElement) {
imgElement.src = srcError;
imgElement.setAttribute('title', 'Houve uma falha!');
alert('Houve uma falha no envio. Por favor, tente novamente.');
} else {
console.error('Elemento de imagem não encontrado dentro do botão.');
}
} finally {
// Marcar que a requisição terminou
botao.dataset.processando = 'false';
} }
} }
}); });
async function isSendedToClicksign(idContract) {
const response = await ApiConsumer.getSendedStatus(idContract);
if (!response.ok) {
throw new Error(`Erro na requisição: ${response.statusText}`);
}
const data = await response.json();
if (data['sended'] === true) {
return true;
}
return false;
}

20
imgSite/edit.svg

@ -1 +1,19 @@
<svg viewBox="0 -0.5 21 21" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <title>edit [#1479]</title> <desc>Created with Sketch.</desc> <defs> </defs> <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="Dribbble-Light-Preview" transform="translate(-99.000000, -400.000000)" fill="#6e26fa"> <g id="icons" transform="translate(56.000000, 160.000000)"> <path d="M61.9,258.010643 L45.1,258.010643 L45.1,242.095788 L53.5,242.095788 L53.5,240.106431 L43,240.106431 L43,260 L64,260 L64,250.053215 L61.9,250.053215 L61.9,258.010643 Z M49.3,249.949769 L59.63095,240 L64,244.114985 L53.3341,254.031929 L49.3,254.031929 L49.3,249.949769 Z" id="edit-[#1479]"> </path> </g> </g> </g> </g></svg> <svg viewBox="0 -0.5 21 21" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
fill="#000000">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<title>edit [#1479]</title>
<desc>Created with Sketch.</desc>
<defs> </defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Dribbble-Light-Preview" transform="translate(-99.000000, -400.000000)" fill="#6e26fa">
<g id="icons" transform="translate(56.000000, 160.000000)">
<path
d="M61.9,258.010643 L45.1,258.010643 L45.1,242.095788 L53.5,242.095788 L53.5,240.106431 L43,240.106431 L43,260 L64,260 L64,250.053215 L61.9,250.053215 L61.9,258.010643 Z M49.3,249.949769 L59.63095,240 L64,244.114985 L53.3341,254.031929 L49.3,254.031929 L49.3,249.949769 Z"
id="edit-[#1479]"> </path>
</g>
</g>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 933 B

After

Width:  |  Height:  |  Size: 1.1 KiB

19
imgSite/error_sync.svg

@ -0,0 +1,19 @@
<svg viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" fill="#6e26fa" stroke="#6e26fa" stroke-width="0.72">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<title>sync-error-solid</title>
<g id="Layer_2" data-name="Layer 2">
<g id="icons_Q2" data-name="icons Q2">
<path
d="M44,5.1V14a2,2,0,0,1-2,2H33a2,2,0,0,1-2-2.3A2.1,2.1,0,0,1,33.1,12h4.3A18,18,0,0,0,6.1,22.2a2,2,0,0,1-2,1.8h0a2,2,0,0,1-2-2.2A22,22,0,0,1,40,8.9V5a2,2,0,0,1,2.3-2A2.1,2.1,0,0,1,44,5.1Z">
</path>
<path
d="M4,42.9V34a2,2,0,0,1,2-2h9a2,2,0,0,1,2,2.3A2.1,2.1,0,0,1,14.9,36H10.6A18,18,0,0,0,41.9,25.8a2,2,0,0,1,2-1.8h0a2,2,0,0,1,2,2.2A22,22,0,0,1,8,39.1V43a2,2,0,0,1-2.3,2A2.1,2.1,0,0,1,4,42.9Z">
</path>
<path d="M24,28a2,2,0,0,0,2-2V16a2,2,0,0,0-4,0V26A2,2,0,0,0,24,28Z"></path>
<circle cx="24" cy="32" r="2"></circle>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

16
imgSite/sended.svg

@ -0,0 +1,16 @@
<svg fill="#6e26fa" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" stroke="#6e26fa"
stroke-width="71.67999999999999">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path
d="M829.44 911.36c45.245 0 81.92-36.675 81.92-81.92V194.56c0-45.245-36.675-81.92-81.92-81.92H194.56c-45.245 0-81.92 36.675-81.92 81.92v634.88c0 45.245 36.675 81.92 81.92 81.92h634.88zm0 40.96H194.56c-67.866 0-122.88-55.014-122.88-122.88V194.56c0-67.866 55.014-122.88 122.88-122.88h634.88c67.866 0 122.88 55.014 122.88 122.88v634.88c0 67.866-55.014 122.88-122.88 122.88z">
</path>
<path
d="M302.806 517.313l139.151 142.131c7.913 8.082 20.879 8.22 28.961.307s8.22-20.879.307-28.961L332.074 488.659c-7.913-8.082-20.879-8.22-28.961-.307s-8.22 20.879-.307 28.961z">
</path>
<path
d="M471.222 659.447l280.689-286.72c7.912-8.082 7.775-21.049-.308-28.961s-21.049-7.775-28.961.308l-280.689 286.72c-7.912 8.082-7.775 21.049.308 28.961s21.049 7.775 28.961-.308z">
</path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

22
imgSite/wait.svg

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" width="64px"
height="64px" viewBox="0 0 128 128" xml:space="preserve">
<g>
<path d="M59.6 0h8v40h-8V0z" fill="#6e26fa" />
<path d="M59.6 0h8v40h-8V0z" fill="#e2d4fe" transform="rotate(30 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#e2d4fe" transform="rotate(60 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#e2d4fe" transform="rotate(90 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#e2d4fe" transform="rotate(120 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#d3bdfd" transform="rotate(150 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#c5a8fd" transform="rotate(180 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#b692fc" transform="rotate(210 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#a87dfc" transform="rotate(240 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#9967fb" transform="rotate(270 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#8b51fb" transform="rotate(300 64 64)" />
<path d="M59.6 0h8v40h-8V0z" fill="#7c3bfa" transform="rotate(330 64 64)" />
<animateTransform attributeName="transform" type="rotate"
values="0 64 64;30 64 64;60 64 64;90 64 64;120 64 64;150 64 64;180 64 64;210 64 64;240 64 64;270 64 64;300 64 64;330 64 64"
calcMode="discrete" dur="1320ms" repeatCount="indefinite"></animateTransform>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

Loading…
Cancel
Save