From e4a55b47762134404b8a63e789087d3648811f60 Mon Sep 17 00:00:00 2001 From: Andres Bolocco Date: Tue, 23 Jun 2020 14:23:39 -0300 Subject: [PATCH] fix srp bill date --- lib/documentTypes/srpBill.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/documentTypes/srpBill.js b/lib/documentTypes/srpBill.js index 17a6a16..ba7af83 100644 --- a/lib/documentTypes/srpBill.js +++ b/lib/documentTypes/srpBill.js @@ -1,5 +1,6 @@ /* eslint-disable camelcase */ const moment = require('moment'); +const stringSimilarity = require('string-similarity'); module.exports = { @@ -28,6 +29,7 @@ module.exports = { }, extractor: (keyValues, rawText) => { + const keys = Object.keys(keyValues); const serviceFromLineIndex = rawText.findIndex((line) => line.match(/^SERVICE FROM (.*)$/g)); let fullNameLine; let first_name; @@ -68,7 +70,14 @@ module.exports = { } // bill date - const bill_date = rawText.slice(-15).find((line) => line.match(/^\w+ \d+, \d+$/g)); + let bill_date = keyValues[keys[stringSimilarity.findBestMatch( + 'Please Pay by', + keys, + ).bestMatchIndex]]; + + if (!bill_date || !bill_date.length || !bill_date.match(/^\w+ \d+, \d+$/g)) { + bill_date = rawText.slice(-20).find((line) => line.match(/^\w+ \d+, \d+$/g)); + } // account number const accountNumberLine = rawText.find((line) => line.match(/^Account# (.*)$/g));