✨ show total expense amount and your part
This commit is contained in:
4 files changed
+48
No files matched your search
@@ -5,6 +5,7 @@ const props = defineProps<{
|
||||
expenses: ExpenseView[];
|
||||
participants: ParticipantView[];
|
||||
currency: string;
|
||||
currentParticipantId?: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -37,10 +38,52 @@ function toggle(id: number) {
|
||||
const sorted = computed(() =>
|
||||
[...props.expenses].sort((a, b) => b.createdAt - a.createdAt),
|
||||
);
|
||||
|
||||
const totalExpensesCents = computed(() =>
|
||||
props.expenses
|
||||
.filter((expense) => expense.type === 'expense')
|
||||
.reduce((sum, expense) => sum + expense.amountCents, 0),
|
||||
);
|
||||
|
||||
const myExpensesCents = computed(() => {
|
||||
const myId = props.currentParticipantId;
|
||||
if (myId === undefined) return 0;
|
||||
return props.expenses
|
||||
.filter(
|
||||
(expense) =>
|
||||
expense.type === 'expense' && expense.participantIds.includes(myId),
|
||||
)
|
||||
.reduce((sum, expense) => {
|
||||
const shares = computeSplit(expense.amountCents, expense.participantIds);
|
||||
return sum + (shares[myId] ?? 0);
|
||||
}, 0);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-3">
|
||||
<div
|
||||
v-if="expenses.length > 0"
|
||||
class="flex gap-3 rounded-2xl border border-stone-200 bg-white p-4 shadow-sm dark:border-stone-800 dark:bg-stone-900"
|
||||
>
|
||||
<div class="flex-1">
|
||||
<p class="text-xs text-stone-500 dark:text-stone-400">
|
||||
{{ t('expenses.total') }}
|
||||
</p>
|
||||
<p class="font-medium text-stone-900 dark:text-stone-100">
|
||||
{{ formatCurrency(totalExpensesCents, currency) }}
|
||||
</p>
|
||||
</div>
|
||||
<div v-if="currentParticipantId !== undefined" class="flex-1">
|
||||
<p class="text-xs text-stone-500 dark:text-stone-400">
|
||||
{{ t('expenses.mine') }}
|
||||
</p>
|
||||
<p class="font-medium text-orange-600 dark:text-orange-400">
|
||||
{{ formatCurrency(myExpensesCents, currency) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="expenses.length === 0"
|
||||
class="rounded-2xl border border-dashed border-stone-300 p-4 text-center text-sm text-stone-500 dark:border-stone-700 dark:text-stone-400"
|
||||
|
||||
@@ -69,6 +69,7 @@ async function removeExpense(id: number) {
|
||||
:expenses="data.expenses"
|
||||
:participants="data.participants"
|
||||
:currency="data.pot.currency"
|
||||
:current-participant-id="me?.id"
|
||||
@edit="editExpense"
|
||||
@remove="removeExpense"
|
||||
/>
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
},
|
||||
"expenses": {
|
||||
"empty": "Noch keine Ausgaben. Füge die erste unten hinzu.",
|
||||
"total": "Gesamtausgaben",
|
||||
"mine": "Deine Ausgaben",
|
||||
"addExpense": "+ Ausgabe hinzufügen",
|
||||
"paidBy": "bezahlt von {name}",
|
||||
"paymentDescription": "{payer} hat {recipient} bezahlt",
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
},
|
||||
"expenses": {
|
||||
"empty": "No expenses yet. Add the first one below.",
|
||||
"total": "Total expenses",
|
||||
"mine": "Your expenses",
|
||||
"addExpense": "+ Add expense",
|
||||
"paidBy": "paid by {name}",
|
||||
"paymentDescription": "{payer} paid {recipient}",
|
||||
|
||||
Reference in new issue
Block a user