-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
37 lines (33 loc) · 1.05 KB
/
utils.js
File metadata and controls
37 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Formatting
function formatCurrency(value) {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
}).format(value || 0);
}
// Export
function exportData() {
const invoices = window.appState.invoices;
if (!invoices.length) {
alert('No data to export');
return;
}
// Prepare data for export
const data = invoices.map(inv => ({
Status: inv.is_duplicate ? 'DUPLICATE' : 'OK',
Date: inv.date,
InvoiceNumber: inv.invoice_number,
Vendor: inv.vendor,
Category: inv.category,
Description: inv.description,
Qty: inv.qty,
UnitCost: inv.unit_cost || inv.your_cost || 0,
TotalCost: ((inv.unit_cost || inv.your_cost || 0) * (inv.qty || 1)).toFixed(2)
}));
// Create Worksheet
const ws = XLSX.utils.json_to_sheet(data);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Invoices");
// Save File
XLSX.writeFile(wb, `InvoiceAI_Export_${new Date().toISOString().slice(0, 10)}.xlsx`);
}