Skip to content

Commit

Permalink
Merge pull request #1456 from adamdecaf/fix-loan-reversal-tnxcode
Browse files Browse the repository at this point in the history
fix: correctly reverse loan transaction codes, test GL credit/debit
  • Loading branch information
adamdecaf authored Aug 2, 2024
2 parents d185d98 + 89aba15 commit 18ee79d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
12 changes: 10 additions & 2 deletions reversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,28 @@ func (f *File) Reversal(effectiveEntryDate time.Time) error {
case
CheckingCredit, CheckingReturnNOCCredit, CheckingPrenoteCredit, CheckingZeroDollarRemittanceCredit,
GLCredit, GLPrenoteCredit, GLReturnNOCCredit, GLZeroDollarRemittanceCredit,
LoanCredit, LoanPrenoteCredit, LoanReturnNOCCredit, LoanZeroDollarRemittanceCredit,
LoanPrenoteCredit, LoanReturnNOCCredit, LoanZeroDollarRemittanceCredit,
SavingsCredit, SavingsPrenoteCredit, SavingsReturnNOCCredit, SavingsZeroDollarRemittanceCredit:
// Credit -> Debit
hasDebits = true
entries[j].TransactionCode += 5

case LoanCredit:
hasDebits = true
entries[j].TransactionCode += 3

case
CheckingDebit, CheckingPrenoteDebit, CheckingReturnNOCDebit, CheckingZeroDollarRemittanceDebit,
GLDebit, GLPrenoteDebit, GLReturnNOCDebit, GLZeroDollarRemittanceDebit,
LoanDebit, LoanReturnNOCDebit,
LoanReturnNOCDebit,
SavingsDebit, SavingsPrenoteDebit, SavingsReturnNOCDebit, SavingsZeroDollarRemittanceDebit:
// Debit -> Credit
hasCredits = true
entries[j].TransactionCode -= 5

case LoanDebit:
hasDebits = true
entries[j].TransactionCode -= 3
}
}

Expand Down
68 changes: 68 additions & 0 deletions reversal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,71 @@ func TestFileDebitReversal(t *testing.T) {
require.Len(t, entries, 1)
require.Equal(t, CheckingCredit, entries[0].TransactionCode)
}

func TestReversal_GL(t *testing.T) {
// Debit
file, err := ReadFile(filepath.Join("test", "testdata", "gl-debit.ach"))
require.NoError(t, err)

b1 := file.Batches[0]
entries := b1.GetEntries()
require.Len(t, entries, 1)
require.Equal(t, GLDebit, entries[0].TransactionCode)

// Reverse
effectiveEntryDate := time.Now().In(time.UTC)
err = file.Reversal(effectiveEntryDate)
require.NoError(t, err)

b1 = file.Batches[0]
require.Equal(t, "REVERSAL", b1.GetHeader().CompanyEntryDescription)

entries = b1.GetEntries()
require.Len(t, entries, 1)
require.Equal(t, GLCredit, entries[0].TransactionCode)

// Reverse the REVERSAL
err = file.Reversal(effectiveEntryDate)
require.NoError(t, err)

b1 = file.Batches[0]
require.Equal(t, "REVERSAL", b1.GetHeader().CompanyEntryDescription)

entries = b1.GetEntries()
require.Len(t, entries, 1)
require.Equal(t, GLDebit, entries[0].TransactionCode)
}

func TestReversal_LoanCredit(t *testing.T) {
// Credit
file, err := ReadFile(filepath.Join("test", "testdata", "loan-credit.ach"))
require.NoError(t, err)

b1 := file.Batches[0]
entries := b1.GetEntries()
require.Len(t, entries, 1)
require.Equal(t, LoanCredit, entries[0].TransactionCode)

// Reverse
effectiveEntryDate := time.Now().In(time.UTC)
err = file.Reversal(effectiveEntryDate)
require.NoError(t, err)

b1 = file.Batches[0]
require.Equal(t, "REVERSAL", b1.GetHeader().CompanyEntryDescription)

entries = b1.GetEntries()
require.Len(t, entries, 1)
require.Equal(t, LoanDebit, entries[0].TransactionCode)

// Reverse the REVERSAL
err = file.Reversal(effectiveEntryDate)
require.NoError(t, err)

b1 = file.Batches[0]
require.Equal(t, "REVERSAL", b1.GetHeader().CompanyEntryDescription)

entries = b1.GetEntries()
require.Len(t, entries, 1)
require.Equal(t, LoanCredit, entries[0].TransactionCode)
}
11 changes: 11 additions & 0 deletions test/testdata/gl-debit.ach
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
101 231380104 1210428821906240000A094101Federal Reserve Bank My Bank Name
5225Name on Account 121042882 PPDREG.SALARY 190625 1121042880000001
64723138010412345678 0100000000 Receiver Account Name 0121042880000001
82250000010023138010000100000000000000000000121042882 121042880000001
9000001000001000000010023138010000100000000000000000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

11 changes: 11 additions & 0 deletions test/testdata/loan-credit.ach
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
101 231380104 1210428821906240000A094101Federal Reserve Bank My Bank Name
5220Name on Account 121042882 PPDREG.SALARY 190625 1121042880000001
65223138010412345678 0100000000 Receiver Account Name 0121042880000001
82200000010023138010000000000000000100000000121042882 121042880000001
9000001000001000000010023138010000000000000000100000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

0 comments on commit 18ee79d

Please sign in to comment.