braid-ui 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +91 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +91 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11081,6 +11081,65 @@ var NotFound = () => {
|
|
|
11081
11081
|
] }) });
|
|
11082
11082
|
};
|
|
11083
11083
|
var NotFound_default = NotFound;
|
|
11084
|
+
|
|
11085
|
+
// src/lib/utils/csv-utils.ts
|
|
11086
|
+
function escapeCsvValue(value) {
|
|
11087
|
+
const stringValue = String(value);
|
|
11088
|
+
if (stringValue.includes(",") || stringValue.includes('"') || stringValue.includes("\n")) {
|
|
11089
|
+
return `"${stringValue.replace(/"/g, '""')}"`;
|
|
11090
|
+
}
|
|
11091
|
+
return stringValue;
|
|
11092
|
+
}
|
|
11093
|
+
function generateStatementCSV(header, transactions) {
|
|
11094
|
+
const lines = [];
|
|
11095
|
+
lines.push("Statement Information");
|
|
11096
|
+
if (header.account) {
|
|
11097
|
+
lines.push(`Account,${escapeCsvValue(header.account)}`);
|
|
11098
|
+
}
|
|
11099
|
+
if (header.productId) {
|
|
11100
|
+
lines.push(`Product ID,${escapeCsvValue(header.productId)}`);
|
|
11101
|
+
}
|
|
11102
|
+
if (header.programId) {
|
|
11103
|
+
lines.push(`Program ID,${escapeCsvValue(header.programId)}`);
|
|
11104
|
+
}
|
|
11105
|
+
if (header.startDate) {
|
|
11106
|
+
lines.push(`Start Date,${escapeCsvValue(header.startDate)}`);
|
|
11107
|
+
}
|
|
11108
|
+
if (header.endDate) {
|
|
11109
|
+
lines.push(`End Date,${escapeCsvValue(header.endDate)}`);
|
|
11110
|
+
}
|
|
11111
|
+
if (header.startingBalance) {
|
|
11112
|
+
lines.push(`Starting Balance,${escapeCsvValue(header.startingBalance)}`);
|
|
11113
|
+
}
|
|
11114
|
+
if (header.endingBalance) {
|
|
11115
|
+
lines.push(`Ending Balance,${escapeCsvValue(header.endingBalance)}`);
|
|
11116
|
+
}
|
|
11117
|
+
lines.push("");
|
|
11118
|
+
lines.push("Transaction Summary");
|
|
11119
|
+
lines.push("Transaction Type,Direction,Amount,Count");
|
|
11120
|
+
transactions.forEach((transaction) => {
|
|
11121
|
+
const row = [
|
|
11122
|
+
escapeCsvValue(transaction.transactionType),
|
|
11123
|
+
escapeCsvValue(transaction.direction),
|
|
11124
|
+
escapeCsvValue(transaction.amount),
|
|
11125
|
+
escapeCsvValue(transaction.count)
|
|
11126
|
+
].join(",");
|
|
11127
|
+
lines.push(row);
|
|
11128
|
+
});
|
|
11129
|
+
return lines.join("\n");
|
|
11130
|
+
}
|
|
11131
|
+
function downloadCSV(content, filename) {
|
|
11132
|
+
const blob = new Blob([content], { type: "text/csv;charset=utf-8;" });
|
|
11133
|
+
const url = URL.createObjectURL(blob);
|
|
11134
|
+
const link = document.createElement("a");
|
|
11135
|
+
link.href = url;
|
|
11136
|
+
link.download = filename;
|
|
11137
|
+
link.style.display = "none";
|
|
11138
|
+
document.body.appendChild(link);
|
|
11139
|
+
link.click();
|
|
11140
|
+
document.body.removeChild(link);
|
|
11141
|
+
URL.revokeObjectURL(url);
|
|
11142
|
+
}
|
|
11084
11143
|
function Statement() {
|
|
11085
11144
|
const [statementType, setStatementType] = useState("root");
|
|
11086
11145
|
const [selectedProgram, setSelectedProgram] = useState("");
|
|
@@ -11203,7 +11262,38 @@ function Statement() {
|
|
|
11203
11262
|
return false;
|
|
11204
11263
|
};
|
|
11205
11264
|
const handleDownloadCSV = () => {
|
|
11206
|
-
|
|
11265
|
+
if (!statementHeader || !statementTransactions.length) {
|
|
11266
|
+
toast({
|
|
11267
|
+
title: "No statement data",
|
|
11268
|
+
description: "Please generate a statement before downloading",
|
|
11269
|
+
variant: "destructive"
|
|
11270
|
+
});
|
|
11271
|
+
return;
|
|
11272
|
+
}
|
|
11273
|
+
try {
|
|
11274
|
+
const csvContent = generateStatementCSV(statementHeader, statementTransactions);
|
|
11275
|
+
const dateStr = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
11276
|
+
let filenamePart = statementType;
|
|
11277
|
+
if (statementType === "program" && selectedProgram) {
|
|
11278
|
+
filenamePart = `program_${selectedProgram}`;
|
|
11279
|
+
} else if (statementType === "product" && selectedProduct) {
|
|
11280
|
+
filenamePart = `product_${selectedProduct}`;
|
|
11281
|
+
} else if (statementType === "account" && accountNumber) {
|
|
11282
|
+
filenamePart = `account_${accountNumber}`;
|
|
11283
|
+
}
|
|
11284
|
+
const filename = `statement_${filenamePart}_${dateStr}.csv`;
|
|
11285
|
+
downloadCSV(csvContent, filename);
|
|
11286
|
+
toast({
|
|
11287
|
+
title: "Download started",
|
|
11288
|
+
description: "Your statement CSV is being downloaded"
|
|
11289
|
+
});
|
|
11290
|
+
} catch (error) {
|
|
11291
|
+
toast({
|
|
11292
|
+
title: "Download failed",
|
|
11293
|
+
description: error instanceof Error ? error.message : "Failed to download CSV",
|
|
11294
|
+
variant: "destructive"
|
|
11295
|
+
});
|
|
11296
|
+
}
|
|
11207
11297
|
};
|
|
11208
11298
|
const handlePrintPDF = () => {
|
|
11209
11299
|
console.log("Printing PDF...");
|