Skip to content

Commit

Permalink
hotfix: remove chunk footer types
Browse files Browse the repository at this point in the history
  • Loading branch information
eulixir committed Apr 20, 2023
1 parent 51a8191 commit 0bd844a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.

## Version History

- 1.1.2 (2023-20-04)
- 1.1.1 (2023-20-04)
- 1.1.0 (2023-18-04)
- 1.0.1 (2023-14-04)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In `mix.exs`, add the ExMachina dependency:
```elixir
def deps do
[
{:ex_cnab, "~> 1.1.1"},
{:ex_cnab, "~> 1.1.2"},
]
end
```
Expand Down
9 changes: 1 addition & 8 deletions app/cnabex/cnab240/services/build_details.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ defmodule ExCnab.Cnab240.Services.BuildDetails do
Service to generate a details
"""

import Helpers.ConvertPosition

alias ExCnab.Cnab240.Templates.{ChunkFooter, ChunkHeader, Details}

@payment_mapper %{
Expand Down Expand Up @@ -83,14 +81,9 @@ defmodule ExCnab.Cnab240.Services.BuildDetails do

%{header: header, detail: details, footer: footer} = detail[detail_key_id]

detail_type =
details
|> hd()
|> convert_position(14, 14)

{:ok, builded_header} = ChunkHeader.generate(header)
{:ok, builded_details} = Details.generate(details)
{:ok, builded_footer} = ChunkFooter.generate(detail_type, footer)
{:ok, builded_footer} = ChunkFooter.generate(footer)

amount = get_chunk_infos(builded_header, builded_footer)

Expand Down
4 changes: 1 addition & 3 deletions app/cnabex/cnab240/services/encode_details.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ defmodule ExCnab.Cnab240.Services.EncodeDetails do
Enum.map(details, fn detail ->
%{header_lote: header, lotes: details, trailer_lote: footer} = detail

%{servico: %{segmento: segmento}} = hd(details)

encoded_header = ChunkHeader.encode(header)
encoded_detail = Details.encode(details)
encoded_footer = ChunkFooter.encode(segmento, footer)
encoded_footer = ChunkFooter.encode(footer)

[encoded_header, encoded_detail, encoded_footer] |> Enum.join("\r\n")
end)
Expand Down
54 changes: 3 additions & 51 deletions app/cnabex/cnab240/templates/chunk_footer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ defmodule ExCnab.Cnab240.Templates.ChunkFooter do
└── Ocorrências (231..240)
```
"""
@spec generate(String.t(), String.t()) :: {:ok, Map.t()} | {:error, String.t()}
def generate("J52", raw_string) do
@spec generate(String.t()) :: {:ok, Map.t()} | {:error, String.t()}
def generate(raw_string) do
control_field = control_fields(raw_string)
total = total_fields(raw_string)

Expand All @@ -48,21 +48,6 @@ defmodule ExCnab.Cnab240.Templates.ChunkFooter do
}}
end

def generate(_, raw_string) do
control_field = control_fields(raw_string)
total = total_fields(raw_string)

{:ok,
%{
controle: control_field,
uso_febraban_1: convert_position(raw_string, 9, 17),
total: total,
numero_aviso_previo: convert_position(raw_string, 60, 65),
uso_febraban_2: convert_position(raw_string, 66, 230),
ocorrencias: convert_position(raw_string, 231, 240)
}}
end

defp control_fields(raw_string) do
%{
codigo_do_banco: convert_position(raw_string, 1, 3),
Expand All @@ -79,7 +64,7 @@ defmodule ExCnab.Cnab240.Templates.ChunkFooter do
}
end

def encode("J52", footer) do
def encode(footer) do
%{
controle: %{
codigo_do_banco: codigo_do_banco,
Expand Down Expand Up @@ -111,37 +96,4 @@ defmodule ExCnab.Cnab240.Templates.ChunkFooter do
]
|> Enum.join()
end

def encode(_type, footer) do
%{
controle: %{
codigo_do_banco: codigo_do_banco,
lote: lote,
registro: registro
},
uso_febraban_1: uso_febraban_1,
total: %{
qnt_registros: qnt_registros,
valor: valor,
qnt_moeda: qnt_moeda
},
numero_aviso_previo: numero_aviso_previo,
uso_febraban_2: uso_febraban_2,
ocorrencias: ocorrencias
} = footer

[
codigo_do_banco,
lote,
registro,
uso_febraban_1,
qnt_registros,
valor,
qnt_moeda,
numero_aviso_previo,
uso_febraban_2,
ocorrencias
]
|> Enum.join()
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ExCnab.MixProject do
def project do
[
app: :ex_cnab,
version: "1.1.1",
version: "1.1.2",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit 0bd844a

Please sign in to comment.