anonym. reports

This commit is contained in:
2026-06-10 16:21:42 -05:00
parent b9ab025794
commit ba6019751f
3 changed files with 16 additions and 5 deletions

View File

@@ -164,7 +164,7 @@ router.get('/reports/customer-revenue', async (req, res) => {
router.get('/reports/customer-revenue/pdf', async (req, res) => {
try {
const { startDate, endDate } = req.query;
const { startDate, endDate, anonymize } = req.query;
if (!startDate || !endDate) {
return res.status(400).json({ error: 'startDate and endDate are required' });
}
@@ -189,6 +189,8 @@ router.get('/reports/customer-revenue/pdf', async (req, res) => {
const rows = result.rows;
const grandTotal = rows.length > 0 ? parseFloat(rows[0].grand_total) || 0 : 0;
const totalInvoices = rows.reduce((s, r) => s + parseInt(r.invoice_count), 0);
const doAnonymize = anonymize === 'true';
const maskName = (name) => doAnonymize ? name.charAt(0) : name;
let rowsHtml = '';
let rank = 0;
@@ -197,7 +199,7 @@ router.get('/reports/customer-revenue/pdf', async (req, res) => {
const rev = parseFloat(r.total_revenue) || 0;
const pct = grandTotal > 0 ? ((rev / grandTotal) * 100).toFixed(1) : '0.0';
rowsHtml += `<tr>
<td class="name">${rank}. ${r.customer_name}</td>
<td class="name">${rank}. ${maskName(r.customer_name)}</td>
<td class="number">${r.invoice_count}</td>
<td class="number">$${formatMoney(rev)}</td>
<td class="number">${pct}%</td>
@@ -223,6 +225,7 @@ router.get('/reports/customer-revenue/pdf', async (req, res) => {
.replace('{{SLOGAN}}', 'Providing IT Services and Support in South Texas Since 1996')
.replace('{{DATE_RANGE}}', dateRange)
.replace('{{GENERATED_DATE}}', generated)
.replace('{{ANONYMIZED_NOTE}}', doAnonymize ? ' (anonymized)' : '')
.replace('{{ROWS}}', rowsHtml);
const pdf = await generatePdfFromHtml(html);