Criando serviço de liberação por adiplência

This commit is contained in:
Kenio 2025-08-18 15:52:10 -03:00
parent dd56b18d74
commit d646ac1a82
6 changed files with 154 additions and 10 deletions

View file

@ -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",

View file

@ -1,9 +0,0 @@
<?php
echo date('Y-m-d', strtotime(date('Y-m-01')));
// Define o ano e o mês que você quer verificar
// $ano = 2024;
// $mes = 7;
// // Usa strtotime para converter para o formato de data no último dia do mês
// $ultimo_dia = date("Y-m-t", strtotime("$ano-$mes-01"));

65
vendor/action/liberation/liberation.php vendored Normal file
View file

@ -0,0 +1,65 @@
<?php
/** Importação de classes */
use vendor\model\FinancialMovements;
use vendor\controller\financial_movements\FinancialMovementsValidate;
try{
/** Instânciamento de classes */
$FinancialMovements = new FinancialMovements();
$FinancialMovementsValidate = new FinancialMovementsValidate();
/** Parametros de entrada */
$cns = isset($_POST['cns']) ? (string)filter_input(INPUT_POST, 'cns',FILTER_SANITIZE_SPECIAL_CHARS ) : '';
$hash = isset($_POST['hash']) ? (string)filter_input(INPUT_POST, 'hash',FILTER_SANITIZE_SPECIAL_CHARS ) : '';
/** Validando os campos de entrada */
$FinancialMovementsValidate->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;
}

View file

@ -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
{

View file

@ -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)
{

View file

@ -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