myadmin/vendor/controller/companies_budgets/CompaniesBudgetsValidate.class.php
2025-08-04 19:45:55 -03:00

684 lines
16 KiB
PHP

<?php
/**
* Classe CompaniesBudgetsValidate.class.php
* @filesource
* @autor Kenio de Souza
* @copyright Copyright 2023 - Souza Consultoria Tecnológica
* @package vendor
* @subpackage controller/companies_budgets
* @version 1.0
* @date 30/06/2023
*/
/** Defino o local onde esta a classe */
namespace vendor\controller\companies_budgets;
/** Importação de classes */
use vendor\model\Main;
class CompaniesBudgetsValidate
{
/** Declaro as variavéis da classe */
private $Main = null;
private $errors = array();
private $info = null;
private $companiesBudgetsId = null;
private $companyId = null;
private $UserId = null;
private $budget = null;
private $dateCreate = null;
private $dayDue = null;
private $readjustmentDate = null;
private $readjustmentIndex = null;
private $readjustmentValue = null;
private $readjustmentBudget = null;
private $readjustmentType = null;
private $readjustmentYear = null;
private $readjustmentMonth = null;
private $often = null;
private $dateStart = null;
private $description = null;
private $financialCategoriesId = null;
private $financialAccountsId = null;
private $productsId = null;
private $sanitize = null;
private $type = null;
private $input = [];
private $array_de_strings = null;
private $array_de_numeros = null;
private $json_saida = null;
/** Construtor da classe */
function __construct()
{
/** Instânciamento da classe de validação */
$this->Main = new Main();
}
/** Método trata campo companies_budgets_id */
public function setCompaniesBudgetsId(int $companiesBudgetsId) : void
{
/** Trata a entrada da informação */
$this->companiesBudgetsId = isset($companiesBudgetsId) ? (int)$this->Main->antiInjection($companiesBudgetsId) : null;
/** Verifica se a informação foi informada */
// if(empty($this->companiesBudgetsId))
// {
// /** Adição de elemento */
// array_push($this->errors, 'O campo "companies_budgets_id", deve ser informado');
// }
}
/** Método trata campo clients_id */
public function setCompanyId(int $companyId) : void
{
/** Trata a entrada da informação */
$this->companyId = $companyId > 0 ? (int)$this->Main->antiInjection($companyId) : 0;
/** Verifica se a informação foi informada */
if($this->companyId ==0)
{
/** Adição de elemento */
array_push($this->errors, 'O cliente deve ser informado');
}
}
/** Método trata campo clients_budgets_id */
public function setClientsBudgetsId(int $companiesBudgetsId) : void
{
/** Trata a entrada da informação */
$this->clientsBudgetsId = $companiesBudgetsId > 0 ? (int)$this->Main->antiInjection($companiesBudgetsId) : 0;
// /** Verifica se a informação foi informada */
// if($this->companyId ==0)
// {
// /** Adição de elemento */
// array_push($this->errors, 'O cliente deve ser informado');
// }
}
/** Método trata campo financial_categories_id */
public function setFinancialCategoriesId(int $financialCategoriesId) : void
{
/** Trata a entrada da informação */
$this->financialCategoriesId = $financialCategoriesId > 0 ? (int)$this->Main->antiInjection($financialCategoriesId) : 0;
/** Verifica se a informação foi informada */
if($this->financialCategoriesId ==0)
{
/** Adição de elemento */
array_push($this->errors, 'A categoria do orçamento deve ser informada');
}
}
/** Método trata campo financial_accounts_id */
public function setFinancialAccountsId(int $financialAccountsId) : void
{
/** Trata a entrada da informação */
$this->financialAccountsId = $financialAccountsId > 0 ? (int)$this->Main->antiInjection($financialAccountsId) : 0;
/** Verifica se a informação foi informada */
if($this->financialAccountsId ==0)
{
/** Adição de elemento */
array_push($this->errors, 'A conta do orçamento deve ser informada');
}
}
/** Método trata campo products_id */
public function setProductsId(string $productsId) : void
{
/** Trata a entrada da informação */
$this->productsId = isset($productsId) ? (string)$this->Main->antiInjection($productsId) : '';
/** Verifica se a informação foi informada */
if(empty($this->productsId))
{
/** Adição de elemento */
array_push($this->errors, 'O produto do orçamento deve ser informada');
} else {//converte a entrada parra um json
// Passo 1: Separar a string em um array usando a vírgula como delimitador
$this->array_de_strings = explode(',', $this->productsId);
// O array resultante será ['6', '7', '4', '5'] (valores como strings)
// Passo 2 (Opcional, mas recomendado): Converter os valores de string para inteiros
$this->array_de_numeros = array_map('intval', $this->array_de_strings);
// O array resultante agora é [6, 7, 4, 5] (valores como números)
// Passo 3: Codificar o array em uma string JSON
$this->json_saida = json_encode($this->array_de_numeros, JSON_PRETTY_PRINT);
}
}
/** Método trata campo users_id */
public function setUserId(int $UserId) : void
{
/** Trata a entrada da informação */
$this->UserId = isset($UserId) ? (int)$this->Main->antiInjection($UserId) : null;
/** Verifica se a informação foi informada */
if(empty($this->UserId))
{
/** Adição de elemento */
array_push($this->errors, 'O colaborador deve ser informado');
}
}
/** Método trata campo budget */
public function setBudget(string $budget) : void
{
/** Trata a entrada da informação */
$this->budget = isset($budget) ? $this->Main->antiInjection($budget) : null;
/** Verifica se a informação foi informada */
if(empty($this->budget))
{
/** Adição de elemento */
array_push($this->errors, 'O valor do orçamento deve ser informado');
}
}
/** Método trata campo date_create */
public function setDateCreate(string $dateCreate) : void
{
/** Trata a entrada da informação */
$this->dateCreate = isset($dateCreate) ? $this->Main->antiInjection($dateCreate) : null;
/** Verifica se a informação foi informada */
if(empty($this->dateCreate))
{
/** Adição de elemento */
array_push($this->errors, 'O campo "date_create", deve ser informado');
}
}
/** Método trata campo day_due */
public function setDayDue(int $dayDue) : void
{
/** Trata a entrada da informação */
$this->dayDue = $dayDue > 0 ? (int)$this->Main->antiInjection($dayDue) : 0;
/** Verifica se a informação foi informada */
if($this->dayDue == 0)
{
/** Adição de elemento */
array_push($this->errors, 'O dia do vencimento deve ser informado');
}
}
/** Método trata campo readjustment_date */
public function setReadjustmentDate(string $readjustmentDate) : void
{
/** Trata a entrada da informação */
$this->readjustmentDate = isset($readjustmentDate) ? $this->Main->antiInjection($readjustmentDate) : null;
/** Verifica se a informação foi informada */
if(empty($this->readjustmentDate))
{
/** Adição de elemento */
array_push($this->errors, 'O campo "readjustment_date", deve ser informado');
}
}
/** Método trata campo readjustment_index */
public function setReadjustmentIndex(string $readjustmentIndex) : void
{
/** Trata a entrada da informação */
$this->readjustmentIndex = isset($readjustmentIndex) ? $this->Main->antiInjection($readjustmentIndex) : null;
/** Verifica se a informação foi informada */
if(empty($this->readjustmentIndex))
{
/** Adição de elemento */
array_push($this->errors, 'O índice do orçamento deve ser informado');
}
}
/** Método trata campo readjustment_value */
public function setReadjustmentValue(string $readjustmentValue) : void
{
/** Trata a entrada da informação */
$this->readjustmentValue = isset($readjustmentValue) ? $this->Main->antiInjection($readjustmentValue) : null;
/** Verifica se a informação foi informada */
if(empty($this->readjustmentValue))
{
/** Adição de elemento */
array_push($this->errors, 'O valor do reajuste deve ser informado');
}
}
/** Método trata campo readjustment_budget */
public function setReadjustmentBudget(string $readjustmentBudget) : void
{
/** Trata a entrada da informação */
$this->readjustmentBudget = isset($readjustmentBudget) ? $this->Main->antiInjection($readjustmentBudget) : null;
/** Verifica se a informação foi informada */
if(empty($this->readjustmentBudget))
{
/** Adição de elemento */
array_push($this->errors, 'O valor atualizado o orçamento deve ser informado');
}
}
/** Método trata campo description */
public function setDescription(string $description) : void
{
/** Trata a entrada da informação */
$this->description = isset($description) ? $this->Main->antiInjection($description) : null;
/** Verifica se a informação foi informada */
if(empty($this->description))
{
/** Adição de elemento */
array_push($this->errors, 'A decrição do orçamento deve ser informada');
}
}
/** Método trata campo readjustment_type */
public function setReadjustmentType(int $readjustmentType) : void
{
/** Trata a entrada da informação */
$this->readjustmentType = $readjustmentType > 0 ? (int)$this->Main->antiInjection($readjustmentType) : null;
/** Verifica se a informação foi informada */
if(empty($this->readjustmentType))
{
/** Adição de elemento */
array_push($this->errors, 'O tipo de reajuste do orçamento deve ser informado');
}
}
/** Método trata campo readjustment_year */
public function setReadjustmentYear(int $readjustmentYear) : void
{
/** Trata a entrada da informação */
$this->readjustmentYear = $readjustmentYear > 0 ? $this->Main->antiInjection($readjustmentYear) : 0;
/** Verifica se a informação foi informada */
if($this->readjustmentYear == 0)
{
/** Adição de elemento */
array_push($this->errors, 'O ano do orçamento deve ser informado');
}
}
/** Método trata campo readjustment_month */
public function setReadjustmentMonth(int $readjustmentMonth) : void
{
/** Trata a entrada da informação */
$this->readjustmentMonth = $readjustmentMonth > 0 ? $this->Main->antiInjection($readjustmentMonth) : 0;
/** Verifica se a informação foi informada */
if($this->readjustmentMonth == 0)
{
/** Adição de elemento */
array_push($this->errors, 'O mês do orçamento deve ser informado');
}
}
/** Método trata campo often */
public function setOften(int $often) : void
{
/** Trata a entrada da informação */
$this->often = $often > 0 ? $this->Main->antiInjection($often) : 0;
/** Verifica se a informação foi informada */
if($this->often == 0)
{
/** Adição de elemento */
array_push($this->errors, 'a freqência do orçamento deve ser informada');
}
}
/** Método trata campo date_start */
public function setDateStart(string $dateStart) : void
{
/** Trata a entrada da informação */
$this->dateStart = isset($dateStart) ? $this->Main->antiInjection($dateStart) : null;
/** Verifica se a informação foi informada */
if(empty($this->dateStart))
{
/** Adição de elemento */
array_push($this->errors, 'A da inicial do orçamento deve ser informada');
}
elseif(!$this->Main->validaData($this->dateStart)){
/** Adição de elemento */
array_push($this->errors, 'A da inicial do orçamento deve ser válida');
}
}
/** Sanitiza array */
public function setSanitizeArray(array $input, string $type)
{
/** Trata a entrada da informação */
$this->sanitize = count($input) > 0 ? $input : [];
$this->type = $type;
/** Limpa array de input */
$this->input = array();
/** Verficia se foram informado itens */
if( count($this->sanitize) > 0 ){
foreach($this->sanitize as $value){
switch ($this->type){
case 'int' :
array_push($this->input, filter_var($value, FILTER_SANITIZE_NUMBER_INT));
break;
case 'string' :
array_push($this->input, filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS));
break;
case 'float' :
array_push($this->input, filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT));
break;
}
}
}
/** Retorna a array tratada */
return $this->input;
}
/** Método retorna campo companies_budgets_id */
public function getCompaniesBudgetsId() : ? int
{
/** Retorno da informação */
return (int)$this->companiesBudgetsId;
}
/** Método retorna campo clients_id */
public function getCompanyId() : ? int
{
/** Retorno da informação */
return (int)$this->companyId;
}
/** Método retorna campo users_id */
public function getUserId() : ? int
{
/** Retorno da informação */
return (int)$this->UserId;
}
/** Método retorna campo budget */
public function getBudget() : ? float
{
/** Retorno da informação */
return (float)$this->Main->MoeadDB($this->budget);
}
/** Método retorna campo date_create */
public function getDateCreate() : ? string
{
/** Retorno da informação */
return (string)$this->dateCreate;
}
/** Método retorna campo description */
public function getDescription() : ? string
{
/** Retorno da informação */
return (string)$this->description;
}
/** Método retorna campo day_due */
public function getDayDue() : ? int
{
/** Retorno da informação */
return (int)$this->dayDue;
}
/** Método retorna campo readjustment_date */
public function getReadjustmentDate() : ? string
{
/** Retorno da informação */
return (string)$this->Main->DataDB($this->readjustmentDate);
}
/** Método retorna campo readjustment_index */
public function getReadjustmentIndex() : ? float
{
/** Retorno da informação */
return (float)$this->Main->MoeadDB($this->readjustmentIndex);
}
/** Método retorna campo readjustment_value */
public function getReadjustmentValue() : ? float
{
/** Retorno da informação */
return (float)$this->Main->MoeadDB($this->readjustmentValue);
}
/** Método retorna campo readjustment_budget */
public function getReadjustmentBudget() : ? float
{
/** Retorno da informação */
return (float)$this->Main->MoeadDB($this->readjustmentBudget);
}
/** Método retorna campo readjustment_type */
public function getReadjustmentType() : ? int
{
/** Retorno da informação */
return (int)$this->readjustmentType;
}
/** Método retorna campo readjustment_year */
public function getReadjustmentYear() : ? int
{
/** Retorno da informação */
return (int)$this->readjustmentYear;
}
/** Método retorna campo readjustment_month */
public function getReadjustmentMonth() : ? int
{
/** Retorno da informação */
return (int)$this->readjustmentMonth;
}
/** Método retorna campo often */
public function getOften() : ? int
{
/** Retorno da informação */
return (int)$this->often;
}
/** Método retorna campo often */
public function getFinancialCategoriesId() : ? int
{
/** Retorno da informação */
return (int)$this->financialCategoriesId;
}
/** Método retorna campo often */
public function getFinancialAccountsId() : ? int
{
/** Retorno da informação */
return (int)$this->financialAccountsId;
}
/** Método retorna campo products_id */
public function getProductsId() : ? string
{
/** Retorno da informação */
return (string)$this->json_saida;
}
/** Método retorna campo date_start */
public function getDateStart() : ? string
{
/** Retorno da informação */
return (string)$this->Main->DataDB($this->dateStart);
}
public function getErrors(): ? string
{
/** Verifico se deve informar os erros */
if (count($this->errors)) {
/** Verifica a quantidade de erros para informar a legenda */
$this->info = count($this->errors) > 1 ? '<center>Os seguintes erros foram encontrados</center>' : '<center>O seguinte erro foi encontrado</center>';
/** Lista os erros */
foreach ($this->errors as $keyError => $error) {
/** Monto a mensagem de erro */
$this->info .= '</br>' . ($keyError + 1) . ' - ' . $error;
}
/** Retorno os erros encontrados */
return (string)$this->info;
} else {
return false;
}
}
function __destruct(){}
}