33 lines
943 B
JavaScript
33 lines
943 B
JavaScript
import { getCategoryLabel } from './categories.js';
|
|
export function exportToCsv(receipts) {
|
|
const headers = ['Date', 'Vendor', 'Title', 'Category', 'Amount', 'Currency', 'Notes', 'Source'];
|
|
const rows = receipts.map((r) => [
|
|
r.date,
|
|
r.vendor,
|
|
r.title,
|
|
getCategoryLabel(r.category),
|
|
r.amount.toFixed(2),
|
|
r.currency,
|
|
r.notes,
|
|
r.source,
|
|
]);
|
|
const csv = [headers, ...rows]
|
|
.map((row) => row
|
|
.map((cell) => {
|
|
const str = String(cell).replace(/"/g, '""');
|
|
return `"${str}"`;
|
|
})
|
|
.join(','))
|
|
.join('\n');
|
|
return csv;
|
|
}
|
|
export function downloadBlob(content, filename, mimeType) {
|
|
const blob = new Blob([content], { type: mimeType });
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|