From d3ff6ea6ec39330e30fd7915dd6536da5803b3b2 Mon Sep 17 00:00:00 2001 From: Andrew Chinn Date: Thu, 24 Aug 2017 20:09:59 -0400 Subject: [PATCH 1/5] Found bug in Credit and Debit entries. Put in fix and reverted tests. --- src/Nacha/Batch.php | 4 ++-- test/Nacha/BatchTest.php | 16 ++++++++-------- test/Nacha/FileTest.php | 28 ++++++++++++++-------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Nacha/Batch.php b/src/Nacha/Batch.php index 6c32f76..670d016 100644 --- a/src/Nacha/Batch.php +++ b/src/Nacha/Batch.php @@ -138,7 +138,7 @@ public function getEntryHash() { * @param Entry $entry * @return bool */ - private function isCredit(Entry $entry) { + private function isDebit(Entry $entry) { $creditEntryTransactionCodes = [26,27,28,29,36,37,38,39,46,47,48,49,55,56]; return in_array($entry->getTransactionCode()->getValue(),$creditEntryTransactionCodes); } @@ -147,7 +147,7 @@ private function isCredit(Entry $entry) { * @param Entry $entry * @return bool */ - private function isDebit(Entry $entry) { + private function isCredit(Entry $entry) { $debitEntryTransactionCodes = [21,22,23,24,31,32,33,34,41,42,43,44,51,52,53,54]; return in_array($entry->getTransactionCode()->getValue(),$debitEntryTransactionCodes); } diff --git a/test/Nacha/BatchTest.php b/test/Nacha/BatchTest.php index 60aeace..0b0d7f2 100644 --- a/test/Nacha/BatchTest.php +++ b/test/Nacha/BatchTest.php @@ -31,7 +31,7 @@ public function setup() { public function testDebitOnlyBatch() { // when $this->batch->addEntry((new DebitEntry) - ->setTransactionCode(22) + ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') @@ -48,7 +48,7 @@ public function testDebitOnlyBatch() { $this->assertEquals((string)$this->batch->getHeader()->getServiceClassCode(), Batch::DEBITS_ONLY); $this->assertEquals( "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n". - "62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n". + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n". "822500000100091012980000000550000000000000001419871234 010212340000001", $output ); @@ -57,7 +57,7 @@ public function testDebitOnlyBatch() { public function testCreditOnlyBatch() { // when $this->batch->addEntry((new CcdEntry) - ->setTransactionCode(27) + ->setTransactionCode(22) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setReceivingDFiAccountNumber('46479999') @@ -74,7 +74,7 @@ public function testCreditOnlyBatch() { $this->assertEquals((string)$this->batch->getHeader()->getServiceClassCode(), Batch::CREDITS_ONLY); $this->assertEquals( "5220MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n". - "62709101298746479999 0000060000Location 23 Best Co 23 S 0099363400000015\n". + "62209101298746479999 0000060000Location 23 Best Co 23 S 0099363400000015\n". "822000000100091012980000000000000000000600001419871234 010212340000001", $output ); @@ -83,7 +83,7 @@ public function testCreditOnlyBatch() { public function testMixedBatch() { // when $this->batch->addEntry((new CcdEntry) - ->setTransactionCode(27) + ->setTransactionCode(22) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setReceivingDFiAccountNumber('46479999') @@ -95,7 +95,7 @@ public function testMixedBatch() { ->setTraceNumber('09936340', 15)); $this->batch->addEntry((new DebitEntry) - ->setTransactionCode(22) + ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') @@ -112,8 +112,8 @@ public function testMixedBatch() { $this->assertEquals((string)$this->batch->getHeader()->getServiceClassCode(), Batch::MIXED); $this->assertEquals( "5200MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n". - "62709101298746479999 0000060000Location 23 Best Co 23 S 0099363400000015\n". - "62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0099363400000015\n". + "62209101298746479999 0000060000Location 23 Best Co 23 S 0099363400000015\n". + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0099363400000015\n". "820000000200182025960000000550000000000600001419871234 010212340000001", $output ); diff --git a/test/Nacha/FileTest.php b/test/Nacha/FileTest.php index 001da3e..9c933c2 100644 --- a/test/Nacha/FileTest.php +++ b/test/Nacha/FileTest.php @@ -44,10 +44,10 @@ public function testBatchesAndEntries() { // then $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000001 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002 -62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000002 9000002000001000000020018202596000000110000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 @@ -72,7 +72,7 @@ public function testNoBlockFill() { $batchA = $this->getBatch(); $batchA->getHeader()->setCompanyEntryDescription('EXPENSES'); $batchA->addDebitEntry((new DebitEntry) - ->setTransactionCode(22) + ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') @@ -84,7 +84,7 @@ public function testNoBlockFill() { ->setTraceNumber('99936340', 15)); $batchA->addDebitEntry((new DebitEntry) - ->setTransactionCode(22) + ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') @@ -102,12 +102,12 @@ public function testNoBlockFill() { // then $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000001 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002 -62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -62209101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 -62209101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 822500000300273038940000001650000000000000001419871234 010212340000002 9000002000001000000040036405192000000220000000000000000 ", (string)$this->file); } @@ -117,7 +117,7 @@ public function testBlockWithEntries() { $batchA = $this->getBatch(); $batchA->getHeader()->setCompanyEntryDescription('EXPENSES'); $batchA->addDebitEntry((new DebitEntry) - ->setTransactionCode(22) + ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') @@ -136,14 +136,14 @@ public function testBlockWithEntries() { // then $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000001 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000002 -62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000002 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000003 -62209101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -62209101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 822500000200182025960000001100000000000000001419871234 010212340000003 9000003000002000000040036405192000000220000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 @@ -170,7 +170,7 @@ private function getBatch() { ->setOriginatingDFiId('01021234'); $batch->addDebitEntry((new DebitEntry) - ->setTransactionCode(22) + ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') From 345b937272a736c417f628cb5b58c54ddaccbef3 Mon Sep 17 00:00:00 2001 From: Andrew Chinn Date: Thu, 24 Aug 2017 21:03:08 -0400 Subject: [PATCH 2/5] Updated Transaction code to add helper methods. Added tests to cover those methods. --- src/Nacha/Batch.php | 7 +- src/Nacha/Field/TransactionCode.php | 81 +++++++++++++++++------- test/Nacha/Field/TransactionCodeTest.php | 38 ++++++++++- 3 files changed, 97 insertions(+), 29 deletions(-) diff --git a/src/Nacha/Batch.php b/src/Nacha/Batch.php index 670d016..0c3bafa 100644 --- a/src/Nacha/Batch.php +++ b/src/Nacha/Batch.php @@ -139,8 +139,8 @@ public function getEntryHash() { * @return bool */ private function isDebit(Entry $entry) { - $creditEntryTransactionCodes = [26,27,28,29,36,37,38,39,46,47,48,49,55,56]; - return in_array($entry->getTransactionCode()->getValue(),$creditEntryTransactionCodes); + return TransactionCode::isDebit($entry->getTransactionCode()->getValue()); + } /** @@ -148,8 +148,7 @@ private function isDebit(Entry $entry) { * @return bool */ private function isCredit(Entry $entry) { - $debitEntryTransactionCodes = [21,22,23,24,31,32,33,34,41,42,43,44,51,52,53,54]; - return in_array($entry->getTransactionCode()->getValue(),$debitEntryTransactionCodes); + return TransactionCode::isCredit($entry->getTransactionCode()->getValue()); } /** diff --git a/src/Nacha/Field/TransactionCode.php b/src/Nacha/Field/TransactionCode.php index 5871710..5b0db1d 100644 --- a/src/Nacha/Field/TransactionCode.php +++ b/src/Nacha/Field/TransactionCode.php @@ -4,57 +4,90 @@ class TransactionCode extends Number { + const CHECKING_CREDIT_RETURN = 21; const CHECKING_DEPOSIT = 22; // Deposit destined for a Checking Account const CHECKING_CREDIT_PRENOTIFICATION = 23; // Prenotification for a checking credit const CHECKING_ZERO_DOLLAR = 24; // Zero dollar with remittance into Checking + const CHECKING_DEBIT_RETURN = 26; const CHECKING_DEBIT = 27; // Debit destined for a Checking Account const CHECKING_DEBIT_PRENOTIFICATION = 28; // Prenotification for a checking debit const CHECKING_DEBIT_ZERO_DOLLAR = 29; // Zero dollar with remittance into Checking - duplicate? + const SAVINGS_CREDIT_RETURN = 31; const SAVINGS_DEPOSIT = 32; // Deposit destined for a Savings Account const SAVINGS_CREDIT_PRENOTIFICATION = 33; // Prenotification for a savings credit const SAVINGS_CREDIT_ZERO_DOLLAR = 34; // Zero dollar with remittance into Savings + const SAVINGS_DEBIT_RETURN = 36; const SAVINGS_DEBIT = 37; // Debit destined for a Savings Account const SAVINGS_DEBIT_PRENOTIFICATION = 38; // Prenotification for a Savings debit const SAVINGS_DEBIT_ZERO_DOLLAR = 39; // Zero dollar with remittance into Savings + + const GL_CREDIT_RETURN = 41; const GL_CREDIT = 42; // General ledger Deposit (Credit) + const GL_CREDIT_PRENOTIFICATION = 43; + const GL_CREDIT_ZERO_DOLLAR = 44; + + const GL_DEBIT_REVERSAL = 46; const GL_DEBIT = 47; // General ledger Withdrawal - const GL_CREDIT_PRENOTIFICATION = 48; // Prenotification for General ledger Deposit (Credit) + const GL_DEBIT_PRENOTIFICATION = 48; // Prenotification for General ledger Deposit (Credit) + const GL_DEBIT_ZERO_DOLLAR = 49; + const LOAN_CREDIT_REVERSAL = 51; const LOAN_CREDIT = 52; // Loan Deposit (Credit) - const LOAN_REVERSAL = 55; // Loan Reversal (Debit) (used rarely; reverses code 52) const LOAN_CREDIT_PRENOTIFICATION = 53; // Pre-Note: Loan Deposit (Credit) + const LOAN_CREDIT_ZERO_DOLLAR = 54; + + const LOAN_REVERSAL = self::LOAN_DEBIT; // Loan Reversal (Debit) (used rarely; reverses code 52) + const LOAN_DEBIT = 55; + const LOAN_DEBIT_RETURN = 56; + + const CREDIT_TRANSACTION_CODES = [ + self::CHECKING_CREDIT_RETURN, self::CHECKING_DEPOSIT, self::CHECKING_CREDIT_PRENOTIFICATION, self::CHECKING_ZERO_DOLLAR, + self::SAVINGS_CREDIT_RETURN, self::SAVINGS_DEPOSIT,self::SAVINGS_CREDIT_PRENOTIFICATION,self::SAVINGS_CREDIT_ZERO_DOLLAR, + self::GL_CREDIT_RETURN,self::GL_CREDIT,self::GL_CREDIT_PRENOTIFICATION,self::GL_CREDIT_ZERO_DOLLAR, + self::LOAN_CREDIT_REVERSAL,self::LOAN_CREDIT,self::LOAN_CREDIT_PRENOTIFICATION,self::LOAN_CREDIT_ZERO_DOLLAR + ]; + + const DEBIT_TRANSACTION_CODES = [ + self::CHECKING_DEBIT_RETURN,self::CHECKING_DEBIT,self::CHECKING_DEBIT_PRENOTIFICATION,self::CHECKING_DEBIT_ZERO_DOLLAR, + self::SAVINGS_DEBIT_RETURN,self::SAVINGS_DEBIT,self::SAVINGS_DEBIT_PRENOTIFICATION,self::SAVINGS_DEBIT_ZERO_DOLLAR, + self::GL_DEBIT_REVERSAL,self::GL_DEBIT,self::GL_DEBIT_PRENOTIFICATION,self::GL_DEBIT_ZERO_DOLLAR, + self::LOAN_DEBIT,self::LOAN_DEBIT_RETURN + ]; public function __construct($value) { parent::__construct($value, 2); - $valid = [ - self::CHECKING_DEPOSIT, - self::CHECKING_CREDIT_PRENOTIFICATION, - self::CHECKING_ZERO_DOLLAR, - self::CHECKING_DEBIT, - self::CHECKING_DEBIT_PRENOTIFICATION, - self::CHECKING_DEBIT_ZERO_DOLLAR, - self::SAVINGS_DEPOSIT, - self::SAVINGS_CREDIT_PRENOTIFICATION, - self::SAVINGS_CREDIT_ZERO_DOLLAR, - self::SAVINGS_DEBIT, - self::SAVINGS_DEBIT_PRENOTIFICATION, - self::SAVINGS_DEBIT_ZERO_DOLLAR, - self::GL_CREDIT, - self::GL_DEBIT, - self::GL_CREDIT_PRENOTIFICATION, - self::LOAN_CREDIT, - self::LOAN_REVERSAL, - self::LOAN_CREDIT_PRENOTIFICATION, - ]; - - if (!in_array($value, $valid)) { + if (!self::isValid($value)) { throw new InvalidFieldException('Invalid transaction code "' . $value . '".'); } } + /** + * @param int $code + * @return bool + */ + public static function isCredit($code) { + return in_array($code,self::CREDIT_TRANSACTION_CODES); + } + + /** + * @param int $code + * @return bool + */ + public static function isDebit($code) { + return in_array($code,self::DEBIT_TRANSACTION_CODES); + } + + /** + * @param $code + * @return bool + */ + public static function isValid($code) { + return in_array($code, array_merge(self::CREDIT_TRANSACTION_CODES,self::DEBIT_TRANSACTION_CODES)); + } + } \ No newline at end of file diff --git a/test/Nacha/Field/TransactionCodeTest.php b/test/Nacha/Field/TransactionCodeTest.php index fc5c70c..f4c965d 100644 --- a/test/Nacha/Field/TransactionCodeTest.php +++ b/test/Nacha/Field/TransactionCodeTest.php @@ -4,8 +4,11 @@ class TransactionCodeTest extends \PHPUnit_Framework_TestCase { + private $creditCodes = [21,22,23,24,31,32,33,34,41,42,43,44,51,52,53,54]; + private $debitCodes = [26,27,28,29,36,37,38,39,46,47,48,49,55,56]; + /** - * @expectedException Nacha\Field\InvalidFieldException + * @expectedException \Nacha\Field\InvalidFieldException */ public function testInvalidType() { new TransactionCode(40); @@ -19,4 +22,37 @@ public function testValid() { $this->assertEquals(TransactionCode::SAVINGS_DEPOSIT, (string)$sec); } + public function testAllValidTransactionCodes() { + $validCodes = array_merge($this->creditCodes,$this->debitCodes); + + foreach($validCodes as $code) { + $this->assertTrue(TransactionCode::isValid($code)); + } + + $invalidCodes = [1,3,4,5,6,7,8,9,0,10,11,12,13,14,15,16,17,18,19,20,25,30,35,40,45,50,57,58,59,60]; + foreach($invalidCodes as $code) { + $this->assertFalse(TransactionCode::isValid($code)); + } + } + + + public function testAllCreditTransactionCodesAreRecognized() { + foreach($this->creditCodes as $code) { + $this->assertTrue(TransactionCode::isCredit($code)); + } + foreach($this->debitCodes as $code) { + $this->assertFalse(TransactionCode::isCredit($code)); + } + } + + public function testAllDebitTransactionCodesAreRecognized() { + foreach($this->creditCodes as $code) { + print_r($code); + $this->assertFalse(TransactionCode::isDebit($code)); + } + foreach($this->debitCodes as $code) { + print_r($code); + $this->assertTrue(TransactionCode::isDebit($code)); + } + } } \ No newline at end of file From bb4514590c78af4205d0be3d1ccc78350d1ebaa8 Mon Sep 17 00:00:00 2001 From: Andrew Chinn Date: Thu, 24 Aug 2017 21:18:12 -0400 Subject: [PATCH 3/5] Removed array as value for class constant. --- src/Nacha/Field/TransactionCode.php | 147 +++++++++++++++++----------- 1 file changed, 90 insertions(+), 57 deletions(-) diff --git a/src/Nacha/Field/TransactionCode.php b/src/Nacha/Field/TransactionCode.php index 5b0db1d..4dd126d 100644 --- a/src/Nacha/Field/TransactionCode.php +++ b/src/Nacha/Field/TransactionCode.php @@ -2,63 +2,51 @@ namespace Nacha\Field; -class TransactionCode extends Number { +class TransactionCode extends Number +{ - const CHECKING_CREDIT_RETURN = 21; - const CHECKING_DEPOSIT = 22; // Deposit destined for a Checking Account + const CHECKING_CREDIT_RETURN = 21; + const CHECKING_DEPOSIT = 22; // Deposit destined for a Checking Account const CHECKING_CREDIT_PRENOTIFICATION = 23; // Prenotification for a checking credit - const CHECKING_ZERO_DOLLAR = 24; // Zero dollar with remittance into Checking + const CHECKING_ZERO_DOLLAR = 24; // Zero dollar with remittance into Checking - const CHECKING_DEBIT_RETURN = 26; - const CHECKING_DEBIT = 27; // Debit destined for a Checking Account + const CHECKING_DEBIT_RETURN = 26; + const CHECKING_DEBIT = 27; // Debit destined for a Checking Account const CHECKING_DEBIT_PRENOTIFICATION = 28; // Prenotification for a checking debit - const CHECKING_DEBIT_ZERO_DOLLAR = 29; // Zero dollar with remittance into Checking - duplicate? + const CHECKING_DEBIT_ZERO_DOLLAR = 29; // Zero dollar with remittance into Checking - duplicate? - const SAVINGS_CREDIT_RETURN = 31; - const SAVINGS_DEPOSIT = 32; // Deposit destined for a Savings Account + const SAVINGS_CREDIT_RETURN = 31; + const SAVINGS_DEPOSIT = 32; // Deposit destined for a Savings Account const SAVINGS_CREDIT_PRENOTIFICATION = 33; // Prenotification for a savings credit - const SAVINGS_CREDIT_ZERO_DOLLAR = 34; // Zero dollar with remittance into Savings - - const SAVINGS_DEBIT_RETURN = 36; - const SAVINGS_DEBIT = 37; // Debit destined for a Savings Account - const SAVINGS_DEBIT_PRENOTIFICATION = 38; // Prenotification for a Savings debit - const SAVINGS_DEBIT_ZERO_DOLLAR = 39; // Zero dollar with remittance into Savings - - - const GL_CREDIT_RETURN = 41; - const GL_CREDIT = 42; // General ledger Deposit (Credit) - const GL_CREDIT_PRENOTIFICATION = 43; - const GL_CREDIT_ZERO_DOLLAR = 44; - - const GL_DEBIT_REVERSAL = 46; - const GL_DEBIT = 47; // General ledger Withdrawal - const GL_DEBIT_PRENOTIFICATION = 48; // Prenotification for General ledger Deposit (Credit) - const GL_DEBIT_ZERO_DOLLAR = 49; - - const LOAN_CREDIT_REVERSAL = 51; - const LOAN_CREDIT = 52; // Loan Deposit (Credit) - const LOAN_CREDIT_PRENOTIFICATION = 53; // Pre-Note: Loan Deposit (Credit) - const LOAN_CREDIT_ZERO_DOLLAR = 54; - - const LOAN_REVERSAL = self::LOAN_DEBIT; // Loan Reversal (Debit) (used rarely; reverses code 52) - const LOAN_DEBIT = 55; - const LOAN_DEBIT_RETURN = 56; - - const CREDIT_TRANSACTION_CODES = [ - self::CHECKING_CREDIT_RETURN, self::CHECKING_DEPOSIT, self::CHECKING_CREDIT_PRENOTIFICATION, self::CHECKING_ZERO_DOLLAR, - self::SAVINGS_CREDIT_RETURN, self::SAVINGS_DEPOSIT,self::SAVINGS_CREDIT_PRENOTIFICATION,self::SAVINGS_CREDIT_ZERO_DOLLAR, - self::GL_CREDIT_RETURN,self::GL_CREDIT,self::GL_CREDIT_PRENOTIFICATION,self::GL_CREDIT_ZERO_DOLLAR, - self::LOAN_CREDIT_REVERSAL,self::LOAN_CREDIT,self::LOAN_CREDIT_PRENOTIFICATION,self::LOAN_CREDIT_ZERO_DOLLAR - ]; - - const DEBIT_TRANSACTION_CODES = [ - self::CHECKING_DEBIT_RETURN,self::CHECKING_DEBIT,self::CHECKING_DEBIT_PRENOTIFICATION,self::CHECKING_DEBIT_ZERO_DOLLAR, - self::SAVINGS_DEBIT_RETURN,self::SAVINGS_DEBIT,self::SAVINGS_DEBIT_PRENOTIFICATION,self::SAVINGS_DEBIT_ZERO_DOLLAR, - self::GL_DEBIT_REVERSAL,self::GL_DEBIT,self::GL_DEBIT_PRENOTIFICATION,self::GL_DEBIT_ZERO_DOLLAR, - self::LOAN_DEBIT,self::LOAN_DEBIT_RETURN - ]; - - public function __construct($value) { + const SAVINGS_CREDIT_ZERO_DOLLAR = 34; // Zero dollar with remittance into Savings + + const SAVINGS_DEBIT_RETURN = 36; + const SAVINGS_DEBIT = 37; // Debit destined for a Savings Account + const SAVINGS_DEBIT_PRENOTIFICATION = 38; // Prenotification for a Savings debit + const SAVINGS_DEBIT_ZERO_DOLLAR = 39; // Zero dollar with remittance into Savings + + + const GL_CREDIT_RETURN = 41; + const GL_CREDIT = 42; // General ledger Deposit (Credit) + const GL_CREDIT_PRENOTIFICATION = 43; + const GL_CREDIT_ZERO_DOLLAR = 44; + + const GL_DEBIT_REVERSAL = 46; + const GL_DEBIT = 47; // General ledger Withdrawal + const GL_DEBIT_PRENOTIFICATION = 48; // Prenotification for General ledger Deposit (Credit) + const GL_DEBIT_ZERO_DOLLAR = 49; + + const LOAN_CREDIT_REVERSAL = 51; + const LOAN_CREDIT = 52; // Loan Deposit (Credit) + const LOAN_CREDIT_PRENOTIFICATION = 53; // Pre-Note: Loan Deposit (Credit) + const LOAN_CREDIT_ZERO_DOLLAR = 54; + + const LOAN_REVERSAL = self::LOAN_DEBIT; // Loan Reversal (Debit) (used rarely; reverses code 52) + const LOAN_DEBIT = 55; + const LOAN_DEBIT_RETURN = 56; + + public function __construct($value) + { parent::__construct($value, 2); if (!self::isValid($value)) { @@ -70,24 +58,69 @@ public function __construct($value) { * @param int $code * @return bool */ - public static function isCredit($code) { - return in_array($code,self::CREDIT_TRANSACTION_CODES); + public static function isCredit($code) + { + return in_array($code, self::getCreditTransactionCodes()); } /** * @param int $code * @return bool */ - public static function isDebit($code) { - return in_array($code,self::DEBIT_TRANSACTION_CODES); + public static function isDebit($code) + { + return in_array($code, self::getDebitTransactionCodes()); } /** * @param $code * @return bool */ - public static function isValid($code) { - return in_array($code, array_merge(self::CREDIT_TRANSACTION_CODES,self::DEBIT_TRANSACTION_CODES)); + public static function isValid($code) + { + return in_array($code, array_merge(self::getCreditTransactionCodes(), self::getDebitTransactionCodes())); + } + + private static function getCreditTransactionCodes() + { + return [ + self::CHECKING_CREDIT_RETURN, + self::CHECKING_DEPOSIT, + self::CHECKING_CREDIT_PRENOTIFICATION, + self::CHECKING_ZERO_DOLLAR, + self::SAVINGS_CREDIT_RETURN, + self::SAVINGS_DEPOSIT, + self::SAVINGS_CREDIT_PRENOTIFICATION, + self::SAVINGS_CREDIT_ZERO_DOLLAR, + self::GL_CREDIT_RETURN, + self::GL_CREDIT, + self::GL_CREDIT_PRENOTIFICATION, + self::GL_CREDIT_ZERO_DOLLAR, + self::LOAN_CREDIT_REVERSAL, + self::LOAN_CREDIT, + self::LOAN_CREDIT_PRENOTIFICATION, + self::LOAN_CREDIT_ZERO_DOLLAR, + ]; + } + + + private static function getDebitTransactionCodes() { + return [ + self::CHECKING_DEBIT_RETURN, + self::CHECKING_DEBIT, + self::CHECKING_DEBIT_PRENOTIFICATION, + self::CHECKING_DEBIT_ZERO_DOLLAR, + self::SAVINGS_DEBIT_RETURN, + self::SAVINGS_DEBIT, + self::SAVINGS_DEBIT_PRENOTIFICATION, + self::SAVINGS_DEBIT_ZERO_DOLLAR, + self::GL_DEBIT_REVERSAL, + self::GL_DEBIT, + self::GL_DEBIT_PRENOTIFICATION, + self::GL_DEBIT_ZERO_DOLLAR, + self::LOAN_DEBIT, + self::LOAN_DEBIT_RETURN, + ]; } } \ No newline at end of file From a29dcd8d22284a691278eea88f3c9934449861a9 Mon Sep 17 00:00:00 2001 From: Andrew Chinn Date: Thu, 24 Aug 2017 21:30:33 -0400 Subject: [PATCH 4/5] put brackets on end of line vs next line. --- src/Nacha/Field/TransactionCode.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Nacha/Field/TransactionCode.php b/src/Nacha/Field/TransactionCode.php index 4dd126d..f155ccf 100644 --- a/src/Nacha/Field/TransactionCode.php +++ b/src/Nacha/Field/TransactionCode.php @@ -2,8 +2,7 @@ namespace Nacha\Field; -class TransactionCode extends Number -{ +class TransactionCode extends Number { const CHECKING_CREDIT_RETURN = 21; const CHECKING_DEPOSIT = 22; // Deposit destined for a Checking Account @@ -45,8 +44,7 @@ class TransactionCode extends Number const LOAN_DEBIT = 55; const LOAN_DEBIT_RETURN = 56; - public function __construct($value) - { + public function __construct($value) { parent::__construct($value, 2); if (!self::isValid($value)) { @@ -58,8 +56,7 @@ public function __construct($value) * @param int $code * @return bool */ - public static function isCredit($code) - { + public static function isCredit($code) { return in_array($code, self::getCreditTransactionCodes()); } @@ -67,8 +64,7 @@ public static function isCredit($code) * @param int $code * @return bool */ - public static function isDebit($code) - { + public static function isDebit($code) { return in_array($code, self::getDebitTransactionCodes()); } @@ -76,13 +72,11 @@ public static function isDebit($code) * @param $code * @return bool */ - public static function isValid($code) - { + public static function isValid($code) { return in_array($code, array_merge(self::getCreditTransactionCodes(), self::getDebitTransactionCodes())); } - private static function getCreditTransactionCodes() - { + private static function getCreditTransactionCodes() { return [ self::CHECKING_CREDIT_RETURN, self::CHECKING_DEPOSIT, From f6e536b83ccb0c7e2424f5d3165e24797030291e Mon Sep 17 00:00:00 2001 From: Andrew Chinn Date: Thu, 24 Aug 2017 23:11:20 -0400 Subject: [PATCH 5/5] Removed print from debugging. --- test/Nacha/Field/TransactionCodeTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Nacha/Field/TransactionCodeTest.php b/test/Nacha/Field/TransactionCodeTest.php index f4c965d..ba3d2e3 100644 --- a/test/Nacha/Field/TransactionCodeTest.php +++ b/test/Nacha/Field/TransactionCodeTest.php @@ -47,11 +47,9 @@ public function testAllCreditTransactionCodesAreRecognized() { public function testAllDebitTransactionCodesAreRecognized() { foreach($this->creditCodes as $code) { - print_r($code); $this->assertFalse(TransactionCode::isDebit($code)); } foreach($this->debitCodes as $code) { - print_r($code); $this->assertTrue(TransactionCode::isDebit($code)); } }