Skip to content

Commit

Permalink
Do not overwrite institution sequence number if one already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jenakan committed Oct 9, 2020
1 parent 50898b6 commit d7f9024
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
20 changes: 16 additions & 4 deletions cashLetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package imagecashletter

import "fmt"
import (
"fmt"
)

// CashLetterError is an Error that describes CashLetter validation issues
type CashLetterError struct {
Expand Down Expand Up @@ -122,11 +124,17 @@ func (cl *CashLetter) build() error {
// Set Bundle Sequence Numbers
b.BundleHeader.SetBundleSequenceNumber(bundleSequenceNumber)

// Sequence Number
cdSequenceNumber := 1

// Check Items
for _, cd := range b.Checks {

// Sequence Number
cdSequenceNumber := 1
if cd.EceInstitutionItemSequenceNumber != "" {
i := cd.parseNumField(cd.EceInstitutionItemSequenceNumber)
cdSequenceNumber = i
}

// Record Numbers
cdAddendumARecordNumber := 1
cdAddendumCRecordNumber := 1
Expand Down Expand Up @@ -212,7 +220,11 @@ func (cl *CashLetter) build() error {
clc.CashLetterItemsCount = cashLetterItemsCount
clc.CashLetterTotalAmount = cashLetterTotalAmount
clc.CashLetterImagesCount = cashLetterImagesCount
clc.ECEInstitutionName = cl.GetHeader().ECEInstitutionRoutingNumber
if cl.CashLetterControl.ECEInstitutionName != "" {
clc.ECEInstitutionName = cl.CashLetterControl.ECEInstitutionName
} else {
clc.ECEInstitutionName = cl.GetHeader().ECEInstitutionRoutingNumber
}
clc.CreditTotalIndicator = creditIndicator
cl.CashLetterControl = clc
return nil
Expand Down
20 changes: 15 additions & 5 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ func TestICLWrite(t *testing.T) {
cl := NewCashLetter(mockCashLetterHeader())
cl.AddBundle(bundle)
cl.AddBundle(returnBundle)
cl.Create()
if err := cl.Create(); err != nil {
t.Errorf("%T: %s", err, err)
}
file.AddCashLetter(cl)

clTwo := NewCashLetter(mockCashLetterHeader())
clTwo.CashLetterHeader.CashLetterID = "A2"
clTwo.AddBundle(bundle)
clTwo.AddBundle(returnBundle)
clTwo.Create()
if err := clTwo.Create(); err != nil {
t.Errorf("%T: %s", err, err)
}
file.AddCashLetter(clTwo)

// Create file
Expand Down Expand Up @@ -138,14 +142,18 @@ func TestICLWriteCreditItem(t *testing.T) {
cl := NewCashLetter(mockCashLetterHeader())
cl.AddCreditItem(ci)
cl.AddBundle(bundle)
cl.Create()
if err := cl.Create(); err != nil {
t.Errorf("%T: %s", err, err)
}
file.AddCashLetter(cl)

clTwo := NewCashLetter(mockCashLetterHeader())
clTwo.CashLetterHeader.CashLetterID = "A2"
clTwo.AddBundle(bundle)

clTwo.Create()
if err := clTwo.Create(); err != nil {
t.Errorf("%T: %s", err, err)
}
file.AddCashLetter(clTwo)

// Create file
Expand Down Expand Up @@ -202,7 +210,9 @@ func TestICLWriteRoutingNumber(t *testing.T) {
cl := NewCashLetter(mockCashLetterHeader())
cl.AddBundle(bundle)
cl.AddRoutingNumberSummary(rns)
cl.Create()
if err := cl.Create(); err != nil {
t.Errorf("%T: %s", err, err)
}
file.AddCashLetter(cl)

// Create file
Expand Down

0 comments on commit d7f9024

Please sign in to comment.