Skip to content

Commit

Permalink
Merge pull request #17 from moov-io/support-4010-810
Browse files Browse the repository at this point in the history
support 4010 810, code refactoring
  • Loading branch information
wadearnold committed Jul 28, 2023
2 parents c8cb523 + f26f88c commit d323a47
Show file tree
Hide file tree
Showing 185 changed files with 5,599 additions and 3,222 deletions.
43 changes: 43 additions & 0 deletions examples/example_4010_810/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.

package main

import (
"fmt"
"log"
"os"
"path"
"strings"

"github.com/moov-io/x12/pkg/file"
. "github.com/moov-io/x12/rules/rule_4010_810"
)

func main() {
reader, err := os.Open(path.Join("examples", "example_4010_810", "sample.txt"))
if err != nil {
log.Fatal(err)
}
defer reader.Close()

newChange := file.NewFile(&InterchangeRule, "~")

if err = newChange.Parse(file.NewScanner(reader, "~")); err != nil {
log.Fatal(err.Error())
return
}

if err = newChange.Validate(); err != nil {
log.Fatal(err.Error())
return
}

fmt.Println(" REGENERATED FILE ")
fmt.Println(strings.ReplaceAll(newChange.String(), "~", "~\n"))

newChange.Print(os.Stdout)

InterchangeRule.Print(os.Stdout, true)
}
115 changes: 115 additions & 0 deletions examples/example_4010_810/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
ISA*00* *00* *12*8004171844 *ZZ*DoETEMPID *121031*1703*U*00401*000000001*0*P*|~
GS*IN*8004171844*DDDss*20121031*17030169*100000001*X*004010~
ST*810*0001~
BIG*20120926*654983115**246322946*BILL-TO-ACCOUNT NUMBER***53**3179144866093189~
CUR*ZZ*USD~
REF*BM*W44FNZ1179123~
REF*IV*204841~
REF*8X*PRO*MATCHING~
REF*06*27231~
REF*4C*INBOUND~
REF*1Z*PI*Payment Initiated~
REF*ACC*DV~
REF*ZZ*LT~
N1*PR*JILL BROWN*PI*NOT PROVIDED~
N3*VIRGINIA AVE~
N4*BISMARCK*ND*585027116~
PER*CN*Ralph Joy*TE*1-331-5555003~
N1*PE*TrimFast*1*532768026~
N3*Routing Number: 12345*Account No: Customers 16-digit~
REF*I5*45666~
PER*CN*Help Desk*TE*(800)-1223-8441~
N1*BY*SCJCO*PI*KMUZ~
N3*VIRGINIA AVE*Mail stop 852.33~
N4*BISMARCK*ND*58502*USA~
PER*CN*Ralph Joy*TE*1-331-5555003~
N1*SE*Volunteer*ZZ*AADD~
N3*Hwy 45~
N4*Dresden*TN*38344*USA~
PER*CN*Randall Der*TE*1-833-5558585~
N1*SF*Wallace Ford~
N3*1 C Tree Road*Bldg 8~
N4*Baton Rouge*LA*708019002*USA~
N1*ST*Memphis Zoo~
N3*790 Any Street~
N4*Memphis*TN*38103*USA~
ITD**ZZ****20121026~
ITD**4****20121003~
ITD**11****20120917~
ITD**3****20121029~
ITD**7****20121113~
DTM*011*20120914~
DTM*003*20120926~
DTM*095*20120926~
DTM*097*20120926~
IT1*1*1*EA*807.5****IN*ARFW 007529-00*VN*852*KF*FREIGHT*OT*1~
QTY*T5***LB~
QTY*39**ZZ||1*EA~
CTP**INV*3.535*228.43*ZZ***807.5~
FA1*ZZ~
FA2*84*1395.5~
FA2*ZZ*45000-98Z890-2012-81-12345-21620-5580889~
TDS*139550~
AMT*2*2223.25*D~
CTT*1~
SE*53*0001~
ST*810*0002~
BIG*20121005*658089516**246322946*BILL-TO-ACCOUNT NUMBER***53**3179144866093189~
CUR*ZZ*USD~
REF*BM*COL 12022~
REF*IV*0056908~
REF*8X*PRO*MATCHING~
REF*06*27231~
REF*4C*OUTBOUND~
REF*1Z*PI*Payment Initiated~
REF*ACC*DV~
REF*ZZ*LT~
N1*PR*JILL BROWNY*PI*NOT PROVIDED~
N3*VIRGINIA AVE~
N4*BISMARCK*ND*58502~
PER*CN*Ralph Joy*TE*1-331-5555003~
N1*PE*TrimFast*1*532768026~
N3*Routing Number: 7777*Account No: Customers 16-digit~
REF*I5*3179144866093189107482~
PER*CN*TrimFast Help Desk*TE*(800)-555-8441~
N1*BY*SCJCO*PI*KMUZ~
N3*Virginia Ave*Mail stop 852.33~
N4*Bismarck*ND*58502*USA~
PER*CN*Ralph Miller*TE*1-331-5555003~
N1*SE*Arkansas Freightways*ZZ*SLTW~
N3*969 Hwy 70~
N4*Little ROck*AR*72205*USA~
PER*CN*Cristopher Bob*TE*1-331-123-6256~
N1*SF*TRANSPORTATION MGR~
N3*HOME DEPOT*WHSE 1~
N4*MILAN*TN*38358*USA~
N1*ST*NEW YANKEE WORKSHOP~
N3*HWY 441 E*919 SUITE A MS 528~
N4*BOSTON*MA*87123*USA~
N1*RC*OLD YANKEE HOUSE*ZZ*01~
N4*BALTIC*CT*06330-9001*USA~
PER*CN**TE*1-331-555-4666~
ITD**ZZ****20121026~
ITD**4****20121015~
ITD**11****20121004~
ITD**3****20121029~
ITD**7****20121113~
DTM*035*20121004*17000000~
DTM*003*20121005~
DTM*095*20121015~
DTM*097*20121005~
N9*ZZ*System Generated~
MSG*Equipment Type= ICKY;Trailer Number= UNWT;40032 Seal # = 155613~
IT1*1*1*EA*827.75****IN*UNWT-001385-00*VN*830*KF*FREIGHT*OT*1~
QTY*T5*10*~
QTY*39*100*~
CTP**INV*827.75*1*ZZ***827.75~
FA1*ZZ~
FA2*84*827.75~
FA2*ZZ*45000-82-67O0240-2012-81-1524286-22020-2430824~
TDS*82775~
AMT*2*2223.25*D~
CTT*1~
SE*58*0002~
GE*2*100000001~
IEA*1*000000001~
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

func main() {

reader, err := os.Open(path.Join("examples", "example_5010_835", "sample2.txt"))
if err != nil {
log.Fatal(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
)

func main() {

reader, err := os.Open(path.Join("examples", "example_5010_837d", "sample1.txt"))
reader, err := os.Open(path.Join("examples", "example_5010_837d", "sample.txt"))
if err != nil {
log.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
)

func main() {

reader, err := os.Open(path.Join("examples", "example_5010_837p", "sample1.txt"))
reader, err := os.Open(path.Join("examples", "example_5010_837p", "sample.txt"))
if err != nil {
log.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
)

func main() {

reader, err := os.Open(path.Join("examples", "example_stp_820", "sample1.txt"))
reader, err := os.Open(path.Join("examples", "example_stp_820", "sample.txt"))
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -47,5 +46,4 @@ func main() {
fmt.Println(strings.ReplaceAll(newFile.String(), segmentTerminator, segmentTerminator+"\n"))

newFile.Print(os.Stdout)

}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
9 changes: 3 additions & 6 deletions pkg/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ package file
import (
"bytes"
"errors"
"github.com/moov-io/x12/pkg/util"
"io"

"github.com/moov-io/x12/pkg/rules"
"github.com/moov-io/x12/pkg/util"
)

func NewFile(rule *rules.InterchangeRule, args ...string) *File {

f := File{rule: rule}

if len(args) > 0 && len(args[0]) == 1 {
if len(args) > 0 && args[0] != "" {
f.terminator = args[0]
}

Expand All @@ -32,15 +31,14 @@ type File struct {
}

func (f File) getTerminator() string {
if len(f.terminator) == 1 {
if f.terminator != "" {
return f.terminator
}

return util.SegmentTerminator
}

func (f *File) Validate() error {

if len(f.Interchanges) == 0 {
return errors.New("unable to find any interchange")
}
Expand Down Expand Up @@ -90,7 +88,6 @@ func (f File) Print(w io.Writer) {
}

func (f *File) Parse(scan Scanner) error {

if f.rule == nil {
return errors.New("unable to find valid rule")
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func TestFile(t *testing.T) {

raw := `ISA*00* *00* *ZZ*133052274 *ZZ*311279999 *120419*2125*^*00501*000002120*0*P*<~
GS*HC*133052274*311279999*20120419*212549*2120*X*005010X222A1~
ST*837*000000533*005010X222A1~
Expand Down Expand Up @@ -212,7 +211,6 @@ GE*1*2120~
IEA*1*000002120~`

t.Run("testing file", func(t *testing.T) {

reader := strings.NewReader(raw)
scan := NewScanner(reader)

Expand Down
7 changes: 1 addition & 6 deletions pkg/file/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

func NewGroup(rule *rules.GroupRule) *FunctionalGroup {

newTransaction := FunctionalGroup{rule: rule}

return &newTransaction
Expand All @@ -43,7 +42,6 @@ func (r *FunctionalGroup) GetGroupControlNumber() string {
}

func (r *FunctionalGroup) Validate(groupRule *rules.GroupRule) error {

if groupRule == nil && r.rule != nil {
groupRule = r.rule
}
Expand Down Expand Up @@ -96,9 +94,7 @@ func (r *FunctionalGroup) Validate(groupRule *rules.GroupRule) error {
}

// Validating Group
if r.GE != nil {

// compare control set number
if r.GE != nil { // compare control set number
if r.GE.GroupControlNumber != r.GS.GroupControlNumber {
return errors.New("has invalid group control number")
}
Expand All @@ -115,7 +111,6 @@ func (r *FunctionalGroup) Validate(groupRule *rules.GroupRule) error {
}

func (r *FunctionalGroup) Parse(data string, args ...string) (int, error) {

if r.rule == nil {
return 0, errors.New("please specify rules for this group")
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/file/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func TestGroupFor837P(t *testing.T) {

raw := `GS*HC*133052274*311279999*20120419*212549*2120*X*005010X222A1~
ST*837*000000533*005010X222A1~
BHT*0019*00*000017120*20120419*212550*CH~
Expand Down Expand Up @@ -210,7 +209,6 @@ SE*191*000000533~
GE*1*2120~`

t.Run("testing group for edi 837p", func(t *testing.T) {

data := strings.ReplaceAll(raw, "\n", "")

newGroup := NewGroup(&rule.GroupRule)
Expand Down
13 changes: 3 additions & 10 deletions pkg/file/interchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
)

func NewInterchange(rule *rules.InterchangeRule, args ...string) *Interchange {

newChange := Interchange{rule: rule}

if len(args) > 0 && len(args[0]) == 1 {
if len(args) > 0 && args[0] != "" {
newChange.terminator = args[0]
}

Expand All @@ -40,7 +39,7 @@ type Interchange struct {
}

func (r Interchange) getTerminator() string {
if len(r.terminator) == 1 {
if r.terminator != "" {
return r.terminator
}

Expand All @@ -64,7 +63,6 @@ func (r *Interchange) GetGroupControlNumbers() []string {
}

func (r *Interchange) Validate(validateRule *rules.InterchangeRule) error {

changeRule := r.rule
if validateRule != nil {
changeRule = validateRule
Expand Down Expand Up @@ -122,9 +120,7 @@ func (r *Interchange) Validate(validateRule *rules.InterchangeRule) error {
}

// Validating
if r.IEA != nil {

// compare control set number
if r.IEA != nil { // compare control set number
if r.IEA.InterchangeControlNumber != r.ISA.InterchangeControlNumber {
return errors.New("has invalid interchange control number")
}
Expand All @@ -151,7 +147,6 @@ func (r *Interchange) Validate(validateRule *rules.InterchangeRule) error {
}

func (r *Interchange) Parse(data string) (int, error) {

if r.rule == nil {
return 0, errors.New("please specify rules for this group")
}
Expand Down Expand Up @@ -245,7 +240,6 @@ func (r Interchange) String(args ...string) string {
// IEA |1 |000002120 |~ | | | | | | | | | | | | | | | | |

func (r Interchange) Print(w io.Writer) {

padChar := byte(' ')
padding := 1
level := 0
Expand Down Expand Up @@ -285,7 +279,6 @@ func (r Interchange) Print(w io.Writer) {
}

for _, d := range selfDumps {

printStr := d.Name + "\t"
for _, item := range d.Items {
printStr = printStr + item + "\t"
Expand Down
Loading

0 comments on commit d323a47

Please sign in to comment.