Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deposit tickets #321

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Bundle struct {
ID string `json:"id"`
// BundleHeader is a Bundle Header Record
BundleHeader *BundleHeader `json:"bundleHeader,omitempty"`
// Credits may be included as part of a bundle, and are often used to represent deposit tickets
Credits []*Credit `json:"credits,omitempty"`
// Checks are Check Items: Check Detail Records, Check Detail Addendum Records, and Image Views
Checks []*CheckDetail `json:"checks,omitempty"`
// Returns are Return Items: Return Detail Records, Return Detail Addendum Records, and Image Views
Expand All @@ -65,6 +67,9 @@ func (b *Bundle) setRecordType() {
return
}
b.BundleHeader.setRecordType()
for i := range b.Credits {
b.Credits[i].setRecordType()
}
for i := range b.Checks {
b.Checks[i].setRecordType()
}
Expand Down Expand Up @@ -92,8 +97,8 @@ func (b *Bundle) Validate() error {
return nil
}

// build creates a valid Bundle by building BundleControl. An error is returned if
// the bundle being built has invalid records.
// build creates a valid Bundle by building BundleControl. An error is returned if the bundle being
// built has invalid records.
func (b *Bundle) build() error {
// Requires a valid BundleHeader
if err := b.BundleHeader.Validate(); err != nil {
Expand All @@ -107,9 +112,21 @@ func (b *Bundle) build() error {
bundleTotalAmount := 0
micrValidTotalAmount := 0
bundleImagesCount := 0
// The current Implementation doe snot support CreditItems as part of a bundle so BundleControl.CreditIndicator = 0
// The current Implementation does not support CreditItems as part of a bundle so BundleControl.CreditIndicator = 0
creditIndicator := 0

// Credit items
for _, cr := range b.Credits {
if err := b.ValidateCredit(cr); err != nil {
return err
}

// A credit record within a Bundle is typically used to present a
// deposit ticket, and its amount is not included in the bundle total
itemCount++
bundleImagesCount += len(cr.ImageViewDetail)
}

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

Expand All @@ -118,13 +135,13 @@ func (b *Bundle) build() error {
return err
}

itemCount = itemCount + 1
bundleTotalAmount = bundleTotalAmount + cd.ItemAmount
itemCount++
bundleTotalAmount += cd.ItemAmount
if cd.MICRValidIndicator == 1 {
micrValidTotalAmount = micrValidTotalAmount + cd.ItemAmount
micrValidTotalAmount += cd.ItemAmount
}

bundleImagesCount = bundleImagesCount + len(cd.ImageViewDetail)
bundleImagesCount += len(cd.ImageViewDetail)
}

// Return Items
Expand All @@ -134,9 +151,9 @@ func (b *Bundle) build() error {
if err := b.ValidateReturnItems(rd); err != nil {
return err
}
itemCount = itemCount + 1
bundleTotalAmount = bundleTotalAmount + rd.ItemAmount
bundleImagesCount = bundleImagesCount + len(rd.ImageViewDetail)
itemCount++
bundleTotalAmount += rd.ItemAmount
bundleImagesCount += len(rd.ImageViewDetail)
}

// build a BundleControl record
Expand Down Expand Up @@ -196,6 +213,20 @@ func (b *Bundle) GetReturns() []*ReturnDetail {
return b.Returns
}

func (b *Bundle) ValidateCredit(cr *Credit) error {
for _, ivDetail := range cr.ImageViewDetail {
if err := ivDetail.Validate(); err != nil {
return err
}
}
for _, ivData := range cr.ImageViewData {
if err := ivData.Validate(); err != nil {
return err
}
}
return nil
}

// ValidateForwardItems calls Validate function for check items
func (b *Bundle) ValidateForwardItems(cd *CheckDetail) error {
// Validate items
Expand Down
12 changes: 12 additions & 0 deletions credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type Credit struct {
DebitCreditIndicator string `json:"debitCreditIndicator,omitempty"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string

ImageViewDetail []ImageViewDetail `json:"imageViewDetail"`
ImageViewData []ImageViewData `json:"imageViewData"`

// validator is composed for image cash letter data validation
validator
// converters is composed for image cash letter to golang Converters
Expand Down Expand Up @@ -264,3 +268,11 @@ func (cr *Credit) DebitCreditIndicatorField() string {
func (cr *Credit) reservedField() string {
return cr.alphaField(cr.reserved, 3)
}

func (cr *Credit) AddImageViewData(ivData ImageViewData) {
cr.ImageViewData = append(cr.ImageViewData, ivData)
}

func (cr *Credit) AddImageViewDetail(ivDetail ImageViewDetail) {
cr.ImageViewDetail = append(cr.ImageViewDetail, ivDetail)
}
2 changes: 1 addition & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var (
msgFileCashLetterID = "%s is not unique"
msgRecordType = "received expecting %d"
msgFileCreditItem = "Credit item outside of cash letter"
msgFileCredit = "Credit outside of cash letter"
msgFileCredit = "Credit outside of cash letter or bundle"
)

// FileError is an error describing issues validating a file
Expand Down
7 changes: 7 additions & 0 deletions fileControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func NewFileControl() FileControl {
return fc
}

func (fc *FileControl) IsZero() bool {
if fc == nil {
return true
}
return *fc == (FileControl{}) || *fc == NewFileControl()
}

func (fc *FileControl) setRecordType() {
if fc == nil {
return
Expand Down
7 changes: 7 additions & 0 deletions fileHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ func NewFileHeader() FileHeader {
return fh
}

func (fh *FileHeader) IsZero() bool {
if fh == nil {
return true
}
return *fh == (FileHeader{}) || *fh == NewFileHeader()
}

func (fh *FileHeader) setRecordType() {
if fh == nil {
return
Expand Down
1 change: 0 additions & 1 deletion imageViewDetail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestMockImageViewDetail(t *testing.T) {
require.Equal(t, "", ivDetail.reserved)
require.Equal(t, "0", ivDetail.OverrideIndicator)
require.Equal(t, "", ivDetail.reservedTwo)

}

// TestParseIVDetail validates parsing an ImageViewDetail
Expand Down
Loading
Loading