Spaces:
Running
Running
Download index.html from BMEMohammed/myspace: direct link, hf CLI and curl.
- Browser
- Download file 52.8 kB
-
https://huggingface.co/spaces/BMEMohammed/myspace/resolve/main/index.html
- Command line
-
hf download hf://spaces/BMEMohammed/myspace/index.html
-
curl -L -o index.html https://huggingface.co/spaces/BMEMohammed/myspace/resolve/main/index.html
52.8 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Barcopharma - Laboratory Equipment Spare Parts</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script> | |
| tailwind.config = { | |
| theme: { | |
| extend: { | |
| colors: { | |
| primary: { | |
| 100: '#fee2e2', | |
| 500: '#ef4444', | |
| 700: '#b91c1c', | |
| 800: '#991b1b', | |
| } | |
| } | |
| } | |
| } | |
| } | |
| </script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <script src="https://unpkg.com/html5-qrcode@2.3.8/html5-qrcode.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.28/jspdf.plugin.autotable.min.js"></script> | |
| <style> | |
| @keyframes pulse { | |
| 0%, 100% { opacity: 1; } | |
| 50% { opacity: 0.5; } | |
| } | |
| .pulse-animation { | |
| animation: pulse 2s infinite; | |
| } | |
| .sidebar { | |
| transition: all 0.3s ease; | |
| } | |
| .sidebar.collapsed { | |
| width: 70px; | |
| } | |
| .sidebar.collapsed .sidebar-text { | |
| display: none; | |
| } | |
| .main-content { | |
| transition: margin-left 0.3s ease; | |
| } | |
| #scanner-container { | |
| transition: all 0.3s ease; | |
| } | |
| .stock-low { | |
| background-color: #fef3c7; | |
| border-left: 4px solid #f59e0b; | |
| } | |
| .stock-out { | |
| background-color: #fee2e2; | |
| border-left: 4px solid #ef4444; | |
| } | |
| .stock-ok { | |
| background-color: #ecfdf5; | |
| border-left: 4px solid #10b981; | |
| } | |
| #pdf-preview { | |
| max-width: 100%; | |
| border: 1px solid #ddd; | |
| margin-top: 10px; | |
| display: none; | |
| } | |
| .status-badge { | |
| font-size: 0.75rem; | |
| padding: 0.25rem 0.5rem; | |
| border-radius: 9999px; | |
| font-weight: 600; | |
| } | |
| .status-in-stock { | |
| background-color: #dcfce7; | |
| color: #166534; | |
| } | |
| .status-low-stock { | |
| background-color: #fef08a; | |
| color: #854d0e; | |
| } | |
| .status-out-of-stock { | |
| background-color: #fee2e2; | |
| color: #991b1b; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50"> | |
| <div class="flex h-screen overflow-hidden"> | |
| <!-- Sidebar --> | |
| <div class="sidebar bg-primary-800 text-white w-64 flex flex-col"> | |
| <div class="p-4 flex items-center justify-between border-b border-primary-700"> | |
| <div class="flex items-center space-x-2"> | |
| <i class="fas fa-microscope text-2xl"></i> | |
| <span class="sidebar-text text-xl font-bold">Barcopharma</span> | |
| </div> | |
| <button id="toggle-sidebar" class="text-white hover:text-primary-200"> | |
| <i class="fas fa-bars"></i> | |
| </button> | |
| </div> | |
| <nav class="flex-1 p-4 space-y-2"> | |
| <a href="#" class="flex items-center space-x-2 p-2 rounded hover:bg-primary-700 bg-primary-700"> | |
| <i class="fas fa-tachometer-alt"></i> | |
| <span class="sidebar-text">Dashboard</span> | |
| </a> | |
| <a href="#" class="flex items-center space-x-2 p-2 rounded hover:bg-primary-700"> | |
| <i class="fas fa-cogs"></i> | |
| <span class="sidebar-text">Spare Parts</span> | |
| </a> | |
| <a href="#" class="flex items-center space-x-2 p-2 rounded hover:bg-primary-700"> | |
| <i class="fas fa-barcode"></i> | |
| <span class="sidebar-text">Scan Parts</span> | |
| </a> | |
| <a href="#" class="flex items-center space-x-2 p-2 rounded hover:bg-primary-700"> | |
| <i class="fas fa-chart-line"></i> | |
| <span class="sidebar-text">Reports</span> | |
| </a> | |
| <a href="#" class="flex items-center space-x-2 p-2 rounded hover:bg-primary-700"> | |
| <i class="fas fa-cog"></i> | |
| <span class="sidebar-text">Settings</span> | |
| </a> | |
| </nav> | |
| <div class="p-4 border-t border-primary-700"> | |
| <div class="flex items-center space-x-2"> | |
| <div class="w-8 h-8 rounded-full bg-primary-600 flex items-center justify-center"> | |
| <i class="fas fa-user-tie"></i> | |
| </div> | |
| <div class="sidebar-text"> | |
| <div class="font-medium">Lab Manager</div> | |
| <div class="text-xs text-primary-300">manager@barcopharma.com</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Main Content --> | |
| <div class="main-content flex-1 flex flex-col overflow-hidden"> | |
| <!-- Header --> | |
| <header class="bg-white shadow-sm p-4 flex justify-between items-center"> | |
| <h1 class="text-2xl font-bold text-gray-800">Laboratory Equipment Spare Parts</h1> | |
| <div class="flex items-center space-x-4"> | |
| <div class="relative"> | |
| <input type="text" placeholder="Search spare parts..." class="pl-10 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i> | |
| </div> | |
| <button class="p-2 rounded-full hover:bg-gray-100 relative"> | |
| <i class="fas fa-bell text-gray-600"></i> | |
| <span class="absolute top-2 right-2 h-2 w-2 rounded-full bg-primary-500"></span> | |
| </button> | |
| </div> | |
| </header> | |
| <!-- Main Content Area --> | |
| <main class="flex-1 overflow-y-auto p-6 bg-gray-50"> | |
| <!-- Stats Cards --> | |
| <div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6"> | |
| <div class="bg-white p-6 rounded-lg shadow"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <p class="text-gray-500">Total Parts</p> | |
| <h3 class="text-2xl font-bold" id="total-items">0</h3> | |
| </div> | |
| <div class="p-3 rounded-full bg-primary-100 text-primary-600"> | |
| <i class="fas fa-cogs text-xl"></i> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-white p-6 rounded-lg shadow"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <p class="text-gray-500">In Stock</p> | |
| <h3 class="text-2xl font-bold" id="in-stock">0</h3> | |
| </div> | |
| <div class="p-3 rounded-full bg-green-100 text-green-600"> | |
| <i class="fas fa-check-circle text-xl"></i> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-white p-6 rounded-lg shadow"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <p class="text-gray-500">Low Stock</p> | |
| <h3 class="text-2xl font-bold" id="low-stock">0</h3> | |
| </div> | |
| <div class="p-3 rounded-full bg-yellow-100 text-yellow-600"> | |
| <i class="fas fa-exclamation-triangle text-xl"></i> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-white p-6 rounded-lg shadow"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <p class="text-gray-500">Out of Stock</p> | |
| <h3 class="text-2xl font-bold" id="out-of-stock">0</h3> | |
| </div> | |
| <div class="p-3 rounded-full bg-primary-100 text-primary-600"> | |
| <i class="fas fa-times-circle text-xl"></i> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Scanner and Add Item Section --> | |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-6"> | |
| <!-- Scanner Section --> | |
| <div class="bg-white p-6 rounded-lg shadow lg:col-span-1"> | |
| <h2 class="text-xl font-bold mb-4">Barcode Scanner</h2> | |
| <div id="scanner-container" class="mb-4 border-2 border-dashed border-gray-300 rounded-lg p-4 flex flex-col items-center justify-center h-64"> | |
| <i class="fas fa-barcode text-4xl text-gray-400 mb-2"></i> | |
| <p class="text-gray-500 mb-4">Click to start scanning</p> | |
| <button id="start-scanner" class="bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700"> | |
| <i class="fas fa-camera mr-2"></i> Start Scanner | |
| </button> | |
| </div> | |
| <div id="scan-result" class="hidden p-3 bg-gray-100 rounded-lg mb-4"> | |
| <p class="font-medium">Scanned Code: <span id="scanned-code" class="font-mono"></span></p> | |
| </div> | |
| <div class="flex space-x-2"> | |
| <input type="text" id="manual-barcode" placeholder="Enter barcode manually" class="flex-1 border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| <button id="manual-submit" class="bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700"> | |
| <i class="fas fa-check"></i> | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Add Item Form --> | |
| <div class="bg-white p-6 rounded-lg shadow lg:col-span-2"> | |
| <h2 class="text-xl font-bold mb-4">Add/Update Spare Part</h2> | |
| <form id="inventory-form" class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div> | |
| <label for="barcode" class="block text-sm font-medium text-gray-700 mb-1">Part Number/Barcode</label> | |
| <input type="text" id="barcode" name="barcode" required class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="name" class="block text-sm font-medium text-gray-700 mb-1">Part Name</label> | |
| <input type="text" id="name" name="name" required class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="category" class="block text-sm font-medium text-gray-700 mb-1">Equipment Category</label> | |
| <select id="category" name="category" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| <option value="analyzer">Analyzer Parts</option> | |
| <option value="centrifuge">Centrifuge Parts</option> | |
| <option value="microscope">Microscope Parts</option> | |
| <option value="incubator">Incubator Parts</option> | |
| <option value="spectrophotometer">Spectrophotometer Parts</option> | |
| <option value="consumables">Consumables</option> | |
| <option value="other">Other</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label for="model" class="block text-sm font-medium text-gray-700 mb-1">Compatible Models</label> | |
| <input type="text" id="model" name="model" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500" placeholder="e.g., Model XYZ-2000"> | |
| </div> | |
| <div> | |
| <label for="price" class="block text-sm font-medium text-gray-700 mb-1">Unit Price ($)</label> | |
| <input type="number" id="price" name="price" step="0.01" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="quantity" class="block text-sm font-medium text-gray-700 mb-1">Quantity</label> | |
| <input type="number" id="quantity" name="quantity" required class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="threshold" class="block text-sm font-medium text-gray-700 mb-1">Low Stock Threshold</label> | |
| <input type="number" id="threshold" name="threshold" value="5" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="location" class="block text-sm font-medium text-gray-700 mb-1">Storage Location</label> | |
| <input type="text" id="location" name="location" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500" placeholder="Shelf A5, Bin 3"> | |
| </div> | |
| <div class="md:col-span-2"> | |
| <label for="description" class="block text-sm font-medium text-gray-700 mb-1">Description/Notes</label> | |
| <textarea id="description" name="description" rows="2" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"></textarea> | |
| </div> | |
| <div class="md:col-span-2 flex justify-end space-x-3"> | |
| <button type="reset" class="px-4 py-2 border rounded-lg hover:bg-gray-100">Clear</button> | |
| <button type="submit" class="bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700"> | |
| <i class="fas fa-save mr-2"></i> Save Part | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| <!-- Inventory Table --> | |
| <div class="bg-white p-6 rounded-lg shadow"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h2 class="text-xl font-bold">Spare Parts Inventory</h2> | |
| <div class="flex space-x-2"> | |
| <button id="export-pdf" class="bg-primary-600 text-white px-3 py-1 rounded-lg hover:bg-primary-700 flex items-center"> | |
| <i class="fas fa-file-pdf mr-2"></i>Export PDF | |
| </button> | |
| <select id="report-type" class="border rounded-lg px-3 py-1 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| <option value="all">Complete Inventory</option> | |
| <option value="low">Low Stock Items</option> | |
| <option value="out">Out of Stock</option> | |
| <option value="analyzer">Analyzer Parts</option> | |
| <option value="centrifuge">Centrifuge Parts</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div class="overflow-x-auto"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Part Number</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Part Name</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Category</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Compatible Models</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Price</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">In Stock</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Location</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="inventory-table-body" class="bg-white divide-y divide-gray-200"> | |
| <!-- Items will be added here dynamically --> | |
| </tbody> | |
| </table> | |
| </div> | |
| <div class="mt-4 flex justify-between items-center"> | |
| <div class="text-sm text-gray-500"> | |
| Showing <span id="showing-from">1</span> to <span id="showing-to">10</span> of <span id="total-items-count">0</span> items | |
| </div> | |
| <div class="flex space-x-2"> | |
| <button id="prev-page" class="px-3 py-1 border rounded-lg hover:bg-gray-100 disabled:opacity-50" disabled> | |
| <i class="fas fa-chevron-left"></i> | |
| </button> | |
| <button id="next-page" class="px-3 py-1 border rounded-lg hover:bg-gray-100 disabled:opacity-50" disabled> | |
| <i class="fas fa-chevron-right"></i> | |
| </button> | |
| </div> | |
| </div> | |
| <!-- PDF Preview (hidden by default) --> | |
| <div id="pdf-preview-container" class="mt-4 hidden"> | |
| <h3 class="text-lg font-semibold mb-2">PDF Preview</h3> | |
| <canvas id="pdf-preview" class="w-full"></canvas> | |
| <div class="mt-2 flex justify-end"> | |
| <button id="download-pdf" class="bg-primary-600 text-white px-3 py-1 rounded-lg hover:bg-primary-700"> | |
| <i class="fas fa-download mr-2"></i>Download PDF | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| </div> | |
| </div> | |
| <!-- Edit Item Modal --> | |
| <div id="edit-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50"> | |
| <div class="bg-white rounded-lg p-6 w-full max-w-md"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-xl font-bold">Edit Spare Part</h3> | |
| <button id="close-edit-modal" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <form id="edit-form"> | |
| <input type="hidden" id="edit-id"> | |
| <div class="space-y-4"> | |
| <div> | |
| <label for="edit-barcode" class="block text-sm font-medium text-gray-700 mb-1">Part Number</label> | |
| <input type="text" id="edit-barcode" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="edit-name" class="block text-sm font-medium text-gray-700 mb-1">Part Name</label> | |
| <input type="text" id="edit-name" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="edit-quantity" class="block text-sm font-medium text-gray-700 mb-1">Quantity</label> | |
| <input type="number" id="edit-quantity" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="edit-threshold" class="block text-sm font-medium text-gray-700 mb-1">Low Stock Threshold</label> | |
| <input type="number" id="edit-threshold" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| <div> | |
| <label for="edit-location" class="block text-sm font-medium text-gray-700 mb-1">Storage Location</label> | |
| <input type="text" id="edit-location" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500"> | |
| </div> | |
| </div> | |
| <div class="mt-6 flex justify-end space-x-3"> | |
| <button type="button" id="cancel-edit" class="px-4 py-2 border rounded-lg hover:bg-gray-100">Cancel</button> | |
| <button type="submit" class="bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700">Save Changes</button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| <!-- Notification Toast --> | |
| <div id="toast" class="fixed bottom-4 right-4 bg-primary-600 text-white px-4 py-2 rounded-lg shadow-lg hidden"> | |
| <div class="flex items-center"> | |
| <i class="fas fa-check-circle mr-2"></i> | |
| <span id="toast-message">Item saved successfully!</span> | |
| </div> | |
| </div> | |
| <script> | |
| // Initialize jsPDF | |
| const { jsPDF } = window.jspdf; | |
| // Sample inventory data with laboratory equipment spare parts | |
| let inventory = [ | |
| { id: 1, barcode: 'LAB-789001', name: 'Centrifuge Motor Assembly', category: 'centrifuge', model: 'CenTraX-2000, CenTraX-3000', price: 345.99, quantity: 4, threshold: 2, location: 'Shelf B2', description: 'Replacement motor for CenTraX series centrifuges' }, | |
| { id: 2, barcode: 'LAB-789002', name: 'Microscope Objective Lens 40x', category: 'microscope', model: 'MicrOptix XL, MicrOptix Pro', price: 129.50, quantity: 8, threshold: 3, location: 'Shelf A3, Bin 1', description: 'High resolution 40x objective lens' }, | |
| { id: 3, barcode: 'LAB-789003', name: 'Analyzer Pump Head', category: 'analyzer', model: 'AutoAnalyzer 5000', price: 275.00, quantity: 2, threshold: 2, location: 'Shelf C1', description: 'Replacement pump head for AA5000 analyzer' }, | |
| { id: 4, barcode: 'LAB-789004', name: 'Incubator Thermostat', category: 'incubator', model: 'ThermoGrow 360, ThermoGrow Pro', price: 89.99, quantity: 0, threshold: 1, location: 'Shelf A1', description: 'Digital thermostat control module' }, | |
| { id: 5, barcode: 'LAB-789005', name: 'Spectrophotometer Cuvette (10pk)', category: 'consumables', model: 'SpectraMax, PhotonMaster', price: 42.50, quantity: 12, threshold: 5, location: 'Shelf D4, Bin 2', description: '10-pack quartz cuvettes for UV-Vis measurements' }, | |
| { id: 6, barcode: 'LAB-789006', name: 'Centrifuge Rotor Adapter', category: 'centrifuge', model: 'CenTraX-3000', price: 65.00, quantity: 1, threshold: 2, location: 'Shelf B2', description: 'Adapter for 50mL tubes in CenTraX-3000' }, | |
| { id: 7, barcode: 'LAB-789007', name: 'Analyzer Tubing Set', category: 'analyzer', model: 'AutoAnalyzer 5000', price: 78.00, quantity: 3, threshold: 2, location: 'Shelf C1', description: 'Complete tubing replacement set for AA5000' }, | |
| ]; | |
| // DOM elements | |
| const inventoryTableBody = document.getElementById('inventory-table-body'); | |
| const inventoryForm = document.getElementById('inventory-form'); | |
| const barcodeInput = document.getElementById('barcode'); | |
| const nameInput = document.getElementById('name'); | |
| const quantityInput = document.getElementById('quantity'); | |
| const thresholdInput = document.getElementById('threshold'); | |
| const editForm = document.getElementById('edit-form'); | |
| const editModal = document.getElementById('edit-modal'); | |
| const closeEditModal = document.getElementById('close-edit-modal'); | |
| const cancelEdit = document.getElementById('cancel-edit'); | |
| const toast = document.getElementById('toast'); | |
| const exportPdfBtn = document.getElementById('export-pdf'); | |
| const pdfPreviewContainer = document.getElementById('pdf-preview-container'); | |
| const pdfPreview = document.getElementById('pdf-preview'); | |
| const downloadPdfBtn = document.getElementById('download-pdf'); | |
| const reportTypeSelect = document.getElementById('report-type'); | |
| const startScannerBtn = document.getElementById('start-scanner'); | |
| const scannerContainer = document.getElementById('scanner-container'); | |
| const scanResult = document.getElementById('scan-result'); | |
| const scannedCode = document.getElementById('scanned-code'); | |
| const manualBarcode = document.getElementById('manual-barcode'); | |
| const manualSubmit = document.getElementById('manual-submit'); | |
| const totalItemsCount = document.getElementById('total-items-count'); | |
| const showingFrom = document.getElementById('showing-from'); | |
| const showingTo = document.getElementById('showing-to'); | |
| const prevPageBtn = document.getElementById('prev-page'); | |
| const nextPageBtn = document.getElementById('next-page'); | |
| const totalItemsElement = document.getElementById('total-items'); | |
| const inStockElement = document.getElementById('in-stock'); | |
| const lowStockElement = document.getElementById('low-stock'); | |
| const outOfStockElement = document.getElementById('out-of-stock'); | |
| // Pagination variables | |
| let currentPage = 1; | |
| const itemsPerPage = 5; | |
| let filteredInventory = []; | |
| // Initialize the app | |
| function init() { | |
| renderInventoryTable(); | |
| updateStats(); | |
| setupEventListeners(); | |
| } | |
| // Set up event listeners | |
| function setupEventListeners() { | |
| // Form submission | |
| inventoryForm.addEventListener('submit', handleFormSubmit); | |
| // Edit modal | |
| closeEditModal.addEventListener('click', () => editModal.classList.add('hidden')); | |
| cancelEdit.addEventListener('click', () => editModal.classList.add('hidden')); | |
| editForm.addEventListener('submit', handleEditSubmit); | |
| // PDF Export | |
| exportPdfBtn.addEventListener('click', generatePdfPreview); | |
| downloadPdfBtn.addEventListener('click', downloadPdf); | |
| // Report type filter | |
| reportTypeSelect.addEventListener('change', () => { | |
| currentPage = 1; | |
| renderInventoryTable(); | |
| }); | |
| // Scanner | |
| startScannerBtn.addEventListener('click', startScanner); | |
| manualSubmit.addEventListener('click', handleManualBarcode); | |
| // Pagination | |
| prevPageBtn.addEventListener('click', goToPrevPage); | |
| nextPageBtn.addEventListener('click', goToNextPage); | |
| } | |
| // Render inventory table | |
| function renderInventoryTable() { | |
| // Clear table | |
| inventoryTableBody.innerHTML = ''; | |
| // Filter inventory based on report type | |
| const reportType = reportTypeSelect.value; | |
| filteredInventory = inventory.filter(item => { | |
| if (reportType === 'all') return true; | |
| if (reportType === 'low') return item.quantity > 0 && item.quantity < item.threshold; | |
| if (reportType === 'out') return item.quantity === 0; | |
| return item.category === reportType; | |
| }); | |
| // Update pagination info | |
| updatePaginationInfo(); | |
| // Get items for current page | |
| const paginatedItems = getPaginatedItems(); | |
| // Render items | |
| if (paginatedItems.length === 0) { | |
| inventoryTableBody.innerHTML = ` | |
| <tr> | |
| <td colspan="9" class="px-6 py-4 text-center text-gray-500">No items found</td> | |
| </tr> | |
| `; | |
| return; | |
| } | |
| paginatedItems.forEach(item => { | |
| const status = getStockStatus(item); | |
| const statusClass = status === 'In Stock' ? 'status-in-stock' : | |
| status === 'Low Stock' ? 'status-low-stock' : 'status-out-of-stock'; | |
| const tr = document.createElement('tr'); | |
| tr.className = item.quantity < item.threshold ? (item.quantity === 0 ? 'stock-out' : 'stock-low') : 'stock-ok'; | |
| tr.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap font-mono">${item.barcode}</td> | |
| <td class="px-6 py-4">${item.name}</td> | |
| <td class="px-6 py-4 whitespace-nowrap capitalize">${item.category}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${item.model || 'N/A'}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${item.price ? '$' + item.price.toFixed(2) : 'N/A'}</td> | |
| <td class="px-6 py-4 whitespace-nowrap">${item.quantity}</td> | |
| <td class="px-6 py-4 whitespace-nowrap"><span class="status-badge ${statusClass}">${status}</span></td> | |
| <td class="px-6 py-4 whitespace-nowrap">${item.location || 'N/A'}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"> | |
| <button class="text-primary-600 hover:text-primary-900 mr-2 edit-btn" data-id="${item.id}">Edit</button> | |
| <button class="text-red-600 hover:text-red-900 delete-btn" data-id="${item.id}">Delete</button> | |
| </td> | |
| `; | |
| inventoryTableBody.appendChild(tr); | |
| }); | |
| // Add event listeners to edit and delete buttons | |
| document.querySelectorAll('.edit-btn').forEach(btn => { | |
| btn.addEventListener('click', (e) => openEditModal(parseInt(e.target.dataset.id))); | |
| }); | |
| document.querySelectorAll('.delete-btn').forEach(btn => { | |
| btn.addEventListener('click', (e) => deleteItem(parseInt(e.target.dataset.id))); | |
| }); | |
| } | |
| // Handle form submission | |
| function handleFormSubmit(e) { | |
| e.preventDefault(); | |
| // Get form values | |
| const id = inventory.length > 0 ? Math.max(...inventory.map(item => item.id)) + 1 : 1; | |
| const formData = new FormData(inventoryForm); | |
| const newItem = { | |
| id, | |
| barcode: formData.get('barcode'), | |
| name: formData.get('name'), | |
| category: formData.get('category'), | |
| model: formData.get('model'), | |
| price: parseFloat(formData.get('price')) || 0, | |
| quantity: parseInt(formData.get('quantity')), | |
| threshold: parseInt(formData.get('threshold')), | |
| location: formData.get('location'), | |
| description: formData.get('description') | |
| }; | |
| // Check if item with same barcode exists | |
| const existingItemIndex = inventory.findIndex(item => item.barcode === newItem.barcode); | |
| if (existingItemIndex !== -1) { | |
| // Update existing item (quantity adjustment) | |
| inventory[existingItemIndex] = { | |
| ...inventory[existingItemIndex], | |
| quantity: inventory[existingItemIndex].quantity + newItem.quantity, | |
| name: newItem.name || inventory[existingItemIndex].name, | |
| category: newItem.category || inventory[existingItemIndex].category, | |
| model: newItem.model || inventory[existingItemIndex].model, | |
| price: newItem.price || inventory[existingItemIndex].price, | |
| threshold: newItem.threshold || inventory[existingItemIndex].threshold, | |
| location: newItem.location || inventory[existingItemIndex].location, | |
| description: newItem.description || inventory[existingItemIndex].description | |
| }; | |
| showToast('Item updated successfully!'); | |
| } else { | |
| // Add new item | |
| inventory.push(newItem); | |
| showToast('New item added successfully!'); | |
| } | |
| // Reset form | |
| inventoryForm.reset(); | |
| // Update UI | |
| renderInventoryTable(); | |
| updateStats(); | |
| } | |
| // Open edit modal | |
| function openEditModal(id) { | |
| const item = inventory.find(item => item.id === id); | |
| if (!item) return; | |
| // Fill form | |
| document.getElementById('edit-id').value = item.id; | |
| document.getElementById('edit-barcode').value = item.barcode; | |
| document.getElementById('edit-name').value = item.name; | |
| document.getElementById('edit-quantity').value = item.quantity; | |
| document.getElementById('edit-threshold').value = item.threshold; | |
| document.getElementById('edit-location').value = item.location || ''; | |
| // Show modal | |
| editModal.classList.remove('hidden'); | |
| } | |
| // Handle edit submission | |
| function handleEditSubmit(e) { | |
| e.preventDefault(); | |
| const id = parseInt(document.getElementById('edit-id').value); | |
| const itemIndex = inventory.findIndex(item => item.id === id); | |
| if (itemIndex !== -1) { | |
| // Update item | |
| inventory[itemIndex] = { | |
| ...inventory[itemIndex], | |
| barcode: document.getElementById('edit-barcode').value, | |
| name: document.getElementById('edit-name').value, | |
| quantity: parseInt(document.getElementById('edit-quantity').value), | |
| threshold: parseInt(document.getElementById('edit-threshold').value), | |
| location: document.getElementById('edit-location').value | |
| }; | |
| // Also update the barcode in the form if it was edited | |
| barcodeInput.value = document.getElementById('edit-barcode').value; | |
| showToast('Item updated successfully!'); | |
| editModal.classList.add('hidden'); | |
| renderInventoryTable(); | |
| updateStats(); | |
| } | |
| } | |
| // Delete item | |
| function deleteItem(id) { | |
| if (confirm('Are you sure you want to delete this item?')) { | |
| inventory = inventory.filter(item => item.id !== id); | |
| showToast('Item deleted successfully!'); | |
| renderInventoryTable(); | |
| updateStats(); | |
| } | |
| } | |
| // Show toast notification | |
| function showToast(message) { | |
| document.getElementById('toast-message').textContent = message; | |
| toast.classList.remove('hidden'); | |
| setTimeout(() => { | |
| toast.classList.add('hidden'); | |
| }, 3000); | |
| } | |
| // Update stats | |
| function updateStats() { | |
| totalItemsElement.textContent = inventory.length; | |
| const inStock = inventory.filter(item => item.quantity >= item.threshold).length; | |
| const lowStock = inventory.filter(item => item.quantity > 0 && item.quantity < item.threshold).length; | |
| const outOfStock = inventory.filter(item => item.quantity === 0).length; | |
| inStockElement.textContent = inStock; | |
| lowStockElement.textContent = lowStock; | |
| outOfStockElement.textContent = outOfStock; | |
| totalItemsCount.textContent = filteredInventory.length; | |
| } | |
| // Generate PDF preview | |
| function generatePdfPreview() { | |
| const reportType = reportTypeSelect.value; | |
| let filteredData = [...inventory]; | |
| let title = 'Complete Inventory Report'; | |
| if (reportType === 'low') { | |
| filteredData = inventory.filter(item => item.quantity > 0 && item.quantity < item.threshold); | |
| title = 'Low Stock Items Report'; | |
| } else if (reportType === 'out') { | |
| filteredData = inventory.filter(item => item.quantity === 0); | |
| title = 'Out of Stock Items Report'; | |
| } else if (reportType !== 'all') { | |
| filteredData = inventory.filter(item => item.category === reportType); | |
| title = `${reportType.charAt(0).toUpperCase() + reportType.slice(1)} Parts Report`; | |
| } | |
| // Create PDF | |
| const doc = new jsPDF(); | |
| // Add title | |
| doc.setFontSize(18); | |
| doc.setTextColor(239, 68, 68); // Red color from primary palette | |
| doc.text(title, 105, 15, null, null, 'center'); | |
| // Add report date | |
| doc.setFontSize(10); | |
| doc.setTextColor(100, 100, 100); | |
| doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 105, 22, null, null, 'center'); | |
| // Add logo | |
| doc.addImage('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEyIDBDNi40OCAwIDIgNC40OCAyIDEwczQuNDggMTAgMTAgMTAgMTAtNC40OCAxMC0xMFMxNy41MiAwIDEyIDB6bTAgMThjLTQuNDEgMC04LTMuNTktOC04IDAtLjYxLjA4LTEuMi4yMS0xLjc2TDUuOCAxMS40Yy4yMyAxLjkzIDEuMDQgMy40NyAyLjI5IDQuMzYtMS4xOS0uMzUtMi4wOS0xLjA0LTIuNS0yLjAyaDMuMDNjLjQ0IDEuNTYgMS42NyAyLjU3IDMuMjUgMi41NyAxLjEgMCAyLjA1LS40NyAyLjY4LTEuMjUuNjYuODUgMS42OCAxLjQgMi44NSAxLjQgMi4wMyAwIDMuNjYtMS44MSAzLjY2LTQuNDUgMC0uMDItLjAxLS4wMy0uMDEtLjA1aDMuMDFjLjAyLjMzLjAzLjY2LjAzIDEgMCA0LjQxLTMuNTkgOC04IDh6bTUuMjQtMTEuNzVjLS4zMS0xLjI1LTEuMy0yLjE5LTIuNTktMi4yNGguMDNjLTEuNDQgMC0yLjY0IDEuMDktMi44NSAyLjUyLS43Mi0xLjA5LTEuOTctMS44Ny0zLjU0LTEuODctMi4yOSAwLTQuMTcgMS44OC00LjE3IDQuMTcgMCAuNDYuMDcuOTEuMiAxLjM0LS42LS4yMy0xLjExLS43NS0xLjExLTEuMzkgMC0uNzcuNjctMS40MyAxLjUtMS40My44MyAwIDEuNS42NiAxLjUgMS41IDAgLjgtLjQ0IDEuNDgtMS4wOSAxLjg0LjE1LjQxLjM0Ljc5LjU4IDEuMTQgMS40MS0xLjQ2IDMuMDYtMi40MSA0Ljk3LTIuNzQuMDYuNjMuMzMgMS4yMS43NSAxLjY2LS41Mi4wOC0xLjA1LjMxLTEuNTEuNjktLjQ2LjM4LS43Ljg5LS43IDEuNDV2MS4zNmMuNzkuMzQgMS42Ni41NCAyLjU4LjU0IDIuODMgMCA1LjEyLTEuODIgNS4xMi00LjA5IDAtLjI0LS4wMy0uNDctLjA2LS43LjY3LS4yOCAxLjE3LS45MyAxLjE3LTEuNzEgMC0uNjYLS40NS0xLjIyLTEuMDYtMS40OXoiIGZpbGw9IiNGRjQ0NDQiLz48L3N2Zz4=', 'PNG', 15, 15, 10, 10); | |
| // Add table | |
| doc.autoTable({ | |
| startY: 30, | |
| head: [ | |
| ['Part #', 'Name', 'Category', 'Stock', 'Price', 'Location'] | |
| ], | |
| body: filteredData.map(item => [ | |
| item.barcode, | |
| item.name, | |
| item.category.charAt(0).toUpperCase() + item.category.slice(1), | |
| `${item.quantity} (${getStockStatus(item)})`, | |
| item.price ? '$' + item.price.toFixed(2) : 'N/A', | |
| item.location || 'N/A' | |
| ]), | |
| theme: 'grid', | |
| headStyles: { | |
| fillColor: [239, 68, 68], // Red color from primary palette | |
| textColor: 255, | |
| fontStyle: 'bold' | |
| }, | |
| alternateRowStyles: { | |
| fillColor: [250, 250, 250] | |
| }, | |
| margin: { top: 30 }, | |
| styles: { | |
| fontSize: 8, | |
| cellPadding: 3, | |
| overflow: 'linebreak' | |
| }, | |
| columnStyles: { | |
| 0: { cellWidth: 25 }, | |
| 1: { cellWidth: 45 }, | |
| 2: { cellWidth: 25 }, | |
| 3: { cellWidth: 20 }, | |
| 4: { cellWidth: 20 }, | |
| 5: { cellWidth: 25 } | |
| } | |
| }); | |
| // Generate preview | |
| const pdfData = doc.output('datauristring'); | |
| const pdfjsLib = window['pdfjs-dist/build/pdf']; | |
| pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.12.313/pdf.worker.min.js'; | |
| pdfjsLib.getDocument({ data: atob(pdfData.substring(28)) }).promise.then(function(pdf) { | |
| return pdf.getPage(1); | |
| }).then(function(page) { | |
| const viewport = page.getViewport({ scale: 1.5 }); | |
| const canvas = document.getElementById('pdf-preview'); | |
| const context = canvas.getContext('2d'); | |
| canvas.height = viewport.height; | |
| canvas.width = viewport.width; | |
| page.render({ | |
| canvasContext: context, | |
| viewport: viewport | |
| }); | |
| pdfPreviewContainer.classList.remove('hidden'); | |
| }); | |
| } | |
| // Download PDF | |
| function downloadPdf() { | |
| const doc = new jsPDF(); | |
| const reportType = reportTypeSelect.value; | |
| let filteredData = [...inventory]; | |
| let title = 'Complete Inventory Report'; | |
| if (reportType === 'low') { | |
| filteredData = inventory.filter(item => item.quantity > 0 && item.quantity < item.threshold); | |
| title = 'Low Stock Items Report'; | |
| } else if (reportType === 'out') { | |
| filteredData = inventory.filter(item => item.quantity === 0); | |
| title = 'Out of Stock Items Report'; | |
| } else if (reportType !== 'all') { | |
| filteredData = inventory.filter(item => item.category === reportType); | |
| title = `${reportType.charAt(0).toUpperCase() + reportType.slice(1)} Parts Report`; | |
| } | |
| // Add title | |
| doc.setFontSize(18); | |
| doc.setTextColor(239, 68, 68); | |
| doc.text(title, 105, 15, null, null, 'center'); | |
| // Add report date | |
| doc.setFontSize(10); | |
| doc.setTextColor(100, 100, 100); | |
| doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 105, 22, null, null, 'center'); | |
| // Add table | |
| doc.autoTable({ | |
| startY: 30, | |
| head: [ | |
| ['Part #', 'Name', 'Category', 'Stock', 'Price', 'Location'] | |
| ], | |
| body: filteredData.map(item => [ | |
| item.barcode, | |
| item.name, | |
| item.category.charAt(0).toUpperCase() + item.category.slice(1), | |
| `${item.quantity} (${getStockStatus(item)})`, | |
| item.price ? '$' + item.price.toFixed(2) : 'N/A', | |
| item.location || 'N/A' | |
| ]), | |
| theme: 'grid', | |
| headStyles: { | |
| fillColor: [239, 68, 68], | |
| textColor: 255, | |
| fontStyle: 'bold' | |
| }, | |
| alternateRowStyles: { | |
| fillColor: [250, 250, 250] | |
| }, | |
| margin: { top: 30 }, | |
| styles: { | |
| fontSize: 8, | |
| cellPadding: 3, | |
| overflow: 'linebreak' | |
| }, | |
| columnStyles: { | |
| 0: { cellWidth: 25 }, | |
| 1: { cellWidth: 45 }, | |
| 2: { cellWidth: 25 }, | |
| 3: { cellWidth: 20 }, | |
| 4: { cellWidth: 20 }, | |
| 5: { cellWidth: 25 } | |
| } | |
| }); | |
| // Save the PDF | |
| doc.save(`Barcopharma_Inventory_Report_${new Date().toISOString().slice(0, 10)}.pdf`); | |
| } | |
| // Start barcode scanner | |
| function startScanner() { | |
| scannerContainer.innerHTML = ''; | |
| const html5QrCode = new Html5Qrcode("scanner-container"); | |
| Html5Qrcode.getCameras().then(devices => { | |
| if (devices && devices.length) { | |
| // Start scanning with the first camera | |
| html5QrCode.start( | |
| devices[0].id, | |
| { | |
| fps: 10, | |
| qrbox: { width: 250, height: 250 } | |
| }, | |
| (decodedText, decodedResult) => { | |
| // Success callback | |
| handleScanResult(decodedText); | |
| html5QrCode.stop().then(() => { | |
| scanResult.classList.remove('hidden'); | |
| }).catch(err => { | |
| console.log("Error stopping scanner", err); | |
| }); | |
| }, | |
| (errorMessage) => { | |
| // Error callback | |
| // console.log(`Scan error: ${errorMessage}`); | |
| } | |
| ) | |
| .catch(err => { | |
| console.log("Error starting scanner", err); | |
| }); | |
| scannerContainer.innerHTML += '<button id="stop-scanner" class="mt-4 bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700">Stop Scanner</button>'; | |
| document.getElementById('stop-scanner').addEventListener('click', () => { | |
| html5QrCode.stop().then(() => { | |
| scannerContainer.innerHTML = ` | |
| <i class="fas fa-barcode text-4xl text-gray-400 mb-2"></i> | |
| <p class="text-gray-500 mb-4">Click to start scanning</p> | |
| <button id="start-scanner" class="bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700"> | |
| <i class="fas fa-camera mr-2"></i> Start Scanner | |
| </button> | |
| `; | |
| document.getElementById('start-scanner').addEventListener('click', startScanner); | |
| }).catch(err => { | |
| console.log("Error stopping scanner", err); | |
| }); | |
| }); | |
| } else { | |
| scannerContainer.innerHTML = ` | |
| <p class="text-red-500 mb-2">No camera devices found</p> | |
| <button id="try-again" class="bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700"> | |
| Try Again | |
| </button> | |
| `; | |
| document.getElementById('try-again').addEventListener('click', startScanner); | |
| } | |
| }); | |
| } | |
| // Handle scan result | |
| function handleScanResult(barcode) { | |
| scannedCode.textContent = barcode; | |
| scanResult.classList.remove('hidden'); | |
| // Auto-fill the form with the scanned barcode | |
| barcodeInput.value = barcode; | |
| // Check if this item exists in inventory | |
| const existingItem = inventory.find(item => item.barcode === barcode); | |
| if (existingItem) { | |
| nameInput.value = existingItem.name; | |
| categoryInput.value = existingItem.category; | |
| // Focus on quantity for easy restocking | |
| quantityInput.focus(); | |
| } else { | |
| // Focus on name for new item entry | |
| nameInput.focus(); | |
| } | |
| } | |
| // Handle manual barcode entry | |
| function handleManualBarcode() { | |
| const barcode = manualBarcode.value.trim(); | |
| if (barcode) { | |
| handleScanResult(barcode); | |
| manualBarcode.value = ''; | |
| } | |
| } | |
| // Get stock status | |
| function getStockStatus(item) { | |
| if (item.quantity === 0) return 'Out of Stock'; | |
| if (item.quantity < item.threshold) return 'Low Stock'; | |
| return 'In Stock'; | |
| } | |
| // Pagination functions | |
| function getPaginatedItems() { | |
| const startIndex = (currentPage - 1) * itemsPerPage; | |
| const endIndex = startIndex + itemsPerPage; | |
| return filteredInventory.slice(startIndex, endIndex); | |
| } | |
| function updatePaginationInfo() { | |
| const totalPages = Math.ceil(filteredInventory.length / itemsPerPage); | |
| showingFrom.textContent = (currentPage - 1) * itemsPerPage + 1; | |
| showingTo.textContent = Math.min(currentPage * itemsPerPage, filteredInventory.length); | |
| prevPageBtn.disabled = currentPage === 1; | |
| nextPageBtn.disabled = currentPage === totalPages || totalPages === 0; | |
| } | |
| function goToPrevPage() { | |
| if (currentPage > 1) { | |
| currentPage--; | |
| renderInventoryTable(); | |
| } | |
| } | |
| function goToNextPage() { | |
| if (currentPage * itemsPerPage < filteredInventory.length) { | |
| currentPage++; | |
| renderInventoryTable(); | |
| } | |
| } | |
| // Initialize the app when DOM is loaded | |
| document.addEventListener('DOMContentLoaded', init); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - <a href="https://enzostvs-deepsite.hf.space?remix=BMEMohammed/myspace" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body> | |
| </html> |