Detailed Payment Analysis
`; let tableHtml = `| Payment Date | Amount (USD) | Days Before Filing | Preference Status | Potential Defenses (OCB, New Value) |
|---|---|---|---|---|
| ${item.date} | ${formatted(item.amount)} | ${item.days} | ${status} | ${item.defense} |
Legal Notes on Defenses
`; html += `Payments marked 'Ordinary Course' or 'New Value' may be shielded from avoidance, even if made within the 90-day preference period. Further review of account history is required to validate these defenses.
`; container.innerHTML = html; } function bpaSwitchTab(tabId) { document.querySelectorAll('.bpa-tab-btn').forEach(b => b.classList.remove('active')); document.querySelectorAll('.bpa-content').forEach(c => c.classList.remove('active')); const idx = tabId === 'builder' ? 0 : 1; document.querySelectorAll('.bpa-tab-btn')[idx].classList.add('active'); document.getElementById('bpa-' + tabId).classList.add('active'); if (tabId === 'report') { bpaRenderReport(); } } function bpaLoadExample() { if(!confirm("Overwrite current data with example preference analysis data?")) return; // Set petition date 95 days ago const petitionDate = new Date(); petitionDate.setDate(petitionDate.getDate() - 95); document.getElementById('inp-petition-date').valueAsDate = petitionDate; // Clear and fill payments document.getElementById('bpa-log-rows-container').innerHTML = ''; // Payment 1: 30 days before filing (AVOIDABLE) const date1 = new Date(petitionDate); date1.setDate(petitionDate.getDate() - 30); bpaAddPaymentRow(date1.toISOString().split('T')[0], 25000); // Payment 2: 120 days before filing (OUTSIDE PREF PERIOD) const date2 = new Date(petitionDate); date2.setDate(petitionDate.getDate() - 120); bpaAddPaymentRow(date2.toISOString().split('T')[0], 10000); // Payment 3: 5 days before filing, potentially saved by New Value const date3 = new Date(petitionDate); date3.setDate(petitionDate.getDate() - 5); bpaAddPaymentRow(date3.toISOString().split('T')[0], 5000, "New Value"); // Payment 4: 80 days before filing, potentially saved by OCB const date4 = new Date(petitionDate); date4.setDate(petitionDate.getDate() - 80); bpaAddPaymentRow(date4.toISOString().split('T')[0], 1500, "Ordinary Course of Business"); document.getElementById('inp-debtor').value = "MegaTech Corp., Case 26-1002A"; document.getElementById('inp-creditor').value = "Global Components LLC"; bpaRenderReport(); bpaSwitchTab('report'); } /* --- PDF Generation --- */ async function bpaGeneratePDF() { bpaRenderReport(); // Final render check const logData = bpaGetLogData(); if (logData.length === 0) { alert("Please add payment entries before generating the PDF."); return; } const meta = { debtor: document.getElementById('inp-debtor').value || "Debtor Name", petitionDate: document.getElementById('inp-petition-date').value || "N/A Date", creditor: document.getElementById('inp-creditor').value || "Target Creditor" }; const totalAvoidable = logData.filter(p => p.days >= 0 && p.days <= 90).reduce((sum, p) => sum + p.amount, 0); const { jsPDF } = window.jspdf; const doc = new jsPDF('l', 'mm', 'a4'); // Landscape for better table fit const blue = [0, 119, 182]; const red = [231, 76, 60]; let y = 20; // 1. Header doc.setFillColor(...blue); doc.rect(0, 0, 297, 20, 'F'); doc.setTextColor(255, 255, 255); doc.setFontSize(16); doc.text("AVOIDABLE PREFERENCE PAYMENT ANALYSIS (11 U.S.C. § 547)", 14, 13); // 2. Metadata doc.setTextColor(0, 0, 0); doc.setFontSize(10); doc.setFont("helvetica", "normal"); doc.text(`Debtor: ${meta.debtor}`, 14, y + 10); doc.text(`Creditor: ${meta.creditor}`, 150, y + 10); doc.text(`Petition Date: ${meta.petitionDate}`, 14, y + 15); doc.text(`Preference Period: 90 Days Prior (1 Year for Insiders)`, 150, y + 15); y += 25; // 3. Summary doc.setFontSize(12); doc.setFont("helvetica", "bold"); doc.setTextColor(...red); doc.text(`Total Payments within 90-Day Preference Period: $${totalAvoidable.toLocaleString()}`, 14, y); y += 5; // 4. Log Table doc.setFontSize(12); doc.setFont("helvetica", "bold"); doc.setTextColor(...blue); doc.text("Detailed Payment Analysis", 14, y + 5); y += 10; const tableBody = logData.map(item => { let status = 'Outside Period'; if (item.days >= 0 && item.days <= 90) { status = 'AVOIDABLE'; } else if (item.days > 90 && item.days <= 365) { status = 'Insider Period'; } return [ item.date, `$${item.amount.toLocaleString()}`, item.days !== 'N/A' ? `${item.days} days` : 'N/A', status, item.defense ]; }); doc.autoTable({ startY: y, head: [['Payment Date', 'Amount', 'Days Before Filing', 'Preference Status', 'Potential Defenses']], body: tableBody, theme: 'grid', headStyles: { fillColor: blue, fontSize: 10 }, styles: { fontSize: 8.5 }, columnStyles: { 0: { cellWidth: 30, fontStyle: 'bold' }, 1: { cellWidth: 30, halign: 'right' }, 3: { cellWidth: 30, fontStyle: 'bold', halign: 'center' }, 4: { cellWidth: 'auto', overflow: 'linebreak' } }, didParseCell: function(data) { // Highlight AVOIDABLE payments if (data.section === 'body' && data.column.index === 3) { if (data.cell.raw === 'AVOIDABLE') { data.cell.styles.fillColor = [240, 200, 200]; data.cell.styles.textColor = [200, 0, 0]; } } } }); // 5. Signature Block let finalY = doc.lastAutoTable.finalY + 20; if (finalY > 180) { doc.addPage(); finalY = 30; } doc.setFontSize(10); doc.text("Analysis Prepared By: ___________________________", 14, finalY); doc.save(`PreferenceAnalysis_${meta.debtor.replace(/\s/g, '_')}.pdf`); }