|
| 1 | +defmodule OnePiece.Nacha.IatBatchHeader do |
| 2 | + import NimbleParsec |
| 3 | + import OnePiece.Nacha.Helpers |
| 4 | + |
| 5 | + @enforce_keys [ |
| 6 | + :record_type_code, |
| 7 | + :service_class_code, |
| 8 | + :iat_indicator, |
| 9 | + :foreign_exchange_indicator, |
| 10 | + :foreign_exchange_reference_indicator, |
| 11 | + :foreign_exchange_reference, |
| 12 | + :iso_destination_country_code, |
| 13 | + :originator_identification, |
| 14 | + :standard_entry_class_code, |
| 15 | + :company_entry_description, |
| 16 | + :iso_originating_currency_code, |
| 17 | + :iso_destination_currency_code, |
| 18 | + :effective_entry_date, |
| 19 | + :settlement_date, |
| 20 | + :originator_status_code, |
| 21 | + :originating_dfi_identification, |
| 22 | + :batch_number, |
| 23 | + :__parsing_info__ |
| 24 | + ] |
| 25 | + |
| 26 | + defstruct @enforce_keys |
| 27 | + |
| 28 | + def post_traverse(rest, parsed_line, context, line, byte_offset) do |
| 29 | + {rest, |
| 30 | + [ |
| 31 | + %__MODULE__{ |
| 32 | + record_type_code: Enum.at(parsed_line, 16), |
| 33 | + service_class_code: Enum.at(parsed_line, 15), |
| 34 | + iat_indicator: Enum.at(parsed_line, 14), |
| 35 | + foreign_exchange_indicator: Enum.at(parsed_line, 13), |
| 36 | + foreign_exchange_reference_indicator: Enum.at(parsed_line, 12), |
| 37 | + foreign_exchange_reference: Enum.at(parsed_line, 11), |
| 38 | + iso_destination_country_code: Enum.at(parsed_line, 10), |
| 39 | + originator_identification: Enum.at(parsed_line, 9), |
| 40 | + standard_entry_class_code: Enum.at(parsed_line, 8), |
| 41 | + company_entry_description: Enum.at(parsed_line, 7), |
| 42 | + iso_originating_currency_code: Enum.at(parsed_line, 6), |
| 43 | + iso_destination_currency_code: Enum.at(parsed_line, 5), |
| 44 | + effective_entry_date: Enum.at(parsed_line, 4), |
| 45 | + settlement_date: Enum.at(parsed_line, 3), |
| 46 | + originator_status_code: Enum.at(parsed_line, 2), |
| 47 | + originating_dfi_identification: Enum.at(parsed_line, 1), |
| 48 | + batch_number: Enum.at(parsed_line, 0), |
| 49 | + __parsing_info__: OnePiece.Nacha.ParsingInfo.new(line, byte_offset) |
| 50 | + } |
| 51 | + ], context} |
| 52 | + end |
| 53 | + |
| 54 | + def iat_batch_header do |
| 55 | + string("5") |
| 56 | + |> label("Record Type Code") |
| 57 | + |> ascii_string([], 3) |
| 58 | + |> label("Service Class Code") |
| 59 | + |> ascii_string([], 16) |
| 60 | + |> label("IAT Indicator") |
| 61 | + |> ascii_string([], 2) |
| 62 | + |> label("Foreign Exchange Indicator") |
| 63 | + |> ascii_string([], 1) |
| 64 | + |> label("Foreign Exchange Reference Indicator") |
| 65 | + |> ascii_string([], 15) |
| 66 | + |> label("Foreign Exchange Reference") |
| 67 | + |> ascii_string([], 2) |
| 68 | + |> label("ISO Destination Country Code") |
| 69 | + |> ascii_string([], 10) |
| 70 | + |> label("Originator Identification") |
| 71 | + |> ascii_string([], 3) |
| 72 | + |> label("Standard Entry Class Code") |
| 73 | + |> ascii_string([], 10) |
| 74 | + |> label("Company Entry Description") |
| 75 | + |> ascii_string([], 3) |
| 76 | + |> label("ISO Originating Currency Code") |
| 77 | + |> ascii_string([], 3) |
| 78 | + |> label("ISO Destination Currency Code") |
| 79 | + |> ascii_string([], 6) |
| 80 | + |> label("Effective Entry Date") |
| 81 | + |> ascii_string([], 3) |
| 82 | + |> label("Settlement Date") |
| 83 | + |> ascii_string([], 1) |
| 84 | + |> label("Originator Status Code") |
| 85 | + |> ascii_string([], 8) |
| 86 | + |> label("Go Identification / Originating DFI Identification") |
| 87 | + |> ascii_string([], 7) |
| 88 | + |> label("Batch Number") |
| 89 | + |> eol() |
| 90 | + |> post_traverse({__MODULE__, :post_traverse, []}) |
| 91 | + |> unwrap_and_tag(:batch_header) |
| 92 | + |> label("IAT Batch Header") |
| 93 | + end |
| 94 | +end |
0 commit comments