diff --git a/my-app/src/routes/groups/movements/[id=integer]/+page.server.ts b/my-app/src/routes/groups/movements/[id=integer]/+page.server.ts index 548ca68..d251415 100644 --- a/my-app/src/routes/groups/movements/[id=integer]/+page.server.ts +++ b/my-app/src/routes/groups/movements/[id=integer]/+page.server.ts @@ -1,4 +1,4 @@ -import { budgetService, categoryService, groupService, spendingService } from '$lib/server/api'; +import { budgetService, categoryService, groupService, paymentService, spendingService } from '$lib/server/api'; import type { PageServerLoad } from './$types'; export const load: PageServerLoad = async ({ cookies, params }) => { @@ -7,13 +7,14 @@ export const load: PageServerLoad = async ({ cookies, params }) => { const spendings: Spending[] = await spendingService.list(id, cookies); const budgets: Budget[] = await budgetService.list(id, cookies); const categories: Category[] = await categoryService.list(id, cookies); + const payments: Payment[] = await paymentService.list(id, cookies); const categoryBalances: CategoryBalance[] = computeBalancesPerCategory( spendings, budgets, categories ); - return { group, spendings, budgets, categories, categoryBalances }; + return { group, spendings, payments, budgets, categories, categoryBalances }; }; function computeBalancesPerCategory( diff --git a/my-app/src/routes/groups/movements/[id=integer]/+page.svelte b/my-app/src/routes/groups/movements/[id=integer]/+page.svelte index 18d1ecd..22144ac 100644 --- a/my-app/src/routes/groups/movements/[id=integer]/+page.svelte +++ b/my-app/src/routes/groups/movements/[id=integer]/+page.svelte @@ -6,6 +6,9 @@ export let data: PageServerData; + const movements = [...data.spendings, ...data.payments]; + movements.sort((a, b) => Date.parse(b.date) - Date.parse(a.date)); + const totalBudgets = data?.categoryBalances.reduce((acc, { budgets }) => acc + budgets, 0); const totalSpendings = data?.categoryBalances.reduce((acc, { spendings }) => acc + spendings, 0); const totalBalance = totalBudgets - totalSpendings; @@ -114,14 +117,25 @@ -{#each data.spendings as spending} -
-

{formatDateTimeString(spending.date)}

- -

{spending.category_id}

-

{spending.description}

-

{formatMoney(spending.amount)}

-
+{#each movements as movement} + {#if 'category_id' in movement} + {@const spending = movement} +
+

{formatDateTimeString(spending.date)}

+ +

{spending.category_id}

+

{spending.description}

+

{formatMoney(spending.amount)}

+
+ {:else} + {@const payment = movement} +
+

{formatDateTimeString(payment.date)}

+ +

{payment.from_id} → {payment.to_id}

+

{formatMoney(payment.amount)}

+
+ {/if} {/each}