Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/controllers/relatorios-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const {
Estado,
Pais,
TomboFoto,
Variedade,
Subespecie,
} = models;

/// ////// Relatório de Inventário de Espécies //////////
Expand Down Expand Up @@ -291,7 +293,7 @@ export const obtemDadosDoRelatorioDeColetaIntervaloDeData = async (req, res, nex
{
[Op.between]: [
Sequelize.literal(`TO_DATE('${dataInicio.slice(0, 10)}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim || new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim ? dataFim.slice(0, 10) : new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
],
},
),
Expand Down Expand Up @@ -403,7 +405,7 @@ export const obtemDadosDoRelatorioDeColetaPorColetorEIntervaloDeData = async (re
{
[Op.between]: [
Sequelize.literal(`TO_DATE('${dataInicio.slice(0, 10)}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim || new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim ? dataFim.slice(0, 10) : new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
],
},
),
Expand Down Expand Up @@ -530,7 +532,7 @@ export const obtemDadosDoRelatorioDeLocalDeColeta = async (req, res, next) => {
{
[Op.between]: [
Sequelize.literal(`TO_DATE('${dataInicio.slice(0, 10)}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim || new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim ? dataFim.slice(0, 10) : new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
],
},
),
Expand All @@ -546,6 +548,8 @@ export const obtemDadosDoRelatorioDeLocalDeColeta = async (req, res, next) => {
'familia_id',
'especie_id',
'genero_id',
'variedade_id',
'sub_especie_id',
'nome_cientifico',
'data_coleta_ano',
'data_coleta_mes',
Expand Down Expand Up @@ -576,6 +580,28 @@ export const obtemDadosDoRelatorioDeLocalDeColeta = async (req, res, next) => {
},
],
},
{
model: Variedade,
attributes: ['id', 'nome'],
include: [
{
model: Autor,
attributes: ['id', 'nome'],
as: 'autor',
},
],
},
{
model: Subespecie,
attributes: ['id', 'nome'],
include: [
{
model: Autor,
attributes: ['id', 'nome'],
as: 'autor',
},
],
},
{
model: LocalColeta,
attributes: ['id', 'descricao'],
Expand Down Expand Up @@ -748,7 +774,7 @@ export const obtemDadosDoRelatorioDeCodigoDeBarras = async (req, res, next) => {
{
[Op.between]: [
Sequelize.literal(`TO_DATE('${dataInicio.slice(0, 10)}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim || new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim ? dataFim.slice(0, 10) : new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
],
},
),
Expand Down Expand Up @@ -815,7 +841,7 @@ export const obtemDadosDoRelatorioDeQuantidade = async (req, res, next) => {
{
[Op.between]: [
Sequelize.literal(`TO_DATE('${dataInicio.slice(0, 10)}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim || new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
Sequelize.literal(`TO_DATE('${(dataFim ? dataFim.slice(0, 10) : new Date().toISOString().slice(0, 10))}', 'YYYY-MM-DD')`),
],
},
),
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/formata-dados-relatorio.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ export function agruparPorLocal(dados) {
let quantidadeTotal = 0;

dados.sort((a, b) => {
const familia = a?.familia?.nome.localeCompare(b?.familia?.nome);
const familia = (a?.familia?.nome || '').localeCompare(b?.familia?.nome || '');
if (familia !== 0) return familia;

const genero = a?.genero?.nome.localeCompare(b?.genero?.nome);
const genero = (a?.genero?.nome || '').localeCompare(b?.genero?.nome || '');
if (genero !== 0) return genero;

return a?.especy?.nome.localeCompare(b?.especy?.nome);
return (a?.especy?.nome || '').localeCompare(b?.especy?.nome || '');
}).forEach(entradaOriginal => {
const locaisColetum = entradaOriginal.locais_coletum;
const cidade = locaisColetum?.cidade;
Expand All @@ -267,7 +267,8 @@ export function agruparPorLocal(dados) {
...entradaOriginal,
latitude: entradaOriginal?.latitude || null,
longitude: entradaOriginal?.longitude || null,
autor: entradaOriginal.especy?.autor?.nome || '',
variedade: entradaOriginal.variedade || null,
sub_especie: entradaOriginal.sub_especy || null,
};

if (!agrupado[chave]) {
Expand Down
41 changes: 36 additions & 5 deletions src/reports/templates/LocaisColeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Registro {
data_coleta_dia: number;
especy: {
nome: string;
autor?: { nome: string } | null;
genero: {
nome: string;
}
Expand All @@ -21,9 +22,16 @@ interface Registro {
genero: {
nome: string;
}
variedade?: {
nome: string;
autor?: { nome: string } | null;
} | null;
sub_especie?: {
nome: string;
autor?: { nome: string } | null;
} | null;
latitude: number | null;
longitude: number | null;
autor?: string;
}

interface LocaisColeta {
Expand Down Expand Up @@ -103,29 +111,52 @@ function RelacaoLocaisColeta({ dados, total, textoFiltro, showCoord = false }: R
};
}

const renderNomeCientifico = (item: Registro) => {
const { especy, genero } = item;
return (
<>
<span style={{ fontStyle: 'italic' }}>{genero?.nome} {especy?.nome}</span>
{especy?.autor?.nome && ` ${especy.autor.nome}`}
{item.sub_especie && (
<>
{' subsp. '}
<span style={{ fontStyle: 'italic' }}>{item.sub_especie.nome}</span>
{item.sub_especie.autor?.nome && ` ${item.sub_especie.autor.nome}`}
</>
)}
{item.variedade && (
<>
{' var. '}
<span style={{ fontStyle: 'italic' }}>{item.variedade.nome}</span>
{item.variedade.autor?.nome && ` ${item.variedade.autor.nome}`}
</>
)}
</>
);
}

const renderTable = (registros: Registro[]) => {
return (
<table>
<thead>
<tr>
<th>Data Coleta</th>
<th>Família</th>
<th>Espécie</th>
{/* <th>Autor</th> */}
<th>Nome Científico</th>
{showCoord && <th>Latitude</th>}
{showCoord && <th>Longitude</th>}
<th style={{ textAlign: 'right' }}>Nº do Tombo</th>
</tr>
</thead>
<tbody>
{registros.map((item, i) => {
const { especy, familia, genero } = item;
const { familia } = item;
const cordenadas = obtemCordenadas(item);
return (
<tr key={`${i}-${item.hcf}`}>
<td>{criaData(item)}</td>
<td>{familia?.nome}</td>
<td style={{ display: 'flex', gap: 10 }}><div style={{ fontStyle: 'italic', display: 'flex', alignItems: 'center', width: 'fit-content' }}>{genero?.nome} {especy?.nome}</div> {item.autor}</td>
<td>{renderNomeCientifico(item)}</td>
{showCoord && <td>{cordenadas.latitude}</td>}
{showCoord && <td>{cordenadas.longitude}</td>}
<td style={{ textAlign: 'right' }}>{item.hcf}</td>
Expand Down
Loading