@midlandsbank/node-nacha
Version:
NACHA ACH EFT File Parser/Formatter for CCD+ / PPD+ / CTX+
113 lines (106 loc) • 4.01 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var createEntry, getTransactionCode, validate;
validate = require('../validate');
const getAccountTypeCode = require('../getAccountTypeCode')
getTransactionCode = function(transactionType, accountType, isPrenote) {
var code, nextCode;
code = getAccountTypeCode(accountType);
nextCode = transactionType === 'D' ? 7 : 2;
return code += isPrenote ? nextCode + 1 : nextCode;
};
createEntry = function(whichKind, entryData) {
var accountType, ach, batch, entry;
ach = this.object;
batch = ach.batches[ach.batches.length - 1];
// toCompany = 'string' === typeof entryData.to ? this.data.to[entryData.to] : entryData.to;
entry = {
recordType: '6',
receivingDFIIdentification: (String(entryData.routing)).slice(0, -1),
checkDigit: String(entryData.routing).slice(-1),
dfiAccount: entryData.account.num,
amount: entryData.amount,
identificationNumber: entryData.identificationNumber,
receivingCompanyName: entryData.name,
addendaIndicator: entryData.addenda != null ? '1' : '0',
// Documentation for entry Trace level between different websites are inconsistent.
// Some say it can be whatever the bank wants while other say it should be first 7 digits of the
// batch's originating dfi along with the entries sequence number. Just made it default to the latter if not specified
traceNumber: entryData.traceNumber || this.data["for"].dfi + ('000000' + (this.data.entryCount - 1)).slice(-7)
};
// In WEB Entries Discretionary Data is used for Payment type code
if (batch.entryClassCode.toUpperCase() !== 'WEB' && entryData.note != null) {
entry.discretionaryData = entryData.note;
}
if(batch.entryClassCode.toUpperCase() === 'WEB' && entryData.paymentTypeCode != null){
// Payment Type Code can be R for recurring or S for single payment
entry.paymentTypeCode = entryData.paymentTypeCode.trim() === 'R' ? 'R' : 'S';
}
if (entryData.addenda != null) {
entry.addenda = {
recordType: '7',
type: '05',
num: 1,
entryNum: this.data.entryCount,
info: entryData.addenda
};
}
this.data.entryCount++;
accountType = entryData.account.type;
entry.transactionCode = getTransactionCode(whichKind, accountType, entryData.prenote);
if (whichKind === 'C') {
switch (batch.serviceClassCode) {
case '200':
break;
case '225':
batch.serviceClassCode = batch.footer.serviceClassCode = '200';
break;
default:
batch.serviceClassCode = batch.footer.serviceClassCode = '220';
}
} else {
switch (batch.serviceClassCode) {
case '200':
break;
case '220':
batch.serviceClassCode = batch.footer.serviceClassCode = '200';
break;
default:
batch.serviceClassCode = batch.footer.serviceClassCode = '225';
}
}
batch.footer.entryHash += Number(entry.receivingDFIIdentification);
ach.file.footer.entryHash += Number(entry.receivingDFIIdentification);
if(entry.amount){
if (whichKind === 'C') {
batch.footer.totalCredit += entry.amount;
ach.file.footer.totalCredit += entry.amount;
} else {
batch.footer.totalDebit += entry.amount;
ach.file.footer.totalDebit += entry.amount;
}
}
if (entry.addenda != null) {
batch.footer.entryAndAddendaCount += 2;
ach.file.footer.entryAndAddendaCount += 2;
ach.file.footer.lineCount += 2;
} else {
batch.footer.entryAndAddendaCount += 1;
ach.file.footer.entryAndAddendaCount += 1;
ach.file.footer.lineCount += 1;
}
ach.file.footer.blockCount = Math.ceil(ach.file.footer.lineCount / 10);
batch.entries.push(entry);
let { web, ccd, ppd } = require('./batch-ccd-ppd-web')
this.ccd = ccd;
this.ppd = ppd;
this.web = web;
return this;
};
module.exports = {
credit: function(entryData) {
return createEntry.call(this, 'C', entryData);
},
debit: function(entryData) {
return createEntry.call(this, 'D', entryData);
}
};