Customs Clearance Dashboard

Customs Clearance Dashboard

Overall Customs Clearance Metrics

Total Shipments Processed

0

Shipments Cleared (On-Time)

0

Shipments Delayed

0

Avg. Clearance Time (Hours)

0.00

Total Customs Duty & Tax Paid

$0.00

Compliance Rate

0.00%

Holds/Inspections

0

Avg. Hold Duration (Hours)

0.00

Clearance Breakdown by Shipment Type

Shipment Type Processed Cleared Delayed Avg. Time (Hrs) Duty/Tax ($) Compliance (%)

Clearance Breakdown by Customs Region/Port

Region/Port Processed Cleared Delayed Duty/Tax ($) Compliance (%)

Compliance Rate

${displayComplianceRate.textContent}

Holds/Inspections

${displayNumHolds.textContent}

Avg. Hold Duration (Hours)

${displayAvgHoldDuration.textContent}

Clearance Breakdown by Shipment Type

${shipmentTypeBreakdownHtml}
Shipment Type Processed Cleared Delayed Avg. Time (Hrs) Duty/Tax ($) Compliance (%)

Clearance Breakdown by Customs Region/Port

${regionPortBreakdownHtml}
Region/Port Processed Cleared Delayed Duty/Tax ($) Compliance (%)
`; // Append to body temporarily to render for html2canvas document.body.appendChild(pdfContentWrapper); try { const canvas = await html2canvas(pdfContentWrapper, { scale: 2, // Increase scale for better resolution useCORS: true, // Required if images are from different origin (though we don't use images here) logging: false // Disable logging for cleaner console }); const imgData = canvas.toDataURL('image/png'); const pdf = new window.jspdf.jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const imgWidth = 210; // A4 width in mm const pageHeight = 297; // A4 height in mm const imgHeight = canvas.height * imgWidth / canvas.width; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; } pdf.save('Customs_Clearance_Dashboard.pdf'); } catch (error) { console.error('Error generating PDF:', error); // Provide a user-friendly message if PDF generation fails alert('Failed to generate PDF. Please try again.'); } finally { // Remove the temporary wrapper document.body.removeChild(pdfContentWrapper); } } // --- Event Listeners --- // Tab switching if (dashboardTabBtn) { dashboardTabBtn.addEventListener('click', function() { switchTab('dashboard'); }); } if (dataConfigTabBtn) { dataConfigTabBtn.addEventListener('click', function() { switchTab('dataConfig'); }); } // Navigation buttons if (prevTabBtn) { prevTabBtn.addEventListener('click', function() { if (currentActiveTab === 'dataConfig') { switchTab('dashboard'); } }); } if (nextTabBtn) { nextTabBtn.addEventListener('click', function() { if (currentActiveTab === 'dashboard') { switchTab('dataConfig'); } }); } // Main metrics input change listener (for real-time updates) const mainMetricInputs = [ totalShipmentsInput, shipmentsClearedInput, shipmentsDelayedInput, totalClearanceTimeHoursInput, totalDutyTaxPaidInput, numHoldsInput, totalHoldDurationHoursInput ]; mainMetricInputs.forEach(input => { if (input) { input.addEventListener('input', function() { updateCustomsMetricsFromInputs(); renderDashboard(); // Update dashboard in real-time }); } }); // Add/Update Shipment Type button if (addUpdateShipmentTypeBtn) { addUpdateShipmentTypeBtn.addEventListener('click', addUpdateShipmentType); } // Clear Shipment Type Form button if (clearShipmentTypeFormBtn) { clearShipmentTypeFormBtn.addEventListener('click', clearShipmentTypeForm); } // Add/Update Region/Port button if (addUpdateRegionPortBtn) { addUpdateRegionPortBtn.addEventListener('click', addUpdateRegionPort); } // Clear Region/Port Form button if (clearRegionPortFormBtn) { clearRegionPortFormBtn.addEventListener('click', clearRegionPortForm); } // PDF download button if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', downloadPdf); } // --- Initial Load --- populateInputFields(); // Populate main metric inputs with initial data clearShipmentTypeForm(); // Initialize shipment type form clearRegionPortForm(); // Initialize region/port form renderDashboard(); // Render dashboard with initial data renderExistingShipmentTypesTable(); // Render existing shipment types in config tab renderExistingRegionPortsTable(); // Render existing regions/ports in config tab switchTab('dashboard'); // Ensure dashboard tab is active on load });
Scroll to Top