c'mon
This commit is contained in:
parent
e701aa86db
commit
f09ef9e226
|
@ -10,12 +10,14 @@
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<!--
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<p id="description">
|
<p id="description">
|
||||||
ZenCard Transactions
|
ZenCard Transactions
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
-->
|
||||||
|
|
||||||
<form method="get" action="#expenses" id="explore">
|
<form method="get" action="#expenses" id="explore">
|
||||||
<p>
|
<p>
|
||||||
|
@ -44,6 +46,10 @@
|
||||||
<section id="expenses">
|
<section id="expenses">
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="export-button">
|
||||||
|
<!-- Export button will be added here dynamically -->
|
||||||
|
</section>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
Follow the money
|
Follow the money
|
||||||
|
@ -54,7 +60,7 @@
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
<script src="index_fichiers/jspdf.min.js"></script>
|
||||||
<script type="module" src="index_fichiers/app.js">
|
<script type="module" src="index_fichiers/app.js">
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
|
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
|
||||||
|
|
||||||
export const DU = 10.68;
|
export const DU = 10.68;
|
||||||
export const MAX_NB_TX = 200;
|
export const MAX_NB_TX = 200;
|
||||||
let txLimit = MAX_NB_TX;
|
let txLimit = MAX_NB_TX;
|
||||||
|
@ -244,6 +245,7 @@ export const fetchExpenses = async (pubkey, minTime, limit = MAX_NB_TX) => {
|
||||||
|
|
||||||
let expensesByRecipient = {};
|
let expensesByRecipient = {};
|
||||||
let totalAmount = 0;
|
let totalAmount = 0;
|
||||||
|
let transactions = [];
|
||||||
|
|
||||||
for (const hit of data.hits.hits) {
|
for (const hit of data.hits.hits) {
|
||||||
|
|
||||||
|
@ -257,6 +259,15 @@ export const fetchExpenses = async (pubkey, minTime, limit = MAX_NB_TX) => {
|
||||||
expensesByRecipient[tx.recipient] += tx.amount/100;
|
expensesByRecipient[tx.recipient] += tx.amount/100;
|
||||||
|
|
||||||
totalAmount += tx.amount;
|
totalAmount += tx.amount;
|
||||||
|
|
||||||
|
transactions.push({
|
||||||
|
date: new Date(tx.medianTime).toLocaleDateString(),
|
||||||
|
walletId: pubkey,
|
||||||
|
income: tx.amount > 0 ? tx.amount / 100 : 0,
|
||||||
|
outcome: tx.amount < 0 ? -tx.amount / 100 : 0,
|
||||||
|
comment: "Transaction Comment", // Add your logic to get the comment
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
totalAmount = totalAmount/100;
|
totalAmount = totalAmount/100;
|
||||||
|
@ -395,10 +406,79 @@ export const fetchCesiumProfiles = async (pubkeys, limit) => {
|
||||||
throw new Error("Failed to fetch data from all nodes");
|
throw new Error("Failed to fetch data from all nodes");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function to export transactions to PDF
|
||||||
|
const exportToPDF = (transactions) => {
|
||||||
|
const pdf = new jsPDF();
|
||||||
|
pdf.text("Transaction Report", 20, 10);
|
||||||
|
|
||||||
|
// Define table columns
|
||||||
|
const columns = ["Date", "Wallet ID", "Income", "Outcome", "Comment"];
|
||||||
|
|
||||||
|
// Initialize y-position for table
|
||||||
|
let y = 20;
|
||||||
|
|
||||||
|
// Add table headers
|
||||||
|
columns.forEach((column, index) => {
|
||||||
|
pdf.text(column, 20 + index * 40, y);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Increment y for the next row
|
||||||
|
y += 10;
|
||||||
|
|
||||||
|
// Add transactions to the table
|
||||||
|
transactions.forEach((transaction) => {
|
||||||
|
pdf.text(transaction.date, 20, y);
|
||||||
|
pdf.text(transaction.walletId, 60, y);
|
||||||
|
pdf.text(transaction.income.toString(), 100, y);
|
||||||
|
pdf.text(transaction.outcome.toString(), 140, y);
|
||||||
|
pdf.text(transaction.comment, 180, y);
|
||||||
|
|
||||||
|
// Increment y for the next row
|
||||||
|
y += 10;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Save the PDF
|
||||||
|
pdf.save("transaction_report.pdf");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export const displayExpenses = (expensesByRecipient, expensesTotalAmount, recipientsCesiumProfiles, chartColors, currentPubkey, currentProfile) => {
|
export const displayExpenses = (expensesByRecipient, expensesTotalAmount, recipientsCesiumProfiles, chartColors, currentPubkey, currentProfile) => {
|
||||||
|
|
||||||
let screenElt = document.querySelector('#expenses');
|
let exportButtonContainer = document.querySelector("#export-button");
|
||||||
|
let exportButton = document.createElement("button");
|
||||||
|
exportButton.textContent = "Export to PDF";
|
||||||
|
exportButton.addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
const { expensesByRecipient, expensesTotalAmount } = await fetchExpenses(
|
||||||
|
currentPubkey,
|
||||||
|
minTime,
|
||||||
|
txLimit
|
||||||
|
);
|
||||||
|
|
||||||
|
let transactions = [];
|
||||||
|
|
||||||
|
for (const recipient in expensesByRecipient) {
|
||||||
|
transactions.push({
|
||||||
|
date: new Date().toLocaleDateString(),
|
||||||
|
walletId: currentPubkey,
|
||||||
|
income: expensesByRecipient[recipient],
|
||||||
|
outcome: 0,
|
||||||
|
comment: "Transaction Comment", // Add your logic to get the comment
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export transactions to PDF
|
||||||
|
exportToPDF(transactions);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error exporting to PDF: ${error}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Append the export button to the container
|
||||||
|
exportButtonContainer.innerHTML = '';
|
||||||
|
exportButtonContainer.appendChild(exportButton);
|
||||||
|
|
||||||
|
let screenElt = document.querySelector('#expenses');
|
||||||
screenElt.innerHTML = '';
|
screenElt.innerHTML = '';
|
||||||
|
|
||||||
let currentProfileTitleElt = document.createElement('h2');
|
let currentProfileTitleElt = document.createElement('h2');
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -55,3 +55,13 @@ footer a:hover {
|
||||||
|
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#export-button {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#export-button button {
|
||||||
|
padding: 8px 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue