UNPKG

docparse-supplier-nge

Version:

process ngrid electric utility bill data for use in the docparse system

106 lines (99 loc) 2.75 kB
/** * @param {String} text holds the supply text section of the bill */ var async = require('async'); var inspect = require('eyespect').inspector({maxLength:20000000}); var isCompSupply = require('./isCompSupply'); var getCompSupplier = require('./getCompSupplier'); var getCostSupply = require('./getCostSupply'); var getToPaySupply = require('./getToPaySupply'); module.exports = function(text, callback) { // test if on competitive supply text = text.replace(/,/g, ''); var isComp; var data = {}; var compData = {}; async.series([ // get cost supply function(cb) { isComp = isCompSupply(text); data.isComp = isComp; if (!data.isComp) { return cb(); } getCompSupplier(text, function (err, reply) { if (err) { return cb(err); } compData.supplierID = reply._id.toString(); compData.supplierCode = reply.supplier_code; cb(); }); }, function(cb) { getCostSupply(text, function (err, reply) { if (err) { return cb(err); } if (isComp) { compData.costSupply = reply; } else { data.costSupply = reply; } cb(); }); }, // get to pay supply (cost supply + cost other supply function(cb) { getToPaySupply(text, function (err, reply) { if (err) { return cb(err); } data.toPaySupply = reply; if (isComp) { compData.toPaySupply = reply; } else { data.toPaySupply = reply; } cb(); }); }, // // standard offer supply cost other // function(cb) { // if (isComp) { // return cb(); // } // var getCostOther = require('./otherCosts/getCostOther'); // getCostOther(text, function (err, reply) { // if (err) { return cb(err); } // data.costOtherSupply = reply.costOther; // data.toPaySupply = reply.costTotal; // cb(); // }); // }, // comp supply cost other function (cb) { if (!isComp) { return cb(); } var getCostOther = require('./comp/getCostOther'); var costOtherData = { costSupply: compData.costSupply, text: text }; getCostOther(costOtherData, function (err, reply) { if (err) { inspect(err, 'error getting comp supply cost other'); return cb(err); } compData.costOther = reply.costOther; cb(); }); } // function confirm_cost_other_supply(cb) { // check_cost_other_supply(data, cb); // } ], function (err) { if (err) { return callback(err); } if (isComp) { data.compData = compData; } callback(null, data); }); };