Skip to content

Commit e8b1c86

Browse files
authored
fix: ledger-item filter method update (#78)
1 parent 7b79d31 commit e8b1c86

File tree

5 files changed

+160
-127
lines changed

5 files changed

+160
-127
lines changed

src/ledger/ledger-collection.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,15 @@ export class LedgerCollection implements ILedgerCollection {
245245
const quarter = getDateQuarter(date);
246246

247247
const boundary = this.filter((li) => {
248-
return li.dateLessThanOrEqualToAndQuarter(date, quarter);
248+
return li.dateLessThanOrEqualToAndQuarter(date, quarter) && li.typeMatches(LedgerItemType.CashFlow);
249249
});
250250

251251
if (boundary.length === 0) {
252252
return 0;
253253
}
254254

255-
const cashFlowItems = boundary.filter((x) => x.typeMatches(LedgerItemType.CashFlow));
256-
257-
if (cashFlowItems.length === 0) {
258-
return 0;
259-
}
260-
261-
const firstMonth = cashFlowItems[0].created.getUTCMonth();
262-
const lastMonth = cashFlowItems[cashFlowItems.length - 1].created.getUTCMonth();
255+
const firstMonth = boundary[0].created.getUTCMonth();
256+
const lastMonth = boundary[boundary.length - 1].created.getUTCMonth();
263257
const monthsWithData = lastMonth - firstMonth + 1;
264258

265259
if (monthsWithData <= 0) {

src/ledger/ledger-item.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class LedgerItem {
9393
return false;
9494
}
9595

96-
if (!this.dateLessThanOrEqualTo(date)) {
96+
if (!this.dateLessThanOrEqualTo(date) || !this.dateMatchesYear(date.getUTCFullYear())) {
9797
return false;
9898
}
9999

0 commit comments

Comments
 (0)