fix KBB picking the wrong last transaction date

This commit is contained in:
Robert Dyer
2024-09-17 14:24:47 -05:00
parent 0fd83a7cf4
commit c81550190b
2 changed files with 11 additions and 8 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ async function getKBB(URL) {
if (diff != 0) {
const daily = parseInt(getTagValue(note, 'kbbDailyMileage'));
if (mileage && daily) {
let lastDate = await getLastTransactionDate(account);
let lastDate = await getLastTransactionDate(account, undefined, true);
const parts = lastDate.split('-');
lastDate = new Date(parts[0], parts[1] - 1, parts[2]);
if (lastDate < new Date()) {
+10 -7
View File
@@ -65,18 +65,21 @@ const Utils = {
return data.data;
},
getLastTransactionDate: async function (account, cutoffDate=undefined) {
if (cutoffDate === undefined) {
getLastTransactionDate: async function (account, cutoffDate=undefined, inbound=false) {
if (cutoffDate === undefined || cutoffDate === null) {
cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() + 1);
}
const filters = {
'account': account.id,
'date': { $lt: cutoffDate },
};
if (!inbound) {
filters['amount'] = { $gt: 0 };
}
const data = await api.runQuery(
api.q('transactions')
.filter({
'account': account.id,
'date': { $lt: cutoffDate },
'amount': { $gt: 0 },
})
.filter(filters)
.select('date')
.orderBy({ 'date': 'desc' })
.limit(1)