Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
- <title>Chex Report Analyzer</title>
- <!-- PDF.js library -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.3.122/pdf.min.js"></script>
- <style>
- body {
- font-family: sans-serif;
- max-width: 800px;
- margin: 2rem auto;
- padding: 0 1rem;
- }
- h1 {
- text-align: center;
- }
- input[type="file"] {
- display: block;
- margin: 1rem 0;
- }
- #downloadLink {
- display: none;
- margin: 1rem 0;
- }
- #summary {
- margin-top: 1.5rem;
- }
- .copy-button {
- margin-top: 0.5rem;
- padding: 0.5rem 1rem;
- font-size: 1rem;
- }
- </style>
- </head>
- <body>
- <h1>Chex Report Analyzer</h1>
- <input type="file" id="pdfInput" accept="application/pdf" />
- <h2>Choose Date to Base Summary On</h2>
- <input type="date" id="summaryDate">
- <a id="downloadLink"></a>
- <div id="summary"></div>
- <script>
- // Automatically trigger the extraction when a new file is uploaded
- document.getElementById('pdfInput').addEventListener('change', processPDF);
- document.getElementById('summaryDate').addEventListener('change', processPDF);
- async function processPDF() {
- const fileInput = document.getElementById('pdfInput');
- if (!fileInput.files.length) {
- alert('Please select a PDF file.');
- return;
- }
- const summaryDateInput = document.getElementById('summaryDate');
- if (!summaryDateInput.value) {
- alert('Please select a date for the summary.');
- return;
- }
- const file = fileInput.files[0];
- const arrayBuffer = await file.arrayBuffer();
- // Configure the workerSrc property
- pdfjsLib.GlobalWorkerOptions.workerSrc =
- 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.3.122/pdf.worker.min.js';
- const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise;
- const summaryDate = await summaryDateInput.value;
- let fullText = '';
- // Extract text from each page
- for (let i = 0; i < pdf.numPages; i++) {
- const page = await pdf.getPage(i + 1);
- const textContent = await page.getTextContent();
- const pageText = textContent.items.map(item => item.str).join(' ');
- fullText += pageText + '\n';
- }
- // Extract the "Inquiries Viewed By Others" section
- const sectionPattern = /Inquiries Viewed By Others([\s\S]*?)Inquiries Viewed Only By You/;
- const sectionMatch = fullText.match(sectionPattern);
- if (!sectionMatch) {
- alert("Could not find the 'Inquiries Viewed By Others' section.");
- return;
- }
- const inquiriesSection = sectionMatch[1];
- const inquiryPattern = /Inquirer:\s*(.*?);\s*(.*?)Phone Number:\s*(.*?)(?:Inquiry Date:\s*(\d{2}\/\d{2}\/\d{4}))/g;
- const inquiries = [];
- let match;
- while ((match = inquiryPattern.exec(inquiriesSection)) !== null) {
- inquiries.push({
- bank_name: match[1].trim(),
- bank_address: match[2].trim(),
- bank_phone: match[3].trim(),
- inquiry_date: match[4].trim()
- });
- }
- if (inquiries.length === 0) {
- alert('No inquiries found.');
- return;
- }
- // Generate CSV content
- const csvContent = 'bank_name,bank_address,bank_phone,inquiry_date\n' +
- inquiries.map(inquiry =>
- `"${inquiry.bank_name}","${inquiry.bank_address}","${inquiry.bank_phone}","${inquiry.inquiry_date}"`)
- .join('\n');
- // Create a download link for the CSV
- const blob = new Blob([csvContent], { type: 'text/csv' });
- const downloadLink = document.getElementById('downloadLink');
- downloadLink.href = URL.createObjectURL(blob);
- downloadLink.download = 'inquiries_viewed_by_others.csv';
- downloadLink.style.display = 'inline-block';
- downloadLink.textContent = '⬇️ Download CSV';
- // Generate the summary
- generateSummary(inquiries,summaryDate);
- }
- function generateSummary(inquiries,summaryDate) {
- const now = new Date(summaryDate);
- //const now = new Date();
- const oneMonthAgo = new Date(now);
- oneMonthAgo.setMonth(now.getMonth() - 1);
- //const twoMonthsAgo = new Date(now);
- //twoMonthsAgo.setMonth(now.getMonth() - 2);
- const threeMonthsAgo = new Date(now);
- threeMonthsAgo.setMonth(now.getMonth() - 3);
- const sixMonthsAgo = new Date(now);
- sixMonthsAgo.setMonth(now.getMonth() - 6);
- const twelveMonthsAgo = new Date(now);
- twelveMonthsAgo.setMonth(now.getMonth() - 12);
- const twentyFourMonthsAgo = new Date(now);
- twentyFourMonthsAgo.setMonth(now.getMonth() - 24);
- let last1Month = 0;
- //let last2Months = 0;
- let last3Months = 0;
- let last6Months = 0;
- let last12Months = 0;
- let last24Months = 0;
- inquiries.forEach(inquiry => {
- const parts = inquiry.inquiry_date.split('/');
- const inquiryDate = new Date(`${parts[2]}-${parts[0]}-${parts[1]}`);
- if (inquiryDate > oneMonthAgo && inquiryDate <= now) last1Month++;
- //if (inquiryDate >= twoMonthsAgo) last2Months++;
- if (inquiryDate > threeMonthsAgo && inquiryDate <= now) last3Months++;
- if (inquiryDate > sixMonthsAgo && inquiryDate <= now) last6Months++;
- if (inquiryDate > twelveMonthsAgo && inquiryDate <= now) last12Months++;
- if (inquiryDate > twentyFourMonthsAgo && inquiryDate <= now) last24Months++;
- });
- // Display the summary
- //<li>Last 2 months: ${last2Months}</li>
- //${last2Months},
- const summaryDiv = document.getElementById('summary');
- summaryDiv.innerHTML = `
- <h2>Inquiry Summary</h2>
- <ul>
- <li>Last 1 month: ${last1Month}</li>
- <li>Last 3 months: ${last3Months}</li>
- <li>Last 6 months: ${last6Months}</li>
- <li>Last 12 months: ${last12Months}</li>
- <li>Last 24 months: ${last24Months}</li>
- </ul>
- <button class="copy-button" onclick="copySummary(${last1Month}, ${last3Months}, ${last6Months}, ${last12Months}, ${last24Months})">
- 📋 Copy Summary
- </button>
- `;
- }
- //m2,
- //${m2}/2,
- function copySummary(m1, m3, m6, m12, m24) {
- const summaryText = `${m1}/1, ${m3}/3, ${m6}/6, ${m12}/12, ${m24}/24`;
- navigator.clipboard.writeText(summaryText)
- .then(() => alert("Summary copied to clipboard:\n" + summaryText))
- .catch(() => alert("Failed to copy summary."));
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment