Skip to content

Commit

Permalink
Merge pull request #548 from RJ-SMTR/hotfix/ler-retorno-consorcios
Browse files Browse the repository at this point in the history
fix: ler retornos consórcios
  • Loading branch information
williamfl2007 authored Dec 19, 2024
2 parents 92d282c + 15b0b93 commit cbffe56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/cnab/repository/cliente-favorecido.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,16 @@ export class ClienteFavorecidoRepository {
const trimmedNames = where.nome.map((n) => n.trim());
const nomes = trimmedNames.map((n) => `'%${n}%'`);
query += ` AND cf.nome ILIKE ANY(ARRAY[${nomes.join(',')}])`;
}

const containsCorsorcio = trimmedNames.some(
(name) => name.toLowerCase().includes('concessionaria') || name.toLowerCase().includes('consorcio')
);
if (containsCorsorcio && where.detalheANumeroDocumento) {
query += ` AND da."numeroDocumentoEmpresa" IN (${where.detalheANumeroDocumento
.map((doc) => `'${doc}'`)
.join(',')})`;
}
}
if (where.detalheANumeroDocumento) {
query += ` AND da."numeroDocumentoEmpresa" IN (${where.detalheANumeroDocumento
.map((doc) => `'${doc}'`)
Expand Down Expand Up @@ -216,6 +224,7 @@ export class ClienteFavorecidoRepository {
query += ` ORDER BY cf.id`;

const result: any[] = await this.clienteFavorecidoRepository.query(compactQuery(query));

return result.map((i) => new ClienteFavorecido(i));
}

Expand Down
9 changes: 9 additions & 0 deletions src/cnab/repository/pagamento/detalhe-a.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ export class DetalheARepository {
const trimmedNames = where.nome.map((n) => n.trim());
const nomes = trimmedNames.map((n) => `'%${n}%'`);
qWhere.query += ` AND cf.nome ILIKE ANY(ARRAY[${nomes.join(',')}])`;

const containsCorsorcio = trimmedNames.some(
(name) => name.toLowerCase().includes('concessionaria') || name.toLowerCase().includes('consorcio')
);
if (containsCorsorcio && where.numeroDocumentoEmpresa) {
qWhere.query += ` AND da."numeroDocumentoEmpresa" = $${qWhere.params.length + 1}`;
qWhere.params.push(where.numeroDocumentoEmpresa);
}
}

const result: any[] = await this.detalheARepository.query(
compactQuery(`
SELECT
Expand Down
7 changes: 5 additions & 2 deletions src/cnab/service/pagamento/detalhe-a.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export class DetalheAService {
const favorecido = await this.clienteFavorecidoService.findOneRaw({
nome: [r.detalheA.nomeTerceiro.stringValue],
dataVencimento: [r.detalheA.dataVencimento.convertedValue],
valorRealEfetivado: [r.detalheA.valorRealEfetivado.convertedValue]
detalheANumeroDocumento: [r.detalheA.numeroDocumentoEmpresa.convertedValue],
valorRealEfetivado: [r.detalheA.valorLancamento.convertedValue]
});


if (!favorecido) {
this.logger.warn(logRegistro + ` Detalhe A Documento: ${r.detalheA.numeroDocumentoEmpresa.convertedValue} - Favorecido não encontrado para o nome: '${r.detalheA.nomeTerceiro.stringValue.trim()}'`);
return 'favorecidoNotFound';
Expand All @@ -55,7 +57,8 @@ export class DetalheAService {
const detalheA = await this.detalheARepository.findOneRaw({
nome: [r.detalheA.nomeTerceiro.stringValue],
dataVencimento: [r.detalheA.dataVencimento.convertedValue],
valorRealEfetivado: [r.detalheA.valorRealEfetivado.convertedValue]
numeroDocumentoEmpresa: r.detalheA.numeroDocumentoEmpresa.convertedValue,
valorRealEfetivado: [r.detalheA.valorLancamento.convertedValue]
});

if (!detalheA) {
Expand Down

0 comments on commit cbffe56

Please sign in to comment.