first commit

This commit is contained in:
Claudecio Martins
2026-06-16 10:04:10 -03:00
commit a951944997
4463 changed files with 419677 additions and 0 deletions
@@ -0,0 +1,212 @@
<?php
namespace WorkbloomERP\Module\v0\Empresa\Models;
use DateTimeImmutable;
class EmpresaModel {
public function __construct(
private ?int $id = null,
private ?string $uuid = null,
private ?bool $is_active = null,
private ?string $nome_empresarial = null,
private ?string $nome_fantasia = null,
private ?string $tipo = null,
private ?int $matriz_id = null,
private ?string $document_cnpj = null,
private ?string $document_ie = null,
private ?string $document_im = null,
private ?string $regime_tributario = null,
private ?string $end_cep = null,
private ?int $end_ibge = null,
private ?string $end_logradouro = null,
private ?string $end_numero = null,
private ?string $end_complemento = null,
private ?string $end_bairro = null,
private ?string $end_cidade = null,
private ?string $end_uf = null,
private ?DateTimeImmutable $created_at = null,
private ?DateTimeImmutable $updated_at = null,
private ?DateTimeImmutable $deleted_at = null,
) {}
public function toArray(): array {
return [
'id' => $this->getId(),
'uuid' => $this->getUuid(),
'is_active' => $this->getIsActive(),
'nome_empresarial' => $this->getNomeEmpresarial(),
'nome_fantasia' => $this->getNomeFantasia(),
'tipo' => $this->getTipo(),
'matriz_id' => $this->getMatrizId(),
'document_cnpj' => $this->getDocumentCnpj(),
'document_ie' => $this->getDocumentIe(),
'document_im' => $this->getDocumentIm(),
'regime_tributario' => $this->getRegimeTributario(),
'end_cep' => $this->getEndCep(),
'end_ibge' => $this->getEndIbge(),
'end_logradouro' => $this->getEndLogradouro(),
'end_numero' => $this->getEndNumero(),
'end_complemento' => $this->getEndComplemento(),
'end_bairro' => $this->getEndBairro(),
'end_cidade' => $this->getEndCidade(),
'end_uf' => $this->getEndUf(),
'created_at' => $this->getCreatedAt() ? $this->getCreatedAt()->format('Y-m-d H:i:s') : null,
'updated_at' => $this->getUpdatedAt() ? $this->getUpdatedAt()->format('Y-m-d H:i:s') : null,
'deleted_at' => $this->getDeletedAt() ? $this->getDeletedAt()->format('Y-m-d H:i:s') : null,
];
}
public function setId(?int $id): void {
$this->id = $id;
}
public function getId(): ?int {
return $this->id;
}
public function setUuid(?string $uuid): void {
$this->uuid = $uuid;
}
public function getUuid(): ?string {
return $this->uuid;
}
public function setIsActive(?bool $is_active): void {
$this->is_active = $is_active;
}
public function getIsActive(): ?bool {
return $this->is_active;
}
public function setNomeEmpresarial(?string $nome_empresarial): void {
$this->nome_empresarial = $nome_empresarial;
}
public function getNomeEmpresarial(): ?string {
return $this->nome_empresarial;
}
public function setNomeFantasia(?string $nome_fantasia): void {
$this->nome_fantasia = $nome_fantasia;
}
public function getNomeFantasia(): ?string {
return $this->nome_fantasia;
}
public function setTipo(?string $tipo): void {
$this->tipo = $tipo;
}
public function getTipo(): ?string {
return $this->tipo;
}
public function setMatrizId(?int $matriz_id): void {
$this->matriz_id = $matriz_id;
}
public function getMatrizId(): ?int {
return $this->matriz_id;
}
public function setDocumentCnpj(?string $document_cnpj): void {
$this->document_cnpj = $document_cnpj;
}
public function getDocumentCnpj(): ?string {
return $this->document_cnpj;
}
public function setDocumentIe(?string $document_ie): void {
$this->document_ie = $document_ie;
}
public function getDocumentIe(): ?string {
return $this->document_ie;
}
public function setDocumentIm(?string $document_im): void {
$this->document_im = $document_im;
}
public function getDocumentIm(): ?string {
return $this->document_im;
}
public function setRegimeTributario(?string $regime_tributario): void {
$this->regime_tributario = $regime_tributario;
}
public function getRegimeTributario(): ?string {
return $this->regime_tributario;
}
public function setEndCep(?string $end_cep): void {
$this->end_cep = $end_cep;
}
public function getEndCep(): ?string {
return $this->end_cep;
}
public function setEndIbge(?int $end_ibge): void {
$this->end_ibge = $end_ibge;
}
public function getEndIbge(): ?int {
return $this->end_ibge;
}
public function setEndLogradouro(?string $end_logradouro): void {
$this->end_logradouro = $end_logradouro;
}
public function getEndLogradouro(): ?string {
return $this->end_logradouro;
}
public function setEndNumero(?string $end_numero): void {
$this->end_numero = $end_numero;
}
public function getEndNumero(): ?string {
return $this->end_numero;
}
public function setEndComplemento(?string $end_complemento): void {
$this->end_complemento = $end_complemento;
}
public function getEndComplemento(): ?string {
return $this->end_complemento;
}
public function setEndBairro(?string $end_bairro): void {
$this->end_bairro = $end_bairro;
}
public function getEndBairro(): ?string {
return $this->end_bairro;
}
public function setEndCidade(?string $end_cidade): void {
$this->end_cidade = $end_cidade;
}
public function getEndCidade(): ?string {
return $this->end_cidade;
}
public function setEndUf(?string $end_uf): void {
$this->end_uf = $end_uf;
}
public function getEndUf(): ?string {
return $this->end_uf;
}
public function setCreatedAt(?DateTimeImmutable $created_at): void {
$this->created_at = $created_at;
}
public function getCreatedAt(): ?DateTimeImmutable {
return $this->created_at;
}
public function setUpdatedAt(?DateTimeImmutable $updated_at): void {
$this->updated_at = $updated_at;
}
public function getUpdatedAt(): ?DateTimeImmutable {
return $this->updated_at;
}
public function setDeletedAt(?DateTimeImmutable $deleted_at): void {
$this->deleted_at = $deleted_at;
}
public function getDeletedAt(): ?DateTimeImmutable {
return $this->deleted_at;
}
}
+268
View File
@@ -0,0 +1,268 @@
<?php
namespace WorkbloomERP\Module\v0\Empresa\Repos;
use DateTimeImmutable;
use WorkbloomERP\Services\DBService;
use WorkbloomERP\Module\v0\Empresa\Models\EmpresaModel;
class EmpresaRepo {
protected string $empresaTable = 'empresa';
public function __construct(
protected DBService $db
) {}
public function insert(EmpresaModel $empresaModel): ?EmpresaModel {
$query =
"INSERT INTO {$this->empresaTable} (
uuid,
is_active,
nome_empresarial,
nome_fantasia,
tipo,
matriz_id,
document_cnpj,
document_ie,
document_im,
regime_tributario,
end_cep,
end_ibge,
end_logradouro,
end_numero,
end_complemento,
end_bairro,
end_cidade,
end_uf,
created_at
) VALUES (
:uuid,
:is_active,
:nome_empresarial,
:nome_fantasia,
:tipo,
:matriz_id,
:document_cnpj,
:document_ie,
:document_im,
:regime_tributario,
:end_cep,
:end_ibge,
:end_logradouro,
:end_numero,
:end_complemento,
:end_bairro,
:end_cidade,
:end_uf,
:created_at
)";
$empresaModel->setCreatedAt(new DateTimeImmutable());
$this->db->execute(
sql: $query,
params: [
':uuid' => $empresaModel->getUuid(),
':is_active' => $empresaModel->getIsActive(),
':nome_empresarial' => $empresaModel->getNomeEmpresarial(),
':nome_fantasia' => $empresaModel->getNomeFantasia(),
':tipo' => $empresaModel->getTipo(),
':matriz_id' => $empresaModel->getMatrizId(),
':document_cnpj' => $empresaModel->getDocumentCnpj(),
':document_ie' => $empresaModel->getDocumentIe(),
':document_im' => $empresaModel->getDocumentIm(),
':regime_tributario' => $empresaModel->getRegimeTributario(),
':end_cep' => $empresaModel->getEndCep(),
':end_ibge' => $empresaModel->getEndIbge(),
':end_logradouro' => $empresaModel->getEndLogradouro(),
':end_numero' => $empresaModel->getEndNumero(),
':end_complemento' => $empresaModel->getEndComplemento(),
':end_bairro' => $empresaModel->getEndBairro(),
':end_cidade' => $empresaModel->getEndCidade(),
':end_uf' => $empresaModel->getEndUf(),
':created_at' => $empresaModel->getCreatedAt()->format('Y-m-d H:i:s'),
]
);
$empresaModel->setId($this->db->lastInsertId());
return $empresaModel;
}
public function update(EmpresaModel $empresaModel): bool {
$query =
"UPDATE {$this->empresaTable} SET
is_active = :is_active,
nome_empresarial = :nome_empresarial,
nome_fantasia = :nome_fantasia,
tipo = :tipo,
matriz_id = :matriz_id,
document_cnpj = :document_cnpj,
document_ie = :document_ie,
document_im = :document_im,
regime_tributario = :regime_tributario,
end_cep = :end_cep,
end_ibge = :end_ibge,
end_logradouro = :end_logradouro,
end_numero = :end_numero,
end_complemento = :end_complemento,
end_bairro = :end_bairro,
end_cidade = :end_cidade,
end_uf = :end_uf,
updated_at = :updated_at
WHERE id = :id OR uuid = :uuid";
$empresaModel->setUpdatedAt(new DateTimeImmutable());
return $this->db->execute(
sql: $query,
params: [
':id' => $empresaModel->getId(),
':uuid' => $empresaModel->getUuid(),
':is_active' => $empresaModel->getIsActive(),
':nome_empresarial' => $empresaModel->getNomeEmpresarial(),
':nome_fantasia' => $empresaModel->getNomeFantasia(),
':tipo' => $empresaModel->getTipo(),
':matriz_id' => $empresaModel->getMatrizId(),
':document_cnpj' => $empresaModel->getDocumentCnpj(),
':document_ie' => $empresaModel->getDocumentIe(),
':document_im' => $empresaModel->getDocumentIm(),
':regime_tributario' => $empresaModel->getRegimeTributario(),
':end_cep' => $empresaModel->getEndCep(),
':end_ibge' => $empresaModel->getEndIbge(),
':end_logradouro' => $empresaModel->getEndLogradouro(),
':end_numero' => $empresaModel->getEndNumero(),
':end_complemento' => $empresaModel->getEndComplemento(),
':end_bairro' => $empresaModel->getEndBairro(),
':end_cidade' => $empresaModel->getEndCidade(),
':end_uf' => $empresaModel->getEndUf(),
':updated_at' => $empresaModel->getUpdatedAt()->format('Y-m-d H:i:s'),
]
);
}
public function delete(EmpresaModel $empresaModel): bool {
$query =
"UPDATE {$this->empresaTable} SET
deleted_at = :deleted_at
WHERE id = :id OR uuid = :uuid";
$empresaModel->setDeletedAt(new DateTimeImmutable());
return $this->db->execute(
sql: $query,
params: [
':id' => $empresaModel->getId(),
':uuid' => $empresaModel->getUuid(),
':deleted_at' => $empresaModel->getDeletedAt()->format('Y-m-d H:i:s'),
]
);
}
public function findByIdentifier(string $identifier, mixed $value): ?EmpresaModel {
$query =
"SELECT
id,
uuid,
is_active,
nome_empresarial,
nome_fantasia,
tipo,
matriz_id,
document_cnpj,
document_ie,
document_im,
regime_tributario,
end_cep,
end_ibge,
end_logradouro,
end_numero,
end_complemento,
end_bairro,
end_cidade,
end_uf,
created_at,
updated_at,
deleted_at
FROM {$this->empresaTable}
WHERE $identifier = :value
AND deleted_at IS NULL
LIMIT 1";
$result = $this->db->fetchOne(
sql: $query,
params: [
':value' => $value
]
);
return $result ? $this->mapToModel($result) : null;
}
public function findAllByMatrizId(int $matriz_id): array {
$query =
"SELECT
id,
uuid,
is_active,
nome_empresarial,
nome_fantasia,
tipo,
matriz_id,
document_cnpj,
document_ie,
document_im,
regime_tributario,
end_cep,
end_ibge,
end_logradouro,
end_numero,
end_complemento,
end_bairro,
end_cidade,
end_uf,
created_at,
updated_at,
deleted_at
FROM {$this->empresaTable}
WHERE (
id = :matriz_id OR
matriz_id = :matriz_id
)
AND deleted_at IS NULL";
$results = $this->db->fetchAll(
sql: $query,
params: [
':matriz_id' => $matriz_id
]
);
return array_map(fn($data) => $this->mapToModel($data), $results);
}
private function mapToModel(array $data): EmpresaModel {
return new EmpresaModel(
id: $data['id'],
uuid: $data['uuid'],
is_active: $data['is_active'],
nome_empresarial: $data['nome_empresarial'],
nome_fantasia: $data['nome_fantasia'],
tipo: $data['tipo'],
matriz_id: $data['matriz_id'],
document_cnpj: $data['document_cnpj'],
document_ie: $data['document_ie'],
document_im: $data['document_im'],
regime_tributario: $data['regime_tributario'],
end_cep: $data['end_cep'],
end_ibge: $data['end_ibge'],
end_logradouro: $data['end_logradouro'],
end_numero: $data['end_numero'],
end_complemento: $data['end_complemento'],
end_bairro: $data['end_bairro'],
end_cidade: $data['end_cidade'],
end_uf: $data['end_uf'],
created_at: $data['created_at'] ? new DateTimeImmutable($data['created_at']) : null,
updated_at: $data['updated_at'] ? new DateTimeImmutable($data['updated_at']) : null,
deleted_at: $data['deleted_at'] ? new DateTimeImmutable($data['deleted_at']) : null,
);
}
}