diff --git a/config/config.json b/config/config.json index 05db70d..a7a71c1 100644 --- a/config/config.json +++ b/config/config.json @@ -24,7 +24,8 @@ "security" : {"method": "aes-256-cbc", "first_key": "1B0B043A1C185F261D", "second_key": "1B0B043A0C05422C1E0A", - "hash": "43170E01071F0D3B1437" + "hash": "43170E01071F0D3B1437", + "liberation": "!Liberation@Orius." }, "start_module" : {"table" : "financial_movements", "action" : "financial_movements_resume", diff --git a/teste.php b/teste.php deleted file mode 100644 index 1cef728..0000000 --- a/teste.php +++ /dev/null @@ -1,9 +0,0 @@ -setCns($cns); + $FinancialMovementsValidate->setHash($hash); + + /** Verifica se não existem erros a serem informados */ + if (!empty($FinancialMovementsValidate->getErrors())) { + + /** Informo */ + throw new InvalidArgumentException($FinancialMovementsValidate->getErrors(), 0); + + } else { + + /** Verifico se o hash enviado é válido */ + if($Main->decryptData($FinancialMovementsValidate->getHash()) === $Main->getLiberation()){ + + /** Consulta por movimentações em atraso de um determinado cliente pelo seu CNS */ + $FinancialMovementsResult = $FinancialMovements->SearchDebit($FinancialMovementsValidate->getCns()); + + print_r($FinancialMovementsResult); + + } else { + + /** Informo */ + throw new InvalidArgumentException('O Hash informado é inválido', 0); + } + + } + + +}catch(Exception $exception){ + + /** Preparo o formulario para retorno **/ + $result = [ + + 'cod' => 0, + 'message' => $exception->getMessage(), + 'title' => 'Atenção', + 'type' => 'exception', + 'authenticate' => $authenticate + + ]; + + /** Envio **/ + echo json_encode($result); + + /** Paro o procedimento **/ + exit; +} \ No newline at end of file diff --git a/vendor/controller/financial_movements/FinancialMovementsValidate.class.php b/vendor/controller/financial_movements/FinancialMovementsValidate.class.php index 9043246..d62ade9 100644 --- a/vendor/controller/financial_movements/FinancialMovementsValidate.class.php +++ b/vendor/controller/financial_movements/FinancialMovementsValidate.class.php @@ -211,6 +211,38 @@ class FinancialMovementsValidate } + /** Método trata campo cns */ + public function setCns(string $cns) : void + { + + /** Trata a entrada da informação */ + $this->cns = isset($cns) ? $this->Main->antiInjection($cns) : ''; + + /** Verifica se a informação foi informada */ + if(empty($this->cns)) + { + + /** Adição de elemento */ + array_push($this->errors, 'O CNS deve ser informado'); + } + } + + /** Método trata campo hash */ + public function setHash(string $hash) : void + { + + /** Trata a entrada da informação */ + $this->hash = isset($hash) ? $this->Main->antiInjection($hash) : ''; + + /** Verifica se a informação foi informada */ + if(empty($this->hash)) + { + + /** Adição de elemento */ + array_push($this->errors, 'O HASH deve ser informado'); + } + } + /** Método trata campo ournumber */ public function setOurNumber(string $ournumber) : void { @@ -1012,6 +1044,24 @@ class FinancialMovementsValidate } + /** Método retorna o campo cns */ + public function getCns() : ? string + { + + /** Retorno da informação */ + return (string)$this->cns; + + } + + /** Método retorna o campo hash */ + public function getHash() : ? string + { + + /** Retorno da informação */ + return (string)$this->hash; + + } + /** Retorna possiveis erros */ public function getErrors(): ? string { diff --git a/vendor/model/FinancialMovements.class.php b/vendor/model/FinancialMovements.class.php index e5a1b93..fef2df3 100644 --- a/vendor/model/FinancialMovements.class.php +++ b/vendor/model/FinancialMovements.class.php @@ -406,6 +406,34 @@ class FinancialMovements } + /** Pesquisa por débito de um determinado cliente via código CNS */ + public function SearchDebit(string $cns) + { + /** Parametros de entrada */ + $this->cns = $cns; + + /** Consulta SQL */ + $this->sql = 'SELECT fm.* + FROM financial_movements fm + INNER JOIN companies c ON fm.company_id = c.company_id + WHERE c.cns = :cns + AND fm.movement_date_paid IS NULL + AND fm.movement_date_scheduled <= CURRENT_DATE'; + + /** Preparo o SQL para execução */ + $this->stmt = $this->connection->connect()->prepare($this->sql); + + /** Preencho os parâmetros do SQL */ + $this->stmt->bindParam(':cns', $this->cns); + + /** Executo o SQL */ + $this->stmt->execute(); + + /** Retorno o resultado */ + return $this->stmt->fetchAll(\PDO::FETCH_OBJ); + } + + /** Localiza um registro especifico */ public function Get(int $financialMovementsId) { diff --git a/vendor/model/Main.class.php b/vendor/model/Main.class.php index d3feb24..b0e3564 100644 --- a/vendor/model/Main.class.php +++ b/vendor/model/Main.class.php @@ -54,6 +54,7 @@ class Main private $dateEnd = null; private $interval = null; private $month = null; + private $liberation = null; function __construct() @@ -66,6 +67,7 @@ class Main $this->firstKey = $this->config->{'app'}->{'security'}->{'first_key'}; $this->secondKey = $this->config->{'app'}->{'security'}->{'second_key'}; $this->hash = $this->config->{'app'}->{'security'}->{'hash'}; + $this->liberation = $this->config->{'app'}->{'security'}->{'liberation'}; /** Parametro do tempo de sessão do usuário */ $this->sessionTime = $this->config->{'app'}->{'session_time'}; @@ -92,6 +94,13 @@ class Main return $this->secondKey; } + + /** Retorna o codigo de liberação */ + public function getLiberation() : string + { + + return (string)$this->liberation; + } /** Retorna o tempo de sessão */ public function getSessionTime() : int