diff --git a/src/Nacha/Batch.php b/src/Nacha/Batch.php index 19651cb..ddd9d56 100644 --- a/src/Nacha/Batch.php +++ b/src/Nacha/Batch.php @@ -4,8 +4,6 @@ use Nacha\Record\BatchFooter; use Nacha\Record\BatchHeader; -use Nacha\Record\CcdEntry; -use Nacha\Record\DebitEntry; use Nacha\Record\Entry; /** @@ -21,10 +19,10 @@ class Batch private $header; - /** @var DebitEntry[] */ + /** @var Entry[] */ private $creditEntries = []; - /** @var CcdEntry[] */ + /** @var Entry[] */ private $debitEntries = []; public function __construct() @@ -60,13 +58,13 @@ public function getTotalCreditAmount() return $amount; } - public function addDebitEntry(DebitEntry $entry) + public function addDebitEntry(Entry $entry) { $this->debitEntries[] = $entry; return $this; } - public function addCreditEntry(CcdEntry $entry) + public function addCreditEntry(Entry $entry) { $this->creditEntries[] = $entry; return $this; diff --git a/src/Nacha/Record/CcdEntry.php b/src/Nacha/Record/CcdEntry.php deleted file mode 100644 index d92c7dd..0000000 --- a/src/Nacha/Record/CcdEntry.php +++ /dev/null @@ -1,109 +0,0 @@ -setAddendaRecordIndicator(0); - $this->setReceivingCompanyId(''); - $this->setDiscretionaryData(''); - } - - public function getCheckDigit() - { - return $this->checkDigit; - } - - public function setCheckDigit($checkDigit) - { - $this->checkDigit = new Number($checkDigit, 1); - return $this; - } - - public function getReceivingDFiAccountNumber() - { - return $this->receivingDFiAccountNumber; - } - - public function setReceivingDFiAccountNumber($receivingDFiAccountNumber) - { - $this->receivingDFiAccountNumber = new String($receivingDFiAccountNumber, 17); - return $this; - } - - public function getReceivingCompanyId() - { - return $this->receivingCompanyId; - } - - public function setReceivingCompanyId($receivingCompanyId) - { - $this->receivingCompanyId = new String($receivingCompanyId, 15); - return $this; - } - - public function getReceivingCompanyName() - { - return $this->receivingCompanyName; - } - - public function setReceivingCompanyName($receivingCompanyName) - { - $this->receivingCompanyName = new String($receivingCompanyName, 22); - return $this; - } - - public function getDiscretionaryData() - { - return $this->discretionaryData; - } - - public function setDiscretionaryData($discretionaryData) - { - $this->discretionaryData = new String($discretionaryData, 2); - return $this; - } - - public function getAddendaRecordIndicator() - { - return $this->addendaRecordIndicator; - } - - public function setAddendaRecordIndicator($addendaRecordIndicator) - { - $this->addendaRecordIndicator = new Number($addendaRecordIndicator, 1); - return $this; - } - - public function __toString() - { - return $this->recordTypeCode . - $this->transactionCode . - $this->receivingDfiId . - $this->checkDigit . - $this->receivingDFiAccountNumber . - $this->amount . - $this->receivingCompanyId . - $this->receivingCompanyName . - $this->discretionaryData . - $this->addendaRecordIndicator . - $this->traceNumber; - } -} diff --git a/src/Nacha/Record/DebitEntry.php b/src/Nacha/Record/DebitEntry.php deleted file mode 100644 index bd6295f..0000000 --- a/src/Nacha/Record/DebitEntry.php +++ /dev/null @@ -1,109 +0,0 @@ -setIndividualId(''); - $this->setDiscretionaryData(''); - $this->setAddendaRecordIndicator(0); - } - - public function getCheckDigit() - { - return $this->checkDigit; - } - - public function setCheckDigit($checkDigit) - { - $this->checkDigit = new Number($checkDigit, 1); - return $this; - } - - public function getDFiAccountNumber() - { - return $this->dFiAccountNumber; - } - - public function setDFiAccountNumber($dFiAccountNumber) - { - $this->dFiAccountNumber = new String($dFiAccountNumber, 17); - return $this; - } - - public function getIndividualId() - { - return $this->individualId; - } - - public function setIndividualId($individualId) - { - $this->individualId = new String($individualId, 15); - return $this; - } - - public function getIdividualName() - { - return $this->idividualName; - } - - public function setIdividualName($idividualName) - { - $this->idividualName = new String($idividualName, 22); - return $this; - } - - public function getDiscretionaryData() - { - return $this->discretionaryData; - } - - public function setDiscretionaryData($discretionaryData) - { - $this->discretionaryData = new String($discretionaryData, 2); - return $this; - } - - public function getAddendaRecordIndicator() - { - return $this->addendaRecordIndicator; - } - - public function setAddendaRecordIndicator($addendaRecordIndicator) - { - $this->addendaRecordIndicator = new Number($addendaRecordIndicator, 1); - return $this; - } - - public function __toString() - { - return $this->recordTypeCode . - $this->transactionCode . - $this->receivingDfiId . - $this->checkDigit . - $this->dFiAccountNumber . - $this->amount . - $this->individualId . - $this->idividualName . - $this->discretionaryData . - $this->addendaRecordIndicator . - $this->traceNumber; - } -} diff --git a/src/Nacha/Record/Entry.php b/src/Nacha/Record/Entry.php index 849fe36..36e39f0 100644 --- a/src/Nacha/Record/Entry.php +++ b/src/Nacha/Record/Entry.php @@ -4,15 +4,22 @@ use Nacha\Field\Amount; use Nacha\Field\Number; +use Nacha\Field\String; use Nacha\Field\TransactionCode; -abstract class Entry +class Entry { protected $recordTypeCode = 6; protected $receivingDfiId; protected $traceNumber; protected $transactionCode; protected $amount; + protected $checkDigit; + protected $dFiAccountNumber; + protected $subjectId; + protected $subjectName; + protected $discretionaryData; + protected $addendaRecordIndicator; private $hashable = 0; @@ -22,6 +29,16 @@ public function __construct() $this->setTransactionCode(TransactionCode::CHECKING_DEPOSIT); $this->setAmount(0); $this->setTraceNumber(0, 0); + + // defaults + $this->setSubjectId(''); + $this->setDiscretionaryData(''); + $this->setAddendaRecordIndicator(0); + } + + public function getCheckDigit() + { + return $this->checkDigit; } public function getReceivingDfiId() @@ -29,6 +46,31 @@ public function getReceivingDfiId() return $this->receivingDfiId; } + public function getDFiAccountNumber() + { + return $this->dFiAccountNumber; + } + + public function getSubjectId() + { + return $this->subjectId; + } + + public function getSubjectName() + { + return $this->subjectName; + } + + public function getDiscretionaryData() + { + return $this->discretionaryData; + } + + public function getAddendaRecordIndicator() + { + return $this->addendaRecordIndicator; + } + public function getHashable() { return $this->hashable; @@ -49,6 +91,12 @@ final public function getTraceNumber() return $this->traceNumber; } + public function setCheckDigit($checkDigit) + { + $this->checkDigit = new Number($checkDigit, 1); + return $this; + } + public function setReceivingDFiId($receivingDfiId) { $this->setHashable($receivingDfiId); @@ -56,6 +104,36 @@ public function setReceivingDFiId($receivingDfiId) return $this; } + public function setDFiAccountNumber($dFiAccountNumber) + { + $this->dFiAccountNumber = new String($dFiAccountNumber, 17); + return $this; + } + + public function setSubjectId($subjectId) + { + $this->subjectId = new String($subjectId, 15); + return $this; + } + + public function setSubjectName($subjectName) + { + $this->subjectName = new String($subjectName, 22); + return $this; + } + + public function setDiscretionaryData($discretionaryData) + { + $this->discretionaryData = new String($discretionaryData, 2); + return $this; + } + + public function setAddendaRecordIndicator($addendaRecordIndicator) + { + $this->addendaRecordIndicator = new Number($addendaRecordIndicator, 1); + return $this; + } + public function setHashable($hashable) { $this->hashable = $hashable; @@ -80,5 +158,18 @@ final public function setTraceNumber($odfi, $count) return $this; } - abstract public function __toString(); + public function __toString() + { + return $this->recordTypeCode . + $this->transactionCode . + $this->receivingDfiId . + $this->checkDigit . + $this->dFiAccountNumber . + $this->amount . + $this->subjectId . + $this->subjectName . + $this->discretionaryData . + $this->addendaRecordIndicator . + $this->traceNumber; + } } diff --git a/test/Nacha/BatchTest.php b/test/Nacha/BatchTest.php index 61a124e..3ee48be 100644 --- a/test/Nacha/BatchTest.php +++ b/test/Nacha/BatchTest.php @@ -2,8 +2,7 @@ namespace Nacha; -use Nacha\Record\CcdEntry; -use Nacha\Record\DebitEntry; +use Nacha\Record\Entry; /** * Class BatchTest @@ -33,14 +32,14 @@ public function setup() public function testDebitOnlyBatch() { // when - $this->batch->addDebitEntry((new DebitEntry) + $this->batch->addDebitEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') + ->setSubjectId('SomePerson1255') + ->setSubjectName('Alex Dubrovsky') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('99936340', 15)); @@ -60,14 +59,14 @@ public function testDebitOnlyBatch() public function testCreditOnlyBatch() { // when - $this->batch->addCreditEntry((new CcdEntry) + $this->batch->addCreditEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) - ->setReceivingDFiAccountNumber('46479999') + ->setDFiAccountNumber('46479999') ->setAmount('600.00') - ->setReceivingCompanyId('Location 23') - ->setReceivingCompanyName('Best Co 23') + ->setSubjectId('Location 23') + ->setSubjectName('Best Co 23') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('09936340', 15)); @@ -87,26 +86,26 @@ public function testCreditOnlyBatch() public function testMixedBatch() { // when - $this->batch->addCreditEntry((new CcdEntry) + $this->batch->addCreditEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) - ->setReceivingDFiAccountNumber('46479999') + ->setDFiAccountNumber('46479999') ->setAmount('600.00') - ->setReceivingCompanyId('Location 23') - ->setReceivingCompanyName('Best Co 23') + ->setSubjectId('Location 23') + ->setSubjectName('Best Co 23') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('09936340', 15)); - $this->batch->addDebitEntry((new DebitEntry) + $this->batch->addDebitEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') + ->setSubjectId('SomePerson1255') + ->setSubjectName('Alex Dubrovsky') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('09936340', 15)); diff --git a/test/Nacha/FileTest.php b/test/Nacha/FileTest.php index 94c6e90..6e593ec 100644 --- a/test/Nacha/FileTest.php +++ b/test/Nacha/FileTest.php @@ -2,8 +2,7 @@ namespace Nacha; -use Nacha\Record\DebitEntry; -use Nacha\Record\CcdEntry; +use Nacha\Record\Entry; class FileTest extends \PHPUnit_Framework_TestCase { @@ -73,26 +72,26 @@ public function testNoBlockFill() { // given $batchA = $this->getBatch(); $batchA->getHeader()->setCompanyEntryDescription('EXPENSES'); - $batchA->addDebitEntry((new DebitEntry) + $batchA->addDebitEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Philip Whitt') + ->setSubjectId('SomePerson1255') + ->setSubjectName('Philip Whitt') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('99936340', 15)); - $batchA->addDebitEntry((new DebitEntry) + $batchA->addDebitEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Philip Whitt') + ->setSubjectId('SomePerson1255') + ->setSubjectName('Philip Whitt') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('99936340', 15)); @@ -119,14 +118,14 @@ public function testBlockWithEntries() { // given $batchA = $this->getBatch(); $batchA->getHeader()->setCompanyEntryDescription('EXPENSES'); - $batchA->addDebitEntry((new DebitEntry) + $batchA->addDebitEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Philip Whitt') + ->setSubjectId('SomePerson1255') + ->setSubjectName('Philip Whitt') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('99936340', 15)); @@ -173,14 +172,14 @@ private function getBatch() { ->setOriginatorStatusCode('2') ->setOriginatingDFiId('01021234'); - $batch->addDebitEntry((new DebitEntry) + $batch->addDebitEntry((new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') + ->setSubjectId('SomePerson1255') + ->setSubjectName('Alex Dubrovsky') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('99936340', 15)); diff --git a/test/Nacha/Record/CcdEntryTest.php b/test/Nacha/Record/CcdEntryTest.php deleted file mode 100644 index 1fff729..0000000 --- a/test/Nacha/Record/CcdEntryTest.php +++ /dev/null @@ -1,44 +0,0 @@ -setTransactionCode(27) - ->setReceivingDfiId('19101298') - ->setCheckDigit(7) - ->setReceivingDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setReceivingCompanyId('Location 23') - ->setReceivingCompanyName('Best Co 23') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('19101298', 15); - - $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62719101298746479999 0000055000LOCATION 23 BEST CO 23 S 0191012980000015', (string)$entry); - } - - public function testEntry_OptionalFields() - { - // given - $entry = (new CcdEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('19101298') - ->setCheckDigit(7) - ->setReceivingDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setReceivingCompanyName('Best Co 23') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('19101298', 15); - - $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62719101298746479999 0000055000 BEST CO 23 0191012980000015', (string)$entry); - } - -} \ No newline at end of file diff --git a/test/Nacha/Record/DebitEntryTest.php b/test/Nacha/Record/EntryTest.php similarity index 81% rename from test/Nacha/Record/DebitEntryTest.php rename to test/Nacha/Record/EntryTest.php index 8c4b40b..538bf6d 100644 --- a/test/Nacha/Record/DebitEntryTest.php +++ b/test/Nacha/Record/EntryTest.php @@ -2,20 +2,20 @@ namespace Nacha\Record; -class DebitEntryTest extends \PHPUnit_Framework_TestCase +class EntryTest extends \PHPUnit_Framework_TestCase { public function testEntry_AllFields() { // given - $entry = (new DebitEntry) + $entry = (new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') + ->setSubjectId('SomePerson1255') + ->setSubjectName('Alex Dubrovsky') ->setDiscretionaryData('S') ->setAddendaRecordIndicator(0) ->setTraceNumber('09101298', 15); @@ -27,13 +27,13 @@ public function testEntry_AllFields() public function testEntry_OptionalFields() { // given - $entry = (new DebitEntry) + $entry = (new Entry) ->setTransactionCode(27) ->setReceivingDfiId('09101298') ->setCheckDigit(7) ->setDFiAccountNumber('46479999') ->setAmount('550.00') - ->setIdividualName('Alex Dubrovsky') + ->setSubjectName('Alex Dubrovsky') ->setAddendaRecordIndicator(0) ->setTraceNumber('09101298', 15);