✨ 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[];
|
expenses: ExpenseView[];
|
||||||
participants: ParticipantView[];
|
participants: ParticipantView[];
|
||||||
currency: string;
|
currency: string;
|
||||||
|
currentParticipantId?: number;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -37,10 +38,52 @@ function toggle(id: number) {
|
|||||||
const sorted = computed(() =>
|
const sorted = computed(() =>
|
||||||
[...props.expenses].sort((a, b) => b.createdAt - a.createdAt),
|
[...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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="space-y-3">
|
<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
|
<p
|
||||||
v-if="expenses.length === 0"
|
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"
|
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"
|
:expenses="data.expenses"
|
||||||
:participants="data.participants"
|
:participants="data.participants"
|
||||||
:currency="data.pot.currency"
|
:currency="data.pot.currency"
|
||||||
|
:current-participant-id="me?.id"
|
||||||
@edit="editExpense"
|
@edit="editExpense"
|
||||||
@remove="removeExpense"
|
@remove="removeExpense"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
},
|
},
|
||||||
"expenses": {
|
"expenses": {
|
||||||
"empty": "Noch keine Ausgaben. Füge die erste unten hinzu.",
|
"empty": "Noch keine Ausgaben. Füge die erste unten hinzu.",
|
||||||
|
"total": "Gesamtausgaben",
|
||||||
|
"mine": "Deine Ausgaben",
|
||||||
"addExpense": "+ Ausgabe hinzufügen",
|
"addExpense": "+ Ausgabe hinzufügen",
|
||||||
"paidBy": "bezahlt von {name}",
|
"paidBy": "bezahlt von {name}",
|
||||||
"paymentDescription": "{payer} hat {recipient} bezahlt",
|
"paymentDescription": "{payer} hat {recipient} bezahlt",
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
},
|
},
|
||||||
"expenses": {
|
"expenses": {
|
||||||
"empty": "No expenses yet. Add the first one below.",
|
"empty": "No expenses yet. Add the first one below.",
|
||||||
|
"total": "Total expenses",
|
||||||
|
"mine": "Your expenses",
|
||||||
"addExpense": "+ Add expense",
|
"addExpense": "+ Add expense",
|
||||||
"paidBy": "paid by {name}",
|
"paidBy": "paid by {name}",
|
||||||
"paymentDescription": "{payer} paid {recipient}",
|
"paymentDescription": "{payer} paid {recipient}",
|
||||||
|
|||||||
Reference in new issue
Block a user