Atualização Companies.class.php

This commit is contained in:
Kenio 2025-07-29 14:20:49 -03:00
parent cc3b7a600f
commit 8b65162d68
2 changed files with 69 additions and 8 deletions

View file

@ -40,6 +40,8 @@ class Companies
private $dateRegister = null;
private $responsible = null;
private $active = null;
private $typeSearch = null;
private $search = null;
/** Construtor da classe */
function __construct()
@ -113,23 +115,53 @@ class Companies
}
/** Lista todos os egistros do banco com ou sem paginação*/
public function All(? int $start, ? int $max)
public function All(? int $start, ? int $max, ?int $typeSearch, ?string $search)
{
/** Parametros de entrada */
$this->start = $start;
$this->max = $max;
$this->typeSearch = $typeSearch;
$this->search = $search;
/** Verifico se há paginação */
if($this->max){
$this->limit = "limit $this->start, $this->max";
$this->limit = " limit $this->start, $this->max";
}
/** Consulta SQL */
$this->sql = 'select * from companies '. $this->limit;
$this->sql = 'select * from companies ';
/** Verifica se há pesquisa */
if($this->typeSearch && $this->search){
/** Verifica o tipo de pesquisa */
if($this->typeSearch == 1){ //Pesquisa por nome da empresa
$this->sql .= 'where name_business like :search ';
}else if($this->typeSearch == 2){ //Pesquisa por CNPJ
$this->sql .= 'where cnpj like :search ';
}else if($this->typeSearch == 3){ //Pesquisa por CEP
$this->sql .= 'where cep like :search ';
}
}
$this->sql .= $this->limit;
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Verifica se há pesquisa */
if($this->typeSearch && $this->search){
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam(':search', $this->search);
}
/** Executo o SQL */
$this->stmt->execute();
@ -139,15 +171,44 @@ class Companies
}
/** Conta a quantidades de registros */
public function Count()
public function Count(?int $typeSearch, ?string $search)
{
$this->typeSearch = $typeSearch;
$this->search = $search;
/** Consulta SQL */
$this->sql = 'select count(company_id) as qtde
from companies ';
/** Verifica se há pesquisa */
if($this->typeSearch && $this->search){
/** Verifica o tipo de pesquisa */
if($this->typeSearch == 1){ //Pesquisa por nome da empresa
$this->sql .= 'where name_business like :search';
}else if($this->typeSearch == 2){ //Pesquisa por CNPJ
$this->sql .= 'where cnpj like :search';
}else if($this->typeSearch == 3){ //Pesquisa por CEP
$this->sql .= 'where cep like :search';
}
}
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Verifica se há pesquisa */
if($this->typeSearch && $this->search){
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam(':search', $this->search);
}
/** Executo o SQL */
$this->stmt->execute();

View file

@ -80,13 +80,13 @@ try{
<div class="col-sm-6 mb-2">
<label for="company_name">Razão Social:</label>
<input type="text" class="form-control form-control" maxlength="255" id="company_name" name="company_name" value="<?php echo $CompanyResult->company_name;?>" placeholder="Informe a razão social da empresa">
<input type="text" class="form-control form-control" maxlength="255" id="company_name" name="company_name" value="<?php echo $CompanyResult->name_business;?>" placeholder="Informe a razão social da empresa">
</div>
<div class="col-sm-6 mb-2">
<label for="fantasy_name">Nome Fantasia:</label>
<input type="text" class="form-control form-control" maxlength="120" id="fantasy_name" name="fantasy_name" value="<?php echo $CompanyResult->fantasy_name;?>" placeholder="Informe o nome fantasia da empresa">
<input type="text" class="form-control form-control" maxlength="120" id="fantasy_name" name="fantasy_name" value="<?php echo $CompanyResult->name_fantasy;?>" placeholder="Informe o nome fantasia da empresa">
</div>
</div>
@ -96,13 +96,13 @@ try{
<div class="col-sm-3 mb-2">
<label for="document">CPF / CNPJ:</label>
<input type="text" class="form-control form-control number" maxlength="14" id="document" name="document" value="<?php echo $Main->formatarCPF_CNPJ($CompanyResult->document);?>" placeholder="Informe CPF/CNPJ">
<input type="text" class="form-control form-control number" maxlength="14" id="document" name="document" value="<?php echo $Main->formatarCPF_CNPJ($CompanyResult->cnpj);?>" placeholder="Informe CPF/CNPJ">
</div>
<div class="col-sm-3 mb-2">
<label for="zip_code">CEP:</label>
<input type="text" class="form-control form-control postal_code" maxlength="9" id="zip_code" name="zip_code" value="<?php echo $CompanyResult->zip_code;?>" placeholder="Informe o CEP">
<input type="text" class="form-control form-control postal_code" maxlength="9" id="zip_code" name="zip_code" value="<?php echo $CompanyResult->cep;?>" placeholder="Informe o CEP">
</div>
<div class="col-sm-4 mb-2">