From d313de7347246f6e3d25d73d3cfc55501e90b21e Mon Sep 17 00:00:00 2001 From: williamfl2007 Date: Thu, 19 Sep 2024 15:22:09 -0300 Subject: [PATCH] Ajuste relatorios e sincronismo --- src/cron-jobs/cron-jobs.service.ts | 2 +- .../find-publicacao-relatorio.interface.ts | 1 + .../relatorio-sintetico.repository.ts | 24 ++++++++++++------- src/relatorio/relatorio.controller.ts | 6 +++-- src/relatorio/relatorio.service.ts | 2 +- .../transacao-view.repository.ts | 21 +++++++--------- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/cron-jobs/cron-jobs.service.ts b/src/cron-jobs/cron-jobs.service.ts index 779057da..a949d745 100644 --- a/src/cron-jobs/cron-jobs.service.ts +++ b/src/cron-jobs/cron-jobs.service.ts @@ -73,7 +73,7 @@ export class CronJobsService { }); } - async onModuleLoad() { + async onModuleLoad() { const THIS_CLASS_WITH_METHOD = 'CronJobsService.onModuleLoad'; this.jobsConfig.push( diff --git a/src/relatorio/interfaces/find-publicacao-relatorio.interface.ts b/src/relatorio/interfaces/find-publicacao-relatorio.interface.ts index 978a6875..54288475 100644 --- a/src/relatorio/interfaces/find-publicacao-relatorio.interface.ts +++ b/src/relatorio/interfaces/find-publicacao-relatorio.interface.ts @@ -7,4 +7,5 @@ export interface IFindPublicacaoRelatorio { valorMax?: number; pago?: boolean; aPagar?: boolean; + emProcessamento?:boolean; } \ No newline at end of file diff --git a/src/relatorio/relatorio-sintetico.repository.ts b/src/relatorio/relatorio-sintetico.repository.ts index 2ede3b3c..aa9a0a40 100644 --- a/src/relatorio/relatorio-sintetico.repository.ts +++ b/src/relatorio/relatorio-sintetico.repository.ts @@ -27,7 +27,10 @@ export class RelatorioSinteticoRepository { if(dataInicio!==undefined && dataFim!==undefined && (dataFim === dataInicio || new Date(dataFim)>new Date(dataInicio))) query = query + ` and dta."dataVencimento" between '${dataInicio}' and '${dataFim}'`; - if(args.pago !==undefined) + if(args.emProcessamento!==undefined && args.emProcessamento===true ){ + query = query +` and app."isPago"=false and dta."ocorrenciasCnab" is null ` + }else + if(args.pago !==undefined) query = query +` and app."isPago"=${args.pago} `; query = query + ` and tt."nomeConsorcio"=res.consorcio `; @@ -122,7 +125,10 @@ export class RelatorioSinteticoRepository { query = query +` and it."nomeConsorcio" in('STPC','STPL') `; } - if(args.pago !==undefined) + if(args.emProcessamento!==undefined && args.emProcessamento===true){ + query = query +` and ap."isPago"=false and da."ocorrenciasCnab" is null ` + }else + if(args.pago !==undefined) query = query +` and ap."isPago"=${args.pago} `; if(args.valorMin!==undefined) @@ -187,8 +193,11 @@ export class RelatorioSinteticoRepository { query = query +` and it."nomeConsorcio" in('STPC','STPL') `; } + if(args.emProcessamento!==undefined && args.emProcessamento===true ){ + query = query +` and ap."isPago"=false and da."ocorrenciasCnab" is null ` + }else if(args.pago !==undefined) - query = query +` and ap."isPago"=${args.pago}`; + query = query +` and ap."isPago"=${args.pago} `; if(args.valorMin!==undefined) query = query +` and it."valor">=${args.valorMin}`; @@ -197,10 +206,11 @@ export class RelatorioSinteticoRepository { query = query + ` and it."valor"<=${args.valorMax}`; } - if((query !==` select distinct res.* from ( `) &&(args.aPagar==true || (args.aPagar === undefined && args.pago === undefined))) + if((query !==` select distinct res.* from ( `) &&(args.aPagar==true || + (args.aPagar === undefined && args.pago === undefined)) &&(args.emProcessamento === undefined || args.emProcessamento === false )) query = query + ` union All `; - if(args.aPagar==true || (args.aPagar === undefined && args.pago === undefined)){ + if(args.aPagar==true || (args.aPagar === undefined && args.pago === undefined)&&(args.emProcessamento === undefined || args.emProcessamento === false)){ query = query +` select distinct tv.id, @@ -258,9 +268,7 @@ export class RelatorioSinteticoRepository { } query = query + ` ) as res - order by res."consorcio", res."favorecido",res."datapagamento" `; - - this.logger.debug(query); + order by res."consorcio", res."favorecido",res."datapagamento" `; return query; } diff --git a/src/relatorio/relatorio.controller.ts b/src/relatorio/relatorio.controller.ts index 3d4433c9..fe11b2ff 100644 --- a/src/relatorio/relatorio.controller.ts +++ b/src/relatorio/relatorio.controller.ts @@ -59,6 +59,7 @@ export class RelatorioController { @ApiQuery({ name: 'valorMax', description: 'Somatório do valor bruto.', required: false, type: Number }) @ApiQuery({ name: 'pago', required: false, type: Boolean, description: ApiDescription({ _: 'Se o pagamento foi pago com sucesso.', default: false }) }) @ApiQuery({ name: 'aPagar', required: false, type: Boolean, description: ApiDescription({ _: 'Se o status for a pagar', default: false }) }) + @ApiQuery({ name: 'emProcessamento', required: false, type: Boolean, description: ApiDescription({ _: 'Se o status for em Processamento', default: false }) }) @HttpCode(HttpStatus.OK) @ApiBearerAuth() @UseGuards(AuthGuard('jwt')) @@ -77,11 +78,12 @@ export class RelatorioController { @Query('valorMax', new ParseNumberPipe({ optional: true })) valorMax: number | undefined, @Query('pago',new ParseBooleanPipe({ optional: true })) pago: boolean | undefined, - @Query('aPagar',new ParseBooleanPipe({ optional: true })) aPagar: boolean | undefined + @Query('aPagar',new ParseBooleanPipe({ optional: true })) aPagar: boolean | undefined, + @Query('emProcessamento',new ParseBooleanPipe({ optional: true })) emProcessamento: boolean | undefined ) { try{ const result = await this.relatorioService.findSintetico({ - dataInicio,dataFim, favorecidoNome, consorcioNome, valorMin, valorMax, pago, aPagar + dataInicio,dataFim, favorecidoNome, consorcioNome, valorMin, valorMax, pago, aPagar,emProcessamento }); return result; }catch(e){ diff --git a/src/relatorio/relatorio.service.ts b/src/relatorio/relatorio.service.ts index e43e10ef..857bc198 100644 --- a/src/relatorio/relatorio.service.ts +++ b/src/relatorio/relatorio.service.ts @@ -97,7 +97,7 @@ export class RelatorioService { const sintenticosData = new RelatorioSinteticoResultDto(); sintenticosData.count = sintetico.length; sintenticosData.data = sintetico; - sintenticosData.valor = sintetico[0].total; + sintenticosData.valor = (sintetico!==undefined && sintetico[0]!==undefined)?sintetico[0].total:0; sintenticosData.status = status; return sintenticosData; } diff --git a/src/transacao-view/transacao-view.repository.ts b/src/transacao-view/transacao-view.repository.ts index 59d447cf..9de71588 100644 --- a/src/transacao-view/transacao-view.repository.ts +++ b/src/transacao-view/transacao-view.repository.ts @@ -81,17 +81,13 @@ export class TransacaoViewRepository { SELECT DISTINCT ON (tv.id) tv.id AS tv_id, - (select ia.id from item_transacao_agrupado ia - where ia."idOrdemPagamento" = ita."idOrdemPagamento" - and ia."idOperadora" = ita."idOperadora" - and ia."dataOrdem" = ita."dataOrdem" - and ia."createdAt" =(select max(itt."createdAt") from item_transacao_agrupado itt - where ia."idOrdemPagamento" = itt."idOrdemPagamento" - and ia."idOperadora" = itt."idOperadora" - and ia."dataOrdem" = itt."dataOrdem") ) as ita_id, + ita.id ita_id, + ita."valor", + tv."valorPago", tv."datetimeTransacao", - tv."datetimeProcessamento", - ita."dataOrdem" + it."dataOrdem", + it."dataCaptura", + da."dataVencimento" FROM item_transacao_agrupado ita INNER JOIN detalhe_a da ON da."itemTransacaoAgrupadoId" = ita.id INNER JOIN item_transacao it ON it."itemTransacaoAgrupadoId" = ita.id @@ -100,9 +96,8 @@ export class TransacaoViewRepository { ON tv."idConsorcio" = ita."idConsorcio" AND tv."idOperadora" = ita."idOperadora" AND tv."operadoraCpfCnpj" = cf."cpfCnpj" - AND tv."datetimeTransacao"::DATE BETWEEN - (ita."dataCaptura"::DATE - (CASE WHEN ita."nomeConsorcio" = 'VLT' THEN INTERVAL '2 DAYS' ELSE INTERVAL '8 DAYS' END)) -- VENCIMENTO - 2 SE VLT; SENÃO QUINTA PGTO - AND (DATE(ita."dataCaptura") - INTERVAL '2 DAYS') -- VENCIMENTO - 2 (OU QUARTA PGTO SE NÃO for VLT) + AND tv."datetimeTransacao"::DATE + BETWEEN (it."dataOrdem"::DATE) - INTERVAL '1 DAYS' AND (it."dataOrdem"::DATE) WHERE (1=1) ${where.length ? `AND ${where.join(' AND ')}` : ''} ORDER BY tv.id ASC, ita.id DESC ) associados