Skip to content

Commit

Permalink
Ajuste relatorios e sincronismo
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfl2007 committed Sep 19, 2024
1 parent 9a08a56 commit d313de7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/cron-jobs/cron-jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class CronJobsService {
});
}

async onModuleLoad() {
async onModuleLoad() {
const THIS_CLASS_WITH_METHOD = 'CronJobsService.onModuleLoad';

this.jobsConfig.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface IFindPublicacaoRelatorio {
valorMax?: number;
pago?: boolean;
aPagar?: boolean;
emProcessamento?:boolean;
}
24 changes: 16 additions & 8 deletions src/relatorio/relatorio-sintetico.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}`;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions src/relatorio/relatorio.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion src/relatorio/relatorio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 8 additions & 13 deletions src/transacao-view/transacao-view.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d313de7

Please sign in to comment.