-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from auguzsto/0.1
feat and fixes relatorios
- Loading branch information
Showing
17 changed files
with
272 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CREATE DATABASE IF NOT EXISTS backend_assim; | ||
|
||
CREATE TABLE cargos( | ||
id BIGINT AUTO_INCREMENT, | ||
nome TEXT NOT NULL, | ||
salario TEXT, | ||
created_at DATETIME NOT NULL, | ||
updated_at DATETIME, | ||
deleted_at DATETIME, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE funcionarios( | ||
id BIGINT AUTO_INCREMENT, | ||
nome TEXT NOT NULL, | ||
data_nascimento DATE, | ||
endereco_completo TEXT, | ||
cpf TEXT NOT NULL UNIQUE, | ||
email TEXT, | ||
telefone TEXT, | ||
cargo_id BIGINT NOT NULL, | ||
created_at DATETIME NOT NULL, | ||
updated_at DATETIME, | ||
deleted_at DATETIME, | ||
PRIMARY KEY (id), | ||
FOREIGN KEY (cargo_id) REFERENCES cargos(id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
namespace App\controllers; | ||
use PDO; | ||
use Exception; | ||
use App\core\Database; | ||
|
||
class RelatorioController { | ||
|
||
public function getNomeTelefoneCargoAll() { | ||
try { | ||
$db = Database::getInstace(); | ||
$data = $db->query("select f.id as funcionario_id, c.id as cargo_id, f.nome AS nome_funcionario, f.telefone , c.nome AS nome_cargo, c.salario FROM cargos c, funcionarios f where f.nome like '%Matheus%' or c.nome like '%a'GROUP BY f.nome;")->fetchAll(PDO::FETCH_ASSOC); | ||
echo json_encode($data); | ||
} catch (Exception $e) { | ||
header('HTTP/1.1 400 Bad Request'); | ||
echo json_encode(["error"=> $e->getMessage()]); | ||
throw $e; | ||
} | ||
} | ||
|
||
public function getNomeTelefoneCargoByNomeCpf(string $params) { | ||
try { | ||
$db = Database::getInstace(); | ||
$data = $db->query("select f.id as funcionario_id, c.id as cargo_id, f.nome AS nome_funcionario, f.telefone , c.nome AS nome_cargo, c.salario FROM cargos c, funcionarios f where f.nome like '%$params%' or c.nome like '%$params%' GROUP BY f.nome;")->fetchAll(PDO::FETCH_ASSOC); | ||
echo json_encode($data); | ||
} catch (Exception $e) { | ||
header('HTTP/1.1 400 Bad Request'); | ||
echo json_encode(["error"=> $e->getMessage()]); | ||
throw $e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import Header from "@/components/Header"; | ||
|
||
import Link from "next/link"; | ||
import ListRelatoriosByNomeCargo from "../../components/ListRelatoriosByNomeCargo"; | ||
import ButtonSearchRelatorio from "../../components/ButtonSearchRelatorio"; | ||
const BuscarFuncionarios = async ({ params }: { params: { slug: string } }) => { | ||
return ( | ||
<> | ||
<Header title={`Busca de cargo ${params.slug}`}/> | ||
<div className="p-1 mt-1 text-2xl flex items-start justify-between w-full"> | ||
<b>Relatórios</b> | ||
<div> | ||
<ButtonSearchRelatorio /> | ||
</div> | ||
</div> | ||
<ListRelatoriosByNomeCargo params={params} /> | ||
</> | ||
); | ||
} | ||
|
||
export default BuscarFuncionarios; |
54 changes: 54 additions & 0 deletions
54
frontend/src/app/relatorios/components/ButtonSearchRelatorio.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use client' | ||
|
||
import Modal from "@/components/Modal"; | ||
import ICargo from "@/types/Cargo"; | ||
import React, { FormEventHandler, useState } from "react"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
interface IButtonSearchRelatorio { | ||
|
||
} | ||
|
||
const ButtonSearchRelatorio = (props: IButtonSearchRelatorio) => { | ||
const [modal, setModal] = useState(false); | ||
const [nomeCargoFuncionario, setNomeCargoFuncionario] = useState(''); | ||
|
||
const router = useRouter(); | ||
|
||
const handlerSearchFuncionario: FormEventHandler<HTMLFormElement> = async (e) => { | ||
e.preventDefault(); | ||
router.push(`/relatorios/buscar/${nomeCargoFuncionario}`); | ||
} | ||
|
||
const handlerModalOpen = () => { | ||
setModal(true) | ||
} | ||
return ( | ||
<> | ||
<button | ||
className="btn btn-neutral" | ||
onClick={handlerModalOpen} | ||
> | ||
Pesquisar | ||
</button> | ||
|
||
<Modal open={modal} close={() => setModal(false)} title="Pesquisar"> | ||
<div id="error" className="modal-open"></div> | ||
<form onSubmit={handlerSearchFuncionario}> | ||
<div className="modal-action"> | ||
<input | ||
className="input input-bordered w-full" | ||
name="nome" | ||
placeholder="Digite cargo ou nome do funcionário" | ||
value={nomeCargoFuncionario} | ||
onChange={(e) => setNomeCargoFuncionario(e.target.value)} | ||
/> | ||
<button type="submit" className="btn">Pesquisar</button> | ||
</div> | ||
</form> | ||
</Modal> | ||
</> | ||
); | ||
} | ||
|
||
export default ButtonSearchRelatorio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getAllRelatorios} from "../../../../api"; | ||
|
||
|
||
const ListRelatorios = async () => { | ||
const relatorios = await getAllRelatorios(); | ||
|
||
return ( | ||
<div> | ||
<table className="table-auto w-full shadow-md mt-5 rounded border-separate border-spacing-y-3"> | ||
<thead className="text-left tracking-wider"> | ||
<tr> | ||
<th className="p-4">Nome do funcionário</th> | ||
<th className="p-4">Telefone</th> | ||
<th className="p-4">Cargo</th> | ||
<th className="p-4">Salario</th> | ||
</tr> | ||
</thead> | ||
<tbody className=""> | ||
{relatorios.map(relatorios => ( | ||
<tr key={relatorios.funcionario_id} className="bg-card rounded"> | ||
<td className="p-4"><a href={`/funcionarios/${relatorios.funcionario_id}`}>{relatorios.nome_funcionario}</a></td> | ||
<td className="p-4">{relatorios.telefone}</td> | ||
<td className="p-4"><a href={`/cargos/${relatorios.cargo_id}`}>{relatorios.nome_cargo}</a></td> | ||
<td className="p-4">{relatorios.salario}</td> | ||
|
||
</tr> | ||
))} | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
} | ||
|
||
export default ListRelatorios; |
34 changes: 34 additions & 0 deletions
34
frontend/src/app/relatorios/components/ListRelatoriosByNomeCargo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getCargoById, getFuncionarioByNome, getRelatorioByNomeCargo } from "../../../../api"; | ||
|
||
const ListRelatoriosByNomeCargo = async ({ params }: { params: { slug: string } }) => { | ||
const relatorios = await getRelatorioByNomeCargo(params.slug); | ||
|
||
return ( | ||
<div> | ||
<table className="table-auto w-full shadow-md mt-5 rounded border-separate border-spacing-y-3"> | ||
<thead className="text-left tracking-wider"> | ||
<tr> | ||
<th className="p-4">Nome do funcionário</th> | ||
<th className="p-4">Telefone</th> | ||
<th className="p-4">Cargo</th> | ||
<th className="p-4">Salario</th> | ||
</tr> | ||
</thead> | ||
<tbody className=""> | ||
{relatorios.map(relatorios => ( | ||
<tr key={relatorios.funcionario_id} className="bg-card rounded"> | ||
<td className="p-4"><a href={`/funcionarios/${relatorios.funcionario_id}`}>{relatorios.nome_funcionario}</a></td> | ||
<td className="p-4">{relatorios.telefone}</td> | ||
<td className="p-4"><a href={`/cargos/${relatorios.cargo_id}`}>{relatorios.nome_cargo}</a></td> | ||
<td className="p-4">{relatorios.salario}</td> | ||
|
||
</tr> | ||
))} | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
} | ||
|
||
export default ListRelatoriosByNomeCargo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Header from "@/components/Header"; | ||
import React from "react"; | ||
import Link from "next/link"; | ||
import ButtonSearchRelatorio from "./components/ButtonSearchRelatorio"; | ||
import ListRelatorios from "./components/ListRelatorios"; | ||
|
||
function RelatoriosPage() { | ||
return ( | ||
<div> | ||
<Header title="Relatório"/> | ||
<div className="p-1 mt-1 text-2xl flex items-start justify-between w-full"> | ||
<b>Relatório</b> | ||
<div> | ||
<ButtonSearchRelatorio/> | ||
</div> | ||
</div> | ||
<ListRelatorios/> | ||
</div> | ||
); | ||
} | ||
|
||
|
||
export default RelatoriosPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
interface IRelatorio { | ||
funcionario_id: number, | ||
cargo_id: number, | ||
nome_funcionario: string, | ||
telefone: string, | ||
nome_cargo: string, | ||
salario: string, | ||
} | ||
|
||
export default IRelatorio; |