Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions m1well.Expenses/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# m1well.Expenses Plugin Changelog

## [1.7.4] - 2025-08-07 (@bono2007)
### Changed
- fix problem with /exp:agg

## [1.7.3] - 2022-07-23 (@dwertheimer)
### Changed
- add more descriptive text for text input
Expand Down
3 changes: 2 additions & 1 deletion m1well.Expenses/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"plugin.description": "Plugin to track your expenses for further analyis",
"plugin.author": "@m1well",
"plugin.url": "https://github.com/NotePlan/plugins/blob/main/m1well.Expenses/README.md",
"plugin.version": "1.7.3",
"plugin.version": "1.7.4",
"lastUpdate": "Fix problem with /exp:agg command when config is missing",
"plugin.dependencies": [],
"plugin.script": "script.js",
"plugin.commands": [
Expand Down
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: () => Promise<boolean> = async () => {
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