28 define(
"ALPHAMERIC_STRING",
'/^[\w\s\^\!\_\@\#\$\%\,\*\:\.\/\+\-]+$/' );
29 define(
"ACH_NOT_ALLOWED",
'/[^\w\s\^\!\_\@\#\$\%\,\*\:\.\/\+\-]/' );
40 function GetFileHeaderRecord( $pAdmEnv, $strRecord ) {
41 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
44 $returnData[
"RecordTypeCode"] = substr( $strRecord, 0, 1 );
45 $returnData[
"PriorityCode"] = intval( substr( $strRecord, 1, 2 ) );
46 $returnData[
"ImmediateDestination"] = substr( $strRecord, 3, 10 );
47 $returnData[
"ImmediateOrigin"] = substr( $strRecord, 13, 10 );
48 $returnData[
"FileCreateDate"] = substr( $strRecord, 23, 6 );
49 $returnData[
"FileCreateTime"] = substr( $strRecord, 29, 4 );
50 $returnData[
"FileIDModifier"] = substr( $strRecord, 33, 1 );
51 $returnData[
"RecordSize"] = substr( $strRecord, 34, 3 );
52 $returnData[
"BlockingFactor"] = substr( $strRecord, 37, 2 );
53 $returnData[
"FormatCode"] = substr( $strRecord, 39, 1 );
54 $returnData[
"ImmediateDestinationName"] = substr( $strRecord, 40, 23 );
55 $returnData[
"ImmediateOriginName"] = substr( $strRecord, 63, 23 );
56 $returnData[
"ReferenceCode"] = substr( $strRecord, 86, 8 );
58 $return[
"data"] = $returnData;
60 }
catch (Exception $ex) {
61 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
62 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
64 $return[
"code"] =
"999";
65 $return[
"error"][] =
"{$logInfo["error
"]} ({$logInfo["code
"]})";
80 function ValidateFileHeaderRecord( $pAdmEnv, $pRecord ) {
81 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
84 if ( $pRecord[
"RecordTypeCode"] !=
"1" ) {
85 $return[
"error"][] =
"Invalid ACH File Header Record Type Code";
88 if ( strlen( trim( $pRecord[
"PriorityCode"] ) ) > 0 && !is_numeric( $pRecord[
"PriorityCode"] ) ) {
89 $return[
"error"][] =
"Invalid ACH File Header Priority Code";
90 }
else if ( strlen( trim( $pRecord[
"PriorityCode"] ) ) == 0 ) {
91 $return[
"warning"][] =
"ACH File Header Priority Code is blank - a number is recommended";
94 if ( !preg_match(
"/ \d{9}/", $pRecord[
"ImmediateDestination"] ) ) {
95 $return[
"error"][] =
"Invalid ACH File Header Immediate Destination";
98 if ( !preg_match(
"/[ d]\d{9}/", $pRecord[
"ImmediateOrigin"] ) ) {
99 $return[
"error"][] =
"Invalid ACH File Header Immediate Origin";
102 if ( !preg_match(
"/\d{6}/", $pRecord[
"FileCreateDate"] ) ) {
103 $return[
"error"][] =
"Invalid ACH File Header File Create Date";
106 $today = date(
"ymd" );
107 if ( $today > $pRecord[
"FileCreateDate"] ) {
108 $return[
"warning"][] =
"Invalid ACH File Header File Create Date old - today: $today (vs {$pRecord["FileCreateDate
"]})";
112 $YY = substr( $pRecord[
"FileCreateDate"], 0, 2 );
113 $MM = substr( $pRecord[
"FileCreateDate"], 2, 2 );
114 $DD = substr( $pRecord[
"FileCreateDate"], 4, 2 );
116 if ( $MM < 1 || $MM > 12 ) {
117 $return[
"error"][] =
"Invalid ACH File Header File Create Date Month";
118 }
else if ( $DD < 1 || $DD > 31 ) {
119 $return[
"error"][] =
"Invalid ACH File Header File Create Date Day";
123 if ( !preg_match(
"/\d{4}/", $pRecord[
"FileCreateTime"] ) ) {
124 $return[
"error"][] =
"Invalid ACH File Header File Create Time";
127 $HH = substr( $pRecord[
"FileCreateTime"], 0, 2 );
128 $MM = substr( $pRecord[
"FileCreateTime"], 2, 2 );
130 if ( $HH < 1 || $HH > 24 ) {
131 $return[
"error"][] =
"Invalid ACH File Header File Create Time Hour";
132 }
else if ( $MM < 1 || $MM > 59 ) {
133 $return[
"error"][] =
"Invalid ACH File Header File Create Time Minute";
137 if ( !preg_match(
"/[A-Z,0-9]/", $pRecord[
"FileIDModifier"] ) ) {
138 $return[
"error"][] =
"Invalid ACH File Header File ID Modifier";
141 if ( !is_numeric( $pRecord[
"RecordSize"] ) ) {
142 $return[
"error"][] =
"Invalid ACH File Header Record Size";
145 if ( !is_numeric( $pRecord[
"BlockingFactor"] ) ) {
146 $return[
"error"][] =
"Invalid ACH File Header Blocking Factor";
149 if ( $pRecord[
"FormatCode"] != 1 ) {
150 $return[
"error"][] =
"Invalid ACH File Header Format Code";
153 if ( !strlen( trim ( $pRecord[
"ImmediateDestinationName"] ) ) ) {
154 $return[
"error"][] =
"Invalid ACH File Header Immediate Destination Name";
156 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"ImmediateDestinationName"] ) ) {
157 $return[
"error"][] =
"Invalid ACH File Header Immediate Destination Name character";
161 if ( !strlen( trim ( $pRecord[
"ImmediateOriginName"] ) ) ) {
162 $return[
"error"][] =
"Invalid ACH File Header Immediate Origin Name";
164 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"ImmediateOriginName"] ) ) {
165 $return[
"error"][] =
"Invalid ACH File Header Immediate Origin Name character";
169 if ( strlen( trim ( $pRecord[
"ReferenceCode"] ) ) != 0 || strlen( $pRecord[
"ReferenceCode"] ) != 8 ) {
170 $return[
"error"][] =
"Invalid ACH File Header Reference Code";
172 }
catch (Exception $ex) {
173 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
174 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
177 $return[
"error"][] =
"Exception: {$logInfo["error
"]} ({$logInfo["code
"]})";
192 function GetCompanyHeaderRecord( $pAdmEnv, $strRecord ) {
193 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
196 $returnData[
"RecordTypeCode"] = substr( $strRecord, 0, 1 );
197 $returnData[
"ServiceClassCode"] = substr( $strRecord, 1, 3 );
198 $returnData[
"CompanyName"] = substr( $strRecord, 4, 16 );
199 $returnData[
"CompanyData"] = substr( $strRecord, 20, 20 );
200 $returnData[
"CompanyID"] = substr( $strRecord, 40, 10 );
201 $returnData[
"StandardEntryClassCode"] = substr( $strRecord, 50, 3 );
202 $returnData[
"CompanyEntryDescription"] = substr( $strRecord, 53, 10 );
203 $returnData[
"CompanyDescriptiveDate"] = substr( $strRecord, 63, 6 );
204 $returnData[
"EffectiveEntryDate"] = substr( $strRecord,69, 6 );
205 $returnData[
"SettlementDate"] = substr( $strRecord, 75, 3 );
206 $returnData[
"OriginatorStatusCode"] = substr( $strRecord, 78, 1 );
207 $returnData[
"OriginatingDFI"] = substr( $strRecord, 79, 8 );
208 $returnData[
"BatchNumber"] = substr( $strRecord, 87, 7 );
210 $return[
"data"] = $returnData;
212 }
catch (Exception $ex) {
213 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
214 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
216 $return[
"code"] =
"999";
217 $return[
"error"] =
"{$logInfo["error
"]} ({$logInfo["code
"]})";
232 function ValidateCompanyHeaderRecord( $pAdmEnv, $pRecord ) {
233 $standardEntryClassCodes = [
"CIE",
"DNE",
"ENR",
"PPD",
"RCK",
"TEL",
"WEB",
235 "ACK",
"ATX",
"CCD",
"CTX",
236 "ARC",
"POP",
"BOC",
"TRC",
"TRX",
"XCK",
"IAT",
237 "MTE",
"POS",
"SHR"];
239 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
242 if ( $pRecord[
"RecordTypeCode"] !=
"5" ) {
243 $return[
"error"][] =
"Invalid ACH Company Header Record Type Code";
246 if ( strlen( trim( $pRecord[
"ServiceClassCode"] ) ) == 0 || !is_numeric( $pRecord[
"ServiceClassCode"] ) ) {
247 $return[
"error"][] =
"Invalid ACH Company Header Service Class Code";
249 $code = trim( $pRecord[
"ServiceClassCode"] );
250 if ( $code != 200 && $code != 220 & $code != 225 ) {
251 $return[
"error"][] =
"ACH Company Header Service Class Code is an unexpected number";
255 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"CompanyName"] ) ) {
256 $return[
"error"][] =
"Invalid ACH Company Header Company Name";
259 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"CompanyData"] ) ) {
260 $return[
"error"][] =
"Invalid ACH Company Header Company Data";
263 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"CompanyID"] ) ) {
264 $return[
"error"][] =
"Invalid ACH Company Header CompanyID";
267 if ( !in_array( $pRecord[
"StandardEntryClassCode"], $standardEntryClassCodes ) ) {
268 $return[
"error"][] =
"Invalid ACH Company Header Standard Entry Class Code: {$pRecord["StandardEntryClassCode
"]}";
271 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"CompanyEntryDescription"] ) ) {
272 $return[
"error"][] =
"Invalid ACH Company Header Company Entry Description";
275 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"CompanyDescriptiveDate"] ) ) {
276 $return[
"error"][] =
"Invalid ACH Company Header Company Descriptive Date";
279 if ( !preg_match(
"/\d{6}/", $pRecord[
"EffectiveEntryDate"] ) ) {
280 $return[
"error"][] =
"Invalid ACH Company Header Effective Entry Date";
283 $today = date(
"ymd" );
284 if ( $today > $pRecord[
"EffectiveEntryDate"] ) {
285 $return[
"warning"][] =
"Invalid ACH Company Header Effective Entry Date old - today: $today (vs {$pRecord["EffectiveEntryDate
"]})";
289 $YY = substr( $pRecord[
"EffectiveEntryDate"], 0, 2 );
290 $MM = substr( $pRecord[
"EffectiveEntryDate"], 2, 2 );
291 $DD = substr( $pRecord[
"EffectiveEntryDate"], 4, 2 );
293 if ( $MM < 1 || $MM > 12 ) {
294 $return[
"error"][] =
"Invalid ACH Company Header Effective Entry Date Month";
295 }
else if ( $DD < 1 || $DD > 31 ) {
296 $return[
"error"][] =
"Invalid ACH Company Header Effective Entry Date Day";
300 if ( strlen( trim ( $pRecord[
"SettlementDate"] ) ) != 0 || strlen( $pRecord[
"SettlementDate"] ) != 3 ) {
301 $return[
"warning"][] =
"Invalid ACH Company Header Settlement Date (originator should leave blank)";
304 if ( $pRecord[
"OriginatorStatusCode"] !=
"1" ) {
305 $return[
"error"][] =
"Invalid ACH Company Header Originator Status Code";
308 if ( !preg_match(
"/\d{8}/", $pRecord[
"OriginatingDFI"] ) ) {
309 $return[
"error"][] =
"Invalid ACH Company Header Originating DFI";
312 if ( !preg_match(
"/\d{7}/", $pRecord[
"BatchNumber"] ) ) {
313 $return[
"error"][] =
"Invalid ACH Company Header Batch Number";
315 }
catch (Exception $ex) {
316 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
317 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
320 $return[
"error"][] =
"Exception: {$logInfo["error
"]} ({$logInfo["code
"]})";
335 function GetEntryDetailRecord( $pAdmEnv, $strRecord ) {
336 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
339 $returnData[
"RecordTypeCode"] = substr( $strRecord, 0, 1 );
340 $returnData[
"TransactionCode"] = substr( $strRecord, 1, 2 );
341 $returnData[
"ReceivingDFI"] = substr( $strRecord, 3, 8 );
342 $returnData[
"CheckDigit"] = substr( $strRecord, 11, 1 );
343 $returnData[
"DFIAccountNumber"] = substr( $strRecord, 12, 17 );
344 $returnData[
"Amount"] = substr( $strRecord, 29, 10 );
345 $returnData[
"IndividualIdentificationNumber"] = substr( $strRecord, 39, 15 );
346 $returnData[
"IndividualName"] = substr( $strRecord, 54, 22 );
347 $returnData[
"DiscretionaryData"] = substr( $strRecord,76, 2 );
348 $returnData[
"AddendaRecordIndicator"] = substr( $strRecord, 78, 1 );
349 $returnData[
"TraceNumber"] = substr( $strRecord, 79, 15 );
351 $return[
"data"] = $returnData;
353 }
catch (Exception $ex) {
354 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
355 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
357 $return[
"code"] =
"999";
358 $return[
"error"] =
"{$logInfo["error
"]} ({$logInfo["code
"]})";
373 function ValidateEntryDetailRecord( $pAdmEnv, $pRecord, $pHeader ) {
374 $transactionCodes = [22, 23, 24, 27, 28, 29, 32, 33, 34, 37, 38, 39, 42, 47, 52, 53];
376 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
379 if ( $pRecord[
"RecordTypeCode"] !=
"6" ) {
380 $return[
"error"][] =
"Invalid ACH Entry Detail Record Type Code";
383 if ( strlen( trim( $pRecord[
"TransactionCode"] ) ) == 0 || !is_numeric( $pRecord[
"TransactionCode"] ) ) {
384 $return[
"error"][] =
"Invalid ACH Entry Detail Transaction Code";
386 $code = trim( $pRecord[
"TransactionCode"] );
387 if ( !in_array( $code, $transactionCodes ) ) {
388 $return[
"error"][] =
"ACH Entry Detail Transaction Code is an unexpected number: {$pRecord["TransactionCode
"]}";
393 if ( !preg_match(
"/^[\d]+$/", $pRecord[
"ReceivingDFI"] ) ) {
394 $return[
"error"][] =
"Invalid ACH Entry Detail Receiving DFI";
397 if ( !preg_match(
"/\d/", $pRecord[
"CheckDigit"] ) ) {
398 $return[
"error"][] =
"Invalid ACH Entry Detail Check Digit";
401 if ( !strlen( trim( $pRecord[
"DFIAccountNumber"] ) ) ) {
402 $return[
"warning"][] =
"Missing ACH Entry Detail DFI Account Number";
405 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"DFIAccountNumber"] ) ) {
406 $return[
"error"][] =
"Invalid ACH Entry Detail DFI Account Number";
409 if ( !preg_match(
"/\d{10}/", $pRecord[
"Amount"] ) ) {
410 $return[
"error"][] =
"Invalid ACH Entry Detail Amount";
413 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"IndividualIdentificationNumber"] ) ) {
414 $return[
"error"][] =
"Invalid ACH Entry Detail Individual Identification Number";
418 if ( !strlen( trim( $pRecord[
"IndividualName"] ) ) ) {
419 $return[
"warning"][] =
"Missing ACH Entry Detail Individual Name";
422 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"IndividualName"] ) ) {
423 $return[
"error"][] =
"Invalid ACH Entry Detail Individual Name";
426 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"DiscretionaryData"] ) ) {
427 $return[
"error"][] =
"Invalid ACH Entry Detail Discretionary Data";
431 if ( $pHeader[
'StandardEntryClassCode'] ==
"WEB" && !preg_match(
"/^[SR]\s/", $pRecord[
"DiscretionaryData"] ) ) {
432 $return[
"error"][] =
"Invalid ACH Entry Detail Discretionary Data for Standard Entry Class Code WEB";
435 if ( !($pRecord[
"AddendaRecordIndicator"] == 0 || $pRecord[
"AddendaRecordIndicator"] == 1) ) {
436 $return[
"error"][] =
"Invalid ACH Entry Detail Addenda Record Indicator";
439 if ( !preg_match(
"/\d{15}/", $pRecord[
"TraceNumber"] ) ) {
440 $return[
"error"][] =
"Invalid ACH Entry Detail Trace Number";
443 }
catch (Exception $ex) {
444 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
445 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
448 $return[
"error"][] =
"Exception: {$logInfo["error
"]} ({$logInfo["code
"]})";
463 function GetAddendaRecord( $pAdmEnv, $strRecord ) {
464 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
467 $returnData[
"RecordTypeCode"] = substr( $strRecord, 0, 1 );
468 $returnData[
"AddendaTypeCode"] = substr( $strRecord, 1, 2 );
469 $returnData[
"PaymentRelatedInformation"] = substr( $strRecord, 3, 80 );
470 $returnData[
"AddendaSequenceNumber"] = substr( $strRecord, 83, 4 );
471 $returnData[
"EntryDetailSequenceNumber"] = substr( $strRecord, 87, 7 );
473 $return[
"data"] = $returnData;
475 }
catch (Exception $ex) {
476 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
477 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
479 $return[
"code"] =
"999";
480 $return[
"error"] =
"{$logInfo["error
"]} ({$logInfo["code
"]})";
496 function ValidateAddendaRecord( $pAdmEnv, $pRecord, $pEntrySequenceNumber ) {
497 $allowedAddendaTypeCodes = [
"02",
"05",
"98",
"99"];
499 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
502 if ( $pRecord[
"RecordTypeCode"] !=
"7" ) {
503 $return[
"error"][] =
"Invalid ACH Addenda Record Type Code";
506 if ( !in_array( $pRecord[
"AddendaTypeCode"], $allowedAddendaTypeCodes ) ) {
507 $return[
"error"][] =
"Invalid ACH Addenda Type Code";
510 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"PaymentRelatedInformation"] ) ) {
511 $return[
"error"][] =
"Invalid ACH Addenda Payment Related Information";
514 if ( !preg_match(
"/\d{4}/", $pRecord[
"AddendaSequenceNumber"] ) ) {
515 $return[
"error"][] =
"Invalid ACH Addenda Sequence Number";
518 if ( !preg_match(
"/\d{7}/", $pRecord[
"EntryDetailSequenceNumber"] ) ) {
519 $return[
"error"][] =
"Invalid ACH Addenda Entry Detail Sequence Number";
522 if ( $pRecord[
"EntryDetailSequenceNumber"] != $pEntrySequenceNumber ) {
523 print
"Test: {$pRecord["EntryDetailSequenceNumber
"]}, $pEntrySequenceNumber";
524 $return[
"error"][] =
"Unexpected ACH Addenda Entry Detail Sequence Number";
527 }
catch (Exception $ex) {
528 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
529 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
532 $return[
"error"][] =
"Exception: {$logInfo["error
"]} ({$logInfo["code
"]})";
547 function GetCompanyControlRecord( $pAdmEnv, $strRecord ) {
548 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
551 $returnData[
"RecordTypeCode"] = substr( $strRecord, 0, 1 );
552 $returnData[
"ServiceClassCode"] = substr( $strRecord, 1, 3 );
553 $returnData[
"EntryAddendaCount"] = substr( $strRecord, 4, 6 );
554 $returnData[
"EntryHash"] = substr( $strRecord, 10, 10 );
555 $returnData[
"TotalDebitEntryDollarAmount"] = substr( $strRecord, 20, 12 );
556 $returnData[
"TotalCreditEntryDollarAmount"] = substr( $strRecord, 32, 12 );
557 $returnData[
"CompanyID"] = substr( $strRecord, 44, 10 );
558 $returnData[
"MessageAuthenticationCode"] = substr( $strRecord, 54, 19 );
559 $returnData[
"Reserved"] = substr( $strRecord, 73, 6 );
560 $returnData[
"OriginatingDFIIdentification"] = substr( $strRecord, 79, 8 );
561 $returnData[
"BatchNumber"] = substr( $strRecord, 87, 7 );
563 $return[
"data"] = $returnData;
565 }
catch (Exception $ex) {
566 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
567 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
569 $return[
"code"] =
"999";
570 $return[
"error"] =
"{$logInfo["error
"]} ({$logInfo["code
"]})";
585 function ValidateCompanyControlRecord( $pAdmEnv, $pRecord ) {
586 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
589 if ( $pRecord[
"RecordTypeCode"] !=
"8" ) {
590 $return[
"error"][] =
"Invalid ACH Company Control Record Type Code";
593 if ( strlen( trim( $pRecord[
"ServiceClassCode"] ) ) == 0 || !is_numeric( $pRecord[
"ServiceClassCode"] ) ) {
594 $return[
"error"][] =
"Invalid ACH Company Control Service Class Code";
596 $code = trim( $pRecord[
"ServiceClassCode"] );
597 if ( $code != 200 && $code != 220 & $code != 225 ) {
598 $return[
"error"][] =
"ACH Company Control Service Class Code is an unexpected number";
602 if ( !preg_match(
"/\d{6}/", $pRecord[
"EntryAddendaCount"] ) ) {
603 $return[
"error"][] =
"Invalid ACH Company Control Entry/Addenda Count";
606 if ( !preg_match(
"/\d{10}/", $pRecord[
"EntryHash"] ) ) {
607 $return[
"error"][] =
"Invalid ACH Company Control Entry Hash";
610 if ( !preg_match(
"/\d{12}/", $pRecord[
"TotalDebitEntryDollarAmount"] ) ) {
611 $return[
"error"][] =
"Invalid ACH Company Control Total Debit Entry dollar amount";
614 if ( !preg_match(
"/\d{12}/", $pRecord[
"TotalCreditEntryDollarAmount"] ) ) {
615 $return[
"error"][] =
"Invalid ACH Company Control Total Credit Entry dollar amount";
618 if ( !preg_match( ALPHAMERIC_STRING, $pRecord[
"CompanyID"] ) ) {
619 $return[
"error"][] =
"Invalid ACH Company Control Company Idetntification";
622 if ( strlen( trim ( $pRecord[
"MessageAuthenticationCode"] ) ) != 0 || strlen( $pRecord[
"MessageAuthenticationCode"] ) != 19 ) {
623 $return[
"error"][] =
"Invalid ACH Company Control Message Authentication Code";
626 if ( !preg_match(
"/\s{6}/", $pRecord[
"Reserved"] ) ) {
627 $return[
"error"][] =
"Invalid ACH Company Control Reserved Field";
630 if ( !preg_match(
"/\d{8}/", $pRecord[
"OriginatingDFIIdentification"] ) ) {
631 $return[
"error"][] =
"Invalid ACH Company Control Originating DFI Identification";
634 if ( !preg_match(
"/\d{7}/", $pRecord[
"BatchNumber"] ) ) {
635 $return[
"error"][] =
"Invalid ACH Company Control Batch Number";
638 }
catch (Exception $ex) {
639 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
640 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
643 $return[
"error"][] =
"Exception: {$logInfo["error
"]} ({$logInfo["code
"]})";
658 function GetFileControlRecord( $pAdmEnv, $strRecord ) {
659 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
662 $returnData[
"RecordTypeCode"] = substr( $strRecord, 0, 1 );
663 $returnData[
"BatchCount"] = substr( $strRecord, 1, 6 );
664 $returnData[
"BlockCount"] = substr( $strRecord, 7, 6 );
665 $returnData[
"EntryAddendaCount"] = substr( $strRecord, 13, 8 );
666 $returnData[
"EntryHash"] = substr( $strRecord, 21, 10 );
667 $returnData[
"TotalDebitEntryDollarAmount"] = substr( $strRecord, 31, 12 );
668 $returnData[
"TotalCreditEntryDollarAmount"] = substr( $strRecord, 43, 12 );
669 $returnData[
"Reserved"] = substr( $strRecord, 55, 39 );
671 $return[
"data"] = $returnData;
673 }
catch (Exception $ex) {
674 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
675 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
677 $return[
"code"] =
"999";
678 $return[
"error"] =
"{$logInfo["error
"]} ({$logInfo["code
"]})";
693 function ValidateFileControlRecord( $pAdmEnv, $pRecord ) {
694 $return = array(
"code" =>
"000",
"warning" => array(),
"error" => array(),
"data" => array());
697 if ( $pRecord[
"RecordTypeCode"] !=
"9" ) {
698 $return[
"error"][] =
"Invalid ACH File Control Record Type Code";
701 if ( !preg_match(
"/\d{6}/", $pRecord[
"BatchCount"] ) ) {
702 $return[
"error"][] =
"Invalid ACH File Control Batch Count";
705 if ( !preg_match(
"/\d{6}/", $pRecord[
"BlockCount"] ) ) {
706 $return[
"error"][] =
"Invalid ACH File Control Block Count";
709 if ( !preg_match(
"/\d{8}/", $pRecord[
"EntryAddendaCount"] ) ) {
710 $return[
"error"][] =
"Invalid ACH File Control Entry/Addenda Count";
713 if ( !preg_match(
"/\d{12}/", $pRecord[
"TotalDebitEntryDollarAmount"] ) ) {
714 $return[
"error"][] =
"Invalid ACH File Control Total Debit Entry Dollar Amount";
717 if ( !preg_match(
"/\d{12}/", $pRecord[
"TotalCreditEntryDollarAmount"] ) ) {
718 $return[
"error"][] =
"Invalid ACH File Control Total Credit Entry Dollar Amount";
720 if ( !preg_match(
"/\s{39}/", $pRecord[
"Reserved"] ) ) {
721 $return[
"error"][] =
"Invalid ACH Company Control Reserved Field";
724 }
catch (Exception $ex) {
725 $logInfo = array(
"error" => $ex->getMessage(),
"code" => $ex->getCode() );
726 $pAdmEnv[
"SYSENV"][
"logger"]->info( HCU_JsonEncode( $logInfo ) );
729 $return[
"error"][] =
"Exception: {$logInfo["error
"]} ({$logInfo["code
"]})";