Atualização Companies.class.php

This commit is contained in:
Kenio 2025-07-29 14:48:05 -03:00
parent d8122c6f64
commit 9efd098840
2 changed files with 34 additions and 19 deletions

View file

@ -129,23 +129,31 @@ class Companies
}
/** Consulta SQL */
$this->sql = 'select * from companies ';
$this->sql = 'select * from companies c ';
/** Verifica se há pesquisa */
if($this->typeSearch && $this->search){
/** Verifica o tipo de pesquisa */
if($this->typeSearch == 1){ //Pesquisa por nome da empresa
if($this->typeSearch == 1){ //CNS
$this->sql .= 'where name_fantasy like :search ';
$this->sql .= 'where c.cns = :search';
}else if($this->typeSearch == 2){ //Pesquisa por CNPJ
}else if($this->typeSearch == 2){ //Pesquisa por Nome Fantasia
$this->sql .= 'where cnpj like :search ';
$this->sql .= 'where c.name_fantasy like :search';
}else if($this->typeSearch == 3){ //Pesquisa por CEP
}else if($this->typeSearch == 3){ //Pesquisa por responsável
$this->sql .= 'where cep like :search ';
$this->sql .= 'where c.responsible like :search';
}else if($this->typeSearch == 4){ //Pesquisa por e-mail
$this->sql .= 'where c.email like :search';
}else if($this->typeSearch == 5){ //Pesquisa por estado
$this->sql .= 'where (select count(s.state_id) from states s where uf = :search and s.state_id = c.state_id) > 0';
}
}
@ -177,28 +185,35 @@ class Companies
$this->search = $search;
/** Consulta SQL */
$this->sql = 'select count(company_id) as qtde
from companies ';
$this->sql = 'select count(c.company_id) as qtde
from companies c';
/** Verifica se há pesquisa */
if($this->typeSearch && $this->search){
/** Verifica o tipo de pesquisa */
if($this->typeSearch == 1){ //Pesquisa por nome da empresa
if($this->typeSearch == 1){ //CNS
$this->sql .= 'where name_fantasy like :search';
$this->sql .= 'where c.cns = :search';
}else if($this->typeSearch == 2){ //Pesquisa por CNPJ
}else if($this->typeSearch == 2){ //Pesquisa por Nome Fantasia
$this->sql .= 'where cnpj like :search';
$this->sql .= 'where c.name_fantasy like :search';
}else if($this->typeSearch == 3){ //Pesquisa por CEP
}else if($this->typeSearch == 3){ //Pesquisa por responsável
$this->sql .= 'where cep like :search';
$this->sql .= 'where c.responsible like :search';
}else if($this->typeSearch == 4){ //Pesquisa por e-mail
$this->sql .= 'where c.email like :search';
}else if($this->typeSearch == 5){ //Pesquisa por estado
$this->sql .= 'where (select count(s.state_id) from states s where uf = :search and s.state_id = c.state_id) > 0';
}
}
echo $this->sql;
/** Preparo o SQL para execução */

View file

@ -71,13 +71,13 @@ if($Main->verifyToken()){
<div class="form-outline mr-1">
<select id="type-search" name="type-search" class="form-control">
<option selected>Selecione</option>
<option value="1" <?php echo $typeSearch == 1 || (int)$typeSearch == 0 ? 'selected' : '';?>>Referência</option>
<option value="1" <?php echo $typeSearch == 1 || (int)$typeSearch == 0 ? 'selected' : '';?>>CNS</option>
<option value="2" <?php echo $typeSearch == 2 ? 'selected' : '';?>>Nome</option>
<option value="3" <?php echo $typeSearch == 3 ? 'selected' : '';?>>Responsável</option>
<option value="4" <?php echo $typeSearch == 4 ? 'selected' : '';?>>Email</option>
<option value="5" <?php echo $typeSearch == 5 ? 'selected' : '';?>>Estado</option>
<option value="6" <?php echo $typeSearch == 6 ? 'selected' : '';?>>Sistema</option>
<option value="7" <?php echo $typeSearch == 7 ? 'selected' : '';?>>Reajuste</option>
<!-- <option value="6" <?php echo $typeSearch == 6 ? 'selected' : '';?>>Sistema</option> -->
<!-- <option value="7" <?php echo $typeSearch == 7 ? 'selected' : '';?>>Reajuste</option> -->
</select>
</div>