Skip to content

Commit

Permalink
ajuste variaveis que não estavam sendo utilizadas
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfl2007 committed Mar 7, 2024
1 parent 9099754 commit 6f68103
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/cnab/dto/arquivo-publicacao.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class ArquivoPublicacaoDTO {
dv_conta_corrente_cliente?: string;

dt_vencimento?: Date;
valor_lancamento?: number;
data_efetivacao?: Date;
valor_lancamento?: number;
data_efetivacao?: Date;
valor_real_efetivado?: number;
ocorrencias: string;
ocorrencias: string;
}
4 changes: 4 additions & 0 deletions src/cnab/dto/detalhe-a.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export class DetalheADTO {
@IsNotEmpty()
valor_real_efetivado?: number;

@ValidateIf(isCreate)
@IsNotEmpty()
nsr: number;

ocorrencias?: string;

}
1 change: 1 addition & 0 deletions src/cnab/repository/cliente-favorecido.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CommonHttpException } from 'src/utils/http-exception/common-http-except

@Injectable()
export class ClienteFavorecidoRepository {

private logger: Logger = new Logger('ClienteFavorecidoRepository', {
timestamp: true,
});
Expand Down
8 changes: 8 additions & 0 deletions src/cnab/service/cliente-favorecido.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ClienteFavorecidoRepository } from '../repository/cliente-favorecido.re
import { SaveClienteFavorecidoDTO } from '../dto/cliente-favorecido.dto';
import { validateDTO } from 'src/utils/validation-utils';
import { CommonHttpException } from 'src/utils/http-exception/common-http-exception';
import { EntityCondition } from 'src/utils/types/entity-condition.type';
import { Nullable } from 'src/utils/types/nullable.type';

@Injectable()
export class ClienteFavorecidoService {
Expand Down Expand Up @@ -86,4 +88,10 @@ export class ClienteFavorecidoService {
await validateDTO(SaveClienteFavorecidoDTO, saveObject);
await this.clienteFavorecidoRepository.save(saveObject);
}

public async findOne(
fields: EntityCondition<ClienteFavorecido> | EntityCondition<ClienteFavorecido>[],
): Promise<Nullable<ClienteFavorecido>> {
return await this.clienteFavorecidoRepository.getOne(fields);
}
}
3 changes: 2 additions & 1 deletion src/cnab/service/cnab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class CnabService {
}

public async getArquivoRetornoCNAB(){
await this.headerArquivoService.saveArquivoRetorno();
await this.headerArquivoService.compareRemessaToRetorno();
}

}
}
87 changes: 81 additions & 6 deletions src/cnab/service/header-arquivo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class HeaderArquivoService {
}

public async findAll(): Promise<HeaderArquivo[]> {
return await this.headerArquivoRepository.findAll();
return await this.headerArquivoRepository.findAll({});
}

private async transacaoToHeaderArquivoDTO(
Expand Down Expand Up @@ -337,9 +337,84 @@ export class HeaderArquivoService {
return true;
}


public async saveArquivoRetorno(_cnab240:ICnab240_104File):Promise<void>{
const headerArquivo = new HeaderArquivo();
headerArquivo.cod_banco = String(_cnab240.headerArquivo.codigoBanco.value);
headerArquivo.agencia =String( _cnab240.headerArquivo.agenciaContaCorrente.value );
headerArquivo.num_conta =String( _cnab240.headerArquivo.numeroConta.value );
headerArquivo.dv_conta =String( _cnab240.headerArquivo.dvConta.value );
headerArquivo.dt_geracao = new Date( _cnab240.headerArquivo.dataGeracaoArquivo.value);
headerArquivo.nome_empresa =String( _cnab240.headerArquivo.nomeEmpresa.value);
headerArquivo.nsa =String( _cnab240.headerArquivo.nsa.value);
headerArquivo.param_transmissao =String( _cnab240.headerArquivo.parametroTransmissao.value);
headerArquivo.tipo_arquivo = "retorno";
headerArquivo.tipo_inscricao =String( _cnab240.headerArquivo.tipoInscricao.value);
headerArquivo.num_inscricao =String( _cnab240.headerArquivo.numeroInscricao.value);

const headerArquivoRemessa = await this.headerArquivoRepository.findOne({
nsa: String(_cnab240.headerArquivo.nsa.value),
tipo_arquivo: "remessa"
});

headerArquivo.id_transacao = headerArquivoRemessa?.id_transacao as number;
const headerArquivoSave = await this.headerArquivoRepository.save(headerArquivo);
_cnab240.lotes.forEach(async l=>{
const headerLote = new HeaderLoteDTO();

headerLote.id_header_arquivo = headerArquivoSave.id_header_arquivo;
headerLote.lote_servico = l.headerLote.loteServico.value ;
headerLote.cod_convenio_banco = l.headerLote.codigoConvenioBanco.value;
headerLote.num_inscricao = l.headerLote.numeroInscricao.value;
headerLote.param_transmissao = l.headerLote.param_transmissao.value ;
headerLote.tipo_compromisso = l.headerLote.tipoCompromisso.value ;
headerLote.tipo_inscricao = l.headerLote.tipoInscricao.value ;

const pagador = await this.pagadorService.findByConta(l.headerLote.numeroConta.value);
headerLote.id_pagador = Number(pagador?.id_pagador);

const headerLoteSave = await this.headerLoteService.save(headerLote);
l.registros.forEach(async r=>{
const detalheA = new DetalheADTO();
detalheA.id_header_lote = headerLoteSave.id_header_lote;
detalheA.data_efetivacao = r.detalheA?.dataEfetivacao as unknown as Date;
detalheA.dt_vencimento = r.detalheA?.dataVencimento as unknown as Date;
detalheA.indicador_bloqueio = r.detalheA?.indicadorBloqueio.value ;
detalheA.indicador_forma_parcelamento = r.detalheA?.indicadorFormaParcelamento.value ;
detalheA.lote_servico = r.detalheA?.loteServico.value ;
detalheA.nsr = r.detalheA?.nsr.value;
detalheA.num_doc_lancamento = r.detalheA?.numeroDocumento.value;
detalheA.num_parcela = r.detalheA?.numeroParcela.value;
detalheA.periodo_vencimento = new Date(r.detalheA?.dataVencimento.value);
detalheA.qtde_moeda = r.detalheA?.quantidadeMoeda.value;
detalheA.qtde_parcelas = r.detalheA?.quantidadeMoeda.value;
detalheA.valor_lancamento = r.detalheA?.valor_lancamento.value;
detalheA.tipo_finalidade_conta = r.detalheA?.tipoContaFinalidade.value ;
detalheA.tipo_moeda = String(r.detalheA?.tipoMoeda.value) ;
detalheA.valor_real_efetivado = r.detalheA?.valorRealEfetivado.value;

const cliente =
await this.clienteFavorecidoService.findOne(
{conta_corrente: r.detalheA?.contaCorrenteDestino.value ,
dv_conta_corrente: r.detalheA?.dvContaDestino.value });

detalheA.id_cliente_favorecido = cliente?.id_cliente_favorecido;

const detalheASave = await this.detalheAService.save(detalheA);

const detalheB = new DetalheBDTO();
detalheB.id_detalhe_a = detalheASave.id_detalhe_a;
detalheB.nsr = r.detalheB?.nsr.value;
detalheB.data_vencimento = r.detalheB?.dataVencimento as unknown as Date;
await this.detalheBService.save(detalheB);
});
})
}


public async compareRemessaToRetorno():Promise<void>{
const arquivosRemessa = await this.headerArquivoRepository.findAll({tipo_arquivo: "remessa"});

arquivosRemessa.forEach(async headerArquivo => {
const arquivoPublicacao = new ArquivoPublicacaoDTO();
arquivoPublicacao.id_header_arquivo = headerArquivo.id_header_arquivo
Expand All @@ -360,11 +435,11 @@ export class HeaderArquivoService {
//DetalheA Retorno
const detalhesA = await this.detalheAService.findMany({ id_header_lote: headerLoteRetorno.id_header_lote});
detalhesA.forEach( async detalheA => {
arquivoPublicacao.lote_servico = detalheA.lote_servico;
arquivoPublicacao.dt_vencimento = detalheA.dt_vencimento;
arquivoPublicacao.valor_lancamento = detalheA.valor_lancamento;
arquivoPublicacao.data_efetivacao = detalheA.data_efetivacao;
arquivoPublicacao.valor_real_efetivado = detalheA.valor_real_efetivado;
arquivoPublicacao.ocorrencias = detalheA.ocorrencias;
arquivoPublicacao.data_efetivacao = detalheA.data_efetivacao;
arquivoPublicacao.valor_real_efetivado = detalheA.valor_real_efetivado;
const clienteFavorecido =
await this.clienteFavorecidoService.getOneByIdClienteFavorecido(detalheA.id_cliente_favorecido);
arquivoPublicacao.nome_cliente = clienteFavorecido.nome ;
Expand All @@ -374,7 +449,7 @@ export class HeaderArquivoService {
arquivoPublicacao.dv_agencia_cliente = clienteFavorecido.dv_agencia;
arquivoPublicacao.conta_corrente_cliente = clienteFavorecido.conta_corrente;
arquivoPublicacao.dv_conta_corrente_cliente = clienteFavorecido.dv_conta_corrente;
arquivoPublicacao.ocorrencias = detalheA.ocorrencias;
arquivoPublicacao.ocorrencias = detalheA.ocorrencias;
void this.arquivoPublicacaoRepository.save(arquivoPublicacao);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/cnab/service/header-lote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class HeaderLoteService {

constructor(private headerLoteRepository: HeaderLoteRepository) {}

public async save(dto: HeaderLoteDTO): Promise<void> {
public async save(dto: HeaderLoteDTO): Promise<HeaderLote> {
await validateDTO(HeaderLoteDTO, dto);
await this.headerLoteRepository.save(dto);
return await this.headerLoteRepository.save(dto);
}

public async findOne(
Expand Down

0 comments on commit 6f68103

Please sign in to comment.