Skip to content

Commit

Permalink
Geração publicacao arquivo remessa/retorno
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfl2007 committed Mar 6, 2024
1 parent 2bbffd9 commit cf5e500
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 5 deletions.
37 changes: 37 additions & 0 deletions src/cnab/dto/arquivo-publicacao.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export class ArquivoPublicacaoDTO {
constructor(dto?: ArquivoPublicacaoDTO) {
if (dto) {
Object.assign(this, dto);
}
}
id_arquivo_publicacao: number;

id_header_arquivo: number;
id_transacao: number;
id_header_lote: number;
dt_geracao_remessa: Date;
hr_geracao_remessa: Date;
dt_geracao_retorno: Date;
hr_geracao_retorno: Date;

lote_servico: string;
nome_pagador: string;
agencia_pagador: string;
dv_agencia_pagador: string;
conta_pagador: string;
dv_conta_pagador: string;

nome_cliente?: string;
cpf_cnpj_cliente?: string;
cod_banco_cliente?: string;
agencia_cliente?: string;
dv_agencia_cliente?: string;
conta_corrente_cliente?: string;
dv_conta_corrente_cliente?: string;

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

ocorrencias?: string;

}
90 changes: 90 additions & 0 deletions src/cnab/entity/arquivo-publicacao.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { EntityHelper } from "src/utils/entity-helper";
import { Column, DeepPartial, PrimaryGeneratedColumn } from "typeorm";

export class ArquivoPublicacao extends EntityHelper {
constructor(
arquivoPublicacao?: ArquivoPublicacao | DeepPartial<ArquivoPublicacao>,
) {
super();
if (arquivoPublicacao !== undefined) {
Object.assign(this, arquivoPublicacao);
}
}
@PrimaryGeneratedColumn()
id_publicacao:number;

@Column({ type: String, unique: false, nullable: false})
id_header_arquivo: number;

@Column({ type: String, unique: false, nullable: false})
id_transacao: number;

@Column({ type: String, unique: false, nullable: false})
id_header_lote: number;

@Column({ type: Date, unique: false, nullable: false})
dt_geracao_remessa: Date;

@Column({ type: Date, unique: false, nullable: false})
hr_geracao_remessa: Date;

@Column({ type: Date, unique: false, nullable: false})
dt_geracao_retorno: Date;

@Column({ type: Date, unique: false, nullable: false})
hr_geracao_retorno: Date;

@Column({ type: String, unique: false, nullable: false})
lote_servico: string;

@Column({ type: String, unique: false, nullable: false})
nome_pagador: string;

@Column({ type: String, unique: false, nullable: false})
agencia_pagador: string;

@Column({ type: String, unique: false, nullable: false})
dv_agencia_pagador: string;

@Column({ type: String, unique: false, nullable: false})
conta_pagador: string;

@Column({ type: String, unique: false, nullable: false})
dv_conta_pagador: string;

@Column({ type: String, unique: false, nullable: false})
nome_cliente?: string;

@Column({ type: String, unique: false, nullable: false})
cpf_cnpj_cliente?: string;

@Column({ type: String, unique: false, nullable: false})
cod_banco_cliente?: string;

@Column({ type: String, unique: false, nullable: false})
agencia_cliente?: string;

@Column({ type: String, unique: false, nullable: false})
dv_agencia_cliente?: string;

@Column({ type: String, unique: false, nullable: false})
conta_corrente_cliente?: string;

@Column({ type: String, unique: false, nullable: false})
dv_conta_corrente_cliente?: string;

@Column({ type: String, unique: false, nullable: false})
dt_vencimento?: Date;

@Column({ type: String, unique: false, nullable: false})
valor_lancamento?: number;

@Column({ type: String, unique: false, nullable: false})
data_efetivacao?: Date;

@Column({ type: String, unique: false, nullable: false})
valor_real_efetivado?: number;

@Column({ type: String, unique: false, nullable: false})
ocorrencias: string;
}
6 changes: 5 additions & 1 deletion src/cnab/entity/detalhe-a.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ export class DetalheA extends EntityHelper {

@Column({ type: Number, unique: false, nullable: false })
nsr: number;
}

@Column({ type: String, unique: false, nullable: false })
ocorrencias: string;

}
21 changes: 21 additions & 0 deletions src/cnab/repository/arquivo-publicacao.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable, Logger } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { ArquivoPublicacao } from "../entity/arquivo-publicacao.entity";
import { ArquivoPublicacaoDTO } from "../dto/arquivo-publicacao.dto";

@Injectable()
export class ArquivoPublicacaoRepository {
private logger: Logger = new Logger('ArquivoPublicacaoRepository', {
timestamp: true,
});

constructor(
@InjectRepository(ArquivoPublicacao)
private arquivoPublicacaoRepository: Repository<ArquivoPublicacao>,
) { }

public async save(dto: ArquivoPublicacaoDTO): Promise<ArquivoPublicacao> {
return this.arquivoPublicacaoRepository.save(dto);
}
}
1 change: 0 additions & 1 deletion src/cnab/repository/transacao.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class TransacaoRepository {

public async save(dto: TransacaoDTO): Promise<Transacao> {
return this.transacaoRepository.save(dto);

}

public async findOne(
Expand Down
19 changes: 18 additions & 1 deletion src/cnab/service/cliente-favorecido.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Injectable, Logger } from '@nestjs/common';
import { HttpStatus, Injectable, Logger } from '@nestjs/common';
import { User } from 'src/users/entities/user.entity';
import { UsersService } from 'src/users/users.service';
import { ClienteFavorecido } from '../entity/cliente-favorecido.entity';
import { ClienteFavorecidoRepository } from '../repository/cliente-favorecido.repository';
import { SaveClienteFavorecidoDTO } from '../dto/cliente-favorecido.dto';
import { validateDTO } from 'src/utils/validation-utils';
import { CommonHttpException } from 'src/utils/http-exception/common-http-exception';

@Injectable()
export class ClienteFavorecidoService {
Expand Down Expand Up @@ -44,6 +45,22 @@ export class ClienteFavorecidoService {
return await this.clienteFavorecidoRepository.findAll({});
}

public async getOneByIdClienteFavorecido(
id_cliente_favorecido: number,
): Promise<ClienteFavorecido> {
const cliente_favorecido =
await this.clienteFavorecidoRepository.getOne({ id_cliente_favorecido: id_cliente_favorecido });
if (!cliente_favorecido) {
throw CommonHttpException.errorDetails(
'cliente_favorecido.conta not found',
{ pagadorConta: id_cliente_favorecido },
HttpStatus.NOT_FOUND,
);
} else {
return cliente_favorecido;
}
}

private async saveFavorecidoFromUser(
user: User,
existingId_facorecido?: number,
Expand Down
1 change: 1 addition & 0 deletions src/cnab/service/cnab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export class CnabService {
public async sendNewCNABs() {
await this.headerArquivoService.saveRemessa()
}

}
54 changes: 53 additions & 1 deletion src/cnab/service/header-arquivo.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ArquivoPublicacaoRepository } from './../repository/arquivo-publicacao.repository';
import { ClienteFavorecidoService } from './cliente-favorecido.service';
import { ArquivoPublicacaoDTO } from './../dto/arquivo-publicacao.dto';
import { Injectable, Logger } from '@nestjs/common';
import { BanksService } from 'src/banks/banks.service';
import { EntityCondition } from 'src/utils/types/entity-condition.type';
Expand Down Expand Up @@ -44,15 +47,17 @@ export class HeaderArquivoService {

constructor(
private headerArquivoRepository: HeaderArquivoRepository,
private arquivoPublicacaoRepository: ArquivoPublicacaoRepository,
private transacaoService: TransacaoService,
private headerLoteService: HeaderLoteService,
private itemTransacaoService: ItemTransacaoService,
private pagadorService: PagadorService,
private detalheAService: DetalheAService,
private detalheBService: DetalheBService,
private clienteFavorecidoService: ClienteFavorecidoService,
private cnab104Service: Cnab104Service,
private banksService: BanksService,
private sftpService: SftpService,
private sftpService: SftpService
) { }

public async saveRemessa(): Promise<void> {
Expand Down Expand Up @@ -331,4 +336,51 @@ export class HeaderArquivoService {
}
return true;
}

public async compareRemessaToRetorno():Promise<void>{
const arquivos = await this.headerArquivoRepository.findAll();

arquivos.forEach(headerArquivo => {
const arquivoPublicacao = new ArquivoPublicacaoDTO();
arquivoPublicacao.id_header_arquivo = headerArquivo.id_header_arquivo
arquivoPublicacao.id_transacao = headerArquivo.id_transacao;

const headersLote =
this.headerLoteService.findMany({id_header_arquivo: headerArquivo.id_header_arquivo});
headersLote.forEach(async headerLote=> {
arquivoPublicacao.id_header_lote = headerLote.id_header_lote;
arquivoPublicacao.dt_geracao_remessa = headerLote.dt_geracao;
arquivoPublicacao.hr_geracao_remessa = headerLote.hr_geracao;
arquivoPublicacao.dt_geracao_retorno = headerLote.dt_geracao;
arquivoPublicacao.hr_geracao_retorno = headerLote.hr_geracao;
arquivoPublicacao.lote_servico = headerLote.lote_servico;
const pagador = await this.pagadorService.getOneByIdPagador(headerLote.id_pagador);

arquivoPublicacao.nome_pagador = pagador.nome_empresa;
arquivoPublicacao.agencia_pagador = pagador.agencia;
arquivoPublicacao.dv_agencia_pagador = pagador.dv_agencia;
arquivoPublicacao.conta_pagador = pagador.conta;
arquivoPublicacao.dv_conta_pagador = pagador.dv_conta;

const detalhesA = await this.detalheAService.findMany({ id_header_lote: headerLote.id_header_lote });
detalhesA.forEach( async detalheA => {
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;
const clienteFavorecido =
await this.clienteFavorecidoService.getOneByIdClienteFavorecido(detalheA.id_cliente_favorecido);
arquivoPublicacao.nome_cliente = clienteFavorecido.nome ;
arquivoPublicacao.cpf_cnpj_cliente = clienteFavorecido.cpf_cnpj;
arquivoPublicacao.cod_banco_cliente = clienteFavorecido.cod_banco ;
arquivoPublicacao.agencia_cliente = clienteFavorecido.agencia;
arquivoPublicacao.dv_agencia_cliente = clienteFavorecido.dv_agencia;
arquivoPublicacao.conta_corrente_cliente = clienteFavorecido.conta_corrente;
arquivoPublicacao.dv_conta_corrente_cliente = clienteFavorecido.dv_conta_corrente;
void this.arquivoPublicacaoRepository.save(arquivoPublicacao);
});
});
});
}
}
3 changes: 2 additions & 1 deletion src/cnab/service/transacao.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { PagadorContaEnum } from '../enums/pagador/pagador.enum';
import { TransacaoRepository } from '../repository/transacao.repository';
import { TransacaoDTO } from './../dto/transacao.dto';
import { ClienteFavorecidoService } from './cliente-favorecido.service';
import { ItemTransacaoService } from './item-transacao.service';

import { PagadorService } from './pagador.service';
import { ItemTransacaoService } from './item-transacao.service';

@Injectable()
export class TransacaoService {
Expand Down

0 comments on commit cf5e500

Please sign in to comment.