Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 49 additions & 52 deletions m1well.Expenses/src/expenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,58 +141,55 @@ const expensesTracking = async (): Promise<boolean> => {
*
* @returns {Promise<boolean>}
*/
const expensesAggregate = async (): Promise<boolean> => {
let config = await provideConfig()
config = validateConfig(config, new Date())

if (!config.folderPath) {
return false
}

const year = Number(await CommandBar.showInput('Please type in the year to aggregate', 'Start aggregate'))

const noteTitleTracking = `${year} Expenses Tracking`
if (!(await provideAndCheckNote(noteTitleTracking, config.folderPath, false, year))) {
return false
}

const trackingNote = DataStore.projectNoteByTitle(noteTitleTracking)?.[0]

if (trackingNote) {
const trackedData = trackingNote.paragraphs.filter((para) => !para.rawContent.startsWith('#')).map((para) => extractExpenseRowFromCsvRow(para.rawContent, config))

if (!checkDataQualityBeforeAggregate(trackedData, year, config)) {
return false
}

const aggregatedData = aggregateByCategoriesAndMonth(trackedData, config.delimiter)

const noteTitleAggregate = `${year} Expenses Aggregate`
if (!(await provideAndCheckNote(noteTitleAggregate, config.folderPath, true))) {
return false
}

const lines: Array<string> = []

if (aggregatedData.length > 0) {
await Editor.openNoteByTitle(noteTitleAggregate)
const note = Editor.note
if (note) {
note.removeParagraphs(note.paragraphs.filter((para) => !para.rawContent.startsWith('#')))
// add results
aggregatedData.forEach((aggregated) => {
if (aggregated.year) {
lines.push(createAggregationExpenseRowWithDelimiter(aggregated, config))
}
})
note.appendParagraph(lines.join('\n'), 'text')
return true
}
}
}

return false
}
const expensesAggregate = async () => {
Copy link
Collaborator

@dwertheimer dwertheimer Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function needs typing (see original code):
: Promise<boolean>

let config = await provideConfig();
config = validateConfig(config, new Date());

if (!config.folderPath) {
return false;
}

const year = Number(await CommandBar.showInput('Please type in the year to aggregate', 'Start aggregate'));

const noteTitleTracking = `${year} Expenses Tracking`;
if (!(await provideAndCheckNote(noteTitleTracking, config.folderPath, false, year))) {
return false;
}
const trackingNote = DataStore.projectNoteByTitle(noteTitleTracking)?.[0];

if (trackingNote) {
const trackedData = trackingNote.paragraphs.filter(para => para.rawContent && !para.rawContent.startsWith('#')).map(para => extractExpenseRowFromCsvRow(para.rawContent, config));

if (!checkDataQualityBeforeAggregate(trackedData, year, config)) {
return false;
}

const aggregatedData = aggregateByCategoriesAndMonth(trackedData, config.delimiter);

const noteTitleAggregate = `${year} Expenses Aggregate`;
if (!(await provideAndCheckNote(noteTitleAggregate, config.folderPath, true))) {
return false;
}

const lines = [];
if (aggregatedData.length > 0) {
await Editor.openNoteByTitle(noteTitleAggregate);
const note = Editor.note;
if (note) {
note.removeParagraphs(note.paragraphs.filter(para => !para.rawContent.startsWith('#')));
// add results
aggregatedData.forEach(aggregated => {
if (aggregated.year) {
lines.push(createAggregationExpenseRowWithDelimiter(aggregated, config));
}
});
note.appendParagraph(lines.join('\n'), 'text');
return true;
}
}
}
return false;
};

/**
* tracking of individual expenses
Expand Down