+ )}
+
+ );
+}
diff --git a/client/src/components/Budget/receiptLinks.test.ts b/client/src/components/Budget/receiptLinks.test.ts
new file mode 100644
index 000000000..cfd4291aa
--- /dev/null
+++ b/client/src/components/Budget/receiptLinks.test.ts
@@ -0,0 +1,39 @@
+// FE-BUDGET-RCPTLINK-001 to FE-BUDGET-RCPTLINK-003
+import { describe, expect, it } from 'vitest';
+
+import { buildTripFile } from '../../../tests/helpers/factories';
+import { linkableReceiptFiles, receiptOfFile } from './receiptLinks';
+
+const names = (files: { original_name: string }[]) => files.map((f) => f.original_name);
+
+describe('receipt links (#2839)', () => {
+ const menu = buildTripFile({ id: 1, original_name: 'menu.jpg' });
+ const confirmation = buildTripFile({ id: 2, original_name: 'hotel-confirmation.pdf', reservation_id: 7 });
+ const linked = buildTripFile({ id: 3, original_name: 'hotel-invoice.pdf', linked_reservation_ids: [9, 7] });
+ const binned = buildTripFile({ id: 4, original_name: 'old.pdf', deleted_at: '2026-01-01 10:00:00' });
+
+ it('FE-BUDGET-RCPTLINK-001: offers the live files the expense does not carry yet', () => {
+ const files = linkableReceiptFiles([menu, confirmation, linked, binned], [receiptOfFile(linked)], null);
+ expect(names(files)).toEqual(['menu.jpg', 'hotel-confirmation.pdf']);
+ });
+
+ it("FE-BUDGET-RCPTLINK-002: the booking's own files lead, by its column or a link row", () => {
+ expect(names(linkableReceiptFiles([menu, confirmation, linked], [], 7))).toEqual([
+ 'hotel-confirmation.pdf',
+ 'hotel-invoice.pdf',
+ 'menu.jpg',
+ ]);
+ expect(names(linkableReceiptFiles([menu, confirmation], [], 8))).toEqual(['menu.jpg', 'hotel-confirmation.pdf']);
+ });
+
+ it('FE-BUDGET-RCPTLINK-003: a file reads as a receipt row under its own id and download path', () => {
+ expect(receiptOfFile(confirmation)).toEqual({
+ id: 2,
+ filename: 'test.pdf',
+ original_name: 'hotel-confirmation.pdf',
+ file_size: null,
+ mime_type: 'application/pdf',
+ url: '/api/trips/1/files/2/download',
+ });
+ });
+});
diff --git a/client/src/components/Budget/receiptLinks.ts b/client/src/components/Budget/receiptLinks.ts
new file mode 100644
index 000000000..02a7905aa
--- /dev/null
+++ b/client/src/components/Budget/receiptLinks.ts
@@ -0,0 +1,37 @@
+import type { BudgetItemReceipt, TripFile } from '../../types';
+
+/** A file of the booking: its own column names it, or one of its link rows does. */
+function onBooking(file: TripFile, reservationId: number): boolean {
+ return Number(file.reservation_id) === reservationId || (file.linked_reservation_ids || []).includes(reservationId);
+}
+
+/**
+ * The trip's files an expense could take as a receipt (#2839): the ones not in
+ * the bin and not on the expense yet. A booking's confirmation is so often its
+ * invoice as well that the files of the booking the expense belongs to lead.
+ */
+export function linkableReceiptFiles(
+ files: readonly TripFile[],
+ receipts: readonly BudgetItemReceipt[],
+ reservationId: number | null | undefined
+): TripFile[] {
+ const taken = new Set(receipts.map((r) => r.id));
+ const live = files.filter((f) => !f.deleted_at && !taken.has(f.id));
+ if (!reservationId) return live;
+ return [...live.filter((f) => onBooking(f, reservationId)), ...live.filter((f) => !onBooking(f, reservationId))];
+}
+
+/**
+ * A trip file as the receipt row the editor lists. Nothing is written yet: the
+ * save sends its id with the others in `receipt_file_ids`, which links it.
+ */
+export function receiptOfFile(file: TripFile): BudgetItemReceipt {
+ return {
+ id: file.id,
+ filename: file.filename,
+ original_name: file.original_name,
+ file_size: file.file_size ?? null,
+ mime_type: file.mime_type,
+ url: file.url,
+ };
+}
diff --git a/client/src/components/Budget/useExpenseForm.test.ts b/client/src/components/Budget/useExpenseForm.test.ts
index 6a962e668..780f32e55 100644
--- a/client/src/components/Budget/useExpenseForm.test.ts
+++ b/client/src/components/Budget/useExpenseForm.test.ts
@@ -1,7 +1,7 @@
import { act, renderHook } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { buildBudgetItem, buildTrip } from '../../../tests/helpers/factories';
+import { buildBudgetItem, buildTrip, buildTripFile } from '../../../tests/helpers/factories';
import { resetAllStores } from '../../../tests/helpers/store';
import { clearExchangeRateCache } from '../../hooks/useExchangeRates';
import { useTripStore, type TripStoreState } from '../../store/tripStore';
@@ -21,7 +21,7 @@ vi.mock('./receiptUploads', () => ({
),
}));
-// FE-BUDGET-EXPFORM-001 to FE-BUDGET-EXPFORM-025
+// FE-BUDGET-EXPFORM-001 to FE-BUDGET-EXPFORM-026
const PEOPLE: TripMember[] = [
{ id: 1, username: 'alice', avatar_url: null },
@@ -475,6 +475,27 @@ describe('useExpenseForm: saving', () => {
expect(result.current.pendingReceiptFiles).toEqual([]);
});
+ it("FE-BUDGET-EXPFORM-026: a trip file linked as a receipt goes out with the save, the booking's files first (#2839)", async () => {
+ const menu = buildTripFile({ id: 21, original_name: 'menu.jpg' });
+ const confirmation = buildTripFile({ id: 22, original_name: 'confirmation.pdf', reservation_id: 4 });
+ const binned = buildTripFile({ id: 23, original_name: 'old.pdf', deleted_at: '2026-01-01 10:00:00' });
+ useTripStore.setState({ files: [menu, confirmation, binned] } as unknown as Partial);
+ const { result } = setup({ prefill: { reservationId: 4 } });
+ expect(result.current.linkableFiles.map((f) => f.id)).toEqual([22, 21]);
+
+ act(() => result.current.handleLinkReceipt(confirmation));
+ act(() => result.current.handleLinkReceipt(confirmation));
+ expect(result.current.receipts.map((r) => r.id)).toEqual([22]);
+ expect(result.current.linkableFiles.map((f) => f.id)).toEqual([21]);
+
+ fill(result, 'Hotel', '200');
+ await save(result);
+ expect(addBudgetItem).toHaveBeenCalledWith(
+ 7,
+ expect.objectContaining({ receipt_file_ids: [22], reservation_id: 4 })
+ );
+ });
+
it('FE-BUDGET-EXPFORM-017: a ticket split sends everyone a line names, ticked or not (#1382)', async () => {
const { result } = setup();
act(() => {
diff --git a/client/src/components/Budget/useExpenseForm.ts b/client/src/components/Budget/useExpenseForm.ts
index 131e4114f..d9385eeb9 100644
--- a/client/src/components/Budget/useExpenseForm.ts
+++ b/client/src/components/Budget/useExpenseForm.ts
@@ -3,7 +3,7 @@ import { useEffect, useEffectEvent, useMemo, useState } from 'react';
import { useTranslation } from '../../i18n';
import { useTripStore } from '../../store/tripStore';
import { isEffectivelyOffline } from '../../sync/networkMode';
-import type { BudgetItem, BudgetItemReceipt } from '../../types';
+import type { BudgetItem, BudgetItemReceipt, TripFile } from '../../types';
import { amountToInputString } from '../../utils/formatters';
import { localToday } from '../Planner/today';
import { useToast } from '../shared/Toast';
@@ -28,6 +28,7 @@ import {
import { catMeta } from './costsCategories';
import { currencyOptions } from './costsModel';
import { useExpenseFx } from './expenseFx';
+import { linkableReceiptFiles, receiptOfFile } from './receiptLinks';
import { saveWithReceipts } from './receiptUploads';
import { usePercentSplit } from './usePercentSplit';
@@ -71,6 +72,7 @@ export function useExpenseForm({
const toast = useToast();
const addBudgetItem = useTripStore((s) => s.addBudgetItem);
const updateBudgetItem = useTripStore((s) => s.updateBudgetItem);
+ const tripFiles = useTripStore((s) => s.files);
const sym = (c: string) => SYMBOLS[c] || c + ' ';
const nameOf = (p: TripMember) => (p.id === me ? t('costs.you') : p.username);
// A saved expense without a currency opens in the trip's own (#2525).
@@ -168,6 +170,16 @@ export function useExpenseForm({
setPendingReceiptFiles((prev) => [...prev, ...Array.from(files)]);
};
+ // A file the trip already has, such as the booking's confirmation, taken as a
+ // receipt (#2839). It joins the list and the save links it, uploaded nothing.
+ const linkableFiles = useMemo(
+ () => linkableReceiptFiles(tripFiles, receipts, editing ? editing.reservation_id : prefill?.reservationId),
+ [tripFiles, receipts, editing, prefill]
+ );
+ const handleLinkReceipt = (file: TripFile) => {
+ setReceipts((prev) => (prev.some((r) => r.id === file.id) ? prev : [...prev, receiptOfFile(file)]));
+ };
+
const handleRemoveReceipt = (receiptId: number) => {
setReceipts((prev) => prev.filter((r) => r.id !== receiptId));
};
@@ -408,11 +420,11 @@ export function useExpenseForm({
};
try {
setUploadingReceipt(pendingReceiptFiles.length > 0);
- await saveWithReceipts(tripId, pendingReceiptFiles, editing ? editing.id : null, (ids) =>
- editing
- ? updateBudgetItem(tripId, editing.id, { ...data, receipt_file_ids: [...receipts.map((r) => r.id), ...ids] })
- : addBudgetItem(tripId, { ...data, receipt_file_ids: ids })
- );
+ // The receipts listed (saved or linked from the trip's files) and the new uploads.
+ await saveWithReceipts(tripId, pendingReceiptFiles, editing ? editing.id : null, (ids) => {
+ const withReceipts = { ...data, receipt_file_ids: [...receipts.map((r) => r.id), ...ids] };
+ return editing ? updateBudgetItem(tripId, editing.id, withReceipts) : addBudgetItem(tripId, withReceipts);
+ });
// Only cleared once the save went through, so a retry after a failure
// does not upload a second copy of every file.
setPendingReceiptFiles([]);
@@ -483,6 +495,8 @@ export function useExpenseForm({
pendingReceiptFiles,
uploadingReceipt,
handleReceiptFileSelect,
+ linkableFiles,
+ handleLinkReceipt,
handleRemoveReceipt,
handleRemovePendingReceipt,
previewReceipts,
diff --git a/client/src/mobile/screens/trip/sheets/MCostSheet.tsx b/client/src/mobile/screens/trip/sheets/MCostSheet.tsx
index bd30243d0..6ea25cf13 100644
--- a/client/src/mobile/screens/trip/sheets/MCostSheet.tsx
+++ b/client/src/mobile/screens/trip/sheets/MCostSheet.tsx
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from 'react'
-import { ArrowRight, Check, ChevronDown, Plus, Trash2, Wallet, Receipt, Paperclip } from 'lucide-react'
+import { ArrowRight, Check, ChevronDown, FileText, Link2, Plus, Trash2, Wallet, Receipt, Paperclip } from 'lucide-react'
import MSheet from '../../../components/MSheet'
import CustomSelect from '../../../../components/shared/CustomSelect'
import { NumericInput } from '../../../../components/shared/NumericInput'
@@ -66,6 +66,7 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
ticketInfo, handleAddEmptyItem, handleUpdateItemName, handleUpdateItemPrice, handleRemoveItem, handleToggleItemParticipant,
customAmounts, handleCustomAmountChange, splitUnits, splitSum, customBalanced, each, equalShares, placeholderShares,
receipts, pendingReceiptFiles, uploadingReceipt, handleReceiptFileSelect, handleRemoveReceipt, handleRemovePendingReceipt,
+ linkableFiles, handleLinkReceipt,
previewReceipts, setPreviewReceipts, valid, saving, save,
} = useExpenseForm({ tripId, base, people, me, editing, prefill, onSaved, oneSaveAtATime: true, keepSavingOnSuccess: true })
@@ -80,6 +81,8 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
}
const [catOpen, setCatOpen] = useState(false)
+ // The trip's files to link as a receipt (#2839), folded open under the receipts header.
+ const [linkingReceipt, setLinkingReceipt] = useState(false)
const [deleteArmed, setDeleteArmed] = useState(false)
const handleDelete = async () => {
@@ -504,26 +507,56 @@ export default function MCostSheet({ tripId, base, people, me, editing, prefill,
className={FIELD_AREA_CLS}
/>
- {/* RECEIPTS */}
-
- {t('costs.receiptsTitle') || t('costs.receipts')}
-
+ {/* RECEIPTS. Where the header and both pills do not fit on one line, the
+ pills move under it rather than squeezing the title. */}
+
{t('common.saving')}...
diff --git a/client/tests/unit/mobile/trip/MCostSheet.test.tsx b/client/tests/unit/mobile/trip/MCostSheet.test.tsx
index bb5969950..6f2596113 100644
--- a/client/tests/unit/mobile/trip/MCostSheet.test.tsx
+++ b/client/tests/unit/mobile/trip/MCostSheet.test.tsx
@@ -5,12 +5,12 @@ import type { TripMember } from '../../../../src/components/Budget/BudgetPanelMe
import { clearExchangeRateCache } from '../../../../src/hooks/useExchangeRates'
import { useTripStore, type TripStoreState } from '../../../../src/store/tripStore'
import type { BudgetItem, BudgetItemMember } from '../../../../src/types'
-import { buildBudgetItem, buildTrip } from '../../../helpers/factories'
+import { buildBudgetItem, buildTrip, buildTripFile } from '../../../helpers/factories'
import { localToday } from '../../../../src/components/Planner/today'
import { resetAllStores } from '../../../helpers/store'
import { act, fireEvent, render, screen, waitFor } from '../../../helpers/render'
-// FE-MOB-COSTSH-001 to FE-MOB-COSTSH-040
+// FE-MOB-COSTSH-001 to FE-MOB-COSTSH-041
// The sheet reads its copy from useTranslation(), so assertions are English.
// EUR formats de-DE style: displayed amounts and inputs use a comma.
@@ -775,4 +775,19 @@ describe('MCostSheet', () => {
expect(screen.getByText('18,00 €')).toBeInTheDocument()
expect(submit()).toBeEnabled()
})
+
+ it('FE-MOB-COSTSH-041: a trip file is linked as a receipt and saved with the expense (#2839)', async () => {
+ useTripStore.setState({ files: [buildTripFile({ id: 51, original_name: 'hotel-confirmation.pdf' })] } as unknown as Partial)
+ renderSheet()
+ fillBasics('Hotel', '200')
+ fireEvent.click(screen.getByRole('button', { name: 'Link' }))
+ fireEvent.click(screen.getByRole('button', { name: 'hotel-confirmation.pdf' }))
+ // Listed with the receipts now, and nothing is left to link.
+ expect(screen.getByRole('button', { name: 'hotel-confirmation.pdf' })).toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'Link' })).toBeNull()
+
+ fireEvent.click(submit())
+ await waitFor(() => expect(addBudgetItem).toHaveBeenCalledTimes(1))
+ expect(addBudgetItem.mock.calls[0][1]).toMatchObject({ receipt_file_ids: [51] })
+ })
})
diff --git a/wiki/Budget-Tracking.md b/wiki/Budget-Tracking.md
index 114d9da12..3a893f28a 100644
--- a/wiki/Budget-Tracking.md
+++ b/wiki/Budget-Tracking.md
@@ -104,6 +104,8 @@ On the phone the booking, transport and place sheets carry the same block. Tap a
An expense can carry the receipt or invoice behind it. **Attach** in the **Receipts & Invoices** block of the expense dialog opens the file picker for images and PDFs, and several files can go on one expense. They are uploaded when the expense is saved, land in the trip's Files with a link to the expense, and are listed in the block from then on; click a name to view it. If the save fails after the upload, the uploaded files are taken back out again. Any that could not be removed are reported (*Save failed, and 1 uploaded receipt is still there. Remove it in the Files tab.*), so you can delete them there.
+A file the trip already has can be the receipt too, so a booking confirmation that doubles as the invoice is not uploaded a second time. **Link**, beside **Attach** while the trip has files the expense does not carry yet, lists them: the files of the booking the expense belongs to come first, and a click puts one on the expense. Like an attached file it is linked when you save, and nothing is uploaded. The file keeps its other links, and **Remove receipt** only takes it off the expense again. The phone sheet has the same **Link** pill beside **Attach receipt / invoice**.
+
Receipts need a connection. If you are offline, the dialog says *Receipts need a connection to upload. Remove the new ones to save the expense offline, or save once you are back online.* An expense without new receipts can be saved offline.
A row with receipts shows a **Receipts** chip beside the name, with the count when there is more than one. Click it to open the viewer: it shows one receipt at a time, pages through them with the **arrow keys**, and offers a download for a PDF.