@ashray.mehta/statement-converter 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,9 +56,9 @@ class ABNAdapter extends TransactionAdapter_1.TransactionAdapter {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  const workBook = XLSX.read(xlsxData, { raw: true, type: 'array' });
58
58
  const sheet = workBook.Sheets[workBook.SheetNames[0]];
59
- const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findText(sheet, "transactiondate");
60
- const addressForDescription = XLSXUtil_1.XLSXUtil.findText(sheet, "description");
61
- const addressForAmount = XLSXUtil_1.XLSXUtil.findText(sheet, "amount");
59
+ const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "transactiondate");
60
+ const addressForDescription = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "description");
61
+ const addressForAmount = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "amount");
62
62
  const startingRow = addressForTransactionDate.r + 1;
63
63
  const range = XLSX.utils.decode_range(sheet['!ref']);
64
64
  const rangeEnd = range.e;
@@ -56,10 +56,10 @@ class AxisAdapter extends TransactionAdapter_1.TransactionAdapter {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  const workBook = XLSX.read(xlsxData, { raw: true, type: 'array' });
58
58
  const sheet = workBook.Sheets[workBook.SheetNames[0]];
59
- const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findText(sheet, "Tran Date");
60
- const addressForDetails = XLSXUtil_1.XLSXUtil.findText(sheet, "PARTICULARS");
61
- const addressForDepositAmount = XLSXUtil_1.XLSXUtil.findText(sheet, "CR");
62
- const addressForWithdrawalAmount = XLSXUtil_1.XLSXUtil.findText(sheet, "DR");
59
+ const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Tran Date");
60
+ const addressForDetails = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "PARTICULARS");
61
+ const addressForDepositAmount = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "CR");
62
+ const addressForWithdrawalAmount = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "DR");
63
63
  const startingRow = addressForTransactionDate.r + 1;
64
64
  const range = XLSX.utils.decode_range(sheet['!ref']);
65
65
  const rangeEnd = range.e;
@@ -57,13 +57,13 @@ class ICICIAdapter extends TransactionAdapter_1.TransactionAdapter {
57
57
  var _a;
58
58
  const workBook = XLSX.read(xlsxData, { raw: true, type: 'array' });
59
59
  const sheet = workBook.Sheets[workBook.SheetNames[0]];
60
- const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findText(sheet, "Transaction Date");
61
- const addressForDetails = (_a = XLSXUtil_1.XLSXUtil.findText(sheet, "Transaction Remark")) !== null && _a !== void 0 ? _a : XLSXUtil_1.XLSXUtil.findText(sheet, "Transaction Remarks");
62
- const addressForAmount = XLSXUtil_1.XLSXUtil.findText(sheet, "Amount (INR)");
63
- const addressForCreditOrDebit = XLSXUtil_1.XLSXUtil.findText(sheet, "CR/DR");
64
- const addressForWithdrawal = XLSXUtil_1.XLSXUtil.findText(sheet, "Withdrawal Amount(INR)");
65
- const addressForDeposit = XLSXUtil_1.XLSXUtil.findText(sheet, "Deposit Amount(INR)");
66
- const addressForLegend = XLSXUtil_1.XLSXUtil.findText(sheet, "Legends Used in Account Statement");
60
+ const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Transaction Date");
61
+ const addressForDetails = (_a = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Transaction Remark")) !== null && _a !== void 0 ? _a : XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Transaction Remarks");
62
+ const addressForAmount = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Amount (INR)");
63
+ const addressForCreditOrDebit = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "CR/DR");
64
+ const addressForWithdrawal = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Withdrawal Amount(INR)");
65
+ const addressForDeposit = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Deposit Amount(INR)");
66
+ const addressForLegend = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Legends Used in Account Statement");
67
67
  const startingRow = addressForTransactionDate.r + 1;
68
68
  const range = XLSX.utils.decode_range(sheet['!ref']);
69
69
  let lastRow;
@@ -3,6 +3,7 @@ import { Transaction } from '../models/Transaction';
3
3
  import { TransactionAdapter } from './TransactionAdapter';
4
4
  export declare class ICICICreditCardAdapter extends TransactionAdapter {
5
5
  convert(xlsxData: ArrayBuffer): Promise<Transaction[]>;
6
+ private findStartingRow;
6
7
  private determineDebitOrCredit;
7
8
  supports(bank: Bank): boolean;
8
9
  }
@@ -46,6 +46,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.ICICICreditCardAdapter = void 0;
49
+ const lodash_es_1 = require("lodash-es");
49
50
  const __1 = require("..");
50
51
  const XLSXUtil_1 = require("../helpers/XLSXUtil");
51
52
  const TransactionAdapter_1 = require("./TransactionAdapter");
@@ -57,22 +58,22 @@ class ICICICreditCardAdapter extends TransactionAdapter_1.TransactionAdapter {
57
58
  var _a, _b, _c, _d, _e;
58
59
  const workBook = XLSX.read(xlsxData, { raw: true, type: 'array' });
59
60
  const sheet = workBook.Sheets[workBook.SheetNames[0]];
60
- const addressForTransactionDate = (_a = XLSXUtil_1.XLSXUtil.findText(sheet, "Transaction Date")) !== null && _a !== void 0 ? _a : XLSXUtil_1.XLSXUtil.findText(sheet, 'Date');
61
- const addressForDetails = (_b = XLSXUtil_1.XLSXUtil.findText(sheet, "Details")) !== null && _b !== void 0 ? _b : XLSXUtil_1.XLSXUtil.findText(sheet, 'Transaction Details');
62
- const addressForAmount = (_d = (_c = XLSXUtil_1.XLSXUtil.findText(sheet, "Amount (INR)")) !== null && _c !== void 0 ? _c : XLSXUtil_1.XLSXUtil.findText(sheet, 'Amount(in Rs)')) !== null && _d !== void 0 ? _d : XLSXUtil_1.XLSXUtil.findText(sheet, 'Intl.Amount');
63
- const addressForReferenceNumber = (_e = XLSXUtil_1.XLSXUtil.findText(sheet, "Reference Number")) !== null && _e !== void 0 ? _e : XLSXUtil_1.XLSXUtil.findText(sheet, 'Sr.No.');
64
- const addressForCreditOrDebit = XLSXUtil_1.XLSXUtil.findText(sheet, "BillingAmountSign");
65
- const startingRow = addressForTransactionDate.r + 1;
61
+ const addressForTransactionDate = (_a = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Transaction Date")) !== null && _a !== void 0 ? _a : XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, 'Date');
62
+ const addressForDetails = (_b = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Details")) !== null && _b !== void 0 ? _b : XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, 'Transaction Details');
63
+ const addressForAmount = (_d = (_c = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Amount (INR)")) !== null && _c !== void 0 ? _c : XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, 'Amount(in Rs)')) !== null && _d !== void 0 ? _d : XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, 'Intl.Amount');
64
+ const addressForReferenceNumber = (_e = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Reference Number")) !== null && _e !== void 0 ? _e : XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, 'Sr.No.');
65
+ const addressForCreditOrDebit = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "BillingAmountSign");
66
66
  const range = XLSX.utils.decode_range(sheet['!ref']);
67
67
  const rangeEnd = range.e;
68
68
  const lastRow = rangeEnd.r;
69
+ const startingRow = this.findStartingRow(sheet, range, addressForTransactionDate);
69
70
  const rows = [...Array(1 + lastRow - startingRow).keys()].map(v => startingRow + v);
70
71
  return rows
71
72
  .filter(row => {
72
73
  // ICICI sometimes has account numbers in the Date field which serve as a separator between inflows and outflows.
73
74
  // This filters those rows out.
74
75
  const dateText = XLSXUtil_1.XLSXUtil.getCellValue(sheet, row, addressForTransactionDate.c);
75
- if (dateText.length === 16) {
76
+ if ((0, lodash_es_1.size)(dateText) === 16) {
76
77
  return false;
77
78
  }
78
79
  else {
@@ -104,6 +105,15 @@ class ICICICreditCardAdapter extends TransactionAdapter_1.TransactionAdapter {
104
105
  });
105
106
  });
106
107
  }
108
+ findStartingRow(sheet, range, addressForTransactionDate) {
109
+ var current = addressForTransactionDate.r; // Right after this is where the data should start, but sometimes there are blank rows after the header.
110
+ for (var current = addressForTransactionDate.r + 1; current <= range.e.r; current++) {
111
+ if (!(0, lodash_es_1.isEmpty)(XLSXUtil_1.XLSXUtil.getCellValue(sheet, current, addressForTransactionDate.c))) {
112
+ return current;
113
+ }
114
+ }
115
+ return addressForTransactionDate.r;
116
+ }
107
117
  determineDebitOrCredit(sheet, row, column) {
108
118
  const cellValue = XLSXUtil_1.XLSXUtil.getCellValue(sheet, row, column);
109
119
  // TODO - Replace parsing with Globalize
@@ -56,11 +56,11 @@ class N26Adapter extends TransactionAdapter_1.TransactionAdapter {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  const workBook = XLSX.read(xlsxData, { raw: true, type: 'array' });
58
58
  const sheet = workBook.Sheets[workBook.SheetNames[0]];
59
- const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findText(sheet, "Booking Date");
60
- const addressForDescription = XLSXUtil_1.XLSXUtil.findText(sheet, "Payment Reference");
61
- const addressForAmount = XLSXUtil_1.XLSXUtil.findText(sheet, "Amount (EUR)");
62
- const addressForPayee = XLSXUtil_1.XLSXUtil.findText(sheet, "Partner Name");
63
- const addressForCategory = XLSXUtil_1.XLSXUtil.findText(sheet, "Type");
59
+ const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Booking Date");
60
+ const addressForDescription = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Payment Reference");
61
+ const addressForAmount = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Amount (EUR)");
62
+ const addressForPayee = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Partner Name");
63
+ const addressForCategory = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Type");
64
64
  const startingRow = addressForTransactionDate.r + 1;
65
65
  const range = XLSX.utils.decode_range(sheet['!ref']);
66
66
  const rangeEnd = range.e;
@@ -56,10 +56,10 @@ class StandardCharteredAdapter extends TransactionAdapter_1.TransactionAdapter {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  const workBook = XLSX.read(xlsxData, { raw: true, type: 'array' });
58
58
  const sheet = workBook.Sheets[workBook.SheetNames[0]];
59
- const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findText(sheet, "Date");
60
- const addressForDetails = XLSXUtil_1.XLSXUtil.findText(sheet, "Transaction");
61
- const addressForDepositAmount = XLSXUtil_1.XLSXUtil.findText(sheet, "Deposit");
62
- const addressForWithdrawalAmount = XLSXUtil_1.XLSXUtil.findText(sheet, "Withdrawal");
59
+ const addressForTransactionDate = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Date");
60
+ const addressForDetails = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Transaction");
61
+ const addressForDepositAmount = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Deposit");
62
+ const addressForWithdrawalAmount = XLSXUtil_1.XLSXUtil.findTextIgnoringWhitespace(sheet, "Withdrawal");
63
63
  const startingRow = addressForTransactionDate.r + 1;
64
64
  const range = XLSX.utils.decode_range(sheet['!ref']);
65
65
  const rangeEnd = range.e;
@@ -1,6 +1,6 @@
1
1
  import { CellAddress, WorkSheet } from 'xlsx';
2
2
  export declare class XLSXUtil {
3
- static findText(sheet: WorkSheet, text: string): CellAddress;
3
+ static findTextIgnoringWhitespace(sheet: WorkSheet, text: string): CellAddress;
4
4
  static getCellValue(sheet: WorkSheet, row: number, column: number): string | number | boolean;
5
5
  static getNumberInCell(sheet: WorkSheet, row: number, column: number): number;
6
6
  }
@@ -5,7 +5,7 @@ const lodash_es_1 = require("lodash-es");
5
5
  const NumberUtil_1 = require("./NumberUtil");
6
6
  const xlsx_1 = require("xlsx");
7
7
  class XLSXUtil {
8
- static findText(sheet, text) {
8
+ static findTextIgnoringWhitespace(sheet, text) {
9
9
  const range = xlsx_1.utils.decode_range(sheet['!ref']);
10
10
  const rangeEnd = range.e;
11
11
  const rangeStart = range.s;
@@ -17,7 +17,9 @@ class XLSXUtil {
17
17
  const cell = sheet[cellAddress];
18
18
  if (!(cell.t == 's' || cell.t == 'str'))
19
19
  continue;
20
- if ((0, lodash_es_1.trim)(cell.v) === (0, lodash_es_1.trim)(text))
20
+ if ((0, lodash_es_1.isEmpty)(cell.v))
21
+ continue;
22
+ if (cell.v.replace(/\s/g, '') === text.replace(/\s/g, ''))
21
23
  return xlsx_1.utils.decode_cell(cellAddress);
22
24
  }
23
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ashray.mehta/statement-converter",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Library to convert statements from frequently used banks to QIF.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",