Skip to content

Commit

Permalink
feat: list payments in moovements page
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Jun 10, 2024
1 parent 9bf2c97 commit e60a194
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -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(
Expand Down
30 changes: 22 additions & 8 deletions my-app/src/routes/groups/movements/[id=integer]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,14 +117,25 @@
</div>
</article>

{#each data.spendings as spending}
<article class="grid">
<p>{formatDateTimeString(spending.date)}</p>
<!-- TODO: show category name -->
<p>{spending.category_id}</p>
<p>{spending.description}</p>
<p class="text-right">{formatMoney(spending.amount)}</p>
</article>
{#each movements as movement}
{#if 'category_id' in movement}
{@const spending = movement}
<article class="grid">
<p>{formatDateTimeString(spending.date)}</p>
<!-- TODO: show category name -->
<p>{spending.category_id}</p>
<p>{spending.description}</p>
<p class="text-right">{formatMoney(spending.amount)}</p>
</article>
{:else}
{@const payment = movement}
<article class="grid">
<p>{formatDateTimeString(payment.date)}</p>
<!-- TODO: show user email -->
<p>{payment.from_id} → {payment.to_id}</p>
<p class="text-right">{formatMoney(payment.amount)}</p>
</article>
{/if}
{/each}

<style>
Expand Down

0 comments on commit e60a194

Please sign in to comment.