From 651cb07c85aa63cf454156f971a82dcb15922eb1 Mon Sep 17 00:00:00 2001 From: Gabriel0109 <82231197+Gabriel0109@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:56:57 -0300 Subject: [PATCH] feat: eleicao usando ordem de pagamento como identificador --- .../relatorio-consolidado.repository.ts | 121 ++++-------------- .../relatorio-sintetico.repository.ts | 86 ++----------- 2 files changed, 41 insertions(+), 166 deletions(-) diff --git a/src/relatorio/relatorio-consolidado.repository.ts b/src/relatorio/relatorio-consolidado.repository.ts index bc01a24e..9f9a7c46 100644 --- a/src/relatorio/relatorio-consolidado.repository.ts +++ b/src/relatorio/relatorio-consolidado.repository.ts @@ -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 `; @@ -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"`; @@ -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 `; @@ -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 = @@ -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 @@ -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 `; diff --git a/src/relatorio/relatorio-sintetico.repository.ts b/src/relatorio/relatorio-sintetico.repository.ts index 364c8b95..d07610b8 100644 --- a/src/relatorio/relatorio-sintetico.repository.ts +++ b/src/relatorio/relatorio-sintetico.repository.ts @@ -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 = @@ -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, `; @@ -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 `; @@ -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' @@ -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("','")}')`;