UNPKG

docparse-supplier-nge

Version:

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

84 lines (81 loc) 2.5 kB
/** * First extract the total other cost value printed on the bill. Then iterate * over all line item other charges and make sure they add up to the printed * total * * @see {Function} get_cost_other_total */ var async = require('async'); var num = require('num'); var inspect = require('eyespect').inspector({maxLength:20000000}); var getOtherCostsText = require('./getOtherCostsText'); var sumOtherCosts = require('./sumOtherCosts'); var processCostOtherText = require('./processCostOtherText'); module.exports = function(text, callback) { var otherCostsText = getOtherCostsText(text); if (!otherCostsText) { var no_output = { total: 0, costs: [] }; return callback(null, no_output); } var total_num; var total_string; var costs = []; processCostOtherText(otherCostsText, callback); }; // async.series([ // function(cb) { // getOtherCostsTotal(otherCostsText, function (err, reply) { // if (err) { return cb(err); } // if (!reply) { // return cb('failed to get total other costs', null); // } // total_string = reply.replace(/\s/g, ''); // total_num = num(total_string); // cb(); // }); // }, // // go line by line and get charges // function (cb) { // var lines = otherCostsText.match(/[^\r\n]+/g); // async.forEach( // lines, // function (line, line_cb) { // get_other_cost_line_item(line, function (err, reply) { // if (err) { return line_cb(err); } // if (!reply) { return line_cb(); } // costs.push(reply); // line_cb(); // }); // }, // function (err) { // cb(); // } // ); // }, // function (cb) { // var cost_other_num = num(0); // if (costs.length > 0) { // cost_other_num = sum_other_costs(costs); // } // var cost_other_string = cost_other_num.toString(); // if (cost_other_string !== total_string) { // console.log(otherCostsText); // inspect(costs, 'other costs'); // inspect(cost_other_string, 'calculated total cost other delivery costs'); // inspect(total_string, 'printed total other '); // return cb('error, calculated total other delivery costs do not match printed total other costs'); // } // cb(); // }, // ], function(err) { // if (err) { return callback(err); } // var output = { // total: total_string, // costs: costs // }; // return callback(null, output); // }); // }