From 2d40dddbcc0cef5582743c740057d72c3d86c8ca Mon Sep 17 00:00:00 2001 From: sheppard Date: Tue, 15 Sep 2015 23:36:59 +0300 Subject: [PATCH 01/19] PSR-2 code style --- src/Nacha/Batch.php | 215 ++++++------ src/Nacha/Exception.php | 4 +- src/Nacha/Field/Amount.php | 28 +- src/Nacha/Field/CompanyEntryDescription.php | 28 +- src/Nacha/Field/CompanyName.php | 15 +- src/Nacha/Field/FileIdModifier.php | 16 +- src/Nacha/Field/InvalidFieldException.php | 4 +- src/Nacha/Field/Number.php | 39 +-- src/Nacha/Field/OriginatorStatusCode.php | 40 +-- src/Nacha/Field/RoutingNumber.php | 16 +- src/Nacha/Field/StandardEntryClass.php | 72 ++-- src/Nacha/Field/String.php | 37 +- src/Nacha/Field/TransactionCode.php | 85 ++--- src/Nacha/File.php | 148 ++++---- src/Nacha/Record/BatchFooter.php | 160 +++++---- src/Nacha/Record/BatchHeader.php | 318 ++++++++++-------- src/Nacha/Record/Block.php | 12 +- src/Nacha/Record/CcdEntry.php | 176 +++++----- src/Nacha/Record/DebitEntry.php | 176 +++++----- src/Nacha/Record/Entry.php | 132 ++++---- src/Nacha/Record/FileFooter.php | 121 ++++--- src/Nacha/Record/FileHeader.php | 223 ++++++------ test/Nacha/BatchTest.php | 225 +++++++------ test/Nacha/Field/AmountTest.php | 100 +++--- .../Field/CompanyEntryDescriptionTest.php | 29 +- test/Nacha/Field/CompanyNameTest.php | 29 +- test/Nacha/Field/NumberTest.php | 67 ++-- test/Nacha/Field/OriginatorStatusCodeTest.php | 29 +- test/Nacha/Field/RoutingNumberTest.php | 29 +- test/Nacha/Field/StandardEntryClassTest.php | 29 +- test/Nacha/Field/StringTest.php | 42 +-- test/Nacha/Field/TransactionCodeTest.php | 29 +- test/Nacha/FileTest.php | 206 ++++++------ test/Nacha/Record/BatchFooterTest.php | 55 +-- test/Nacha/Record/BatchHeaderTest.php | 77 +++-- test/Nacha/Record/BlockTest.php | 16 +- test/Nacha/Record/CcdEntryTest.php | 65 ++-- test/Nacha/Record/DebitEntryTest.php | 65 ++-- test/Nacha/Record/FileFooterTest.php | 43 +-- test/Nacha/Record/FileHeaderTest.php | 57 ++-- test/ci.xml | 32 +- 41 files changed, 1783 insertions(+), 1506 deletions(-) diff --git a/src/Nacha/Batch.php b/src/Nacha/Batch.php index c94921a..19651cb 100644 --- a/src/Nacha/Batch.php +++ b/src/Nacha/Batch.php @@ -2,112 +2,125 @@ namespace Nacha; -use Nacha\Record\BatchHeader; use Nacha\Record\BatchFooter; -use Nacha\Record\DebitEntry; +use Nacha\Record\BatchHeader; use Nacha\Record\CcdEntry; +use Nacha\Record\DebitEntry; use Nacha\Record\Entry; /** * Class Batch * @package Nacha */ -class Batch { - - // Service Class Codes - const MIXED = 200; - const CREDITS_ONLY = 220; - const DEBITS_ONLY = 225; - - private $header; - - /** @var DebitEntry[] */ - private $creditEntries = []; - - /** @var CcdEntry[] */ - private $debitEntries = []; - - public function __construct() { - $this->header = new BatchHeader(); - } - - public function getHeader() { - return $this->header; - } - public function getTotalEntryCount() { - return count($this->debitEntries) + count($this->creditEntries); - } - public function getTotalDebitAmount() { - $amount = 0; - foreach ($this->debitEntries as $entry) { - $amount += (int)(string)$entry->getAmount(); - } - return $amount; - } - public function getTotalCreditAmount() { - $amount = 0; - foreach ($this->creditEntries as $entry) { - $amount += (int)(string)$entry->getAmount(); - } - return $amount; - } - public function addDebitEntry(DebitEntry $entry) { - $this->debitEntries[] = $entry; - return $this; - } - public function addCreditEntry(CcdEntry $entry) { - $this->creditEntries[] = $entry; - return $this; - } - - public function getEntryHash() { - $hash = 0; - /** @var Entry[] $entries */ - $entries = array_merge($this->debitEntries, $this->creditEntries); - - foreach ($entries as $entry) { - $hash += $entry->getHashable(); - } - - $hashStr = substr((string)$hash, -10); // only take 10 digits from end of string to 10 - return intval($hashStr); - } - - public function __toString() { - $entries = ''; - - $footer = (new BatchFooter) - ->setEntryAddendaCount($this->getTotalEntryCount()) - ->setEntryHash($this->getEntryHash()) - ->setCompanyIdNumber((string)$this->header->getCompanyId()) - ->setOriginatingDfiId((string)$this->header->getOriginatingDFiId()) - ->setBatchNumber((string)$this->getHeader()->getBatchNumber()); - - foreach ($this->debitEntries as $entry) { - $entries .= (string)$entry."\n"; - } - - foreach ($this->creditEntries as $entry) { - $entries .= (string)$entry."\n"; - } - - // calculate service code - // default service code - $this->header->setServiceClassCode(self::MIXED); - if (count($this->debitEntries) > 0 && count($this->creditEntries) > 0) { - $this->header->setServiceClassCode(self::MIXED); - } else if (count($this->debitEntries) > 0 && count($this->creditEntries) == 0) { - $this->header->setServiceClassCode(self::DEBITS_ONLY); - } else if (count($this->debitEntries) == 0 && count($this->creditEntries) > 0) { - $this->header->setServiceClassCode(self::CREDITS_ONLY); - } - - - $footer->setTotalDebitAmount($this->getTotalDebitAmount()); - $footer->setTotalCreditAmount($this->getTotalCreditAmount()); - $footer->setServiceClassCode((string)$this->header->getServiceClassCode()); - - return (string)$this->header."\n".$entries.$footer; - } - -} \ No newline at end of file +class Batch +{ + // Service Class Codes + const MIXED = 200; + const CREDITS_ONLY = 220; + const DEBITS_ONLY = 225; + + private $header; + + /** @var DebitEntry[] */ + private $creditEntries = []; + + /** @var CcdEntry[] */ + private $debitEntries = []; + + public function __construct() + { + $this->header = new BatchHeader(); + } + + public function getHeader() + { + return $this->header; + } + + public function getTotalEntryCount() + { + return count($this->debitEntries) + count($this->creditEntries); + } + + public function getTotalDebitAmount() + { + $amount = 0; + foreach ($this->debitEntries as $entry) { + $amount += (int)(string)$entry->getAmount(); + } + return $amount; + } + + public function getTotalCreditAmount() + { + $amount = 0; + foreach ($this->creditEntries as $entry) { + $amount += (int)(string)$entry->getAmount(); + } + return $amount; + } + + public function addDebitEntry(DebitEntry $entry) + { + $this->debitEntries[] = $entry; + return $this; + } + + public function addCreditEntry(CcdEntry $entry) + { + $this->creditEntries[] = $entry; + return $this; + } + + public function getEntryHash() + { + $hash = 0; + /** @var Entry[] $entries */ + $entries = array_merge($this->debitEntries, $this->creditEntries); + + foreach ($entries as $entry) { + $hash += $entry->getHashable(); + } + + $hashStr = substr((string)$hash, -10); // only take 10 digits from end of string to 10 + return intval($hashStr); + } + + public function __toString() + { + $entries = ''; + + $footer = (new BatchFooter) + ->setEntryAddendaCount($this->getTotalEntryCount()) + ->setEntryHash($this->getEntryHash()) + ->setCompanyIdNumber((string)$this->header->getCompanyId()) + ->setOriginatingDfiId((string)$this->header->getOriginatingDFiId()) + ->setBatchNumber((string)$this->getHeader()->getBatchNumber()); + + foreach ($this->debitEntries as $entry) { + $entries .= (string)$entry . "\n"; + } + + foreach ($this->creditEntries as $entry) { + $entries .= (string)$entry . "\n"; + } + + // calculate service code + // default service code + $this->header->setServiceClassCode(self::MIXED); + if (count($this->debitEntries) > 0 && count($this->creditEntries) > 0) { + $this->header->setServiceClassCode(self::MIXED); + } elseif (count($this->debitEntries) > 0 && count($this->creditEntries) == 0) { + $this->header->setServiceClassCode(self::DEBITS_ONLY); + } elseif (count($this->debitEntries) == 0 && count($this->creditEntries) > 0) { + $this->header->setServiceClassCode(self::CREDITS_ONLY); + } + + + $footer->setTotalDebitAmount($this->getTotalDebitAmount()); + $footer->setTotalCreditAmount($this->getTotalCreditAmount()); + $footer->setServiceClassCode((string)$this->header->getServiceClassCode()); + + return (string)$this->header . "\n" . $entries . $footer; + } +} diff --git a/src/Nacha/Exception.php b/src/Nacha/Exception.php index 0a906aa..4a6e396 100644 --- a/src/Nacha/Exception.php +++ b/src/Nacha/Exception.php @@ -2,4 +2,6 @@ namespace Nacha; -class Exception extends \Exception {} \ No newline at end of file +class Exception extends \Exception +{ +} diff --git a/src/Nacha/Field/Amount.php b/src/Nacha/Field/Amount.php index bf9ab62..476dbf6 100644 --- a/src/Nacha/Field/Amount.php +++ b/src/Nacha/Field/Amount.php @@ -2,20 +2,20 @@ namespace Nacha\Field; -class Amount extends Number { +class Amount extends Number +{ + public function __construct($value) + { + // float value, preserve decimal places + $value = number_format((float)$value, 2, '.', ''); - public function __construct($value) { - // float value, preserve decimal places - $value = number_format((float)$value, 2, '.', ''); + // remove dots + $value = str_replace('.', '', $value); - // remove dots - $value = str_replace('.', '', $value); + if (strlen($value) > 10) { + throw new InvalidFieldException('Amount "' . $value . '" is too large.'); + } - if (strlen($value) > 10) { - throw new InvalidFieldException('Amount "' . $value . '" is too large.'); - } - - parent::__construct($value, 10); - } - -} \ No newline at end of file + parent::__construct($value, 10); + } +} diff --git a/src/Nacha/Field/CompanyEntryDescription.php b/src/Nacha/Field/CompanyEntryDescription.php index e3381ce..e9a2779 100644 --- a/src/Nacha/Field/CompanyEntryDescription.php +++ b/src/Nacha/Field/CompanyEntryDescription.php @@ -2,18 +2,22 @@ namespace Nacha\Field; -class CompanyEntryDescription extends String { +class CompanyEntryDescription extends String +{ + // upper case trigger words + private $triggers = [ + "reversal", "reclaim", "nonsettled", "autoenroll", "redepcheck", "no check", "return fee", + "hcclaimpmt" + ]; - // upper case trigger words - private $triggers = ["reversal", "reclaim", "nonsettled", "autoenroll", "redepcheck", "no check", "return fee", "hcclaimpmt"]; + public function __construct($value) + { + foreach ($this->triggers as $trigger) { + if (stristr(strtolower($value), $trigger)) { + $value = strtoupper($value); + } + } - public function __construct($value) { - foreach ($this->triggers as $trigger) { - if (stristr(strtolower($value), $trigger)) { - $value = strtoupper($value); - } - } - - parent::__construct($value, 10); - } + parent::__construct($value, 10); + } } diff --git a/src/Nacha/Field/CompanyName.php b/src/Nacha/Field/CompanyName.php index 15f0368..16fa02f 100644 --- a/src/Nacha/Field/CompanyName.php +++ b/src/Nacha/Field/CompanyName.php @@ -2,11 +2,12 @@ namespace Nacha\Field; -class CompanyName extends String { - - public function __construct($value) { - $value = strtolower($value) == 'check destroyed' ? strtoupper($value) : $value; - - parent::__construct($value, 16); - } +class CompanyName extends String +{ + public function __construct($value) + { + $value = strtolower($value) == 'check destroyed' ? strtoupper($value) : $value; + + parent::__construct($value, 16); + } } diff --git a/src/Nacha/Field/FileIdModifier.php b/src/Nacha/Field/FileIdModifier.php index 3f0029c..c1668f1 100644 --- a/src/Nacha/Field/FileIdModifier.php +++ b/src/Nacha/Field/FileIdModifier.php @@ -2,12 +2,14 @@ namespace Nacha\Field; -class FileIdModifier extends String { - public function __construct($value) { - parent::__construct(strtoupper($value), 1); +class FileIdModifier extends String +{ + public function __construct($value) + { + parent::__construct(strtoupper($value), 1); - if (!preg_match('/^[A-Z0-9]$/', (string)$value)) { - throw new InvalidFieldException('File Id Modifier "' . $value . '" must be A-Z 0-9.'); - } - } + if (!preg_match('/^[A-Z0-9]$/', (string)$value)) { + throw new InvalidFieldException('File Id Modifier "' . $value . '" must be A-Z 0-9.'); + } + } } diff --git a/src/Nacha/Field/InvalidFieldException.php b/src/Nacha/Field/InvalidFieldException.php index aa8cd95..c616d7c 100644 --- a/src/Nacha/Field/InvalidFieldException.php +++ b/src/Nacha/Field/InvalidFieldException.php @@ -2,4 +2,6 @@ namespace Nacha\Field; -class InvalidFieldException extends \Nacha\Exception {} \ No newline at end of file +class InvalidFieldException extends \Nacha\Exception +{ +} diff --git a/src/Nacha/Field/Number.php b/src/Nacha/Field/Number.php index 3c122e5..2bdc9a9 100644 --- a/src/Nacha/Field/Number.php +++ b/src/Nacha/Field/Number.php @@ -2,26 +2,27 @@ namespace Nacha\Field; -class Number { +class Number +{ + protected $value; + protected $length; - protected $value; - protected $length; + public function __construct($value, $length) + { + $this->value = (int)$value; + $this->length = $length; - public function __construct($value, $length) { - $this->value = (int)$value; - $this->length = $length; + if (!is_int($this->value)) { + throw new InvalidFieldException('Value "' . $value . '" must be an integer.'); + } - if (!is_int($this->value)) { - throw new InvalidFieldException('Value "' . $value . '" must be an integer.'); - } + if (strlen($value) > $length) { + throw new InvalidFieldException('Length of "' . $value . '" must be ' . $length . '.'); + } + } - if (strlen($value) > $length) { - throw new InvalidFieldException('Length of "' . $value . '" must be '.$length.'.'); - } - } - - public function __toString() { - return sprintf("%0{$this->length}d", $this->value); - } - -} \ No newline at end of file + public function __toString() + { + return sprintf("%0{$this->length}d", $this->value); + } +} diff --git a/src/Nacha/Field/OriginatorStatusCode.php b/src/Nacha/Field/OriginatorStatusCode.php index 1450cd5..7df5f65 100644 --- a/src/Nacha/Field/OriginatorStatusCode.php +++ b/src/Nacha/Field/OriginatorStatusCode.php @@ -2,26 +2,26 @@ namespace Nacha\Field; -class OriginatorStatusCode extends Number { +class OriginatorStatusCode extends Number +{ + const PREPARED_BY_OPERATOR = 0; + const ORIGINATOR_IS_FI = 1; + const ORIGINATOR_IS_EXEMPT = 2; // same as fed + const ORIGINATOR_IS_FED = 2; // same as exempt - const PREPARED_BY_OPERATOR = 0; - const ORIGINATOR_IS_FI = 1; - const ORIGINATOR_IS_EXEMPT = 2; // same as fed - const ORIGINATOR_IS_FED = 2; // same as exempt + public function __construct($value) + { + parent::__construct($value, 1); - public function __construct($value) { - parent::__construct($value, 1); + $valid = [ + self::PREPARED_BY_OPERATOR, + self::ORIGINATOR_IS_FI, + self::ORIGINATOR_IS_EXEMPT, + self::ORIGINATOR_IS_FED, + ]; - $valid = [ - self::PREPARED_BY_OPERATOR, - self::ORIGINATOR_IS_FI, - self::ORIGINATOR_IS_EXEMPT, - self::ORIGINATOR_IS_FED, - ]; - - if (!in_array($value, $valid)) { - throw new InvalidFieldException('Invalid originator status code "' . $value . '".'); - } - } - -} \ No newline at end of file + if (!in_array($value, $valid)) { + throw new InvalidFieldException('Invalid originator status code "' . $value . '".'); + } + } +} diff --git a/src/Nacha/Field/RoutingNumber.php b/src/Nacha/Field/RoutingNumber.php index 2a59da0..fb94b22 100644 --- a/src/Nacha/Field/RoutingNumber.php +++ b/src/Nacha/Field/RoutingNumber.php @@ -2,12 +2,14 @@ namespace Nacha\Field; -class RoutingNumber extends Number { - public function __construct($value) { - parent::__construct($value, 9); +class RoutingNumber extends Number +{ + public function __construct($value) + { + parent::__construct($value, 9); - if (!preg_match('/^[0-9]{9}$/', (string)$value)) { - throw new InvalidFieldException('Routing "' . $value . '" must be a 9 digit number.'); - } - } + if (!preg_match('/^[0-9]{9}$/', (string)$value)) { + throw new InvalidFieldException('Routing "' . $value . '" must be a 9 digit number.'); + } + } } diff --git a/src/Nacha/Field/StandardEntryClass.php b/src/Nacha/Field/StandardEntryClass.php index ac6dc05..19d4ab2 100644 --- a/src/Nacha/Field/StandardEntryClass.php +++ b/src/Nacha/Field/StandardEntryClass.php @@ -2,43 +2,45 @@ namespace Nacha\Field; -class StandardEntryClass extends String { +class StandardEntryClass extends String +{ + const ACK = 'ACK'; + const ADV = 'ADV'; + const ARC = 'ARC'; + const ATX = 'ATX'; + const BOC = 'BOC'; + const CCD = 'CCD'; + const CIE = 'CIE'; + const COR = 'COR'; + const CTX = 'CTX'; + const DNE = 'DNE'; + const ENR = 'ENR'; + const MTE = 'MTE'; + const POS = 'POS'; + const PPD = 'PPD'; + const POP = 'POP'; + const RCK = 'RCK'; + const SHR = 'SHR'; + const TEL = 'TEL'; + const TRC = 'TRC'; + const TRX = 'TRX'; + const WEB = 'WEB'; + const XCK = 'XCK'; - const ACK = 'ACK'; - const ADV = 'ADV'; - const ARC = 'ARC'; - const ATX = 'ATX'; - const BOC = 'BOC'; - const CCD = 'CCD'; - const CIE = 'CIE'; - const COR = 'COR'; - const CTX = 'CTX'; - const DNE = 'DNE'; - const ENR = 'ENR'; - const MTE = 'MTE'; - const POS = 'POS'; - const PPD = 'PPD'; - const POP = 'POP'; - const RCK = 'RCK'; - const SHR = 'SHR'; - const TEL = 'TEL'; - const TRC = 'TRC'; - const TRX = 'TRX'; - const WEB = 'WEB'; - const XCK = 'XCK'; + private $validClasses = [ + self::ACK, self::ADV, self::ARC, self::ATX, self::BOC, self::CCD, self::CIE, self::COR, self::CTX, self::DNE, + self::ENR, self::MTE, self::POS, self::PPD, self::POP, self::RCK, self::SHR, self::TEL, self::TRC, self::TRX, + self::WEB, self::XCK, + ]; - private $validClasses = [ - self::ACK, self::ADV, self::ARC, self::ATX, self::BOC, self::CCD, self::CIE, self::COR, self::CTX, self::DNE, self::ENR, - self::MTE, self::POS, self::PPD, self::POP, self::RCK, self::SHR, self::TEL, self::TRC, self::TRX, self::WEB, self::XCK, - ]; + public function __construct($value) + { + $value = strtoupper($value); - public function __construct($value) { - $value = strtoupper($value); + parent::__construct($value, 3); - parent::__construct($value, 3); - - if (!in_array($value, $this->validClasses)) { - throw new InvalidFieldException($value.' is not a valid standard entry class.'); - } - } + if (!in_array($value, $this->validClasses)) { + throw new InvalidFieldException($value . ' is not a valid standard entry class.'); + } + } } diff --git a/src/Nacha/Field/String.php b/src/Nacha/Field/String.php index 837ef2d..07e205e 100644 --- a/src/Nacha/Field/String.php +++ b/src/Nacha/Field/String.php @@ -2,24 +2,27 @@ namespace Nacha\Field; -class String { +class String +{ + protected $value; + protected $length; - protected $value; - protected $length; + public function __construct($value, $length) + { + $this->value = substr($value, 0, $length); + $this->length = $length; - public function __construct($value, $length) { - $this->value = substr($value, 0, $length); - $this->length = $length; + if (!is_string($value)) { + throw new InvalidFieldException('Value "' . $value . '" must be an string.'); + } - if (!is_string($value)) { - throw new InvalidFieldException('Value "' . $value . '" must be an string.'); + if (!preg_match('/^[\w\s-]*$/', $value)) { + throw new InvalidFieldException('Value "' . $value . '" has invalid ascii characters.'); + } + } - } else if (!preg_match('/^[\w\s-]*$/', $value)) { - throw new InvalidFieldException('Value "' . $value . '" has invalid ascii characters.'); - } - } - - public function __toString() { - return sprintf('%-' . $this->length . 's', $this->value); - } -} \ No newline at end of file + public function __toString() + { + return sprintf('%-' . $this->length . 's', $this->value); + } +} diff --git a/src/Nacha/Field/TransactionCode.php b/src/Nacha/Field/TransactionCode.php index c3f6ffe..ca28d8a 100644 --- a/src/Nacha/Field/TransactionCode.php +++ b/src/Nacha/Field/TransactionCode.php @@ -2,45 +2,46 @@ namespace Nacha\Field; -class TransactionCode extends Number { - - 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 = 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_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 = 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 - - 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, - ]; - - if (!in_array($value, $valid)) { - throw new InvalidFieldException('Invalid transaction code "' . $value . '".'); - } - } - -} \ No newline at end of file +class TransactionCode extends Number +{ + + 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 = 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_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 = 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 + + 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, + ]; + + if (!in_array($value, $valid)) { + throw new InvalidFieldException('Invalid transaction code "' . $value . '".'); + } + } +} diff --git a/src/Nacha/File.php b/src/Nacha/File.php index a706a8a..118a015 100644 --- a/src/Nacha/File.php +++ b/src/Nacha/File.php @@ -3,75 +3,83 @@ namespace Nacha; use Nacha\Record\Block; -use Nacha\Record\FileHeader; use Nacha\Record\FileFooter; +use Nacha\Record\FileHeader; -class File { - - private $header; - /** @var Batch[] */ - private $batches = []; - - public function __construct() { - $this->header = new FileHeader(); - } - - public function getHeader() { - return $this->header; - } - public function getBatches() { - return $this->batches; - } - public function addBatch(Batch $batch) { - $this->batches[] = $batch; - $batch->getHeader()->setBatchNumber(count($this->batches)); - } - - private function getHash() { - $hash = 0; - foreach ($this->batches as $batch) { - $hash += $batch->getEntryHash(); - } - return substr((string)$hash, -10); // only take 10 digits from end of string to 10 - } - - public function __toString() { - $batches = ''; - - $fileFooter = (new FileFooter) - ->setEntryHash($this->getHash()) - ->setBatchCount(count($this->batches)); - - $totalDebits = 0; - $totalCredits = 0; - $totalEntryCount = 0; - - foreach ($this->batches as $batch) { - $totalEntryCount += $batch->getTotalEntryCount(); - $totalDebits += $batch->getTotalDebitAmount(); // is this total amount of debits, or entries? - $totalCredits += $batch->getTotalCreditAmount(); // is this total amount of credits, or entries? - - $batches .= $batch."\n"; - } - - // block padding - // num entries + num batches header/footer + file header/footer - $totalRecords = $totalEntryCount + (count($this->batches) * 2) + 2; - $blocksNeeded = (ceil($totalRecords / 10) * 10) - $totalRecords; - - $block = ''; - for ($x=0; $x<$blocksNeeded % 10; $x++) { - $block .= (new Block)."\n"; - } - - $fileFooter->setBlockCount(round($totalRecords / 10)); - $fileFooter->setEntryAddendaCount($totalEntryCount); - $fileFooter->setTotalDebits($totalDebits); - $fileFooter->setTotalCredits($totalCredits); - - $output = $this->header."\n".$batches.$fileFooter."\n".$block; - - return rtrim($output, "\n"); - } - -} \ No newline at end of file +class File +{ + + private $header; + /** @var Batch[] */ + private $batches = []; + + public function __construct() + { + $this->header = new FileHeader(); + } + + public function getHeader() + { + return $this->header; + } + + public function getBatches() + { + return $this->batches; + } + + public function addBatch(Batch $batch) + { + $this->batches[] = $batch; + $batch->getHeader()->setBatchNumber(count($this->batches)); + } + + private function getHash() + { + $hash = 0; + foreach ($this->batches as $batch) { + $hash += $batch->getEntryHash(); + } + return substr((string)$hash, -10); // only take 10 digits from end of string to 10 + } + + public function __toString() + { + $batches = ''; + + $fileFooter = (new FileFooter) + ->setEntryHash($this->getHash()) + ->setBatchCount(count($this->batches)); + + $totalDebits = 0; + $totalCredits = 0; + $totalEntryCount = 0; + + foreach ($this->batches as $batch) { + $totalEntryCount += $batch->getTotalEntryCount(); + $totalDebits += $batch->getTotalDebitAmount(); // is this total amount of debits, or entries? + $totalCredits += $batch->getTotalCreditAmount(); // is this total amount of credits, or entries? + + $batches .= $batch . "\n"; + } + + // block padding + // num entries + num batches header/footer + file header/footer + $totalRecords = $totalEntryCount + (count($this->batches) * 2) + 2; + $blocksNeeded = (ceil($totalRecords / 10) * 10) - $totalRecords; + + $block = ''; + for ($x = 0; $x < $blocksNeeded % 10; $x++) { + $block .= (new Block) . "\n"; + } + + $fileFooter->setBlockCount(round($totalRecords / 10)); + $fileFooter->setEntryAddendaCount($totalEntryCount); + $fileFooter->setTotalDebits($totalDebits); + $fileFooter->setTotalCredits($totalCredits); + + $output = $this->header . "\n" . $batches . $fileFooter . "\n" . $block; + + return rtrim($output, "\n"); + } +} diff --git a/src/Nacha/Record/BatchFooter.php b/src/Nacha/Record/BatchFooter.php index 6f71e16..c15e5bc 100644 --- a/src/Nacha/Record/BatchFooter.php +++ b/src/Nacha/Record/BatchFooter.php @@ -2,81 +2,99 @@ namespace Nacha\Record; -use Nacha\Field\String; use Nacha\Field\Number; +use Nacha\Field\String; + +class BatchFooter +{ + private $recordTypeCode = 8; // not able to overwrite this + private $serviceClassCode; + private $entryAddendaCount; + private $entryHash; + private $totalDebitAmount; + private $totalCreditAmount; + private $companyIdNumber; + private $messageAuthenticationCode; + private $reserved; + private $originatingDfiId; + private $batchNumber; + + public function __construct() + { + // defaults/optional + $this->reserved = new String('', 6); + $this->setEntryAddendaCount(0); + $this->setMessageAuthenticationCode(''); + $this->setTotalDebitAmount(0); + $this->setTotalCreditAmount(0); + } + + public function setServiceClassCode($serviceClassCode) + { + $this->serviceClassCode = new Number($serviceClassCode, 3); + return $this; + } + + public function setEntryAddendaCount($entryAddendaCount) + { + $this->entryAddendaCount = new Number($entryAddendaCount, 6); + return $this; + } + + public function setEntryHash($entryHash) + { + $this->entryHash = new Number($entryHash, 10); + return $this; + } + + public function setTotalDebitAmount($totalDebitAmount) + { + $this->totalDebitAmount = new Number($totalDebitAmount, 12); + return $this; + } -class BatchFooter { + public function setTotalCreditAmount($totalCreditAmount) + { + $this->totalCreditAmount = new Number($totalCreditAmount, 12); + return $this; + } - private $recordTypeCode = 8; // not able to overwrite this - private $serviceClassCode; - private $entryAddendaCount; - private $entryHash; - private $totalDebitAmount; - private $totalCreditAmount; - private $companyIdNumber; - private $messageAuthenticationCode; - private $reserved; - private $originatingDfiId; - private $batchNumber; + public function setCompanyIdNumber($companyIdNumber) + { + $this->companyIdNumber = new Number($companyIdNumber, 10); + return $this; + } - public function __construct() { - // defaults/optional - $this->reserved = new String('', 6); - $this->setEntryAddendaCount(0); - $this->setMessageAuthenticationCode(''); - $this->setTotalDebitAmount(0); - $this->setTotalCreditAmount(0); - } + public function setMessageAuthenticationCode($messageAuthenticationCode) + { + $this->messageAuthenticationCode = new String($messageAuthenticationCode, 19); + return $this; + } - public function setServiceClassCode($serviceClassCode) { - $this->serviceClassCode = new Number($serviceClassCode, 3); - return $this; - } - public function setEntryAddendaCount($entryAddendaCount) { - $this->entryAddendaCount = new Number($entryAddendaCount, 6); - return $this; - } - public function setEntryHash($entryHash) { - $this->entryHash = new Number($entryHash, 10); - return $this; - } - public function setTotalDebitAmount($totalDebitAmount) { - $this->totalDebitAmount = new Number($totalDebitAmount, 12); - return $this; - } - public function setTotalCreditAmount($totalCreditAmount) { - $this->totalCreditAmount = new Number($totalCreditAmount, 12); - return $this; - } - public function setCompanyIdNumber($companyIdNumber) { - $this->companyIdNumber = new Number($companyIdNumber, 10); - return $this; - } - public function setMessageAuthenticationCode($messageAuthenticationCode) { - $this->messageAuthenticationCode = new String($messageAuthenticationCode, 19); - return $this; - } - public function setOriginatingDfiId($originatingDfiId) { - $this->originatingDfiId = new Number($originatingDfiId, 8); - return $this; - } - public function setBatchNumber($batchNumber) { - $this->batchNumber = new Number($batchNumber, 7); - return $this; - } + public function setOriginatingDfiId($originatingDfiId) + { + $this->originatingDfiId = new Number($originatingDfiId, 8); + return $this; + } - public function __toString() { - return $this->recordTypeCode. - $this->serviceClassCode. - $this->entryAddendaCount. - $this->entryHash. - $this->totalDebitAmount. - $this->totalCreditAmount. - $this->companyIdNumber. - $this->messageAuthenticationCode. - $this->reserved. - $this->originatingDfiId. - $this->batchNumber; - } + public function setBatchNumber($batchNumber) + { + $this->batchNumber = new Number($batchNumber, 7); + return $this; + } -} \ No newline at end of file + public function __toString() + { + return $this->recordTypeCode . + $this->serviceClassCode . + $this->entryAddendaCount . + $this->entryHash . + $this->totalDebitAmount . + $this->totalCreditAmount . + $this->companyIdNumber . + $this->messageAuthenticationCode . + $this->reserved . + $this->originatingDfiId . + $this->batchNumber; + } +} diff --git a/src/Nacha/Record/BatchHeader.php b/src/Nacha/Record/BatchHeader.php index 356fd59..ff20952 100644 --- a/src/Nacha/Record/BatchHeader.php +++ b/src/Nacha/Record/BatchHeader.php @@ -2,141 +2,189 @@ namespace Nacha\Record; -use Nacha\Field\String; -use Nacha\Field\Number; -use Nacha\Field\CompanyName; -use Nacha\Field\StandardEntryClass; use Nacha\Field\CompanyEntryDescription; +use Nacha\Field\CompanyName; +use Nacha\Field\Number; use Nacha\Field\OriginatorStatusCode; +use Nacha\Field\StandardEntryClass; +use Nacha\Field\String; + +class BatchHeader +{ + + private $recordTypeCode = 5; // not able to overwrite this + private $serviceClassCode; + private $companyName; + private $companyDiscretionaryData; + private $companyId; + private $standardEntryClassCode; + private $companyEntryDescription; + private $companyDescriptiveDate; + private $effectiveEntryDate; + private $settlementDate; + private $originatorStatusCode; + private $originatingDFiId; + private $batchNumber; + + public function __construct() + { + // defaults + $this->setEffectiveEntryDate(date('ymd', time())); + + // Set by operator + $this->setSettlementDate(''); + + // optional fields + $this->setCompanyDiscretionaryData(''); + $this->setCompanyDescriptiveDate(''); + } + + public function getServiceClassCode() + { + return $this->serviceClassCode; + } + + public function getCompanyName() + { + return $this->companyName; + } + + public function getCompanyDiscretionaryData() + { + return $this->companyDiscretionaryData; + } + + public function getCompanyId() + { + return $this->companyId; + } + + public function getStandardEntryClassCode() + { + return $this->standardEntryClassCode; + } + + public function getCompanyEntryDescription() + { + return $this->companyEntryDescription; + } + + public function getCompanyDescriptiveDate() + { + return $this->companyDescriptiveDate; + } + + public function getEffectiveEntryDate() + { + return $this->effectiveEntryDate; + } + + public function getSettlementDate() + { + return $this->settlementDate; + } + + public function getOriginatorStatusCode() + { + return $this->originatorStatusCode; + } + + public function getOriginatingDFiId() + { + return $this->originatingDFiId; + } + + public function getBatchNumber() + { + return $this->batchNumber; + } + + public function setServiceClassCode($serviceClassCode) + { + $this->serviceClassCode = new Number($serviceClassCode, 3); + return $this; + } + + public function setCompanyName($companyName) + { + $this->companyName = new CompanyName($companyName); + return $this; + } + + public function setCompanyDiscretionaryData($companyDiscretionaryData) + { + $this->companyDiscretionaryData = new String($companyDiscretionaryData, 20); + return $this; + } + + public function setCompanyId($companyId) + { + $this->companyId = new String($companyId, 10); + return $this; + } + + public function setStandardEntryClassCode($standardEntryClassCode) + { + $this->standardEntryClassCode = new StandardEntryClass($standardEntryClassCode); + return $this; + } + + public function setCompanyEntryDescription($companyEntryDescription) + { + $this->companyEntryDescription = new CompanyEntryDescription($companyEntryDescription); + return $this; + } + + public function setCompanyDescriptiveDate($companyDescriptiveDate) + { + $this->companyDescriptiveDate = new String($companyDescriptiveDate, 6); + return $this; + } + + public function setEffectiveEntryDate($effectiveEntryDate) + { + $this->effectiveEntryDate = new String($effectiveEntryDate, 6); + return $this; + } + + public function setSettlementDate($settlementDate) + { + $this->settlementDate = new String($settlementDate, 3); + return $this; + } + + public function setOriginatorStatusCode($originatorStatusCode) + { + $this->originatorStatusCode = new OriginatorStatusCode($originatorStatusCode); + return $this; + } + + public function setOriginatingDFiId($originatingDFiId) + { + $this->originatingDFiId = new String($originatingDFiId, 8); + return $this; + } + + public function setBatchNumber($batchNumber) + { + $this->batchNumber = new Number($batchNumber, 7); + return $this; + } -class BatchHeader { - - private $recordTypeCode = 5; // not able to overwrite this - private $serviceClassCode; - private $companyName; - private $companyDiscretionaryData; - private $companyId; - private $standardEntryClassCode; - private $companyEntryDescription; - private $companyDescriptiveDate; - private $effectiveEntryDate; - private $settlementDate; - private $originatorStatusCode; - private $originatingDFiId; - private $batchNumber; - - public function __construct() { - // defaults - $this->setEffectiveEntryDate(date('ymd', time())); - - // Set by operator - $this->setSettlementDate(''); - - // optional fields - $this->setCompanyDiscretionaryData(''); - $this->setCompanyDescriptiveDate(''); - } - - public function getServiceClassCode() { - return $this->serviceClassCode; - } - public function getCompanyName() { - return $this->companyName; - } - public function getCompanyDiscretionaryData() { - return $this->companyDiscretionaryData; - } - public function getCompanyId() { - return $this->companyId; - } - public function getStandardEntryClassCode() { - return $this->standardEntryClassCode; - } - public function getCompanyEntryDescription() { - return $this->companyEntryDescription; - } - public function getCompanyDescriptiveDate() { - return $this->companyDescriptiveDate; - } - public function getEffectiveEntryDate() { - return $this->effectiveEntryDate; - } - public function getSettlementDate() { - return $this->settlementDate; - } - public function getOriginatorStatusCode() { - return $this->originatorStatusCode; - } - public function getOriginatingDFiId() { - return $this->originatingDFiId; - } - public function getBatchNumber() { - return $this->batchNumber; - } - - public function setServiceClassCode($serviceClassCode) { - $this->serviceClassCode = new Number($serviceClassCode, 3); - return $this; - } - public function setCompanyName($companyName) { - $this->companyName = new CompanyName($companyName); - return $this; - } - public function setCompanyDiscretionaryData($companyDiscretionaryData) { - $this->companyDiscretionaryData = new String($companyDiscretionaryData, 20); - return $this; - } - public function setCompanyId($companyId) { - $this->companyId = new String($companyId, 10); - return $this; - } - public function setStandardEntryClassCode($standardEntryClassCode) { - $this->standardEntryClassCode = new StandardEntryClass($standardEntryClassCode); - return $this; - } - public function setCompanyEntryDescription($companyEntryDescription) { - $this->companyEntryDescription = new CompanyEntryDescription($companyEntryDescription); - return $this; - } - public function setCompanyDescriptiveDate($companyDescriptiveDate) { - $this->companyDescriptiveDate = new String($companyDescriptiveDate, 6); - return $this; - } - public function setEffectiveEntryDate($effectiveEntryDate) { - $this->effectiveEntryDate = new String($effectiveEntryDate, 6); - return $this; - } - public function setSettlementDate($settlementDate) { - $this->settlementDate = new String($settlementDate, 3); - return $this; - } - public function setOriginatorStatusCode($originatorStatusCode) { - $this->originatorStatusCode = new OriginatorStatusCode($originatorStatusCode); - return $this; - } - public function setOriginatingDFiId($originatingDFiId) { - $this->originatingDFiId = new String($originatingDFiId, 8); - return $this; - } - public function setBatchNumber($batchNumber) { - $this->batchNumber = new Number($batchNumber, 7); - return $this; - } - - public function __toString() { - return $this->recordTypeCode. - $this->serviceClassCode. - $this->companyName. - $this->companyDiscretionaryData. - $this->companyId. - $this->standardEntryClassCode. - $this->companyEntryDescription. - $this->companyDescriptiveDate. - $this->effectiveEntryDate. - $this->settlementDate. - $this->originatorStatusCode. - $this->originatingDFiId. - $this->batchNumber; - } - -} \ No newline at end of file + public function __toString() + { + return $this->recordTypeCode . + $this->serviceClassCode . + $this->companyName . + $this->companyDiscretionaryData . + $this->companyId . + $this->standardEntryClassCode . + $this->companyEntryDescription . + $this->companyDescriptiveDate . + $this->effectiveEntryDate . + $this->settlementDate . + $this->originatorStatusCode . + $this->originatingDFiId . + $this->batchNumber; + } +} diff --git a/src/Nacha/Record/Block.php b/src/Nacha/Record/Block.php index 3914387..3860a8d 100644 --- a/src/Nacha/Record/Block.php +++ b/src/Nacha/Record/Block.php @@ -2,10 +2,10 @@ namespace Nacha\Record; -class Block { - - public function __toString() { - return '9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'; - } - +class Block +{ + public function __toString() + { + return '9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'; + } } diff --git a/src/Nacha/Record/CcdEntry.php b/src/Nacha/Record/CcdEntry.php index dc9f45a..d92c7dd 100644 --- a/src/Nacha/Record/CcdEntry.php +++ b/src/Nacha/Record/CcdEntry.php @@ -2,84 +2,108 @@ namespace Nacha\Record; -use Nacha\Field\String; use Nacha\Field\Number; +use Nacha\Field\String; // Cash Collection and Disbursement Entry (CCD) -class CcdEntry extends Entry { - - private $checkDigit; - private $receivingDFiAccountNumber; - private $receivingCompanyId; - private $receivingCompanyName; - private $discretionaryData; - private $addendaRecordIndicator; - - public function __construct() { - parent::__construct(); - - // defaults - $this->setAddendaRecordIndicator(0); - $this->setReceivingCompanyId(''); - $this->setDiscretionaryData(''); - } - - public function getCheckDigit() { - return $this->checkDigit; - } - public function getReceivingDFiAccountNumber() { - return $this->receivingDFiAccountNumber; - } - public function getReceivingCompanyId() { - return $this->receivingCompanyId; - } - public function getReceivingCompanyName() { - return $this->receivingCompanyName; - } - public function getDiscretionaryData() { - return $this->discretionaryData; - } - public function getAddendaRecordIndicator() { - return $this->addendaRecordIndicator; - } - - public function setCheckDigit($checkDigit) { - $this->checkDigit = new Number($checkDigit, 1); - return $this; - } - public function setReceivingDFiAccountNumber($receivingDFiAccountNumber) { - $this->receivingDFiAccountNumber = new String($receivingDFiAccountNumber, 17); - return $this; - } - public function setReceivingCompanyId($receivingCompanyId) { - $this->receivingCompanyId = new String($receivingCompanyId, 15); - return $this; - } - public function setReceivingCompanyName($receivingCompanyName) { - $this->receivingCompanyName = new String($receivingCompanyName, 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 __toString() { - return $this->recordTypeCode. - $this->transactionCode. - $this->receivingDfiId. - $this->checkDigit. - $this->receivingDFiAccountNumber. - $this->amount. - $this->receivingCompanyId. - $this->receivingCompanyName. - $this->discretionaryData. - $this->addendaRecordIndicator. - $this->traceNumber; - } +class CcdEntry extends Entry +{ + + private $checkDigit; + private $receivingDFiAccountNumber; + private $receivingCompanyId; + private $receivingCompanyName; + private $discretionaryData; + private $addendaRecordIndicator; + + public function __construct() + { + parent::__construct(); + + // defaults + $this->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 index 992311e..bd6295f 100644 --- a/src/Nacha/Record/DebitEntry.php +++ b/src/Nacha/Record/DebitEntry.php @@ -2,84 +2,108 @@ namespace Nacha\Record; -use Nacha\Field\String; use Nacha\Field\Number; +use Nacha\Field\String; // PPD, TEL, WEB debit -class DebitEntry extends Entry { - - private $checkDigit; - private $dFiAccountNumber; - private $individualId; - private $idividualName; - private $discretionaryData; - private $addendaRecordIndicator; - - public function __construct() { - parent::__construct(); - - // defaults - $this->setIndividualId(''); - $this->setDiscretionaryData(''); - $this->setAddendaRecordIndicator(0); - } - - public function getCheckDigit() { - return $this->checkDigit; - } - public function getDFiAccountNumber() { - return $this->dFiAccountNumber; - } - public function getIndividualId() { - return $this->individualId; - } - public function getIdividualName() { - return $this->idividualName; - } - public function getDiscretionaryData() { - return $this->discretionaryData; - } - public function getAddendaRecordIndicator() { - return $this->addendaRecordIndicator; - } - - public function setCheckDigit($checkDigit) { - $this->checkDigit = new Number($checkDigit, 1); - return $this; - } - public function setDFiAccountNumber($dFiAccountNumber) { - $this->dFiAccountNumber = new String($dFiAccountNumber, 17); - return $this; - } - public function setIndividualId($individualId) { - $this->individualId = new String($individualId, 15); - return $this; - } - public function setIdividualName($idividualName) { - $this->idividualName = new String($idividualName, 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 __toString() { - return $this->recordTypeCode. - $this->transactionCode. - $this->receivingDfiId. - $this->checkDigit. - $this->dFiAccountNumber. - $this->amount. - $this->individualId. - $this->idividualName. - $this->discretionaryData. - $this->addendaRecordIndicator. - $this->traceNumber; - } +class DebitEntry extends Entry +{ + + private $checkDigit; + private $dFiAccountNumber; + private $individualId; + private $idividualName; + private $discretionaryData; + private $addendaRecordIndicator; + + public function __construct() + { + parent::__construct(); + + // defaults + $this->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 ab6c4ea..849fe36 100644 --- a/src/Nacha/Record/Entry.php +++ b/src/Nacha/Record/Entry.php @@ -2,65 +2,83 @@ namespace Nacha\Record; +use Nacha\Field\Amount; use Nacha\Field\Number; use Nacha\Field\TransactionCode; -use Nacha\Field\Amount; -abstract class Entry { - - protected $recordTypeCode = 6; - protected $receivingDfiId; - protected $traceNumber; - protected $transactionCode; - protected $amount; - - private $hashable = 0; - - public function __construct() { - // initialize - $this->setTransactionCode(TransactionCode::CHECKING_DEPOSIT); - $this->setAmount(0); - $this->setTraceNumber(0, 0); - } - - public function getReceivingDfiId() { - return $this->receivingDfiId; - } - public function getHashable() { - return $this->hashable; - } - public function getAmount() { - return $this->amount; - } - public function getTransactionCode() { - return $this->transactionCode; - } - public final function getTraceNumber() { - return $this->traceNumber; - } - - public function setReceivingDFiId($receivingDfiId) { - $this->setHashable($receivingDfiId); - $this->receivingDfiId = new Number($receivingDfiId, 8); - return $this; - } - public function setHashable($hashable) { - $this->hashable = $hashable; - return $this; - } - public function setAmount($amount) { - $this->amount = new Amount($amount); - return $this; - } - public function setTransactionCode($transactionCode) { - $this->transactionCode = new TransactionCode($transactionCode); - return $this; - } - public final function setTraceNumber($odfi, $count) { - $this->traceNumber = (new Number($odfi, 8)) . (new Number($count, 7)); - return $this; - } - - abstract public function __toString(); +abstract class Entry +{ + protected $recordTypeCode = 6; + protected $receivingDfiId; + protected $traceNumber; + protected $transactionCode; + protected $amount; + + private $hashable = 0; + + public function __construct() + { + // initialize + $this->setTransactionCode(TransactionCode::CHECKING_DEPOSIT); + $this->setAmount(0); + $this->setTraceNumber(0, 0); + } + + public function getReceivingDfiId() + { + return $this->receivingDfiId; + } + + public function getHashable() + { + return $this->hashable; + } + + public function getAmount() + { + return $this->amount; + } + + public function getTransactionCode() + { + return $this->transactionCode; + } + + final public function getTraceNumber() + { + return $this->traceNumber; + } + + public function setReceivingDFiId($receivingDfiId) + { + $this->setHashable($receivingDfiId); + $this->receivingDfiId = new Number($receivingDfiId, 8); + return $this; + } + + public function setHashable($hashable) + { + $this->hashable = $hashable; + return $this; + } + + public function setAmount($amount) + { + $this->amount = new Amount($amount); + return $this; + } + + public function setTransactionCode($transactionCode) + { + $this->transactionCode = new TransactionCode($transactionCode); + return $this; + } + + final public function setTraceNumber($odfi, $count) + { + $this->traceNumber = (new Number($odfi, 8)) . (new Number($count, 7)); + return $this; + } + abstract public function __toString(); } diff --git a/src/Nacha/Record/FileFooter.php b/src/Nacha/Record/FileFooter.php index cadaccb..071883e 100644 --- a/src/Nacha/Record/FileFooter.php +++ b/src/Nacha/Record/FileFooter.php @@ -2,64 +2,77 @@ namespace Nacha\Record; -use Nacha\Field\String; use Nacha\Field\Number; +use Nacha\Field\String; + +class FileFooter +{ + + private $recordTypeCode = 9; // not able to overwrite this + private $batchCount; + private $blockCount; + private $entryAddendaCount; + private $entryHash; + private $totalDebits; + private $totalCredits; + private $reserved; + + public function __construct() + { + // defaults + $this->reserved = new String('', 39); + $this->setBatchCount(0); + $this->setBlockCount(0); + $this->setEntryAddendaCount(0); + $this->setTotalDebits(0); + $this->setTotalCredits(0); + } + + public function setBatchCount($batchCount) + { + $this->batchCount = new Number($batchCount, 6); + return $this; + } -class FileFooter { + public function setBlockCount($blockCount) + { + $this->blockCount = new Number($blockCount, 6); + return $this; + } - private $recordTypeCode = 9; // not able to overwrite this - private $batchCount; - private $blockCount; - private $entryAddendaCount; - private $entryHash; - private $totalDebits; - private $totalCredits; - private $reserved; + public function setEntryAddendaCount($entryAddendaCount) + { + $this->entryAddendaCount = new Number($entryAddendaCount, 8); + return $this; + } - public function __construct() { - // defaults - $this->reserved = new String('', 39); - $this->setBatchCount(0); - $this->setBlockCount(0); - $this->setEntryAddendaCount(0); - $this->setTotalDebits(0); - $this->setTotalCredits(0); - } + public function setEntryHash($entryHash) + { + $this->entryHash = new Number($entryHash, 10); + return $this; + } - public function setBatchCount($batchCount) { - $this->batchCount = new Number($batchCount, 6); - return $this; - } - public function setBlockCount($blockCount) { - $this->blockCount = new Number($blockCount, 6); - return $this; - } - public function setEntryAddendaCount($entryAddendaCount) { - $this->entryAddendaCount = new Number($entryAddendaCount, 8); - return $this; - } - public function setEntryHash($entryHash) { - $this->entryHash = new Number($entryHash, 10); - return $this; - } - public function setTotalDebits($totalDebits) { - $this->totalDebits = new Number($totalDebits, 12); - return $this; - } - public function setTotalCredits($totalCredits) { - $this->totalCredits = new Number($totalCredits, 12); - return $this; - } + public function setTotalDebits($totalDebits) + { + $this->totalDebits = new Number($totalDebits, 12); + return $this; + } - public function __toString() { - return $this->recordTypeCode. - $this->batchCount. - $this->blockCount. - $this->entryAddendaCount. - $this->entryHash. - $this->totalDebits. - $this->totalCredits. - $this->reserved; - } + public function setTotalCredits($totalCredits) + { + $this->totalCredits = new Number($totalCredits, 12); + return $this; + } -} \ No newline at end of file + public function __toString() + { + return $this->recordTypeCode . + $this->batchCount . + $this->blockCount . + $this->entryAddendaCount . + $this->entryHash . + $this->totalDebits . + $this->totalCredits . + $this->reserved; + } +} diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index a71ab02..cca4f6a 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -2,105 +2,130 @@ namespace Nacha\Record; -use Nacha\Field\String; +use Nacha\Field\FileIdModifier; use Nacha\Field\Number; use Nacha\Field\RoutingNumber; -use Nacha\Field\FileIdModifier; +use Nacha\Field\String; + +class FileHeader +{ + + private $recordTypeCode = 1; // not able to overwrite this + private $priorityCode; + private $immediateDestination; + private $immediateOrigin; + private $fileCreationDate; + private $fileCreationTime; + private $fileIdModifier; + private $recordSize; + private $blockingFactor; + private $formatCode; + private $immediateDestinationName; + private $immediateOriginName; + private $referenceCode; + + public function __construct() + { + // defaults + $this->setRecordSize(94); + $this->setBlockingFactor(10); + $this->setFormatCode(1); + $this->setFileIdModifier('A'); + $this->setFileCreationDate(date('ymd')); + + // optional + $this->setImmediateDestinationName(''); + $this->setImmediateOriginName(''); + $this->setReferenceCode(''); + $this->setFileCreationTime(''); + } + + public function setPriorityCode($priorityCode) + { + $this->priorityCode = new Number($priorityCode, 2); + return $this; + } + + public function setImmediateDestination($immediateDestination) + { + $this->immediateDestination = new RoutingNumber($immediateDestination); + return $this; + } + + public function setImmediateOrigin($immediateOrigin) + { + $this->immediateOrigin = new RoutingNumber($immediateOrigin); + return $this; + } + + public function setFileCreationDate($fileCreationDate) + { + $this->fileCreationDate = new String($fileCreationDate, 6); + return $this; + } + + public function setFileCreationTime($fileCreationTime) + { + $this->fileCreationTime = new String($fileCreationTime, 4); + return $this; + } + + public function setFileIdModifier($fileIdModifier) + { + $this->fileIdModifier = new FileIdModifier($fileIdModifier); + return $this; + } + + public function setRecordSize($recordSize) + { + $this->recordSize = new Number($recordSize, 3); + return $this; + } + + public function setBlockingFactor($blockingFactor) + { + $this->blockingFactor = new Number($blockingFactor, 2); + return $this; + } + + public function setFormatCode($formatCode) + { + $this->formatCode = new Number($formatCode, 1); + return $this; + } + + public function setImmediateDestinationName($immediateDestinationName) + { + $this->immediateDestinationName = new String($immediateDestinationName, 23); + return $this; + } + + public function setImmediateOriginName($immediateOriginName) + { + $this->immediateOriginName = new String($immediateOriginName, 23); + return $this; + } + + public function setReferenceCode($referenceCode) + { + $this->referenceCode = new String($referenceCode, 8); + return $this; + } -class FileHeader { - - private $recordTypeCode = 1; // not able to overwrite this - private $priorityCode; - private $immediateDestination; - private $immediateOrigin; - private $fileCreationDate; - private $fileCreationTime; - private $fileIdModifier; - private $recordSize; - private $blockingFactor; - private $formatCode; - private $immediateDestinationName; - private $immediateOriginName; - private $referenceCode; - - public function __construct() { - // defaults - $this->setRecordSize(94); - $this->setBlockingFactor(10); - $this->setFormatCode(1); - $this->setFileIdModifier('A'); - $this->setFileCreationDate(date('ymd')); - - // optional - $this->setImmediateDestinationName(''); - $this->setImmediateOriginName(''); - $this->setReferenceCode(''); - $this->setFileCreationTime(''); - } - - public function setPriorityCode($priorityCode) { - $this->priorityCode = new Number($priorityCode, 2); - return $this; - } - public function setImmediateDestination($immediateDestination) { - $this->immediateDestination = new RoutingNumber($immediateDestination); - return $this; - } - public function setImmediateOrigin($immediateOrigin) { - $this->immediateOrigin = new RoutingNumber($immediateOrigin); - return $this; - } - public function setFileCreationDate($fileCreationDate) { - $this->fileCreationDate = new String($fileCreationDate, 6); - return $this; - } - public function setFileCreationTime($fileCreationTime) { - $this->fileCreationTime = new String($fileCreationTime, 4); - return $this; - } - public function setFileIdModifier($fileIdModifier) { - $this->fileIdModifier = new FileIdModifier($fileIdModifier); - return $this; - } - public function setRecordSize($recordSize) { - $this->recordSize = new Number($recordSize, 3); - return $this; - } - public function setBlockingFactor($blockingFactor) { - $this->blockingFactor = new Number($blockingFactor, 2); - return $this; - } - public function setFormatCode($formatCode) { - $this->formatCode = new Number($formatCode, 1); - return $this; - } - public function setImmediateDestinationName($immediateDestinationName) { - $this->immediateDestinationName = new String($immediateDestinationName, 23); - return $this; - } - public function setImmediateOriginName($immediateOriginName) { - $this->immediateOriginName = new String($immediateOriginName, 23); - return $this; - } - public function setReferenceCode($referenceCode) { - $this->referenceCode = new String($referenceCode, 8); - return $this; - } - - public function __toString() { - return $this->recordTypeCode. - $this->priorityCode. - ' '.$this->immediateDestination. // Prefixed with a space - ' '.$this->immediateOrigin. // Prefixed with a space - $this->fileCreationDate. - $this->fileCreationTime. - $this->fileIdModifier. - $this->recordSize. - $this->blockingFactor. - $this->formatCode. - $this->immediateDestinationName. - $this->immediateOriginName. - $this->referenceCode; - } - -} \ No newline at end of file + public function __toString() + { + return $this->recordTypeCode . + $this->priorityCode . + ' ' . $this->immediateDestination . // Prefixed with a space + ' ' . $this->immediateOrigin . // Prefixed with a space + $this->fileCreationDate . + $this->fileCreationTime . + $this->fileIdModifier . + $this->recordSize . + $this->blockingFactor . + $this->formatCode . + $this->immediateDestinationName . + $this->immediateOriginName . + $this->referenceCode; + } +} diff --git a/test/Nacha/BatchTest.php b/test/Nacha/BatchTest.php index 09f600b..d3fd7d2 100644 --- a/test/Nacha/BatchTest.php +++ b/test/Nacha/BatchTest.php @@ -2,121 +2,126 @@ namespace Nacha; -use Nacha\Record\DebitEntry; use Nacha\Record\CcdEntry; +use Nacha\Record\DebitEntry; /** * Class BatchTest * @package Nacha */ -class BatchTest extends \PHPUnit_Framework_TestCase { - - /** @var Batch */ - private $batch; - - public function setup() { - $this->batch = new Batch(); - $this->batch->getHeader()->setBatchNumber(1) - ->setCompanyName('MY BEST COMP') - ->setCompanyDiscretionaryData('INCLUDES OVERTIME') - ->setCompanyId('1419871234') - ->setStandardEntryClassCode('PPD') - ->setCompanyEntryDescription('PAYROLL') - ->setCompanyDescriptiveDate('0602') - ->setEffectiveEntryDate('0112') - ->setOriginatorStatusCode('2') - ->setOriginatingDFiId('01021234'); - } - - public function testDebitOnlyBatch() { - // when - $this->batch->addDebitEntry((new DebitEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('99936340', 15)); - - // then - $output = (string)$this->batch; - - $this->assertEquals((string)$this->batch->getHeader()->getServiceClassCode(), Batch::DEBITS_ONLY); - $this->assertEquals( - "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n". - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n". - "822500000100091012980000000550000000000000001419871234 010212340000001", - $output - ); - } - - public function testCreditOnlyBatch() { - // when - $this->batch->addCreditEntry((new CcdEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setReceivingDFiAccountNumber('46479999') - ->setAmount('600.00') - ->setReceivingCompanyId('Location 23') - ->setReceivingCompanyName('Best Co 23') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('09936340', 15)); - - // then - $output = (string)$this->batch; - - $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". - "822000000100091012980000000000000000000600001419871234 010212340000001", - $output - ); - } - - public function testMixedBatch() { - // when - $this->batch->addCreditEntry((new CcdEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setReceivingDFiAccountNumber('46479999') - ->setAmount('600.00') - ->setReceivingCompanyId('Location 23') - ->setReceivingCompanyName('Best Co 23') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('09936340', 15)); - - $this->batch->addDebitEntry((new DebitEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('09936340', 15)); - - // then - $output = (string)$this->batch; - - $this->assertEquals((string)$this->batch->getHeader()->getServiceClassCode(), Batch::MIXED); - $this->assertEquals( - "5200MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n". - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0099363400000015\n". - "62709101298746479999 0000060000Location 23 Best Co 23 S 0099363400000015\n". - "820000000200182025960000000550000000000600001419871234 010212340000001", - $output - ); - } +class BatchTest extends \PHPUnit_Framework_TestCase +{ + + /** @var Batch */ + private $batch; + + public function setup() + { + $this->batch = new Batch(); + $this->batch->getHeader()->setBatchNumber(1) + ->setCompanyName('MY BEST COMP') + ->setCompanyDiscretionaryData('INCLUDES OVERTIME') + ->setCompanyId('1419871234') + ->setStandardEntryClassCode('PPD') + ->setCompanyEntryDescription('PAYROLL') + ->setCompanyDescriptiveDate('0602') + ->setEffectiveEntryDate('0112') + ->setOriginatorStatusCode('2') + ->setOriginatingDFiId('01021234'); + } + + public function testDebitOnlyBatch() + { + // when + $this->batch->addDebitEntry((new DebitEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setDFiAccountNumber('46479999') + ->setAmount('550.00') + ->setIndividualId('SomePerson1255') + ->setIdividualName('Alex Dubrovsky') + ->setDiscretionaryData('S') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('99936340', 15)); + + // then + $output = (string)$this->batch; + + $this->assertEquals((string)$this->batch->getHeader()->getServiceClassCode(), Batch::DEBITS_ONLY); + $this->assertEquals( + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "822500000100091012980000000550000000000000001419871234 010212340000001", + $output + ); + } + + public function testCreditOnlyBatch() + { + // when + $this->batch->addCreditEntry((new CcdEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setReceivingDFiAccountNumber('46479999') + ->setAmount('600.00') + ->setReceivingCompanyId('Location 23') + ->setReceivingCompanyName('Best Co 23') + ->setDiscretionaryData('S') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('09936340', 15)); + + // then + $output = (string)$this->batch; + + $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" . + "822000000100091012980000000000000000000600001419871234 010212340000001", + $output + ); + } + + public function testMixedBatch() + { + // when + $this->batch->addCreditEntry((new CcdEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setReceivingDFiAccountNumber('46479999') + ->setAmount('600.00') + ->setReceivingCompanyId('Location 23') + ->setReceivingCompanyName('Best Co 23') + ->setDiscretionaryData('S') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('09936340', 15)); + + $this->batch->addDebitEntry((new DebitEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setDFiAccountNumber('46479999') + ->setAmount('550.00') + ->setIndividualId('SomePerson1255') + ->setIdividualName('Alex Dubrovsky') + ->setDiscretionaryData('S') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('09936340', 15)); + + // then + $output = (string)$this->batch; + + $this->assertEquals((string)$this->batch->getHeader()->getServiceClassCode(), Batch::MIXED); + $this->assertEquals( + "5200MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0099363400000015\n" . + "62709101298746479999 0000060000Location 23 Best Co 23 S 0099363400000015\n" . + "820000000200182025960000000550000000000600001419871234 010212340000001", + $output + ); + } } \ No newline at end of file diff --git a/test/Nacha/Field/AmountTest.php b/test/Nacha/Field/AmountTest.php index 18c225f..aaaf051 100644 --- a/test/Nacha/Field/AmountTest.php +++ b/test/Nacha/Field/AmountTest.php @@ -2,52 +2,58 @@ namespace Nacha\Field; -class AmountTest extends \PHPUnit_Framework_TestCase { - - /** - * @expectedException \Nacha\Field\InvalidFieldException - */ - public function testInvalidLength_Float() { - new Amount(100000000.00); // only accepts $99M - } - - /** - * @expectedException \Nacha\Field\InvalidFieldException - */ - public function testInvalidLength_String() { - new Amount('100000000.00'); // only accepts $99M - } - - public function testFloatOperations() { - // given - $sec = new Amount(100.99); - - // then - $this->assertEquals('10099', (string)$sec); - } - - public function testFloatStringOperations() { - // given - $sec = new Amount('100.99'); - - // then - $this->assertEquals('10099', (string)$sec); - } - - public function testFloatOperations_PreservesZeroDecimals() { - // given - $sec = new Amount(100.00); - - // then - $this->assertEquals('10000', (string)$sec); - } - - public function testFloatStringOperations_PreservesZeroDecimals() { - // given - $sec = new Amount('100.00'); - - // then - $this->assertEquals('10000', (string)$sec); - } +class AmountTest extends \PHPUnit_Framework_TestCase +{ + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testInvalidLengthFloat() + { + new Amount(100000000.00); // only accepts $99M + } + + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testInvalidLengthString() + { + new Amount('100000000.00'); // only accepts $99M + } + + public function testFloatOperations() + { + // given + $sec = new Amount(100.99); + + // then + $this->assertEquals('10099', (string)$sec); + } + + public function testFloatStringOperations() + { + // given + $sec = new Amount('100.99'); + + // then + $this->assertEquals('10099', (string)$sec); + } + + public function testFloatOperationsPreservesZeroDecimals() + { + // given + $sec = new Amount(100.00); + + // then + $this->assertEquals('10000', (string)$sec); + } + + public function testFloatStringOperationsPreservesZeroDecimals() + { + // given + $sec = new Amount('100.00'); + + // then + $this->assertEquals('10000', (string)$sec); + } } \ No newline at end of file diff --git a/test/Nacha/Field/CompanyEntryDescriptionTest.php b/test/Nacha/Field/CompanyEntryDescriptionTest.php index 3c57c39..32e62e4 100644 --- a/test/Nacha/Field/CompanyEntryDescriptionTest.php +++ b/test/Nacha/Field/CompanyEntryDescriptionTest.php @@ -2,22 +2,25 @@ namespace Nacha\Field; -class CompanyEntryDescriptionTest extends \PHPUnit_Framework_TestCase { +class CompanyEntryDescriptionTest extends \PHPUnit_Framework_TestCase +{ - public function testUpperCaseTriggerWord() { - // given - $entry = new CompanyEntryDescription('no check found'); + public function testUpperCaseTriggerWord() + { + // given + $entry = new CompanyEntryDescription('no check found'); - // then - $this->assertEquals('NO CHECK F', (string)$entry); - } + // then + $this->assertEquals('NO CHECK F', (string)$entry); + } - public function testUpperCaseTriggerWord_Negative() { - // given - $entry = new CompanyEntryDescription('some prod'); + public function testUpperCaseTriggerWord_Negative() + { + // given + $entry = new CompanyEntryDescription('some prod'); - // then - $this->assertEquals('some prod ', (string)$entry); - } + // then + $this->assertEquals('some prod ', (string)$entry); + } } \ No newline at end of file diff --git a/test/Nacha/Field/CompanyNameTest.php b/test/Nacha/Field/CompanyNameTest.php index a4f8f96..39f9ee7 100644 --- a/test/Nacha/Field/CompanyNameTest.php +++ b/test/Nacha/Field/CompanyNameTest.php @@ -2,22 +2,25 @@ namespace Nacha\Field; -class CompanyNameTest extends \PHPUnit_Framework_TestCase { +class CompanyNameTest extends \PHPUnit_Framework_TestCase +{ - public function testUpperCaseTriggerWord() { - // given - $entry = new CompanyName('check destroyed'); + public function testUpperCaseTriggerWord() + { + // given + $entry = new CompanyName('check destroyed'); - // then - $this->assertEquals('CHECK DESTROYED ', (string)$entry); - } + // then + $this->assertEquals('CHECK DESTROYED ', (string)$entry); + } - public function stestUpperCaseTriggerWord_Negative() { - // given - $entry = new CompanyEntryDescription('check available'); + public function stestUpperCaseTriggerWord_Negative() + { + // given + $entry = new CompanyEntryDescription('check available'); - // then - $this->assertEquals('check available', (string)$entry); - } + // then + $this->assertEquals('check available', (string)$entry); + } } \ No newline at end of file diff --git a/test/Nacha/Field/NumberTest.php b/test/Nacha/Field/NumberTest.php index 7267144..348aac1 100644 --- a/test/Nacha/Field/NumberTest.php +++ b/test/Nacha/Field/NumberTest.php @@ -2,36 +2,41 @@ namespace Nacha\Field; -class NumberTest extends \PHPUnit_Framework_TestCase { - - public function testPadding() { - // given - $nbr = new Number(101, 10); - - // then - $this->assertEquals('0000000101', (string)$nbr); - } - - public function testMaxPadding() { - // given - $nbr = new Number(1234567891, 10); - - // then - $this->assertEquals('1234567891', (string)$nbr); - } - - /** - * @expectedException \Nacha\Field\InvalidFieldException - */ - public function testTruncation() { - new Number(111101, 5); - } - - /** - * @expectedException \Nacha\Field\InvalidFieldException - */ - public function testNotNumber() { - new Number("testme", 5); - } +class NumberTest extends \PHPUnit_Framework_TestCase +{ + + public function testPadding() + { + // given + $nbr = new Number(101, 10); + + // then + $this->assertEquals('0000000101', (string)$nbr); + } + + public function testMaxPadding() + { + // given + $nbr = new Number(1234567891, 10); + + // then + $this->assertEquals('1234567891', (string)$nbr); + } + + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testTruncation() + { + new Number(111101, 5); + } + + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testNotNumber() + { + new Number("testme", 5); + } } \ No newline at end of file diff --git a/test/Nacha/Field/OriginatorStatusCodeTest.php b/test/Nacha/Field/OriginatorStatusCodeTest.php index b745d0f..d21f181 100644 --- a/test/Nacha/Field/OriginatorStatusCodeTest.php +++ b/test/Nacha/Field/OriginatorStatusCodeTest.php @@ -2,21 +2,24 @@ namespace Nacha\Field; -class OriginatorStatusCodeTest extends \PHPUnit_Framework_TestCase { +class OriginatorStatusCodeTest extends \PHPUnit_Framework_TestCase +{ - /** - * @expectedException Nacha\Field\InvalidFieldException - */ - public function testInvalidType() { - new OriginatorStatusCode(3); - } + /** + * @expectedException Nacha\Field\InvalidFieldException + */ + public function testInvalidType() + { + new OriginatorStatusCode(3); + } - public function testValid() { - // given - $sec = new OriginatorStatusCode(OriginatorStatusCode::ORIGINATOR_IS_EXEMPT); + public function testValid() + { + // given + $sec = new OriginatorStatusCode(OriginatorStatusCode::ORIGINATOR_IS_EXEMPT); - // then - $this->assertEquals(OriginatorStatusCode::ORIGINATOR_IS_EXEMPT, (string)$sec); - } + // then + $this->assertEquals(OriginatorStatusCode::ORIGINATOR_IS_EXEMPT, (string)$sec); + } } \ No newline at end of file diff --git a/test/Nacha/Field/RoutingNumberTest.php b/test/Nacha/Field/RoutingNumberTest.php index 952ee7c..e1f25a2 100644 --- a/test/Nacha/Field/RoutingNumberTest.php +++ b/test/Nacha/Field/RoutingNumberTest.php @@ -2,21 +2,24 @@ namespace Nacha\Field; -class RoutingNumberTest extends \PHPUnit_Framework_TestCase { +class RoutingNumberTest extends \PHPUnit_Framework_TestCase +{ - public function testLength() { - // given - $nbr = new RoutingNumber('001243123'); + public function testLength() + { + // given + $nbr = new RoutingNumber('001243123'); - // then - $this->assertEquals('001243123', (string)$nbr); - } + // then + $this->assertEquals('001243123', (string)$nbr); + } - /** - * @expectedException \Nacha\Field\InvalidFieldException - */ - public function testInvalidLength() { - new RoutingNumber(111101); - } + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testInvalidLength() + { + new RoutingNumber(111101); + } } \ No newline at end of file diff --git a/test/Nacha/Field/StandardEntryClassTest.php b/test/Nacha/Field/StandardEntryClassTest.php index cfc8290..8c7918c 100644 --- a/test/Nacha/Field/StandardEntryClassTest.php +++ b/test/Nacha/Field/StandardEntryClassTest.php @@ -2,21 +2,24 @@ namespace Nacha\Field; -class StandardEntryClassTest extends \PHPUnit_Framework_TestCase { +class StandardEntryClassTest extends \PHPUnit_Framework_TestCase +{ - /** - * @expectedException Nacha\Field\InvalidFieldException - */ - public function testInvalidType() { - new StandardEntryClass('asd'); - } + /** + * @expectedException Nacha\Field\InvalidFieldException + */ + public function testInvalidType() + { + new StandardEntryClass('asd'); + } - public function testValid() { - // given - $sec = new StandardEntryClass('ppd'); + public function testValid() + { + // given + $sec = new StandardEntryClass('ppd'); - // then - $this->assertEquals('PPD', (string)$sec); - } + // then + $this->assertEquals('PPD', (string)$sec); + } } \ No newline at end of file diff --git a/test/Nacha/Field/StringTest.php b/test/Nacha/Field/StringTest.php index 7ffaf51..524690d 100644 --- a/test/Nacha/Field/StringTest.php +++ b/test/Nacha/Field/StringTest.php @@ -2,27 +2,31 @@ namespace Nacha\Field; -class StringTest extends \PHPUnit_Framework_TestCase { +class StringTest extends \PHPUnit_Framework_TestCase +{ - public function testPadding() { - // given - $str = new String('Hello World', 32); + public function testPadding() + { + // given + $str = new String('Hello World', 32); - // then - $this->assertEquals('Hello World ', (string)$str); - } + // then + $this->assertEquals('Hello World ', (string)$str); + } - /** - * @expectedException \Nacha\Field\InvalidFieldException - */ - public function testNotString() { - new String(12, 32); - } + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testNotString() + { + new String(12, 32); + } - /** - * @expectedException \Nacha\Field\InvalidFieldException - */ - public function testInvalidCharacter() { - new String("!testtext", 32); - } + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testInvalidCharacter() + { + new String("!testtext", 32); + } } \ No newline at end of file diff --git a/test/Nacha/Field/TransactionCodeTest.php b/test/Nacha/Field/TransactionCodeTest.php index fc5c70c..ae11077 100644 --- a/test/Nacha/Field/TransactionCodeTest.php +++ b/test/Nacha/Field/TransactionCodeTest.php @@ -2,21 +2,24 @@ namespace Nacha\Field; -class TransactionCodeTest extends \PHPUnit_Framework_TestCase { +class TransactionCodeTest extends \PHPUnit_Framework_TestCase +{ - /** - * @expectedException Nacha\Field\InvalidFieldException - */ - public function testInvalidType() { - new TransactionCode(40); - } + /** + * @expectedException Nacha\Field\InvalidFieldException + */ + public function testInvalidType() + { + new TransactionCode(40); + } - public function testValid() { - // given - $sec = new TransactionCode(TransactionCode::SAVINGS_DEPOSIT); + public function testValid() + { + // given + $sec = new TransactionCode(TransactionCode::SAVINGS_DEPOSIT); - // then - $this->assertEquals(TransactionCode::SAVINGS_DEPOSIT, (string)$sec); - } + // then + $this->assertEquals(TransactionCode::SAVINGS_DEPOSIT, (string)$sec); + } } \ No newline at end of file diff --git a/test/Nacha/FileTest.php b/test/Nacha/FileTest.php index 3734329..ba10cf6 100644 --- a/test/Nacha/FileTest.php +++ b/test/Nacha/FileTest.php @@ -3,60 +3,93 @@ namespace Nacha; use Nacha\Record\DebitEntry; -use Nacha\Record\CcdEntry; - -class FileTest extends \PHPUnit_Framework_TestCase { - - public function setup() { - $this->file = new File(); - $this->file->getHeader()->setPriorityCode(1) - ->setImmediateDestination('051000033') - ->setImmediateOrigin('059999997') - ->setFileCreationDate('060210') - ->setFileCreationTime('2232') - ->setFormatCode('1') - ->setImmediateDestinationName('ImdDest Name') - ->setImmediateOriginName('ImdOriginName') - ->setReferenceCode('Reference'); - } - - public function testBatchesEntryCount() { - // when - $this->file->addBatch($this->getBatch()); - $this->file->addBatch($this->getBatch()); - - // then - $this->assertEquals('0000001', (string)$this->file->getBatches()[0]->getHeader()->getBatchNumber()); - $this->assertEquals('0000002', (string)$this->file->getBatches()[1]->getHeader()->getBatchNumber()); - } - - public function testBatchesAndEntries() { - // given - $batchA = $this->getBatch(); - - $batchB = $this->getBatch(); - $batchB->getHeader()->setCompanyEntryDescription('EXPENSES'); - - // when - $this->file->addBatch($batchA); - $this->file->addBatch($batchB); - - // then - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc + +class FileTest extends \PHPUnit_Framework_TestCase +{ + + public function setup() + { + $this->file = new File(); + $this->file->getHeader()->setPriorityCode(1) + ->setImmediateDestination('051000033') + ->setImmediateOrigin('059999997') + ->setFileCreationDate('060210') + ->setFileCreationTime('2232') + ->setFormatCode('1') + ->setImmediateDestinationName('ImdDest Name') + ->setImmediateOriginName('ImdOriginName') + ->setReferenceCode('Reference'); + } + + public function testBatchesEntryCount() + { + // when + $this->file->addBatch($this->getBatch()); + $this->file->addBatch($this->getBatch()); + + // then + $this->assertEquals('0000001', (string)$this->file->getBatches()[0]->getHeader()->getBatchNumber()); + $this->assertEquals('0000002', (string)$this->file->getBatches()[1]->getHeader()->getBatchNumber()); + } + + private function getBatch() + { + $batch = new Batch(); + $batch->getHeader() + ->setCompanyName('MY BEST COMP') + ->setCompanyDiscretionaryData('INCLUDES OVERTIME') + ->setCompanyId('1419871234') + ->setStandardEntryClassCode('PPD') + ->setCompanyEntryDescription('PAYROLL') + ->setCompanyDescriptiveDate('0602') + ->setEffectiveEntryDate('0112') + ->setOriginatorStatusCode('2') + ->setOriginatingDFiId('01021234'); + + $batch->addDebitEntry((new DebitEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setDFiAccountNumber('46479999') + ->setAmount('550.00') + ->setIndividualId('SomePerson1255') + ->setIdividualName('Alex Dubrovsky') + ->setDiscretionaryData('S') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('99936340', 15)); + + return $batch; + } + + public function testBatchesAndEntries() + { + // given + $batchA = $this->getBatch(); + + $batchB = $this->getBatch(); + $batchB->getHeader()->setCompanyEntryDescription('EXPENSES'); + + // when + $this->file->addBatch($batchA); + $this->file->addBatch($batchB); + + // then + $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000001 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002 62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000002 -9000002000001000000020018202596000000110000000000000000 +9000002000001000000020018202596000000110000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", (string)$this->file); - } + } - public function testBlockFill() { - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc -9000000000000000000000000000000000000000000000000000000 + public function testBlockFill() + { + $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc +9000000000000000000000000000000000000000000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 @@ -65,31 +98,32 @@ public function testBlockFill() { 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", (string)$this->file); - } - - public function testBlockWithEntries() { - // given - $batchA = $this->getBatch(); - $batchA->getHeader()->setCompanyEntryDescription('EXPENSES'); - $batchA->addDebitEntry((new DebitEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Philip Whitt') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('99936340', 15)); - - // when - $this->file->addBatch($this->getBatch()); - $this->file->addBatch($this->getBatch()); - $this->file->addBatch($batchA); - - // then - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc + } + + public function testBlockWithEntries() + { + // given + $batchA = $this->getBatch(); + $batchA->getHeader()->setCompanyEntryDescription('EXPENSES'); + $batchA->addDebitEntry((new DebitEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setDFiAccountNumber('46479999') + ->setAmount('550.00') + ->setIndividualId('SomePerson1255') + ->setIdividualName('Philip Whitt') + ->setDiscretionaryData('S') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('99936340', 15)); + + // when + $this->file->addBatch($this->getBatch()); + $this->file->addBatch($this->getBatch()); + $this->file->addBatch($batchA); + + // then + $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000001 @@ -100,7 +134,7 @@ public function testBlockWithEntries() { 62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 822500000200182025960000001100000000000000001419871234 010212340000003 -9000003000001000000040036405192000000220000000000000000 +9000003000001000000040036405192000000220000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 @@ -109,34 +143,6 @@ public function testBlockWithEntries() { 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", (string)$this->file); - } - - private function getBatch() { - $batch = new Batch(); - $batch->getHeader() - ->setCompanyName('MY BEST COMP') - ->setCompanyDiscretionaryData('INCLUDES OVERTIME') - ->setCompanyId('1419871234') - ->setStandardEntryClassCode('PPD') - ->setCompanyEntryDescription('PAYROLL') - ->setCompanyDescriptiveDate('0602') - ->setEffectiveEntryDate('0112') - ->setOriginatorStatusCode('2') - ->setOriginatingDFiId('01021234'); - - $batch->addDebitEntry((new DebitEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('99936340', 15)); - - return $batch; - } + } } diff --git a/test/Nacha/Record/BatchFooterTest.php b/test/Nacha/Record/BatchFooterTest.php index 2b4a152..f949043 100644 --- a/test/Nacha/Record/BatchFooterTest.php +++ b/test/Nacha/Record/BatchFooterTest.php @@ -2,35 +2,38 @@ namespace Nacha\Record; -class BatchFooterTest extends \PHPUnit_Framework_TestCase { +class BatchFooterTest extends \PHPUnit_Framework_TestCase +{ - public function testBatchFooter_AllFields() { - // given - $batchFooter = (new BatchFooter) - ->setServiceClassCode(200) - ->setEntryAddendaCount(2) - ->setEntryHash('9101298') - ->setTotalDebitAmount('4000') - ->setTotalCreditAmount('95000') - ->setCompanyIdNumber('1419871234') - ->setOriginatingDfiId('09991234') - ->setBatchNumber(1); + public function testBatchFooter_AllFields() + { + // given + $batchFooter = (new BatchFooter) + ->setServiceClassCode(200) + ->setEntryAddendaCount(2) + ->setEntryHash('9101298') + ->setTotalDebitAmount('4000') + ->setTotalCreditAmount('95000') + ->setCompanyIdNumber('1419871234') + ->setOriginatingDfiId('09991234') + ->setBatchNumber(1); - $this->assertEquals(94, strlen($batchFooter)); - $this->assertEquals('820000000200091012980000000040000000000950001419871234 099912340000001', (string)$batchFooter); - } + $this->assertEquals(94, strlen($batchFooter)); + $this->assertEquals('820000000200091012980000000040000000000950001419871234 099912340000001', (string)$batchFooter); + } - public function testBatchFooter_OptionalFields() { - // given - $batchFooter = (new BatchFooter) - ->setServiceClassCode(200) - ->setEntryHash('9101298') - ->setCompanyIdNumber('1419871234') - ->setOriginatingDfiId('09991234') - ->setBatchNumber(1); + public function testBatchFooter_OptionalFields() + { + // given + $batchFooter = (new BatchFooter) + ->setServiceClassCode(200) + ->setEntryHash('9101298') + ->setCompanyIdNumber('1419871234') + ->setOriginatingDfiId('09991234') + ->setBatchNumber(1); - $this->assertEquals(94, strlen($batchFooter)); - $this->assertEquals('820000000000091012980000000000000000000000001419871234 099912340000001', (string)$batchFooter); - } + $this->assertEquals(94, strlen($batchFooter)); + $this->assertEquals('820000000000091012980000000000000000000000001419871234 099912340000001', (string)$batchFooter); + } } \ No newline at end of file diff --git a/test/Nacha/Record/BatchHeaderTest.php b/test/Nacha/Record/BatchHeaderTest.php index db5962c..5d59376 100644 --- a/test/Nacha/Record/BatchHeaderTest.php +++ b/test/Nacha/Record/BatchHeaderTest.php @@ -4,42 +4,45 @@ use Nacha\Field\StandardEntryClass; -class BatchHeaderTest extends \PHPUnit_Framework_TestCase { - - public function testBatchHeader_AllFields() { - // given - $batchHeader = (new BatchHeader) - ->setServiceClassCode(200) - ->setCompanyName('MY BEST COMP') - ->setCompanyDiscretionaryData('INCLUDES OVERTIME') - ->setCompanyId('1419871234') - ->setStandardEntryClassCode(StandardEntryClass::PPD) - ->setCompanyEntryDescription('PAYROLL') - ->setCompanyDescriptiveDate('0602') - ->setEffectiveEntryDate('0112') - ->setOriginatorStatusCode('2') - ->setOriginatingDFiId('01021234') - ->setBatchNumber(1); - - $this->assertEquals(94, strlen($batchHeader)); - $this->assertEquals('5200MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001', (string)$batchHeader); - } - - public function testBatchHeader_OptionalFields() { - // given - $batchHeader = (new BatchHeader) - ->setServiceClassCode(200) - ->setCompanyName('MY BEST COMP') - ->setCompanyId('1419871234') - ->setStandardEntryClassCode(StandardEntryClass::PPD) - ->setCompanyEntryDescription('PAYROLL') - ->setEffectiveEntryDate('0112') - ->setOriginatorStatusCode('2') - ->setOriginatingDFiId('01021234') - ->setBatchNumber(1); - - $this->assertEquals(94, strlen($batchHeader)); - $this->assertEquals('5200MY BEST COMP 1419871234PPDPAYROLL 0112 2010212340000001', (string)$batchHeader); - } +class BatchHeaderTest extends \PHPUnit_Framework_TestCase +{ + + public function testBatchHeader_AllFields() + { + // given + $batchHeader = (new BatchHeader) + ->setServiceClassCode(200) + ->setCompanyName('MY BEST COMP') + ->setCompanyDiscretionaryData('INCLUDES OVERTIME') + ->setCompanyId('1419871234') + ->setStandardEntryClassCode(StandardEntryClass::PPD) + ->setCompanyEntryDescription('PAYROLL') + ->setCompanyDescriptiveDate('0602') + ->setEffectiveEntryDate('0112') + ->setOriginatorStatusCode('2') + ->setOriginatingDFiId('01021234') + ->setBatchNumber(1); + + $this->assertEquals(94, strlen($batchHeader)); + $this->assertEquals('5200MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001', (string)$batchHeader); + } + + public function testBatchHeader_OptionalFields() + { + // given + $batchHeader = (new BatchHeader) + ->setServiceClassCode(200) + ->setCompanyName('MY BEST COMP') + ->setCompanyId('1419871234') + ->setStandardEntryClassCode(StandardEntryClass::PPD) + ->setCompanyEntryDescription('PAYROLL') + ->setEffectiveEntryDate('0112') + ->setOriginatorStatusCode('2') + ->setOriginatingDFiId('01021234') + ->setBatchNumber(1); + + $this->assertEquals(94, strlen($batchHeader)); + $this->assertEquals('5200MY BEST COMP 1419871234PPDPAYROLL 0112 2010212340000001', (string)$batchHeader); + } } \ No newline at end of file diff --git a/test/Nacha/Record/BlockTest.php b/test/Nacha/Record/BlockTest.php index 2fbc512..923fedc 100644 --- a/test/Nacha/Record/BlockTest.php +++ b/test/Nacha/Record/BlockTest.php @@ -2,14 +2,16 @@ namespace Nacha\Record; -class BlockTest extends \PHPUnit_Framework_TestCase { +class BlockTest extends \PHPUnit_Framework_TestCase +{ - public function testBatchHeader_AllFields() { - // given - $block = new Block; + public function testBatchHeader_AllFields() + { + // given + $block = new Block; - // then - $this->assertEquals(94, strlen((string)$block)); - } + // then + $this->assertEquals(94, strlen((string)$block)); + } } \ No newline at end of file diff --git a/test/Nacha/Record/CcdEntryTest.php b/test/Nacha/Record/CcdEntryTest.php index bda6c0f..2bb55d5 100644 --- a/test/Nacha/Record/CcdEntryTest.php +++ b/test/Nacha/Record/CcdEntryTest.php @@ -2,40 +2,43 @@ namespace Nacha\Record; -class CcdEntryTest extends \PHPUnit_Framework_TestCase { +class CcdEntryTest extends \PHPUnit_Framework_TestCase +{ - public function testEntry_AllFields() { - // given - $entry = (new CcdEntry) - ->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); + public function testEntry_AllFields() + { + // given + $entry = (new CcdEntry) + ->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); - } + $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); + 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); - } + $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/DebitEntryTest.php index 8a2ed0b..bc2f6f4 100644 --- a/test/Nacha/Record/DebitEntryTest.php +++ b/test/Nacha/Record/DebitEntryTest.php @@ -2,40 +2,43 @@ namespace Nacha\Record; -class DebitEntryTest extends \PHPUnit_Framework_TestCase { +class DebitEntryTest extends \PHPUnit_Framework_TestCase +{ - public function testEntry_AllFields() { - // given - $entry = (new DebitEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setIndividualId('SomePerson1255') - ->setIdividualName('Alex Dubrovsky') - ->setDiscretionaryData('S') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('09101298', 15); + public function testEntry_AllFields() + { + // given + $entry = (new DebitEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setDFiAccountNumber('46479999') + ->setAmount('550.00') + ->setIndividualId('SomePerson1255') + ->setIdividualName('Alex Dubrovsky') + ->setDiscretionaryData('S') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('09101298', 15); - $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0091012980000015', (string)$entry); - } + $this->assertEquals(94, strlen($entry)); + $this->assertEquals('62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0091012980000015', (string)$entry); + } - public function testEntry_OptionalFields() { - // given - $entry = (new DebitEntry) - ->setTransactionCode(27) - ->setReceivingDfiId('09101298') - ->setCheckDigit(7) - ->setDFiAccountNumber('46479999') - ->setAmount('550.00') - ->setIdividualName('Alex Dubrovsky') - ->setAddendaRecordIndicator(0) - ->setTraceNumber('09101298', 15); + public function testEntry_OptionalFields() + { + // given + $entry = (new DebitEntry) + ->setTransactionCode(27) + ->setReceivingDfiId('09101298') + ->setCheckDigit(7) + ->setDFiAccountNumber('46479999') + ->setAmount('550.00') + ->setIdividualName('Alex Dubrovsky') + ->setAddendaRecordIndicator(0) + ->setTraceNumber('09101298', 15); - $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62709101298746479999 0000055000 Alex Dubrovsky 0091012980000015', (string)$entry); - } + $this->assertEquals(94, strlen($entry)); + $this->assertEquals('62709101298746479999 0000055000 Alex Dubrovsky 0091012980000015', (string)$entry); + } } \ No newline at end of file diff --git a/test/Nacha/Record/FileFooterTest.php b/test/Nacha/Record/FileFooterTest.php index cdf8eb2..9f5c60b 100644 --- a/test/Nacha/Record/FileFooterTest.php +++ b/test/Nacha/Record/FileFooterTest.php @@ -2,29 +2,32 @@ namespace Nacha\Record; -class FileFooterTest extends \PHPUnit_Framework_TestCase { +class FileFooterTest extends \PHPUnit_Framework_TestCase +{ - public function testFileFooter_AllFields() { - // given - $fileFooter = (new FileFooter) - ->setBatchCount(1) - ->setBlockCount(1) - ->setEntryAddendaCount(1) - ->setEntryHash(9101298) - ->setTotalDebits(95000) - ->setTotalCredits(95000); + public function testFileFooter_AllFields() + { + // given + $fileFooter = (new FileFooter) + ->setBatchCount(1) + ->setBlockCount(1) + ->setEntryAddendaCount(1) + ->setEntryHash(9101298) + ->setTotalDebits(95000) + ->setTotalCredits(95000); - $this->assertEquals(94, strlen($fileFooter)); - $this->assertEquals('9000001000001000000010009101298000000095000000000095000 ', (string)$fileFooter); - } + $this->assertEquals(94, strlen($fileFooter)); + $this->assertEquals('9000001000001000000010009101298000000095000000000095000 ', (string)$fileFooter); + } - public function testFileFooter_OptionalFields() { - // given - $fileFooter = (new FileFooter) - ->setEntryHash(9101298); + public function testFileFooter_OptionalFields() + { + // given + $fileFooter = (new FileFooter) + ->setEntryHash(9101298); - $this->assertEquals(94, strlen($fileFooter)); - $this->assertEquals('9000000000000000000000009101298000000000000000000000000 ', (string)$fileFooter); - } + $this->assertEquals(94, strlen($fileFooter)); + $this->assertEquals('9000000000000000000000009101298000000000000000000000000 ', (string)$fileFooter); + } } \ No newline at end of file diff --git a/test/Nacha/Record/FileHeaderTest.php b/test/Nacha/Record/FileHeaderTest.php index 23d5f14..06f7fcf 100644 --- a/test/Nacha/Record/FileHeaderTest.php +++ b/test/Nacha/Record/FileHeaderTest.php @@ -2,36 +2,39 @@ namespace Nacha\Record; -class FileHeaderTest extends \PHPUnit_Framework_TestCase { +class FileHeaderTest extends \PHPUnit_Framework_TestCase +{ - public function testFileHeader_AllFields() { - // given - $fileHeader = (new FileHeader) - ->setPriorityCode(1) - ->setImmediateDestination('051000033') - ->setImmediateOrigin('059999997') - ->setFileCreationDate('060210') - ->setFileCreationTime('2232') - ->setFormatCode('1') - ->setImmediateDestinationName('ImdDest Name') - ->setImmediateOriginName('ImdOriginName') - ->setReferenceCode('Reference'); // will be truncated + public function testFileHeader_AllFields() + { + // given + $fileHeader = (new FileHeader) + ->setPriorityCode(1) + ->setImmediateDestination('051000033') + ->setImmediateOrigin('059999997') + ->setFileCreationDate('060210') + ->setFileCreationTime('2232') + ->setFormatCode('1') + ->setImmediateDestinationName('ImdDest Name') + ->setImmediateOriginName('ImdOriginName') + ->setReferenceCode('Reference'); // will be truncated - $this->assertEquals(94, strlen($fileHeader)); - $this->assertEquals('101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc', (string)$fileHeader); - } + $this->assertEquals(94, strlen($fileHeader)); + $this->assertEquals('101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc', (string)$fileHeader); + } - public function testFileHeader_OptionalFields() { - // given - $fileHeader = (new FileHeader) - ->setPriorityCode(1) - ->setImmediateDestination('051000033') - ->setImmediateOrigin('059999997') - ->setFileCreationDate('060210') - ->setFormatCode('1'); + public function testFileHeader_OptionalFields() + { + // given + $fileHeader = (new FileHeader) + ->setPriorityCode(1) + ->setImmediateDestination('051000033') + ->setImmediateOrigin('059999997') + ->setFileCreationDate('060210') + ->setFormatCode('1'); - $this->assertEquals(94, strlen($fileHeader)); - $this->assertEquals('101 051000033 059999997060210 A094101 ', (string)$fileHeader); - } + $this->assertEquals(94, strlen($fileHeader)); + $this->assertEquals('101 051000033 059999997060210 A094101 ', (string)$fileHeader); + } } \ No newline at end of file diff --git a/test/ci.xml b/test/ci.xml index af07a37..1bc775c 100644 --- a/test/ci.xml +++ b/test/ci.xml @@ -1,19 +1,21 @@ - - - Nacha - - + + + Nacha + + - - - ../src - - + + + ../src + + - - - - - + + + + + From ac1411dd88b807ec7cac49b04f2303a619723fe7 Mon Sep 17 00:00:00 2001 From: sheppard Date: Thu, 22 Oct 2015 15:35:09 +0300 Subject: [PATCH 02/19] According to ACH file specs http://content.pncmc.com/live/pnc/corporate/treasury-management/ach-conversion/ACH-File-Specifications.pdf, "All alphabetic characters must be in upper case" --- src/Nacha/Field/String.php | 3 ++- test/Nacha/BatchTest.php | 8 ++++---- .../Field/CompanyEntryDescriptionTest.php | 2 +- test/Nacha/Field/StringTest.php | 2 +- test/Nacha/FileTest.php | 18 +++++++++--------- test/Nacha/Record/CcdEntryTest.php | 4 ++-- test/Nacha/Record/DebitEntryTest.php | 4 ++-- test/Nacha/Record/FileHeaderTest.php | 2 +- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Nacha/Field/String.php b/src/Nacha/Field/String.php index 07e205e..90b5319 100644 --- a/src/Nacha/Field/String.php +++ b/src/Nacha/Field/String.php @@ -23,6 +23,7 @@ public function __construct($value, $length) public function __toString() { - return sprintf('%-' . $this->length . 's', $this->value); + $str = sprintf('%-' . $this->length . 's', $this->value); + return strtoupper($str); } } diff --git a/test/Nacha/BatchTest.php b/test/Nacha/BatchTest.php index d3fd7d2..61a124e 100644 --- a/test/Nacha/BatchTest.php +++ b/test/Nacha/BatchTest.php @@ -51,7 +51,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" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . "822500000100091012980000000550000000000000001419871234 010212340000001", $output ); @@ -78,7 +78,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" . + "62709101298746479999 0000060000LOCATION 23 BEST CO 23 S 0099363400000015\n" . "822000000100091012980000000000000000000600001419871234 010212340000001", $output ); @@ -117,8 +117,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 0000055000SomePerson1255 Alex Dubrovsky S 0099363400000015\n" . - "62709101298746479999 0000060000Location 23 Best Co 23 S 0099363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0099363400000015\n" . + "62709101298746479999 0000060000LOCATION 23 BEST CO 23 S 0099363400000015\n" . "820000000200182025960000000550000000000600001419871234 010212340000001", $output ); diff --git a/test/Nacha/Field/CompanyEntryDescriptionTest.php b/test/Nacha/Field/CompanyEntryDescriptionTest.php index 32e62e4..3d1475b 100644 --- a/test/Nacha/Field/CompanyEntryDescriptionTest.php +++ b/test/Nacha/Field/CompanyEntryDescriptionTest.php @@ -20,7 +20,7 @@ public function testUpperCaseTriggerWord_Negative() $entry = new CompanyEntryDescription('some prod'); // then - $this->assertEquals('some prod ', (string)$entry); + $this->assertEquals('SOME PROD ', (string)$entry); } } \ No newline at end of file diff --git a/test/Nacha/Field/StringTest.php b/test/Nacha/Field/StringTest.php index 524690d..250fdd4 100644 --- a/test/Nacha/Field/StringTest.php +++ b/test/Nacha/Field/StringTest.php @@ -11,7 +11,7 @@ public function testPadding() $str = new String('Hello World', 32); // then - $this->assertEquals('Hello World ', (string)$str); + $this->assertEquals('HELLO WORLD ', (string)$str); } /** diff --git a/test/Nacha/FileTest.php b/test/Nacha/FileTest.php index ba10cf6..c97a785 100644 --- a/test/Nacha/FileTest.php +++ b/test/Nacha/FileTest.php @@ -74,12 +74,12 @@ public function testBatchesAndEntries() $this->file->addBatch($batchB); // then - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc + $this->assertEquals("101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000001 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000002 9000002000001000000020018202596000000110000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 @@ -88,7 +88,7 @@ public function testBatchesAndEntries() public function testBlockFill() { - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc + $this->assertEquals("101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC 9000000000000000000000000000000000000000000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 @@ -123,16 +123,16 @@ public function testBlockWithEntries() $this->file->addBatch($batchA); // then - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc + $this->assertEquals("101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000001 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000002 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 +62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000002 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000003 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 +62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015 +62709101298746479999 0000055000SOMEPERSON1255 PHILIP WHITT S 0999363400000015 822500000200182025960000001100000000000000001419871234 010212340000003 9000003000001000000040036405192000000220000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 diff --git a/test/Nacha/Record/CcdEntryTest.php b/test/Nacha/Record/CcdEntryTest.php index 2bb55d5..1fff729 100644 --- a/test/Nacha/Record/CcdEntryTest.php +++ b/test/Nacha/Record/CcdEntryTest.php @@ -21,7 +21,7 @@ public function testEntry_AllFields() ->setTraceNumber('19101298', 15); $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62719101298746479999 0000055000Location 23 Best Co 23 S 0191012980000015', (string)$entry); + $this->assertEquals('62719101298746479999 0000055000LOCATION 23 BEST CO 23 S 0191012980000015', (string)$entry); } public function testEntry_OptionalFields() @@ -38,7 +38,7 @@ public function testEntry_OptionalFields() ->setTraceNumber('19101298', 15); $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62719101298746479999 0000055000 Best Co 23 0191012980000015', (string)$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/DebitEntryTest.php index bc2f6f4..8c4b40b 100644 --- a/test/Nacha/Record/DebitEntryTest.php +++ b/test/Nacha/Record/DebitEntryTest.php @@ -21,7 +21,7 @@ public function testEntry_AllFields() ->setTraceNumber('09101298', 15); $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0091012980000015', (string)$entry); + $this->assertEquals('62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0091012980000015', (string)$entry); } public function testEntry_OptionalFields() @@ -38,7 +38,7 @@ public function testEntry_OptionalFields() ->setTraceNumber('09101298', 15); $this->assertEquals(94, strlen($entry)); - $this->assertEquals('62709101298746479999 0000055000 Alex Dubrovsky 0091012980000015', (string)$entry); + $this->assertEquals('62709101298746479999 0000055000 ALEX DUBROVSKY 0091012980000015', (string)$entry); } } \ No newline at end of file diff --git a/test/Nacha/Record/FileHeaderTest.php b/test/Nacha/Record/FileHeaderTest.php index 06f7fcf..5150e7b 100644 --- a/test/Nacha/Record/FileHeaderTest.php +++ b/test/Nacha/Record/FileHeaderTest.php @@ -20,7 +20,7 @@ public function testFileHeader_AllFields() ->setReferenceCode('Reference'); // will be truncated $this->assertEquals(94, strlen($fileHeader)); - $this->assertEquals('101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc', (string)$fileHeader); + $this->assertEquals('101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC', (string)$fileHeader); } public function testFileHeader_OptionalFields() From 6b8be4458ca5b12b170cb0f1ebc13253929908d3 Mon Sep 17 00:00:00 2001 From: kulparoman Date: Mon, 2 Nov 2015 18:38:37 +0200 Subject: [PATCH 03/19] Fix file footer generation. --- src/Nacha/Field/Number.php | 5 + src/Nacha/File.php | 81 +++++++++--- src/Nacha/Record/FileFooter.php | 9 ++ src/Nacha/Record/FileHeader.php | 226 ++++++++++++++++++-------------- 4 files changed, 208 insertions(+), 113 deletions(-) diff --git a/src/Nacha/Field/Number.php b/src/Nacha/Field/Number.php index 3c122e5..2561561 100644 --- a/src/Nacha/Field/Number.php +++ b/src/Nacha/Field/Number.php @@ -19,6 +19,11 @@ public function __construct($value, $length) { throw new InvalidFieldException('Length of "' . $value . '" must be '.$length.'.'); } } + + public function getIntVal() + { + return $this->value; + } public function __toString() { return sprintf("%0{$this->length}d", $this->value); diff --git a/src/Nacha/File.php b/src/Nacha/File.php index a706a8a..a605b6a 100644 --- a/src/Nacha/File.php +++ b/src/Nacha/File.php @@ -6,6 +6,10 @@ use Nacha\Record\FileHeader; use Nacha\Record\FileFooter; +/** + * Class File + * @package Nacha + */ class File { private $header; @@ -16,17 +20,67 @@ public function __construct() { $this->header = new FileHeader(); } + /** + * @return FileHeader + */ public function getHeader() { return $this->header; } + + /** + * @return Batch[] + */ public function getBatches() { return $this->batches; } + + /** + * @param Batch $batch + */ public function addBatch(Batch $batch) { $this->batches[] = $batch; $batch->getHeader()->setBatchNumber(count($this->batches)); } + /** + * @return mixed + */ + public function getFooter() + { + return $this->generateFooter(); + } + + /** + * @return FileFooter + */ + private function generateFooter() + { + $fileFooter = new FileFooter(); + $totalDebits = 0; + $totalCredits = 0; + $totalEntryCount = 0; + + foreach ($this->batches as $batch) { + $totalEntryCount += $batch->getTotalEntryCount(); + $totalDebits += $batch->getTotalDebitAmount(); // is this total amount of debits, or entries? + $totalCredits += $batch->getTotalCreditAmount(); // is this total amount of credits, or entries? + } + + $totalRecords = $totalEntryCount + (count($this->batches) * 2) + 2; + + $fileFooter->setEntryHash($this->getHash()); + $fileFooter->setBatchCount(count($this->batches)); + $fileFooter->setBlockCount(round($totalRecords / 10)); + $fileFooter->setEntryAddendaCount($totalEntryCount); + $fileFooter->setTotalDebits($totalDebits); + $fileFooter->setTotalCredits($totalCredits); + + return $fileFooter; + } + + /** + * @return string + */ private function getHash() { $hash = 0; foreach ($this->batches as $batch) { @@ -35,28 +89,24 @@ private function getHash() { return substr((string)$hash, -10); // only take 10 digits from end of string to 10 } + /** + * @return string + */ public function __toString() { + /** + * @var FileFooter $fileFooter + */ $batches = ''; - - $fileFooter = (new FileFooter) - ->setEntryHash($this->getHash()) - ->setBatchCount(count($this->batches)); - - $totalDebits = 0; - $totalCredits = 0; - $totalEntryCount = 0; + $fileFooter = $this->getFooter(); foreach ($this->batches as $batch) { - $totalEntryCount += $batch->getTotalEntryCount(); - $totalDebits += $batch->getTotalDebitAmount(); // is this total amount of debits, or entries? - $totalCredits += $batch->getTotalCreditAmount(); // is this total amount of credits, or entries? - $batches .= $batch."\n"; } + $totalRecords = $fileFooter->getEntryAddendaCount() + (count($this->batches) * 2) + 2; + // block padding // num entries + num batches header/footer + file header/footer - $totalRecords = $totalEntryCount + (count($this->batches) * 2) + 2; $blocksNeeded = (ceil($totalRecords / 10) * 10) - $totalRecords; $block = ''; @@ -64,11 +114,6 @@ public function __toString() { $block .= (new Block)."\n"; } - $fileFooter->setBlockCount(round($totalRecords / 10)); - $fileFooter->setEntryAddendaCount($totalEntryCount); - $fileFooter->setTotalDebits($totalDebits); - $fileFooter->setTotalCredits($totalCredits); - $output = $this->header."\n".$batches.$fileFooter."\n".$block; return rtrim($output, "\n"); diff --git a/src/Nacha/Record/FileFooter.php b/src/Nacha/Record/FileFooter.php index cadaccb..70efaa4 100644 --- a/src/Nacha/Record/FileFooter.php +++ b/src/Nacha/Record/FileFooter.php @@ -5,6 +5,10 @@ use Nacha\Field\String; use Nacha\Field\Number; +/** + * Class FileFooter + * @package Nacha\Record + */ class FileFooter { private $recordTypeCode = 9; // not able to overwrite this @@ -51,6 +55,11 @@ public function setTotalCredits($totalCredits) { return $this; } + public function getEntryAddendaCount() + { + return $this->entryAddendaCount->getIntVal(); + } + public function __toString() { return $this->recordTypeCode. $this->batchCount. diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index a71ab02..3424ab6 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -7,100 +7,136 @@ use Nacha\Field\RoutingNumber; use Nacha\Field\FileIdModifier; -class FileHeader { - - private $recordTypeCode = 1; // not able to overwrite this - private $priorityCode; - private $immediateDestination; - private $immediateOrigin; - private $fileCreationDate; - private $fileCreationTime; - private $fileIdModifier; - private $recordSize; - private $blockingFactor; - private $formatCode; - private $immediateDestinationName; - private $immediateOriginName; - private $referenceCode; - - public function __construct() { - // defaults - $this->setRecordSize(94); - $this->setBlockingFactor(10); - $this->setFormatCode(1); - $this->setFileIdModifier('A'); - $this->setFileCreationDate(date('ymd')); - - // optional - $this->setImmediateDestinationName(''); - $this->setImmediateOriginName(''); - $this->setReferenceCode(''); - $this->setFileCreationTime(''); - } - - public function setPriorityCode($priorityCode) { - $this->priorityCode = new Number($priorityCode, 2); - return $this; - } - public function setImmediateDestination($immediateDestination) { - $this->immediateDestination = new RoutingNumber($immediateDestination); - return $this; - } - public function setImmediateOrigin($immediateOrigin) { - $this->immediateOrigin = new RoutingNumber($immediateOrigin); - return $this; - } - public function setFileCreationDate($fileCreationDate) { - $this->fileCreationDate = new String($fileCreationDate, 6); - return $this; - } - public function setFileCreationTime($fileCreationTime) { - $this->fileCreationTime = new String($fileCreationTime, 4); - return $this; - } - public function setFileIdModifier($fileIdModifier) { - $this->fileIdModifier = new FileIdModifier($fileIdModifier); - return $this; - } - public function setRecordSize($recordSize) { - $this->recordSize = new Number($recordSize, 3); - return $this; - } - public function setBlockingFactor($blockingFactor) { - $this->blockingFactor = new Number($blockingFactor, 2); - return $this; - } - public function setFormatCode($formatCode) { - $this->formatCode = new Number($formatCode, 1); - return $this; - } - public function setImmediateDestinationName($immediateDestinationName) { - $this->immediateDestinationName = new String($immediateDestinationName, 23); - return $this; - } - public function setImmediateOriginName($immediateOriginName) { - $this->immediateOriginName = new String($immediateOriginName, 23); - return $this; - } - public function setReferenceCode($referenceCode) { - $this->referenceCode = new String($referenceCode, 8); - return $this; - } - - public function __toString() { - return $this->recordTypeCode. - $this->priorityCode. - ' '.$this->immediateDestination. // Prefixed with a space - ' '.$this->immediateOrigin. // Prefixed with a space - $this->fileCreationDate. - $this->fileCreationTime. - $this->fileIdModifier. - $this->recordSize. - $this->blockingFactor. - $this->formatCode. - $this->immediateDestinationName. - $this->immediateOriginName. - $this->referenceCode; - } +class FileHeader +{ + private $recordTypeCode = 1; // not able to overwrite this + private $priorityCode; + private $immediateDestination; + private $immediateOrigin; + private $fileCreationDate; + private $fileCreationTime; + private $fileIdModifier; + private $recordSize; + private $blockingFactor; + private $formatCode; + private $immediateDestinationName; + private $immediateOriginName; + private $referenceCode; + + const CREATE_DATE_FORMAT = 'ymd'; + + public function __construct() + { + // defaults + $this->setRecordSize(94); + $this->setBlockingFactor(10); + $this->setFormatCode(1); + $this->setFileIdModifier('A'); + $this->setFileCreationDate(date(self::CREATE_DATE_FORMAT)); + + // optional + $this->setImmediateDestinationName(''); + $this->setImmediateOriginName(''); + $this->setReferenceCode(''); + $this->setFileCreationTime(''); + } + + public function setPriorityCode($priorityCode) + { + $this->priorityCode = new Number($priorityCode, 2); + return $this; + } + + public function setImmediateDestination($immediateDestination) + { + $this->immediateDestination = new RoutingNumber($immediateDestination); + return $this; + } + + public function setImmediateOrigin($immediateOrigin) + { + $this->immediateOrigin = new RoutingNumber($immediateOrigin); + return $this; + } + + public function setFileCreationDate($fileCreationDate) + { + $this->fileCreationDate = new String($fileCreationDate, 6); + return $this; + } + + public function setFileCreationTime($fileCreationTime) + { + $this->fileCreationTime = new String($fileCreationTime, 4); + return $this; + } + + public function setFileIdModifier($fileIdModifier) + { + $this->fileIdModifier = new FileIdModifier($fileIdModifier); + return $this; + } + + public function setRecordSize($recordSize) + { + $this->recordSize = new Number($recordSize, 3); + return $this; + } + + public function setBlockingFactor($blockingFactor) + { + $this->blockingFactor = new Number($blockingFactor, 2); + return $this; + } + + public function setFormatCode($formatCode) + { + $this->formatCode = new Number($formatCode, 1); + return $this; + } + + public function setImmediateDestinationName($immediateDestinationName) + { + $this->immediateDestinationName = new String($immediateDestinationName, 23); + return $this; + } + + public function setImmediateOriginName($immediateOriginName) + { + $this->immediateOriginName = new String($immediateOriginName, 23); + return $this; + } + + public function setReferenceCode($referenceCode) + { + $this->referenceCode = new String($referenceCode, 8); + return $this; + } + + public function getEffectiveDate() + { + $dateArray = date_parse_from_format(self::CREATE_DATE_FORMAT, $this->fileCreationDate); + $date = new \DateTime(); + $date->setDate($dateArray['year'], $dateArray['month'], $dateArray['day']); + + return $date->add(\DateInterval::createFromDateString('1 day')); + } + + public function __toString() + { + return $this->recordTypeCode . + $this->priorityCode . + ' ' . $this->immediateDestination . // Prefixed with a space + ' ' . $this->immediateOrigin . // Prefixed with a space + $this->fileCreationDate . + $this->fileCreationTime . + $this->fileIdModifier . + $this->recordSize . + $this->blockingFactor . + $this->formatCode . + $this->immediateDestinationName . + $this->immediateOriginName . + $this->referenceCode; + } } \ No newline at end of file From cd4643635106e7f31b7c005340abc37bdb530d2a Mon Sep 17 00:00:00 2001 From: sheppard Date: Mon, 2 Nov 2015 19:18:14 +0200 Subject: [PATCH 04/19] fix trailing spaces issues --- test/Nacha/FileTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Nacha/FileTest.php b/test/Nacha/FileTest.php index c97a785..db5a9f9 100644 --- a/test/Nacha/FileTest.php +++ b/test/Nacha/FileTest.php @@ -72,7 +72,7 @@ public function testBatchesAndEntries() // when $this->file->addBatch($batchA); $this->file->addBatch($batchB); - + // then $this->assertEquals("101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 @@ -81,7 +81,7 @@ public function testBatchesAndEntries() 5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002 62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015 822500000100091012980000000550000000000000001419871234 010212340000002 -9000002000001000000020018202596000000110000000000000000 +9000002000001000000020018202596000000110000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", (string)$this->file); } @@ -89,7 +89,7 @@ public function testBatchesAndEntries() public function testBlockFill() { $this->assertEquals("101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC -9000000000000000000000000000000000000000000000000000000 +9000000000000000000000000000000000000000000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 @@ -134,7 +134,7 @@ public function testBlockWithEntries() 62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015 62709101298746479999 0000055000SOMEPERSON1255 PHILIP WHITT S 0999363400000015 822500000200182025960000001100000000000000001419871234 010212340000003 -9000003000001000000040036405192000000220000000000000000 +9000003000001000000040036405192000000220000000000000000 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 From c59e18c362b0f515d868c01a51ce7d883a7b90f9 Mon Sep 17 00:00:00 2001 From: kulparoman Date: Tue, 3 Nov 2015 10:50:03 +0200 Subject: [PATCH 05/19] Add total count methods for footer. Add phpDoc. --- src/Nacha/Field/Number.php | 75 +++++++++----- src/Nacha/Record/FileFooter.php | 178 ++++++++++++++++++++++---------- src/Nacha/Record/FileHeader.php | 58 +++++++++++ 3 files changed, 229 insertions(+), 82 deletions(-) diff --git a/src/Nacha/Field/Number.php b/src/Nacha/Field/Number.php index 2561561..4fa82b3 100644 --- a/src/Nacha/Field/Number.php +++ b/src/Nacha/Field/Number.php @@ -2,31 +2,54 @@ namespace Nacha\Field; -class Number { - - protected $value; - protected $length; - - public function __construct($value, $length) { - $this->value = (int)$value; - $this->length = $length; - - if (!is_int($this->value)) { - throw new InvalidFieldException('Value "' . $value . '" must be an integer.'); - } - - if (strlen($value) > $length) { - throw new InvalidFieldException('Length of "' . $value . '" must be '.$length.'.'); - } - } - - public function getIntVal() - { - return $this->value; - } - - public function __toString() { - return sprintf("%0{$this->length}d", $this->value); - } +/** + * Class Number + * @package Nacha\Field + */ +class Number +{ + /**@var int */ + protected $value; + /**@var int */ + protected $length; + + public function __construct($value, $length) + { + $this->value = (int)$value; + $this->length = $length; + + if (!is_int($this->value)) { + throw new InvalidFieldException('Value "' . $value . '" must be an integer.'); + } + + if (strlen($value) > $length) { + throw new InvalidFieldException('Length of "' . $value . '" must be ' . $length . '.'); + } + } + + /** + * @return int + */ + public function getIntVal() + { + return $this->value; + } + + /** + * @param int $decimals + * @return float + */ + public function getFloatVal($decimals = 2) + { + return ($this->value / pow(10, $decimals)); + } + + /** + * @return string + */ + public function __toString() + { + return sprintf("%0{$this->length}d", $this->value); + } } \ No newline at end of file diff --git a/src/Nacha/Record/FileFooter.php b/src/Nacha/Record/FileFooter.php index 70efaa4..7e9dc7e 100644 --- a/src/Nacha/Record/FileFooter.php +++ b/src/Nacha/Record/FileFooter.php @@ -9,66 +9,132 @@ * Class FileFooter * @package Nacha\Record */ -class FileFooter { +class FileFooter +{ + private $recordTypeCode = 9; // not able to overwrite this + /**@var \Nacha\Field\Number */ + private $batchCount; + /**@var \Nacha\Field\Number */ + private $blockCount; + /**@var \Nacha\Field\Number */ + private $entryAddendaCount; + /**@var \Nacha\Field\Number */ + private $entryHash; + /**@var \Nacha\Field\Number */ + private $totalDebits; + /**@var \Nacha\Field\Number */ + private $totalCredits; + /**@var \Nacha\Field\String */ + private $reserved; - private $recordTypeCode = 9; // not able to overwrite this - private $batchCount; - private $blockCount; - private $entryAddendaCount; - private $entryHash; - private $totalDebits; - private $totalCredits; - private $reserved; + public function __construct() + { + // defaults + $this->reserved = new String('', 39); + $this->setBatchCount(0); + $this->setBlockCount(0); + $this->setEntryAddendaCount(0); + $this->setTotalDebits(0); + $this->setTotalCredits(0); + } - public function __construct() { - // defaults - $this->reserved = new String('', 39); - $this->setBatchCount(0); - $this->setBlockCount(0); - $this->setEntryAddendaCount(0); - $this->setTotalDebits(0); - $this->setTotalCredits(0); - } + /** + * @param $batchCount + * @return $this + */ + public function setBatchCount($batchCount) + { + $this->batchCount = new Number($batchCount, 6); + return $this; + } - public function setBatchCount($batchCount) { - $this->batchCount = new Number($batchCount, 6); - return $this; - } - public function setBlockCount($blockCount) { - $this->blockCount = new Number($blockCount, 6); - return $this; - } - public function setEntryAddendaCount($entryAddendaCount) { - $this->entryAddendaCount = new Number($entryAddendaCount, 8); - return $this; - } - public function setEntryHash($entryHash) { - $this->entryHash = new Number($entryHash, 10); - return $this; - } - public function setTotalDebits($totalDebits) { - $this->totalDebits = new Number($totalDebits, 12); - return $this; - } - public function setTotalCredits($totalCredits) { - $this->totalCredits = new Number($totalCredits, 12); - return $this; - } + /** + * @param $blockCount + * @return $this + */ + public function setBlockCount($blockCount) + { + $this->blockCount = new Number($blockCount, 6); + return $this; + } - public function getEntryAddendaCount() - { - return $this->entryAddendaCount->getIntVal(); - } + /** + * @param $entryAddendaCount + * @return $this + */ + public function setEntryAddendaCount($entryAddendaCount) + { + $this->entryAddendaCount = new Number($entryAddendaCount, 8); + return $this; + } - public function __toString() { - return $this->recordTypeCode. - $this->batchCount. - $this->blockCount. - $this->entryAddendaCount. - $this->entryHash. - $this->totalDebits. - $this->totalCredits. - $this->reserved; - } + /** + * @param $entryHash + * @return $this + */ + public function setEntryHash($entryHash) + { + $this->entryHash = new Number($entryHash, 10); + return $this; + } + + /** + * @param $totalDebits + * @return $this + */ + public function setTotalDebits($totalDebits) + { + $this->totalDebits = new Number($totalDebits, 12); + return $this; + } + + /** + * @param $totalCredits + * @return $this + */ + public function setTotalCredits($totalCredits) + { + $this->totalCredits = new Number($totalCredits, 12); + return $this; + } + + /** + * @return int + */ + public function getEntryAddendaCount() + { + return $this->entryAddendaCount->getIntVal(); + } + + /** + * @return float + */ + public function getTotalDebit() + { + return $this->totalDebits->getFloatVal(); + } + + /** + * @return float + */ + public function getTotalCredit() + { + return $this->totalDebits->getFloatVal(); + } + + /** + * @return string + */ + public function __toString() + { + return $this->recordTypeCode . + $this->batchCount . + $this->blockCount . + $this->entryAddendaCount . + $this->entryHash . + $this->totalDebits . + $this->totalCredits . + $this->reserved; + } } \ No newline at end of file diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index 3424ab6..afd41e0 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -7,6 +7,10 @@ use Nacha\Field\RoutingNumber; use Nacha\Field\FileIdModifier; +/** + * Class FileHeader + * @package Nacha\Record + */ class FileHeader { private $recordTypeCode = 1; // not able to overwrite this @@ -41,78 +45,129 @@ public function __construct() $this->setFileCreationTime(''); } + /** + * @param $priorityCode + * @return $this + */ public function setPriorityCode($priorityCode) { $this->priorityCode = new Number($priorityCode, 2); return $this; } + /** + * @param $immediateDestination + * @return $this + */ public function setImmediateDestination($immediateDestination) { $this->immediateDestination = new RoutingNumber($immediateDestination); return $this; } + /** + * @param $immediateOrigin + * @return $this + */ public function setImmediateOrigin($immediateOrigin) { $this->immediateOrigin = new RoutingNumber($immediateOrigin); return $this; } + /** + * @param $fileCreationDate + * @return $this + */ public function setFileCreationDate($fileCreationDate) { $this->fileCreationDate = new String($fileCreationDate, 6); return $this; } + /** + * @param $fileCreationTime + * @return $this + */ public function setFileCreationTime($fileCreationTime) { $this->fileCreationTime = new String($fileCreationTime, 4); return $this; } + /** + * @param $fileIdModifier + * @return $this + */ public function setFileIdModifier($fileIdModifier) { $this->fileIdModifier = new FileIdModifier($fileIdModifier); return $this; } + /** + * @param $recordSize + * @return $this + */ public function setRecordSize($recordSize) { $this->recordSize = new Number($recordSize, 3); return $this; } + /** + * @param $blockingFactor + * @return $this + */ public function setBlockingFactor($blockingFactor) { $this->blockingFactor = new Number($blockingFactor, 2); return $this; } + /** + * @param $formatCode + * @return $this + */ public function setFormatCode($formatCode) { $this->formatCode = new Number($formatCode, 1); return $this; } + /** + * @param $immediateDestinationName + * @return $this + */ public function setImmediateDestinationName($immediateDestinationName) { $this->immediateDestinationName = new String($immediateDestinationName, 23); return $this; } + /** + * @param $immediateOriginName + * @return $this + */ public function setImmediateOriginName($immediateOriginName) { $this->immediateOriginName = new String($immediateOriginName, 23); return $this; } + /** + * @param $referenceCode + * @return $this + */ public function setReferenceCode($referenceCode) { $this->referenceCode = new String($referenceCode, 8); return $this; } + /** + * @return \DateTime + */ public function getEffectiveDate() { $dateArray = date_parse_from_format(self::CREATE_DATE_FORMAT, $this->fileCreationDate); @@ -122,6 +177,9 @@ public function getEffectiveDate() return $date->add(\DateInterval::createFromDateString('1 day')); } + /** + * @return string + */ public function __toString() { return $this->recordTypeCode . From 88e5a588ecb7e9fd9673a3b2ecb86795d0fe2323 Mon Sep 17 00:00:00 2001 From: kulparoman Date: Tue, 3 Nov 2015 11:42:29 +0200 Subject: [PATCH 06/19] Fix file footer. --- src/Nacha/Record/FileFooter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nacha/Record/FileFooter.php b/src/Nacha/Record/FileFooter.php index 7e9dc7e..1b77ec2 100644 --- a/src/Nacha/Record/FileFooter.php +++ b/src/Nacha/Record/FileFooter.php @@ -119,7 +119,7 @@ public function getTotalDebit() */ public function getTotalCredit() { - return $this->totalDebits->getFloatVal(); + return $this->totalCredits->getFloatVal(); } /** From 0dd161b4ccd23d7c1ebf4ba3d1035f112f11d2b5 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sat, 26 Mar 2016 22:36:48 -0400 Subject: [PATCH 07/19] Force line endings so tests pass on Windows --- test/Nacha/FileTest.php | 106 +++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/test/Nacha/FileTest.php b/test/Nacha/FileTest.php index 9c933c2..d31ae5e 100644 --- a/test/Nacha/FileTest.php +++ b/test/Nacha/FileTest.php @@ -40,31 +40,33 @@ public function testBatchesAndEntries() { // when $this->file->addBatch($batchA); $this->file->addBatch($batchB); + $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "822500000100091012980000000550000000000000001419871234 010212340000001\n" . + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "822500000100091012980000000550000000000000001419871234 010212340000002\n" . + "9000002000001000000020018202596000000110000000000000000 \n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"; // then - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc -5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -822500000100091012980000000550000000000000001419871234 010212340000001 -5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -822500000100091012980000000550000000000000001419871234 010212340000002 -9000002000001000000020018202596000000110000000000000000 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", (string)$this->file); + $this->assertEquals($test_string, (string)$this->file); } public function testBlockFill() { - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc -9000000000001000000000000000000000000000000000000000000 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", (string)$this->file); + $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + "9000000000001000000000000000000000000000000000000000000 \n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"; + $this->assertEquals($test_string, (string)$this->file); } public function testNoBlockFill() { @@ -98,18 +100,19 @@ public function testNoBlockFill() { // when $this->file->addBatch($this->getBatch()); $this->file->addBatch($batchA); - + $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "822500000100091012980000000550000000000000001419871234 010212340000001\n" . + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015\n" . + "62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015\n" . + "822500000300273038940000001650000000000000001419871234 010212340000002\n" . + "9000002000001000000040036405192000000220000000000000000 "; + // then - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc -5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -822500000100091012980000000550000000000000001419871234 010212340000001 -5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 -62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 -822500000300273038940000001650000000000000001419871234 010212340000002 -9000002000001000000040036405192000000220000000000000000 ", (string)$this->file); + $this->assertEquals($test_string, (string)$this->file); } public function testBlockWithEntries() { @@ -132,28 +135,29 @@ public function testBlockWithEntries() { $this->file->addBatch($this->getBatch()); $this->file->addBatch($this->getBatch()); $this->file->addBatch($batchA); + $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "822500000100091012980000000550000000000000001419871234 010212340000001\n" . + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000002\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "822500000100091012980000000550000000000000001419871234 010212340000002\n" . + "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000003\n" . + "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015\n" . + "822500000200182025960000001100000000000000001419871234 010212340000003\n" . + "9000003000002000000040036405192000000220000000000000000 \n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"; // then - $this->assertEquals("101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc -5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -822500000100091012980000000550000000000000001419871234 010212340000001 -5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000002 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -822500000100091012980000000550000000000000001419871234 010212340000002 -5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000003 -62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015 -62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015 -822500000200182025960000001100000000000000001419871234 010212340000003 -9000003000002000000040036405192000000220000000000000000 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", (string)$this->file); + $this->assertEquals($test_string, (string)$this->file); } private function getBatch() { From 8befde231193ade065d284d472e0871ff2c47256 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sat, 26 Mar 2016 22:44:11 -0400 Subject: [PATCH 08/19] Failing test with long immediate origin (greater than PHP_INT_MAX) --- test/Nacha/Record/FileHeaderTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/Nacha/Record/FileHeaderTest.php b/test/Nacha/Record/FileHeaderTest.php index 23d5f14..67d1cc4 100644 --- a/test/Nacha/Record/FileHeaderTest.php +++ b/test/Nacha/Record/FileHeaderTest.php @@ -34,4 +34,21 @@ public function testFileHeader_OptionalFields() { $this->assertEquals('101 051000033 059999997060210 A094101 ', (string)$fileHeader); } + public function testFileHeader_LongImmediateOrigin() { + // given + $fileHeader = (new FileHeader) + ->setPriorityCode(1) + ->setImmediateDestination('051000033') + ->setImmediateOrigin('9059999997') + ->setFileCreationDate('060210') + ->setFileCreationTime('2232') + ->setFormatCode('1') + ->setImmediateDestinationName('ImdDest Name') + ->setImmediateOriginName('ImdOriginName') + ->setReferenceCode('Reference'); // will be truncated + + $this->assertEquals(94, strlen($fileHeader)); + $this->assertEquals('101 05100003390599999970602102232A094101ImdDest Name ImdOriginName Referenc', (string)$fileHeader); + } + } \ No newline at end of file From 38fe0c09268d9c6149e9b20b6298e3ffcc5c3dcf Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sat, 26 Mar 2016 22:45:21 -0400 Subject: [PATCH 09/19] Fix FileHeader with long immediate origin --- src/Nacha/Record/FileHeader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index 511886f..05bca43 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -51,7 +51,7 @@ public function setImmediateOrigin($immediateOrigin) { $this->immediateOrigin = new RoutingNumber($immediateOrigin); } else { - $this->immediateOrigin = new Number($immediateOrigin, 10); + $this->immediateOrigin = new String($immediateOrigin, 10); } return $this; } From 1100f1ffeaa4d69593d19ff7cc0a56de504bd6e9 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sat, 26 Mar 2016 22:48:57 -0400 Subject: [PATCH 10/19] Extra test to prevent invalid padding --- src/Nacha/Record/FileHeader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index 05bca43..f19851c 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -50,7 +50,7 @@ public function setImmediateOrigin($immediateOrigin) { if(strlen($immediateOrigin) == 9) { $this->immediateOrigin = new RoutingNumber($immediateOrigin); } - else { + else if (strlen($immediateOrigin) == 10) { $this->immediateOrigin = new String($immediateOrigin, 10); } return $this; From 1900c655a333a79b483dceb9819ca87d78b402d6 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sun, 27 Mar 2016 00:21:17 -0400 Subject: [PATCH 11/19] Proper regex for invalid ASCII ranges --- src/Nacha/Field/String.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nacha/Field/String.php b/src/Nacha/Field/String.php index 90b5319..4567d11 100644 --- a/src/Nacha/Field/String.php +++ b/src/Nacha/Field/String.php @@ -16,7 +16,7 @@ public function __construct($value, $length) throw new InvalidFieldException('Value "' . $value . '" must be an string.'); } - if (!preg_match('/^[\w\s-]*$/', $value)) { + if (preg_match('/[^\x20-\x7F]/', $value)) { throw new InvalidFieldException('Value "' . $value . '" has invalid ascii characters.'); } } From ac1b59b4d53d8dc99ae5cddff593ce036bdcbd14 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sun, 27 Mar 2016 00:21:38 -0400 Subject: [PATCH 12/19] Fix test since String class converts to uppercase --- test/Nacha/Field/StringTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Nacha/Field/StringTest.php b/test/Nacha/Field/StringTest.php index 2f58dae..a2ddccd 100644 --- a/test/Nacha/Field/StringTest.php +++ b/test/Nacha/Field/StringTest.php @@ -34,7 +34,7 @@ public function testValidCharacters() { $str = new String($allValidAsciiChars, strlen($allValidAsciiChars)); // then - $this->assertEquals($allValidAsciiChars, (string)$str); + $this->assertEquals(strtoupper($allValidAsciiChars), (string)$str); } /** From 4a91b72c67d1de98199cf30f8fe00b0521c880a6 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sun, 27 Mar 2016 00:22:08 -0400 Subject: [PATCH 13/19] Undo regression from long immediate origin fix --- src/Nacha/Record/FileHeader.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index afd41e0..83826a3 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -71,7 +71,12 @@ public function setImmediateDestination($immediateDestination) */ public function setImmediateOrigin($immediateOrigin) { - $this->immediateOrigin = new RoutingNumber($immediateOrigin); + if(strlen($immediateOrigin) == 9) { + $this->immediateOrigin = new RoutingNumber($immediateOrigin); + } + else if(strlen($immediateOrigin) == 10) { + $this->immediateOrigin = new String($immediateOrigin, 10); + } return $this; } @@ -182,10 +187,13 @@ public function getEffectiveDate() */ public function __toString() { + $origin = $this->immediateOrigin instanceof RoutingNumber ? (' ' . $this->immediateOrigin) : + $this->immediateOrigin; + return $this->recordTypeCode . $this->priorityCode . ' ' . $this->immediateDestination . // Prefixed with a space - ' ' . $this->immediateOrigin . // Prefixed with a space + $origin . $this->fileCreationDate . $this->fileCreationTime . $this->fileIdModifier . From 034861a7b7fc649afd8418601547957dff86ed01 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sun, 27 Mar 2016 00:26:07 -0400 Subject: [PATCH 14/19] More test fixes for uppercase --- test/Nacha/FileTest.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/Nacha/FileTest.php b/test/Nacha/FileTest.php index d31ae5e..94c6e90 100644 --- a/test/Nacha/FileTest.php +++ b/test/Nacha/FileTest.php @@ -40,12 +40,12 @@ public function testBatchesAndEntries() { // when $this->file->addBatch($batchA); $this->file->addBatch($batchB); - $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + $test_string = "101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC\n" . "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . "822500000100091012980000000550000000000000001419871234 010212340000001\n" . "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002\n" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . "822500000100091012980000000550000000000000001419871234 010212340000002\n" . "9000002000001000000020018202596000000110000000000000000 \n" . "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . @@ -56,7 +56,7 @@ public function testBatchesAndEntries() { } public function testBlockFill() { - $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + $test_string = "101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC\n" . "9000000000001000000000000000000000000000000000000000000 \n" . "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . @@ -100,14 +100,14 @@ public function testNoBlockFill() { // when $this->file->addBatch($this->getBatch()); $this->file->addBatch($batchA); - $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + $test_string = "101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC\n" . "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . "822500000100091012980000000550000000000000001419871234 010212340000001\n" . "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000002\n" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . - "62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015\n" . - "62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 PHILIP WHITT S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 PHILIP WHITT S 0999363400000015\n" . "822500000300273038940000001650000000000000001419871234 010212340000002\n" . "9000002000001000000040036405192000000220000000000000000 "; @@ -135,16 +135,16 @@ public function testBlockWithEntries() { $this->file->addBatch($this->getBatch()); $this->file->addBatch($this->getBatch()); $this->file->addBatch($batchA); - $test_string = "101 051000033 0599999970602102232A094101ImdDest Name ImdOriginName Referenc\n" . + $test_string = "101 051000033 0599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC\n" . "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000001\n" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . "822500000100091012980000000550000000000000001419871234 010212340000001\n" . "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDPAYROLL 0602 0112 2010212340000002\n" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . "822500000100091012980000000550000000000000001419871234 010212340000002\n" . "5225MY BEST COMP INCLUDES OVERTIME 1419871234PPDEXPENSES 0602 0112 2010212340000003\n" . - "62709101298746479999 0000055000SomePerson1255 Alex Dubrovsky S 0999363400000015\n" . - "62709101298746479999 0000055000SomePerson1255 Philip Whitt S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 ALEX DUBROVSKY S 0999363400000015\n" . + "62709101298746479999 0000055000SOMEPERSON1255 PHILIP WHITT S 0999363400000015\n" . "822500000200182025960000001100000000000000001419871234 010212340000003\n" . "9000003000002000000040036405192000000220000000000000000 \n" . "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" . From f0a1ed8e3c022472b259e70eecb5bc5c2c5eb3e0 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sun, 27 Mar 2016 00:42:45 -0400 Subject: [PATCH 15/19] One more uppercase test fix --- test/Nacha/Record/FileHeaderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Nacha/Record/FileHeaderTest.php b/test/Nacha/Record/FileHeaderTest.php index b8df347..7b90dcd 100644 --- a/test/Nacha/Record/FileHeaderTest.php +++ b/test/Nacha/Record/FileHeaderTest.php @@ -51,7 +51,7 @@ public function testFileHeader_LongImmediateOrigin() { ->setReferenceCode('Reference'); // will be truncated $this->assertEquals(94, strlen($fileHeader)); - $this->assertEquals('101 05100003390599999970602102232A094101ImdDest Name ImdOriginName Referenc', (string)$fileHeader); + $this->assertEquals('101 05100003390599999970602102232A094101IMDDEST NAME IMDORIGINNAME REFERENC', (string)$fileHeader); } } \ No newline at end of file From 414d5dfe75e549b08e07e01c7dda2c45f5fed381 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Sun, 27 Mar 2016 00:42:59 -0400 Subject: [PATCH 16/19] Fix incorrect block count in file footer --- src/Nacha/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nacha/File.php b/src/Nacha/File.php index a605b6a..16dc21e 100644 --- a/src/Nacha/File.php +++ b/src/Nacha/File.php @@ -70,7 +70,7 @@ private function generateFooter() $fileFooter->setEntryHash($this->getHash()); $fileFooter->setBatchCount(count($this->batches)); - $fileFooter->setBlockCount(round($totalRecords / 10)); + $fileFooter->setBlockCount(ceil($totalRecords / 10)); $fileFooter->setEntryAddendaCount($totalEntryCount); $fileFooter->setTotalDebits($totalDebits); $fileFooter->setTotalCredits($totalCredits); From 4c54ace1b6eab12b963430de7f9f19cab0e8d69d Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Mon, 28 Mar 2016 11:25:33 -0400 Subject: [PATCH 17/19] Fix batch footer and add tests for large company IDs --- src/Nacha/Record/BatchFooter.php | 2 +- test/Nacha/Record/BatchFooterTest.php | 14 ++++++++++++++ test/Nacha/Record/BatchHeaderTest.php | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Nacha/Record/BatchFooter.php b/src/Nacha/Record/BatchFooter.php index c15e5bc..23d87ce 100644 --- a/src/Nacha/Record/BatchFooter.php +++ b/src/Nacha/Record/BatchFooter.php @@ -61,7 +61,7 @@ public function setTotalCreditAmount($totalCreditAmount) public function setCompanyIdNumber($companyIdNumber) { - $this->companyIdNumber = new Number($companyIdNumber, 10); + $this->companyIdNumber = new String($companyIdNumber, 10); return $this; } diff --git a/test/Nacha/Record/BatchFooterTest.php b/test/Nacha/Record/BatchFooterTest.php index f949043..388df90 100644 --- a/test/Nacha/Record/BatchFooterTest.php +++ b/test/Nacha/Record/BatchFooterTest.php @@ -36,4 +36,18 @@ public function testBatchFooter_OptionalFields() $this->assertEquals('820000000000091012980000000000000000000000001419871234 099912340000001', (string)$batchFooter); } + public function testBatchFooter_LongCompanyId() + { + // given + $batchFooter = (new BatchFooter) + ->setServiceClassCode(200) + ->setEntryHash('9101298') + ->setCompanyIdNumber('9059999997') + ->setOriginatingDfiId('09991234') + ->setBatchNumber(1); + + $this->assertEquals(94, strlen($batchFooter)); + $this->assertEquals('820000000000091012980000000000000000000000009059999997 099912340000001', (string)$batchFooter); + } + } \ No newline at end of file diff --git a/test/Nacha/Record/BatchHeaderTest.php b/test/Nacha/Record/BatchHeaderTest.php index 5d59376..7cab7de 100644 --- a/test/Nacha/Record/BatchHeaderTest.php +++ b/test/Nacha/Record/BatchHeaderTest.php @@ -45,4 +45,22 @@ public function testBatchHeader_OptionalFields() $this->assertEquals('5200MY BEST COMP 1419871234PPDPAYROLL 0112 2010212340000001', (string)$batchHeader); } + public function testBatchHeader_LongCompanyId() + { + // given + $batchHeader = (new BatchHeader) + ->setServiceClassCode(200) + ->setCompanyName('MY BEST COMP') + ->setCompanyId('9059999997') + ->setStandardEntryClassCode(StandardEntryClass::PPD) + ->setCompanyEntryDescription('PAYROLL') + ->setEffectiveEntryDate('0112') + ->setOriginatorStatusCode('2') + ->setOriginatingDFiId('01021234') + ->setBatchNumber(1); + + $this->assertEquals(94, strlen($batchHeader)); + $this->assertEquals('5200MY BEST COMP 9059999997PPDPAYROLL 0112 2010212340000001', (string)$batchHeader); + } + } \ No newline at end of file From e4ecd262e4988fc18a12eb6a2f4b9d73c656a080 Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Tue, 29 Mar 2016 13:08:13 -0400 Subject: [PATCH 18/19] Remove CcdEntry and DebitEntry in favor of the more generic Entry class to contain debits and credits for all types. Fixes #10 --- src/Nacha/Batch.php | 10 +- src/Nacha/Record/CcdEntry.php | 109 ------------------ src/Nacha/Record/DebitEntry.php | 109 ------------------ src/Nacha/Record/Entry.php | 95 ++++++++++++++- test/Nacha/BatchTest.php | 31 +++-- test/Nacha/FileTest.php | 27 +++-- test/Nacha/Record/CcdEntryTest.php | 44 ------- .../{DebitEntryTest.php => EntryTest.php} | 12 +- 8 files changed, 131 insertions(+), 306 deletions(-) delete mode 100644 src/Nacha/Record/CcdEntry.php delete mode 100644 src/Nacha/Record/DebitEntry.php delete mode 100644 test/Nacha/Record/CcdEntryTest.php rename test/Nacha/Record/{DebitEntryTest.php => EntryTest.php} (81%) 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); From 23013d8dfde93c0bd99e5a21a705152001ebb3cc Mon Sep 17 00:00:00 2001 From: Jeremy Forsythe Date: Thu, 22 Dec 2016 22:54:34 -0500 Subject: [PATCH 19/19] Compatible with PHP 7 --- src/Nacha/Field/CompanyEntryDescription.php | 2 +- src/Nacha/Field/CompanyName.php | 2 +- src/Nacha/Field/FileIdModifier.php | 2 +- src/Nacha/Field/StandardEntryClass.php | 2 +- src/Nacha/Field/{String.php => Str.php} | 2 +- src/Nacha/Record/BatchFooter.php | 8 ++++---- src/Nacha/Record/BatchHeader.php | 14 +++++++------- src/Nacha/Record/Entry.php | 10 +++++----- src/Nacha/Record/FileFooter.php | 6 +++--- src/Nacha/Record/FileHeader.php | 14 +++++++------- test/Nacha/Field/StringTest.php | 10 +++++----- 11 files changed, 36 insertions(+), 36 deletions(-) rename src/Nacha/Field/{String.php => Str.php} (98%) diff --git a/src/Nacha/Field/CompanyEntryDescription.php b/src/Nacha/Field/CompanyEntryDescription.php index e9a2779..24e07c8 100644 --- a/src/Nacha/Field/CompanyEntryDescription.php +++ b/src/Nacha/Field/CompanyEntryDescription.php @@ -2,7 +2,7 @@ namespace Nacha\Field; -class CompanyEntryDescription extends String +class CompanyEntryDescription extends Str { // upper case trigger words private $triggers = [ diff --git a/src/Nacha/Field/CompanyName.php b/src/Nacha/Field/CompanyName.php index 16fa02f..baa71af 100644 --- a/src/Nacha/Field/CompanyName.php +++ b/src/Nacha/Field/CompanyName.php @@ -2,7 +2,7 @@ namespace Nacha\Field; -class CompanyName extends String +class CompanyName extends Str { public function __construct($value) { diff --git a/src/Nacha/Field/FileIdModifier.php b/src/Nacha/Field/FileIdModifier.php index c1668f1..2f6acf2 100644 --- a/src/Nacha/Field/FileIdModifier.php +++ b/src/Nacha/Field/FileIdModifier.php @@ -2,7 +2,7 @@ namespace Nacha\Field; -class FileIdModifier extends String +class FileIdModifier extends Str { public function __construct($value) { diff --git a/src/Nacha/Field/StandardEntryClass.php b/src/Nacha/Field/StandardEntryClass.php index 19d4ab2..683352a 100644 --- a/src/Nacha/Field/StandardEntryClass.php +++ b/src/Nacha/Field/StandardEntryClass.php @@ -2,7 +2,7 @@ namespace Nacha\Field; -class StandardEntryClass extends String +class StandardEntryClass extends Str { const ACK = 'ACK'; const ADV = 'ADV'; diff --git a/src/Nacha/Field/String.php b/src/Nacha/Field/Str.php similarity index 98% rename from src/Nacha/Field/String.php rename to src/Nacha/Field/Str.php index 4567d11..6530c94 100644 --- a/src/Nacha/Field/String.php +++ b/src/Nacha/Field/Str.php @@ -2,7 +2,7 @@ namespace Nacha\Field; -class String +class Str { protected $value; protected $length; diff --git a/src/Nacha/Record/BatchFooter.php b/src/Nacha/Record/BatchFooter.php index 23d87ce..131d0e8 100644 --- a/src/Nacha/Record/BatchFooter.php +++ b/src/Nacha/Record/BatchFooter.php @@ -3,7 +3,7 @@ namespace Nacha\Record; use Nacha\Field\Number; -use Nacha\Field\String; +use Nacha\Field\Str; class BatchFooter { @@ -22,7 +22,7 @@ class BatchFooter public function __construct() { // defaults/optional - $this->reserved = new String('', 6); + $this->reserved = new Str('', 6); $this->setEntryAddendaCount(0); $this->setMessageAuthenticationCode(''); $this->setTotalDebitAmount(0); @@ -61,13 +61,13 @@ public function setTotalCreditAmount($totalCreditAmount) public function setCompanyIdNumber($companyIdNumber) { - $this->companyIdNumber = new String($companyIdNumber, 10); + $this->companyIdNumber = new Str($companyIdNumber, 10); return $this; } public function setMessageAuthenticationCode($messageAuthenticationCode) { - $this->messageAuthenticationCode = new String($messageAuthenticationCode, 19); + $this->messageAuthenticationCode = new Str($messageAuthenticationCode, 19); return $this; } diff --git a/src/Nacha/Record/BatchHeader.php b/src/Nacha/Record/BatchHeader.php index ff20952..ee66d46 100644 --- a/src/Nacha/Record/BatchHeader.php +++ b/src/Nacha/Record/BatchHeader.php @@ -7,7 +7,7 @@ use Nacha\Field\Number; use Nacha\Field\OriginatorStatusCode; use Nacha\Field\StandardEntryClass; -use Nacha\Field\String; +use Nacha\Field\Str; class BatchHeader { @@ -113,13 +113,13 @@ public function setCompanyName($companyName) public function setCompanyDiscretionaryData($companyDiscretionaryData) { - $this->companyDiscretionaryData = new String($companyDiscretionaryData, 20); + $this->companyDiscretionaryData = new Str($companyDiscretionaryData, 20); return $this; } public function setCompanyId($companyId) { - $this->companyId = new String($companyId, 10); + $this->companyId = new Str($companyId, 10); return $this; } @@ -137,19 +137,19 @@ public function setCompanyEntryDescription($companyEntryDescription) public function setCompanyDescriptiveDate($companyDescriptiveDate) { - $this->companyDescriptiveDate = new String($companyDescriptiveDate, 6); + $this->companyDescriptiveDate = new Str($companyDescriptiveDate, 6); return $this; } public function setEffectiveEntryDate($effectiveEntryDate) { - $this->effectiveEntryDate = new String($effectiveEntryDate, 6); + $this->effectiveEntryDate = new Str($effectiveEntryDate, 6); return $this; } public function setSettlementDate($settlementDate) { - $this->settlementDate = new String($settlementDate, 3); + $this->settlementDate = new Str($settlementDate, 3); return $this; } @@ -161,7 +161,7 @@ public function setOriginatorStatusCode($originatorStatusCode) public function setOriginatingDFiId($originatingDFiId) { - $this->originatingDFiId = new String($originatingDFiId, 8); + $this->originatingDFiId = new Str($originatingDFiId, 8); return $this; } diff --git a/src/Nacha/Record/Entry.php b/src/Nacha/Record/Entry.php index 36e39f0..67d8c7c 100644 --- a/src/Nacha/Record/Entry.php +++ b/src/Nacha/Record/Entry.php @@ -4,7 +4,7 @@ use Nacha\Field\Amount; use Nacha\Field\Number; -use Nacha\Field\String; +use Nacha\Field\Str; use Nacha\Field\TransactionCode; class Entry @@ -106,25 +106,25 @@ public function setReceivingDFiId($receivingDfiId) public function setDFiAccountNumber($dFiAccountNumber) { - $this->dFiAccountNumber = new String($dFiAccountNumber, 17); + $this->dFiAccountNumber = new Str($dFiAccountNumber, 17); return $this; } public function setSubjectId($subjectId) { - $this->subjectId = new String($subjectId, 15); + $this->subjectId = new Str($subjectId, 15); return $this; } public function setSubjectName($subjectName) { - $this->subjectName = new String($subjectName, 22); + $this->subjectName = new Str($subjectName, 22); return $this; } public function setDiscretionaryData($discretionaryData) { - $this->discretionaryData = new String($discretionaryData, 2); + $this->discretionaryData = new Str($discretionaryData, 2); return $this; } diff --git a/src/Nacha/Record/FileFooter.php b/src/Nacha/Record/FileFooter.php index 1b77ec2..9295fde 100644 --- a/src/Nacha/Record/FileFooter.php +++ b/src/Nacha/Record/FileFooter.php @@ -2,7 +2,7 @@ namespace Nacha\Record; -use Nacha\Field\String; +use Nacha\Field\Str; use Nacha\Field\Number; /** @@ -24,13 +24,13 @@ class FileFooter private $totalDebits; /**@var \Nacha\Field\Number */ private $totalCredits; - /**@var \Nacha\Field\String */ + /**@var \Nacha\Field\Str */ private $reserved; public function __construct() { // defaults - $this->reserved = new String('', 39); + $this->reserved = new Str('', 39); $this->setBatchCount(0); $this->setBlockCount(0); $this->setEntryAddendaCount(0); diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index 83826a3..3ae7d32 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -2,7 +2,7 @@ namespace Nacha\Record; -use Nacha\Field\String; +use Nacha\Field\Str; use Nacha\Field\Number; use Nacha\Field\RoutingNumber; use Nacha\Field\FileIdModifier; @@ -75,7 +75,7 @@ public function setImmediateOrigin($immediateOrigin) $this->immediateOrigin = new RoutingNumber($immediateOrigin); } else if(strlen($immediateOrigin) == 10) { - $this->immediateOrigin = new String($immediateOrigin, 10); + $this->immediateOrigin = new Str($immediateOrigin, 10); } return $this; } @@ -86,7 +86,7 @@ public function setImmediateOrigin($immediateOrigin) */ public function setFileCreationDate($fileCreationDate) { - $this->fileCreationDate = new String($fileCreationDate, 6); + $this->fileCreationDate = new Str($fileCreationDate, 6); return $this; } @@ -96,7 +96,7 @@ public function setFileCreationDate($fileCreationDate) */ public function setFileCreationTime($fileCreationTime) { - $this->fileCreationTime = new String($fileCreationTime, 4); + $this->fileCreationTime = new Str($fileCreationTime, 4); return $this; } @@ -146,7 +146,7 @@ public function setFormatCode($formatCode) */ public function setImmediateDestinationName($immediateDestinationName) { - $this->immediateDestinationName = new String($immediateDestinationName, 23); + $this->immediateDestinationName = new Str($immediateDestinationName, 23); return $this; } @@ -156,7 +156,7 @@ public function setImmediateDestinationName($immediateDestinationName) */ public function setImmediateOriginName($immediateOriginName) { - $this->immediateOriginName = new String($immediateOriginName, 23); + $this->immediateOriginName = new Str($immediateOriginName, 23); return $this; } @@ -166,7 +166,7 @@ public function setImmediateOriginName($immediateOriginName) */ public function setReferenceCode($referenceCode) { - $this->referenceCode = new String($referenceCode, 8); + $this->referenceCode = new Str($referenceCode, 8); return $this; } diff --git a/test/Nacha/Field/StringTest.php b/test/Nacha/Field/StringTest.php index a2ddccd..9611156 100644 --- a/test/Nacha/Field/StringTest.php +++ b/test/Nacha/Field/StringTest.php @@ -8,7 +8,7 @@ class StringTest extends \PHPUnit_Framework_TestCase public function testPadding() { // given - $str = new String('Hello World', 32); + $str = new Str('Hello World', 32); // then $this->assertEquals('HELLO WORLD ', (string)$str); @@ -16,7 +16,7 @@ public function testPadding() public function testOptional() { // given - $str = new String('', 10); + $str = new Str('', 10); // then $this->assertEquals(' ', (string)$str); @@ -31,7 +31,7 @@ public function testValidCharacters() { } // when - $str = new String($allValidAsciiChars, strlen($allValidAsciiChars)); + $str = new Str($allValidAsciiChars, strlen($allValidAsciiChars)); // then $this->assertEquals(strtoupper($allValidAsciiChars), (string)$str); @@ -41,7 +41,7 @@ public function testValidCharacters() { * @expectedException \Nacha\Field\InvalidFieldException */ public function testNotString() { - new String(12, 32); + new Str(12, 32); } public function testInvalidCharacter() { @@ -50,7 +50,7 @@ public function testInvalidCharacter() { $invalid = 'validtext'.chr($ascii); try { - new String($invalid, strlen($invalid)); + new Str($invalid, strlen($invalid)); $this->assertTrue(false, 'Should throw an exception for invalid ASCII:'.$ascii);