ananthakumaran / paisa

Paisa – Personal Finance Manager. https://paisa.fyi demo: https://demo.paisa.fyi
https://paisa.fyi
GNU Affero General Public License v3.0
2.34k stars 117 forks source link

`findAbove` returns the current row value #57

Closed pashagolub closed 10 months ago

pashagolub commented 10 months ago

If I try to find the value from a previous row, I always get the current row value, which is not what I expect from the function with findAbove name.

The fix is trivial:

  findAbove(column: string, options: any) {
    const regexp = new RegExp(options.hash.regexp || ".+");
    let i: number = options.data.root.ROW.index - 1; 
                                            ^^^^^^^
    while (i >= 0) {
      const row = options.data.root.SHEET[i];
      const cell = row[column] || "";
      const match = cell.match(regexp);
      if (match) {
        if (options.hash.group) {
          return match[options.hash.group];
        }
        return cell;
      }
      i--;
    }
    return null;
  },