RMA # ${rma_state.rmaNum}
PENDING RECEIPT
Customer & Order Details
- Customer:
- ${D.customerName}
- Order #:
- ${D.orderNum}
- Email:
- ${D.customerEmail}
- Purchase Date:
- ${D.purchaseDate}
- Return Address:
- ${D.returnAddress}
Product & Requested Action
- Product:
- ${D.productName}
- S/N:
- ${D.serialNum || 'N/A'}
- Price:
- ${rma_formatCurrency(D.purchasePrice)}
- Action:
- ${D.requestedAction}
Issue Description
${D.issueDetails}
Return Instructions
- Please clearly write the RMA number on the outside of the return package.
- Items must be received within 30 days of the RMA Issue Date.
- Include all original accessories and packaging.
`;
}
// --- Tab Switching ---
function rma_showTab(targetId, element) {
tabButtons.forEach(btn => btn.classList.remove('rma-active'));
document.querySelectorAll('.rma-tab-content').forEach(content => content.classList.remove('active'));
if (element) {
element.classList.add('rma-active');
}
document.getElementById(targetId).classList.add('active');
if (targetId === 'viewer') {
rma_collectData();
rma_renderPreview();
}
}
window.rma_showTab = rma_showTab;
// --- PDF Export ---
function rma_downloadPDF() {
if (typeof jspdf === 'undefined' || typeof jspdf.plugin.autotable === 'undefined') {
alert('Error: PDF library not fully loaded for export.');
return;
}
rma_collectData(); // Ensure the latest data is used
const D = rma_state.data;
const { jsPDF } = jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'letter' }); // Using Letter size for document
doc.setFont('sans-serif', 'normal');
const margin = 40;
const pageWidth = doc.internal.pageSize.getWidth();
let yPos = margin;
// --- Header ---
doc.setFontSize(24);
doc.setFont('sans-serif', 'bold');
doc.setTextColor('#1e40af'); // Dark Blue
doc.text("Return Merchandise Authorization (RMA)", margin, yPos);
doc.setFontSize(16);
doc.text(rma_state.companyName, pageWidth - margin, yPos, { align: 'right' });
yPos += 30;
// RMA Number and Status
doc.setFontSize(18);
doc.setTextColor('#b91c1c'); // Red
doc.text(`RMA # ${rma_state.rmaNum}`, margin, yPos);
doc.setFontSize(12);
doc.setFont('sans-serif', 'normal');
doc.setTextColor('#f59e0b'); // Amber
doc.text("STATUS: PENDING RECEIPT", pageWidth - margin, yPos, { align: 'right' });
yPos += 20;
doc.setDrawColor('#9ca3af'); // Gray line
doc.setLineWidth(1);
doc.line(margin, yPos, pageWidth - margin, yPos);
yPos += 20;
// --- Details Table ---
doc.setFontSize(14);
doc.setFont('sans-serif', 'bold');
doc.setTextColor('#374151');
doc.text("Request Details:", margin, yPos);
yPos += 15;
const detailsTable = [
['Customer Name:', D.customerName, 'RMA Date:', rma_state.issueDate],
['Order #:', D.orderNum, 'Purchase Date:', D.purchaseDate],
['Email:', D.customerEmail, 'Product:', D.productName],
['Serial #:', D.serialNum || 'N/A', 'Requested Action:', D.requestedAction],
['Price ($):', rma_formatCurrency(D.purchasePrice), 'Return Address:', D.returnAddress],
];
doc.autoTable({
body: detailsTable,
startY: yPos,
theme: 'plain',
styles: { fontSize: 9, cellPadding: 5 },
columnStyles: { 0: { fontStyle: 'bold', cellWidth: 80 }, 2: { fontStyle: 'bold', cellWidth: 80 } },
didDrawPage: function(data) { yPos = data.cursor.y; }
});
yPos = doc.lastAutoTable.finalY + 20;
// --- Issue Description ---
if (yPos > doc.internal.pageSize.getHeight() - 100) { doc.addPage(); yPos = margin; }
doc.setFontSize(14);
doc.text("Issue Description:", margin, yPos);
yPos += 15;
doc.setFontSize(10);
doc.setFont('sans-serif', 'normal');
doc.setTextColor('#4b5563');
const issueLines = doc.splitTextToSize(D.issueDetails, contentWidth);
doc.text(issueLines, margin, yPos);
yPos += (issueLines.length * 12) + 20;
// --- Instructions ---
if (yPos > doc.internal.pageSize.getHeight() - 80) { doc.addPage(); yPos = margin; }
doc.setFontSize(14);
doc.text("Return Instructions:", margin, yPos);
yPos += 15;
doc.setFontSize(10);
const instructions = [
"1. Please clearly write the RMA number on the outside of the return package.",
"2. Items must be received within 30 days of the RMA Issue Date.",
"3. Include all original accessories and packaging."
];
instructions.forEach(line => {
doc.text(line, margin, yPos);
yPos += 12;
});
doc.save(`RMA_Form_${rma_state.rmaNum}.pdf`);
}
// --- Initialization ---
document.addEventListener('DOMContentLoaded', () => {
// 1. Set default date to today
document.getElementById('purchaseDate').value = new Date().toISOString().slice(0, 10);
// 2. Attach listeners
document.getElementById('input-next-btn').addEventListener('click', () => rma_showTab('viewer', document.querySelector('.rma-tab-btn[data-tab="viewer"]')));
document.getElementById('rma-download-pdf-btn').addEventListener('click', rma_downloadPDF);
});