Skip to content

Commit

Permalink
Merge pull request #464 from RJ-SMTR/feature/ajuste_totais_sintetico
Browse files Browse the repository at this point in the history
Ajuste totais e filtros relatorio sintetico
  • Loading branch information
williamfl2007 authored Sep 13, 2024
2 parents 83fc648 + 3e8cec6 commit 22b1123
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/relatorio/dtos/relatorio-sintetico.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class RelatorioSinteticoDto {
}

valor: number = 0;
total: number = 0;
nome: String;
@Exclude()
agrupadoCount: number = 1;
Expand Down
99 changes: 85 additions & 14 deletions src/relatorio/relatorio-sintetico.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class RelatorioSinteticoRepository {
const dataInicio = args.dataInicio.toISOString().slice(0,10)
const dataFim = args.dataFim.toISOString().slice(0,10)
let query = ` select distinct res.*,
(select sum(dta."valorLancamento")::float valor
(select sum(ss."valorLancamento")::float from
(select distinct dta.id,dta."valorLancamento"
from detalhe_a dta
inner join item_transacao_agrupado tt on dta."itemTransacaoAgrupadoId"=tt.id
left join item_transacao itt on itt."itemTransacaoAgrupadoId" = tt."id"
Expand All @@ -29,8 +30,41 @@ export class RelatorioSinteticoRepository {
if(args.pago !==undefined)
query = query +` and app."isPago"=${args.pago} `;

query = query + ` and tt."nomeConsorcio"=res.consorcio `;
query = query + ` ) as subTotal `;
query = query + ` and tt."nomeConsorcio"=res.consorcio `;
query = query + ` )as ss) as subTotal,
(select sum(tt."valorLancamento")::float from
(select distinct dta.id,dta."valorLancamento"
from detalhe_a dta
inner join item_transacao_agrupado tt on dta."itemTransacaoAgrupadoId"=tt.id
left join item_transacao itt on itt."itemTransacaoAgrupadoId" = tt."id"
left join arquivo_publicacao app on app."itemTransacaoId"=itt.id
WHERE (1=1) `;
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)
query = query +` and app."isPago"=${args.pago} `;

if((args.consorcioNome!==undefined) && !(['Todos'].some(i=>args.consorcioNome?.includes(i)))){
query = query +` and tt."nomeConsorcio" in('${args.consorcioNome?.join("','")}')`;
}else
if((args.favorecidoNome!==undefined) && !(['Todos'].some(i=>args.favorecidoNome?.includes(i))))
query = query +` and tt."nomeConsorcio" in(res.consorcio) `;
else
if(
(['Todos'].some(i=>args.consorcioNome?.includes(i))) && (['Todos'].some(i=>args.favorecidoNome?.includes(i)))
||
((args.consorcioNome!==undefined) && (args.favorecidoNome!==undefined))
){
query = query +` and tt."nomeConsorcio"
in ('STPC','STPL','VLT','Santa Cruz','Internorte','Intersul','Transcarioca','MobiRio') `;
}
else if((['Todos'].some(i=>args.favorecidoNome?.includes(i)))){
query = query +` and tt."nomeConsorcio" in('STPC','STPL') `;
}

query = query + ` )as tt )as total `;

query = query + ` from ( `;
if(args.aPagar === undefined || args.aPagar === false){
Expand Down Expand Up @@ -70,11 +104,23 @@ export class RelatorioSinteticoRepository {
(dataFim === dataInicio || new Date(dataFim)>new Date(dataInicio)))
query = query + ` and da."dataVencimento" between '${dataInicio}' and '${dataFim}'`;

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

if((args.favorecidoNome!==undefined) && !(['Todos'].some(i=>args.favorecidoNome?.includes(i))))
query = query +` and cf."nome" in('${args.favorecidoNome?.join("','")}')`;
}else
if((args.favorecidoNome!==undefined) && !(['Todos'].some(i=>args.favorecidoNome?.includes(i)))){
query = query +` and cf."nome" in('${args.favorecidoNome?.join("','")}')`;
}else
if(
(['Todos'].some(i=>args.consorcioNome?.includes(i))) && (['Todos'].some(i=>args.favorecidoNome?.includes(i)))
||
((args.consorcioNome!==undefined) && (args.favorecidoNome!==undefined))
){
query = query +` and it."nomeConsorcio"
in ('STPC','STPL','VLT','Santa Cruz','Internorte','Intersul','Transcarioca','MobiRio') `;
}else
if((['Todos'].some(i=>args.favorecidoNome?.includes(i)))){
query = query +` and it."nomeConsorcio" in('STPC','STPL') `;
}

if(args.pago !==undefined)
query = query +` and ap."isPago"=${args.pago} `;
Expand Down Expand Up @@ -123,11 +169,23 @@ export class RelatorioSinteticoRepository {
(dataFim === dataInicio || new Date(dataFim)>new Date(dataInicio)))
query = query + ` and da."dataVencimento" between '${dataInicio}' and '${dataFim}'`;

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

if((args.favorecidoNome!==undefined) && !(['Todos'].some(i=>args.favorecidoNome?.includes(i))))
query = query +` and cf."nome" in('${args.favorecidoNome?.join("','")}')`;
} else
if((args.favorecidoNome!==undefined) && !(['Todos'].some(i=>args.favorecidoNome?.includes(i)))){
query = query +` and cf."nome" in('${args.favorecidoNome?.join("','")}')`;
} else
if(
(['Todos'].some(i=>args.consorcioNome?.includes(i))) && (['Todos'].some(i=>args.favorecidoNome?.includes(i)))
||
((args.consorcioNome!==undefined) && (args.favorecidoNome!==undefined))
){
query = query +` and it."nomeConsorcio"
in ('STPC','STPL','VLT','Santa Cruz','Internorte','Intersul','Transcarioca','MobiRio') `;
}else
if((['Todos'].some(i=>args.favorecidoNome?.includes(i)))){
query = query +` and it."nomeConsorcio" in('STPC','STPL') `;
}

if(args.pago !==undefined)
query = query +` and ap."isPago"=${args.pago}`;
Expand Down Expand Up @@ -170,11 +228,24 @@ export class RelatorioSinteticoRepository {
(dataFim === dataInicio || new Date(dataFim)>new Date(dataInicio)))
query = query + ` and tv."datetimeTransacao" between '${dataInicio}' and '${dataFim}'`;

if((args.consorcioNome!==undefined) && !(['Todos'].some(i=>args.consorcioNome?.includes(i))))
if((args.consorcioNome!==undefined) && !(['Todos'].some(i=>args.consorcioNome?.includes(i)))){
query = query +` and tv."nomeConsorcio" in('${args.consorcioNome?.join("','")}')`;
if((args.favorecidoNome!==undefined) && !(['Todos'].some(i=>args.favorecidoNome?.includes(i))))
}else
if((args.favorecidoNome!==undefined) && !(['Todos'].some(i=>args.favorecidoNome?.includes(i)))){
query = query +` and cf."nome" in('${args.favorecidoNome?.join("','")}')`;
}else
if(
(['Todos'].some(i=>args.consorcioNome?.includes(i))) && (['Todos'].some(i=>args.favorecidoNome?.includes(i)))
||
((args.consorcioNome!==undefined) && (args.favorecidoNome!==undefined))
){
query = query +` and tv."nomeConsorcio"
in ('STPC','STPL','VLT','Santa Cruz','Internorte','Intersul','Transcarioca','MobiRio') `;
}else

if((['Todos'].some(i=>args.favorecidoNome?.includes(i)))){
query = query +` and tv."nomeConsorcio" in('STPC','STPL') `;
}

if(args.valorMin!==undefined)
query = query +` and tv."valorPago">=${args.valorMin}`;
Expand Down
4 changes: 2 additions & 2 deletions src/relatorio/relatorio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export class RelatorioService {
}

private async instanceDataSintetico(args: IFindPublicacaoRelatorio,status:string){
const sintetico = await this.relatorioSinteticoRepository.findSintetico(args);
const sintetico = await this.relatorioSinteticoRepository.findSintetico(args);
const sintenticosData = new RelatorioSinteticoResultDto();
sintenticosData.count = sintetico.length;
sintenticosData.data = sintetico;
sintenticosData.valor = +sintetico.reduce((s, i) => s + i.valor, 0).toFixed(2);
sintenticosData.valor = sintetico[0].total;
sintenticosData.status = status;
return sintenticosData;
}
Expand Down

0 comments on commit 22b1123

Please sign in to comment.