@midlandsbank/node-nacha
Version:
NACHA ACH EFT File Parser/Formatter for CCD+ / PPD+ / CTX+
88 lines (78 loc) • 2.55 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var createBatch, toDate, toYYMMDD, tomorrowDate, validate;
let { credit, debit } = require('./entry-ccd-ppd-web')
validate = require('../validate');
toYYMMDD = require('../../dates').toYYMMDD;
tomorrowDate = function() {
var tomorrow;
tomorrow = new Date;
tomorrow.setDate(tomorrow.getDate() + 1);
return tomorrow;
};
toDate = function(dateOrString) {
if ('string' === typeof dateOrString) {
return dateOrString;
}
return toYYMMDD(dateOrString);
};
createBatch = function(whichKind, batchData) {
var ach, batch, next, note, ref1, ref2;
this.data.batchData = batchData;
ach = this.object;
// Some specifications say company Id should always be the originators DFI
// but others it can be a customer Id setup for a company for processing purposes
let companyId = batchData.companyId || this.data.from.fein
let originatingDFIIdentification = batchData.originatingDFIIdentification || this.data["from"].fein.trim().substring(0, 8)
let batchNum = ach.batches.length + 1 // We add one because this batch has been added yet
batch = {
recordType: '5',
originatorStatusCode: '1',
num: batchNum,
entryClassCode: whichKind,
companyName: batchData.companyName || this.data.from.name,
companyId: companyId,
originatingDFIIdentification: originatingDFIIdentification,
effectiveDate: toDate(batchData.effectiveDate || tomorrowDate()),
description: batchData.description,
entries: [],
footer: {
recordType: '8',
companyId: companyId,
originatingDFIIdentification: originatingDFIIdentification,
num: batchNum,
entryAndAddendaCount: 0,
entryHash: 0,
totalDebit: 0,
totalCredit: 0
}
};
if (batchData.date != null) {
batch.date = batchData.date;
}
note = (ref2 = batchData.discretionaryData) != null ? ref2 : batchData.note;
if (note != null) {
batch.discretionaryData = note;
}
ach.batches.push(batch);
ach.file.footer.batchCount++;
ach.file.footer.lineCount += 2;
ach.file.footer.blockCount = Math.ceil(ach.file.footer.lineCount / 10);
return next = {
credit: credit,
debit: debit,
data: this.data,
object: ach,
validate: validate.bind(ach, ach)
};
};
module.exports = {
ccd: function(batchData) {
return createBatch.call(this, 'CCD', batchData);
},
ppd: function(batchData) {
return createBatch.call(this, 'PPD', batchData);
},
web: function(batchData) {
return createBatch.call(this, 'WEB', batchData);
}
};