From 7ca5f67c1b8c321a45b8cbd2e0d5257218af3756 Mon Sep 17 00:00:00 2001 From: Casey Timm Date: Fri, 1 Aug 2025 10:18:29 -0400 Subject: [PATCH] Making things nicer --- package.json | 4 +- src/app.html | 23 +- src/lib/budgetlist.svelte | 234 ++++++++++++++++++ src/lib/db.js | 16 ++ src/lib/editTransaction.svelte | 2 +- src/lib/united.js | 13 +- src/routes/(protected)/+layout.svelte | 2 +- src/routes/(protected)/+page.server.js | 6 +- src/routes/(protected)/+page.svelte | 23 +- .../(protected)/budget/[slug]/+page.svelte | 231 +---------------- vite.config.js | 4 + 11 files changed, 300 insertions(+), 258 deletions(-) create mode 100644 src/lib/budgetlist.svelte diff --git a/package.json b/package.json index 7d95975..033513b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "0.0.1", "type": "module", "scripts": { - "dev": "vite dev --host", + "dev": "vite dev --host --port 3000", "build": "vite build", "preview": "vite preview", "prepare": "svelte-kit sync || echo ''", @@ -40,4 +40,4 @@ "puppeteer-extra-plugin-stealth": "^2.11.2", "tailwindcss": "^4.1.11" } -} +} \ No newline at end of file diff --git a/src/app.html b/src/app.html index 1391f88..af68be5 100644 --- a/src/app.html +++ b/src/app.html @@ -1,12 +1,15 @@ - - - - - %sveltekit.head% - - -
%sveltekit.body%
- - + + + + + + %sveltekit.head% + + + +
%sveltekit.body%
+ + + \ No newline at end of file diff --git a/src/lib/budgetlist.svelte b/src/lib/budgetlist.svelte new file mode 100644 index 0000000..32adf5a --- /dev/null +++ b/src/lib/budgetlist.svelte @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + +{#if loading} + {@render loadingModal()} +{/if} diff --git a/src/lib/db.js b/src/lib/db.js index 4cbaa4f..226b2dd 100644 --- a/src/lib/db.js +++ b/src/lib/db.js @@ -568,6 +568,22 @@ export async function getUnderallocatedTransactions() { return result; } +export async function getOrphanedTransactions() { + const result = await db` + SELECT budget.name as budget_name, + budget_transaction.id as trans_id, + budget_transaction.budget_id as budget_id, + budget_transaction.transaction_id as transaction_id, + budget_transaction.amount as budget_amount, + budget_transaction.notes as notes + FROM budget_transaction + LEFT JOIN budget on budget_id = budget.id + WHERE transaction_id IS NULL + `; + // result = Result [{ id: 1, amount: 100.00, notes: "Unallocated funds" }, ...] + return result; +} + export async function getLast30DaysTransactionsSums() { let result = await db` SELECT cast(date as date) as date, SUM(amount) diff --git a/src/lib/editTransaction.svelte b/src/lib/editTransaction.svelte index b29bb7d..c71dcf9 100644 --- a/src/lib/editTransaction.svelte +++ b/src/lib/editTransaction.svelte @@ -8,7 +8,7 @@ let { transaction, close, budgets } = $props(); let id = $derived(transaction.id); let description = $derived(transaction.description || 'No description'); - let amount = $derived(transaction.amount || 0); + let amount = $derived(transaction.amount.toFixed(2) || 0); let date = $derived(new Date(transaction.date || Date.now())); let out_of_budget = $derived(transaction.out_of_budget || false); let budget_id = $derived(transaction.budget_id || null); diff --git a/src/lib/united.js b/src/lib/united.js index a2da1e9..dde85e3 100644 --- a/src/lib/united.js +++ b/src/lib/united.js @@ -21,6 +21,7 @@ export function isNeedCode() { export function isRunning() { return running; } + const browser = await chromium.launchPersistentContext('context', { channel: 'chrome', headless: false, @@ -186,9 +187,9 @@ export async function pullData(amount = 100) { state.push(`Checking for pending transactions for account ID: ${account.id}`); let currentPend = - await db`SELECT id, amount, description, date from transaction where account_id = ${account.id} AND pending=true`; + await db`SELECT id, amount, description, date from transaction where account_id = ${account.id} AND pending=true`; for (const pend of currentPend) { - const found = transactions.find((t) => `${t.postedDate}:${t.amount}` === pend.id && t.transactionType == "Memo"); + const found = transactions.find((t) => `${t.description}:${t.amount}` === pend.id && t.transactionType == "Memo"); if (found && found.transactionType != "Memo") {state.push( @@ -200,7 +201,7 @@ export async function pullData(amount = 100) { { state.push(`Orphaning no longer pending budget transaction with no new parent`); - await db`UPDATE budget_transaction SET transaction_id = null WHERE transaction_id = ${pend.id}`; + await db`UPDATE budget_transaction SET transaction_id = null, notes = notes || ${pend.description} WHERE transaction_id = ${pend.id}`; state.push(`Removing pending transaction: ${pend.id}`); await db`DELETE FROM transaction WHERE id = ${pend.id}`; } @@ -218,7 +219,7 @@ export async function pullData(amount = 100) { const accountId = transaction.accountId; const id = pending - ? `${transaction.postedDate}:${transaction.amount}` + ? `${transaction.description}:${transaction.amount}` : transaction.hostTranNumber; await db`INSERT INTO transaction ( @@ -251,7 +252,7 @@ export async function pullData(amount = 100) { pending = EXCLUDED.pending`; } } - +/* state.push('Orphaning transactions'); const orphaned = await db`SELECT bt.id as id @@ -262,7 +263,7 @@ export async function pullData(amount = 100) { state.push(`Orphaning transaction: ${orphan.id}`); await db`UPDATE budget_transaction set transaction_id = null where id = ${orphan.id}`; } - +*/ state.push('Done'); } catch (error) { console.error('Error in pullData:', error); diff --git a/src/routes/(protected)/+layout.svelte b/src/routes/(protected)/+layout.svelte index c8a10c9..5d54923 100644 --- a/src/routes/(protected)/+layout.svelte +++ b/src/routes/(protected)/+layout.svelte @@ -91,7 +91,7 @@
  • - -
    - -
    -
  • - {/each} - - - - - - + - - - - - - -{#if loading} - {@render loadingModal()} -{/if} diff --git a/vite.config.js b/vite.config.js index 4d92090..f27a544 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,4 +5,8 @@ import { SvelteKitPWA } from '@vite-pwa/sveltekit'; export default defineConfig({ plugins: [tailwindcss(), sveltekit(), SvelteKitPWA({registerType: 'autoUpdate', pwaAssets: { config: 'pwa-assets.config.js' }})], + server: { + allowedHosts: ['budget.caseytimm.com'] + + } });