diff --git a/src/lib/db.js b/src/lib/db.js index 2d4944d..7235c50 100644 --- a/src/lib/db.js +++ b/src/lib/db.js @@ -271,7 +271,8 @@ export async function getTransactions(accountId) { transaction.notes as notes, transaction.payee as payee, transaction.date as date, - transaction.statement_description as statement_description + transaction.statement_description as statement_description, + transaction.out_of_budget as out_of_budget from transaction where account_id = ${accountId} order by date desc @@ -289,6 +290,15 @@ export async function setTransactionNote(transactionId, note) { return result; } +export async function setTransactionOutOfBudget(transactionId, oob) { + const result = await db` + update transaction + set out_of_budget = ${oob} + where id = ${transactionId} + `; + return result; +} + export async function getRules(data) { try { const rules = await db` diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 1bb2d63..32adbc9 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -41,7 +41,7 @@
{@render children()} diff --git a/src/routes/account/[slug]/+page.svelte b/src/routes/account/[slug]/+page.svelte index 055bc70..57e60e3 100644 --- a/src/routes/account/[slug]/+page.svelte +++ b/src/routes/account/[slug]/+page.svelte @@ -11,7 +11,7 @@ let budgets = $derived(data.budgets); let budgetTransactions = $derived(data.budgetTransactions); let notes = $state(''); - let currentTransaction = $state({ budget_id: null, amount: 0, notes: '' }); + let currentTransaction = $state({ budget_id: null, amount: 0, notes: '', out_of_budget: false }); let account = $derived(data.account); let hide = $derived(account?.hide || false); let inTotal = $derived(account?.in_total || false); @@ -31,7 +31,10 @@ headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ notes: $state.snapshot(notes) }) + body: JSON.stringify({ + notes: $state.snapshot(notes), + out_of_budget: currentTransaction.out_of_budget + }) }); loading = false; let result = await res; @@ -40,6 +43,7 @@ currentTransaction.notes = notes; // Optionally, you can also update the UI or show a success message addToast('Notes saved successfully', 'success'); + invalidateAll(); } else { // Handle error case console.error('Failed to save notes'); @@ -93,30 +97,39 @@ )} {@const remaining = transaction.amount - budgetTotal}{currentTransaction?.date?.toDateString()}
+ + diff --git a/src/routes/transcation/[slug]/+server.js b/src/routes/transcation/[slug]/+server.js index 8cf21ea..4d91472 100644 --- a/src/routes/transcation/[slug]/+server.js +++ b/src/routes/transcation/[slug]/+server.js @@ -1,13 +1,18 @@ -import {setTransactionNote} from '$lib/db'; +import { setTransactionNote, setTransactionOutOfBudget } from '$lib/db'; export async function POST(request) { - let body = await request.request.json(); - let res = await setTransactionNote(request.params.slug, body.notes); + let body = await request.request.json(); - return new Response(JSON.stringify({success: true}), { - headers: { - 'Content-Type': 'application/json' - } - }); + let res; + + if (body.notes !== undefined) await setTransactionNote(request.params.slug, body.notes); + + if (body.out_of_budget !== undefined) + res = await setTransactionOutOfBudget(request.params.slug, body.out_of_budget); + + return new Response(JSON.stringify({ success: true }), { + headers: { + 'Content-Type': 'application/json' + } + }); } -