From d7f902482a7c7e946fd9c5bfda51a742dd09d5a8 Mon Sep 17 00:00:00 2001 From: jenakan Date: Fri, 9 Oct 2020 12:07:16 -0400 Subject: [PATCH] Do not overwrite institution sequence number if one already exists --- cashLetter.go | 20 ++++++++++++++++---- writer_test.go | 20 +++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/cashLetter.go b/cashLetter.go index 4c7261ba..257218c3 100644 --- a/cashLetter.go +++ b/cashLetter.go @@ -4,7 +4,9 @@ package imagecashletter -import "fmt" +import ( + "fmt" +) // CashLetterError is an Error that describes CashLetter validation issues type CashLetterError struct { @@ -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 @@ -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 diff --git a/writer_test.go b/writer_test.go index f2335219..ae217529 100644 --- a/writer_test.go +++ b/writer_test.go @@ -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 @@ -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 @@ -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