Skip to content

Commit

Permalink
Npm Package Update - For IAT Addenda record sequence number fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepvish1213 committed Dec 4, 2023
1 parent fe516ba commit 34f91a0
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 108 deletions.
38 changes: 38 additions & 0 deletions lib/entry-addenda/fieldsWithTraceNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
recordTypeCode: {
name: 'Record Type Code',
width: 1,
position: 1,
required: true,
type: 'numeric',
value: '7'
},

addendaTypeCode: {
name: 'Addenda Type Code',
width: 2,
position: 2,
required: true,
type: 'numeric',
value: '05'
},

paymentRelatedInformation: {
name: 'Payment Related Information',
width: 76,
position: 3,
required: false,
type: 'alphanumeric',
value: ''
},

traceNumber: {
name: 'Trace Number',
width: 15,
position: 4,
required: false,
type: 'numeric',
blank: true,
value: ''
}
};
53 changes: 50 additions & 3 deletions lib/entry-addenda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,58 @@ let validate = require('./../validate');

let highLevelOverrides = ['addendaTypeCode', 'paymentRelatedInformation', 'addendaSequenceNumber', 'entryDetailSequenceNumber'];

function EntryAddenda(options) {
function EntryAddenda(options, standardEntryClassCode) {

// Allow the file header defaults to be overriden if provided
// Allow the file header defaults to be override if provided
this.fields = options.fields ? _.merge(options.fields, require('./fields'), _.defaults) : _.cloneDeep(require('./fields'));

if (['MTE', 'POS', 'SHR', 'IAT'].indexOf(standardEntryClassCode) !== -1 && ['17', '18'].indexOf(options.addendaTypeCode) === -1) {
this.fields = _.merge(options.fields, require('./fieldsWithTraceNumber'), _.defaults)
if (standardEntryClassCode === 'IAT') {
let reservedWith;
let paymentRelatedInfoWidth
switch (options.addendaTypeCode) {
case '10':
reservedWith = 6;
paymentRelatedInfoWidth = 78
break;
case '13':
reservedWith = 10;
paymentRelatedInfoWidth = 74
break;
case '14':
reservedWith = 10;
paymentRelatedInfoWidth = 74
break;
case '15':
reservedWith = 34;
paymentRelatedInfoWidth = 50
break;
default:
reservedWith = 14;
paymentRelatedInfoWidth = 70
break;
}
this.fields.paymentRelatedInformation.width = paymentRelatedInfoWidth;
this.fields.reserved = {
name: 'Reserved',
width: reservedWith,
position: 4,
required: false,
type: 'alphanumeric',
value: '',
blank: true
}
this.fields.entryDetailSequenceNumber = {
name: 'Entry Detail Sequence Number',
width: 7,
position: 5,
required: false,
type: 'numeric',
value: ''
}
delete this.fields.traceNumber
}
}
// Set our high-level values
utils.overrideLowLevel(highLevelOverrides, options, this);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sp-nacha",
"description": "NACHA file format is a set of instructions that, when uploaded into a bank portal, successfully initiates a batch of ACH payments. NACHA file format is the protocol for structuring those instructions in a way that successfully initiates the payments. NACHA is a highly customizable Node.js module exposing a high & low-level API for generating ACH files for use within the ACH network.",
"version": "1.1.6",
"version": "1.1.7",
"keywords": [
"Seerportal Nacha",
"Dataseers Nacha",
Expand Down
59 changes: 59 additions & 0 deletions test/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,63 @@ describe('Entry', function () {
})
}).timeout(10000);
})
let MTERecords = [{
"id": 20514,
"standardEntryClassCode": "MTE",
"immediateDestination": "011002725",
"immediateOrigin": "121042882",
"immediateDestinationName": "BERKSHIRE BANK",
"immediateOriginName": "WELLS FARGO BANK NA",
"referenceCode": " ",
"batchChildren": [{
"id": 20514,
"companyName": "Compan NamePRDEE",
"companyIdentification": "1022337788",
"serviceClassCode": "200",
"standardEntryClassCode": "MTE",
"companyDiscretionaryData": "NA",
"companyEntryDescription": "Accounting",
"companyDescriptiveDate": "",
"effectiveEntryDate": Moment().toDate(),
"originatingDFI": "121042882",
"entryChildren": [{
"id": 20514,
"transactionCode": "27",
"receivingDFI": "011002725",
"DFIAccount": "12345678",
"amount": "1000",
"idNumber": "ICICI Bank ",
"individualName": "45678654 ",
"discretionaryData": "21",
"transactionType": "Debit",
"addendaRecords": [{
"id": 204,
"queued_transaction_id": 20514,
"addenda_type_code": "02",
"payment_related_information": "This is211TERM021000490614101010Target Store 0049 ANYTOWN VA",
"ach_return_code": null,
"original_entry_trace_number": null,
"date_of_death": null,
"created_at": "2023-12-04 13:01:15",
"modified_at": "2023-12-04 13:01:15"
}]
}]
}],
"recordCount": 1,
"fileCharCount": "PHIN"
}]
describe('Generate MTE ACH File', async function () {
it('should create an MTE ACH file successfully', function (done) {
GenerateAchFile(MTERecords, './test/ach_file','MTE_').then((result) => {
expect(result.error).to.equal(false);
expect(result.message).to.equal('Successfully writing file.');
return done()
}).catch(error => {
console.log('===========', error)
expect(true).to.be.false;
expect(error.message).to.equal('Successfully writing file.');
return done();
})
}).timeout(10000);
})
});
7 changes: 4 additions & 3 deletions test/generateFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ let dataAddenda = [{
}]


async function GenerateAchFile(queuedTransaction = [], fileFullPath = './') {
async function GenerateAchFile(queuedTransaction = [], fileFullPath = './', prefix = '') {
return new Promise((resolve, reject) => {
let totalRunsFile = [];
queuedTransaction = queuedTransaction.length > 0 ? queuedTransaction : dataAddenda;
queuedTransaction.forEach(({batchChildren, id, ...restField}) => {
try {
let standardEntryClassCode = restField.standardEntryClassCode
let Nacha2AimPointFile = new NachaAimPoint.File(restField);
let totalBatchNumber = batchChildren.length;
let totalCreditAmount = 0
Expand All @@ -85,7 +86,7 @@ async function GenerateAchFile(queuedTransaction = [], fileFullPath = './') {
addendaRecords.forEach(addenda => {
let addendaEntry = new NachaAimPoint.EntryAddenda({
paymentRelatedInformation: addenda.payment_related_information
});
}, standardEntryClassCode);
entryRecord.addAddenda(addendaEntry);
})
}
Expand All @@ -101,7 +102,7 @@ async function GenerateAchFile(queuedTransaction = [], fileFullPath = './') {
return reject({row_id: id, message: e.message, error: true})
}
})
let fileName = `ACH${restField.immediateOrigin}PEIN${Moment().format('YYYYMMDDHHmmssSS')}.ach`;
let fileName = `${prefix}ACH${restField.immediateOrigin}PEIN${Moment().format('YYYYMMDDHHmmssSS')}.ach`;
if (successRecords.length > 0) {
Nacha2AimPointFile.generateFile(function (result) {
FS.writeFile(path.join(fileFullPath, fileName), result, function (error) {
Expand Down
Loading

0 comments on commit 34f91a0

Please sign in to comment.