Skip to content

Commit

Permalink
Merge pull request #534 from RJ-SMTR/feat/nova-logica-eleicao
Browse files Browse the repository at this point in the history
feat: eleicao usando ordem de pagamento como identificador e valores condicionais
  • Loading branch information
williamfl2007 authored Dec 9, 2024
2 parents d6c352e + 651cb07 commit f3082a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 166 deletions.
121 changes: 27 additions & 94 deletions src/relatorio/relatorio-consolidado.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,12 @@ export class RelatorioConsolidadoRepository {
` AND tv."nomeConsorcio" in ('STPC','STPL','VLT','Santa Cruz',
'Internorte','Intersul','Transcarioca','MobiRio','TEC') `;
} else if (nomeConsorcio !== undefined && !['Todos'].some((i) => nomeConsorcio?.includes(i))) query = query + ` and tv."nomeConsorcio" in('${nomeConsorcio?.join("','")}')`;
if (eleicao) {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" = 1030 `;
}
if (eleicao !== undefined) {

query += ` and tv."idOrdemPagamento" LIKE '%U%'`;
} else {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' ||
dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" != '1030' `;
}

query += `and tv."idOrdemPagamento" NOT LIKE '%U%' `;
}
query = query + `) as cs `;

Expand Down Expand Up @@ -117,30 +98,12 @@ export class RelatorioConsolidadoRepository {
} else if (pago !== undefined) {
query += ` and ap."isPago"=${pago} and TRIM(da."ocorrenciasCnab")<>'' `;
}
if (eleicao) {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" = 1030 `;
}
if (eleicao !== undefined) {

query += ` and ita."idOrdemPagamento" LIKE '%U%'`;
} else {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" != '1030' `;
}

query += `and ita."idOrdemPagamento" NOT LIKE '%U%' `;
}
query += `) as cs `;
query += ` group by cs."consorcio"`;
Expand Down Expand Up @@ -182,30 +145,12 @@ export class RelatorioConsolidadoRepository {
query = query + ` and tv."datetimeTransacao" between '${dataInicio + ' 00:00:00'}' and '${dataFim + ' 23:59:59'}' `;

if (favorecidoNome !== undefined && !['Todos'].some((i) => favorecidoNome?.includes(i))) query = query + ` and cf.nome in('${favorecidoNome?.join("','")}')`;
if (eleicao) {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" = 1030 `;
}
if (eleicao !== undefined) {

query += ` and ita."idOrdemPagamento" LIKE '%U%'`;
} else {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" != '1030' `;
}

query += `and ita."idOrdemPagamento" NOT LIKE '%U%' `;
}
query = query + ` ) as cs `;

Expand All @@ -226,6 +171,12 @@ export class RelatorioConsolidadoRepository {
}

private getQueryOperadores(dataInicio: string, dataFim: string, pago?: boolean, valorMin?: number, valorMax?: number, favorecidoNome?: string[], emProcessamento?: boolean, eleicao?: boolean) {
let valor = '';
if(eleicao){
valor ='da."valorRealEfetivado"'
} else {
valor = ' da."valorLancamento"'
}
let query = ` select * from ( `;
query = query + ` select cs."favorecido" nomeFavorecido,sum(cs."valor_agrupado")::float valor from ( `;
query =
Expand All @@ -234,7 +185,7 @@ export class RelatorioConsolidadoRepository {
ita."nomeConsorcio" AS consorcio,
cf.nome AS favorecido,
cf."cpfCnpj" AS favorecido_cpfcnpj,
da."valorLancamento" AS valor_agrupado
${valor} AS valor_agrupado
from transacao_agrupado ta
inner join item_transacao_agrupado ita on ita."transacaoAgrupadoId"=ta."id"
inner join detalhe_a da on da."itemTransacaoAgrupadoId"= ita.id
Expand All @@ -252,30 +203,12 @@ export class RelatorioConsolidadoRepository {
if (favorecidoNome !== undefined && !['Todos'].some((i) => favorecidoNome?.includes(i))) query = query + ` and cf.nome in('${favorecidoNome?.join("','")}')`;
console.log(eleicao)

if (eleicao) {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" = 1030 `;
}
if (eleicao !== undefined) {

query += ` and ita."idOrdemPagamento" LIKE '%U%'`;
} else {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" != '1030' `;
}

query += `and ita."idOrdemPagamento" NOT LIKE '%U%' `;
}
query = query + `) as cs `;

Expand Down
86 changes: 14 additions & 72 deletions src/relatorio/relatorio-sintetico.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class RelatorioSinteticoRepository {
public getQueryNaoApagar(args: IFindPublicacaoRelatorio) {
const dataInicio = args.dataInicio.toISOString().slice(0, 10);
const dataFim = args.dataFim.toISOString().slice(0, 10);
let valor = '';
let query = ` select distinct res.*, `;
query = query + `(select sum(ss."valorLancamento")::float from `;
query =
Expand All @@ -157,33 +158,12 @@ export class RelatorioSinteticoRepository {
query = query + ` and app."isPago"=${args.pago} and TRIM(dta."ocorrenciasCnab")<>'' `;
}
if (args.eleicao !== undefined) {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' ||
dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'

) {
query += ` and dta."valorLancamento" = 1030 `;
}

query += ` and tt."idOrdemPagamento" LIKE '%U%'`;
} else {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and dta."valorLancamento" != '1030' `;
}
}

query += `and tt."idOrdemPagamento" NOT LIKE '%U%' `;
}
query = query + ` and tt."nomeConsorcio"=res.consorcio `;
query = query + ` )as ss) as subTotal, `;

Expand Down Expand Up @@ -216,30 +196,11 @@ export class RelatorioSinteticoRepository {
query = query + ` and tt."nomeConsorcio" in('STPC','STPL','TEC') `;
}
if (args.eleicao !== undefined) {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' ||
dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and dta."valorLancamento" = 1030 `;
}
valor = 'da."valorRealEfetivado"'
query += ` and tt."idOrdemPagamento" LIKE '%U%'`;
} else {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and dta."valorLancamento" != '1030' `;
}
valor = 'it."valor"'
query += `and tt."idOrdemPagamento" NOT LIKE '%U%' `;
}
query = query + ` )as tt )as total `;

Expand All @@ -266,7 +227,7 @@ export class RelatorioSinteticoRepository {
it."nomeConsorcio" AS consorcio,
cf.nome AS favorecido,
cf."cpfCnpj",
it."valor"::float as valor,
${valor}::float as valor,
case
when(not(ap."isPago") and TRIM(da."ocorrenciasCnab")='')then 'Aguardando Pagamento'
when (ap."isPago") then 'pago'
Expand All @@ -287,30 +248,11 @@ export class RelatorioSinteticoRepository {
where `;
if (dataInicio !== undefined && dataFim !== undefined && (dataFim === dataInicio || new Date(dataFim) > new Date(dataInicio))) query = query + ` da."dataVencimento" between '${dataInicio}' and '${dataFim}'`;
if (args.eleicao !== undefined) {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06'||
dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" = 1030 `;
}

query += ` and ita."idOrdemPagamento" LIKE '%U%'`;
} else {
if (
dataInicio === '2024-11-22' ||
dataFim === '2024-11-22' ||
dataInicio === '2024-11-05' ||
dataFim === '2024-11-05' ||
dataInicio === '2024-12-06' ||
dataFim === '2024-12-06' || dataInicio === '2024-12-05' ||
dataFim === '2024-12-05'
) {
query += ` and da."valorLancamento" != '1030' `;
}

query += `and ita."idOrdemPagamento" NOT LIKE '%U%' `;
}
if (args.consorcioNome !== undefined && !['Todos'].some((i) => args.consorcioNome?.includes(i))) {
query = query + ` and it."nomeConsorcio" in('${args.consorcioNome?.join("','")}')`;
Expand Down

0 comments on commit f3082a5

Please sign in to comment.