Add basic receipt logging

This commit is contained in:
2026-01-19 13:53:42 +01:00
parent e5933aacc2
commit e9d795fdf1
5 changed files with 169 additions and 45 deletions

View File

@@ -38,23 +38,39 @@ async function initDB(db) {
CREATE TABLE IF NOT EXISTS bot_config (
id INTEGER PRIMARY KEY CHECK (id = 1),
weekly_budget REAL DEFAULT 0,
exchange_rate_eur_kr REAL DEFAULT 0,
last_budget_notification_date TEXT
last_date_msg_receipts DATE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
`);
await db.exec(`
CREATE TABLE IF NOT EXISTS grocery_budgets (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
discord_id VARCHAR(50) NOT NULL,
budget_spent REAL,
total_spent REAL
CREATE TABLE IF NOT EXISTS grocery_spendings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
discord_id VARCHAR(50) NOT NULL,
message_id VARCHAR(50) NOT NULL,
message_raw TEXT DEFAULT "-",
amount DECIMAL(10, 2) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
budget_id INTEGER,
FOREIGN KEY (budget_id) REFERENCES weekly_budgets(id)
);
`);
await db.exec(`
CREATE TABLE IF NOT EXISTS weekly_budgets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
budget_amount DECIMAL(10, 2) NOT NULL,
exchange_rate DECIMAL(10, 6) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT date_check CHECK (end_date > start_date)
);
CREATE INDEX IF NOT EXISTS idx_budget_dates ON weekly_budgets (start_date, end_date);
`);
// Optional: Initialize the row if it doesn't exist yet
await db.exec(`
INSERT OR IGNORE INTO bot_config (id, weekly_budget, last_budget_notification_date)
VALUES (1, 0, NULL);
INSERT OR IGNORE INTO bot_config (id, weekly_budget)
VALUES (1, 10);
`);
console.log('[DATABASE] Created new DB table');
}